Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Convolutional Neural Networks/dummy/__pycache__/cache.cpython-35.pyc
Views: 13377
��Y� � @ s� d d l Z d d l Z d d l Z d d � Z d d � Z e d k r� d d � Z e d � e d d d e d d d d � Z e d e � e � Gd d � d � Z e d � e d d d e d d d d � Z e j � d S)� Nc O s� t j j | � rN t | d d �� } t j | � } Wd QRXt d | � nI | | | � } t | d d �� } t j | | � Wd QRXt d | � | 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�cache s r c C s? t j | � } t | d d �� } t j | | � Wd QRXd S)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. r r N)�npr r r r )�in_pathZout_path�datar r r r �convert_numpy2pickleJ s r �__main__c C s | | S)Nr )�a�br r r �expensive_functioni s r z"Computing expensive_function() ...r zcache_expensive_function.pklr r �{ r i� zresult =c @ s( e Z d Z d d � Z d d � Z d S)�ExpensiveClassc C s# | | _ | | _ | | | _ d S)N)�c�d�result)�selfr r! r r r �__init__ s zExpensiveClass.__init__c C s4 t d | j � t d | j � t d | j � d S)Nzc =zd =zresult = c * d =)r r r! r"