CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
y33-j3T

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: y33-j3T/Coursera-Deep-Learning
Path: blob/master/Convolutional Neural Networks/dummy/__pycache__/cache.cpython-35.pyc
Views: 13377


��Y��	@s�ddlZddlZddlZdd�Zdd�Zedkr�dd�Zed	�ed
dded
ddd�Z	ede	�e�Gdd�d�Z
ed�ed
dde
dddd�Zej�dS)�Nc
Os�tjj|�rNt|dd��}tj|�}WdQRXtd|�nI|||�}t|dd��}tj||�WdQRXtd|�|S)a�
    Cache-wrapper for a function or class. If the cache-file exists
    then the data is reloaded and returned, otherwise the function
    is called and the result is saved to cache. The fn-argument can
    also be a class instead, in which case an object-instance is
    created and saved to the cache-file.
    :param cache_path:
        File-path for the cache-file.
    :param fn:
        Function or class to be called.
    :param args:
        Arguments to the function or class-init.
    :param kwargs:
        Keyword arguments to the function or class-init.
    :return:
        The result of calling the function or creating the object-instance.
    �mode�rbNz- Data loaded from cache-file: �wbz- Data saved to cache-file: )�os�path�exists�open�pickle�load�print�dump)�
cache_path�fn�args�kwargs�file�obj�r�/output/cache.py�cachesrc
Cs?tj|�}t|dd��}tj||�WdQRXdS)a�
    Convert a numpy-file to pickle-file.
    The first version of the cache-function used numpy for saving the data.
    Instead of re-calculating all the data, you can just convert the
    cache-file using this function.
    :param in_path:
        Input file in numpy-format written using numpy.save().
    :param out_path:
        Output file written as a pickle-file.
    :return:
        Nothing.
    rrN)�npr
rr	r)�in_pathZout_path�datarrrr�convert_numpy2pickleJsr�__main__cCs||S)Nr)�a�brrr�expensive_functionisrz"Computing expensive_function() ...r
zcache_expensive_function.pklrr�{ri�zresult =c@s(eZdZdd�Zdd�ZdS)�ExpensiveClasscCs#||_||_|||_dS)N)�c�d�result)�selfr r!rrr�__init__s		zExpensiveClass.__init__cCs4td|j�td|j�td|j�dS)Nzc =zd =zresult = c * d =)rr r!r")r#rrr�print_result�szExpensiveClass.print_resultN)�__name__�
__module__�__qualname__r$r%rrrrr~srz)Creating object from ExpensiveClass() ...zcache_ExpensiveClass.pklr r!)
rr	�numpyrrrr&rrr"rrr%rrrr�<module>s ,