Skip to content

Instantly share code, notes, and snippets.

View karanpathak's full-sized avatar

Karan Pathak karanpathak

View GitHub Profile
# Define our function
def func(x):
print("Example of Computationally intensive function!")
print("The result is not cached for this particular input")
sleep(4.0)
return np.square(x)
# Pass it to Memory.cache method
func_mem = mem.cache(func, verbose=0)
# Create a new cache directory
cache_dir2 = "<path-to-your-directory>/sample_cache_dir2"
memory2 = Memory(cache_dir2, mmap_mode='c')
# Pass function to Memory.cache
@memory2.cache(verbose=0)
def func_memmap(x):
print("Example of Computationally intensive function!")
print("The result is not cached for this particular input")
@mem.cache(verbose=0)
def func_as_decorator(x):
print("Example of Computationally intensive function!")
print("The result is not cached for this particular input")
sleep(4.0)
return np.square(x)
input1 = np.vander(np.arange(10**4)).astype(np.float)
input2 = np.vander(np.random.uniform(low=0,high=10**5, size=5000))
print("Shape of input1: ",input1.shape)
print("Shape of input2: ",input2.shape)
# Import the Memory class from joblib
from joblib import Memory
# Create your cache directory
cache_dir="<path-to-your-directory>/sample_cache_dir"
# Create a memory object
mem = Memory(cache_dir)
# install dependencies
sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get install -y cmake
sudo apt-get install -y libgtk2.0-dev
sudo apt-get install -y pkg-config
sudo apt-get install -y python-numpy python-dev
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y libjpeg-dev libpng-dev libtiff-dev libjasper-dev