This module contains basic helper utilities such as optimized compression of arbitrary data objects `save` and `load`, code timing `timer`, and fine-level plotting control `figParams`, as well as nbdev project tools (used to create this website, found at https://nbdev.fast.ai/).
C:\Anaconda3\lib\site-packages\numpy\_distributor_init.py:32: UserWarning: loaded more than 1 DLL from .libs:
C:\Anaconda3\lib\site-packages\numpy\.libs\libopenblas.NOIJJG62EMASZI6NYURL6JBKM4EVBGM7.gfortran-win_amd64.dll
C:\Anaconda3\lib\site-packages\numpy\.libs\libopenblas.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll
  stacklevel=1)

timer[source]

timer(func:callable)

Decorator that reports the execution time and optionally returns the time difference by adding a return_time Boolean keyword argument to the function being wrapped.

@timer
def say_hi():
    '''
    Example function for `timer`.
    Will show the correct docs thanks to `wraps`.
    '''
    print('hi')
say_hi()
hi
say_hi : Elapsed time: 0.0000 seconds
say_hi(return_time=True)
hi
say_hi : Elapsed time: 0.0005 seconds
0.0004961490631103516

filesize[source]

filesize(fname:str='data.gz', exp:int=1e-06)

Returns filesize in bytes*exp, which defaults to megabytes.

filesize('setup.py')
'setup.py is 0.003158 megabytes'

save[source]

save(data, fname='data.gz')

Saves data as fname using gzip and pickle. Maximizes speed and compression of objects.

a=[0]
save(a,fname='data.gz')
data.gz is 3.7e-05 megabytes

load[source]

load(fname='data.gz', delete=False)

Loads fname, returning pickled data.

load(fname='data.gz',delete=True)
[0]

push[source]

push(branch='master', comment='auto')

Pushes all current files to given branch with comment.

refresh[source]

refresh(comment='auto', branch='master')

Builds nbdev library and docs.

backup[source]

backup(comment='Backup')

Like Push but with branch set to backup.

fig_params[source]

fig_params(reset:bool=False, X:float=3.5, Y:float=3, hspace:float=0.0, offset:float=-0.4, font:str='Times New Roman', fontsize:int=12, ticksize:int=6, tickwidth:int=2, linewidth:int=2)

Changes the rcParams for plotting, with the option to reset to default.

force_aspect[source]

force_aspect(ax:matplotlib.axes, aspect:int=1)

Forces the aspect of the axes object ax.

matshow[source]

matshow(x:ndarray, aspect:int=1, save:bool=True, fname:str='test')

Simplified image plot of matrix x with forced aspect that can save fname to path.

class RNG[source]

RNG(seed:Optional[int]=None, update=False)

Globally stable random number generator. Initialized with fixed seed. Contains normal, random, and multimodal methods, each with an absval and asint argument, which convert to positive values and round to integers respectively.

rng=RNG(seed=0,update=True)
random(0,1)
0.6369616873214543
normal([0,1],[1,2],shape=(10,2))
array([[-0.13210486,  2.2808453 ],
       [ 0.10490012, -0.07133875],
       [ 0.36159505,  3.60800009],
       [ 0.94708096, -0.40747047],
       [-1.26542147, -0.24654893],
       [ 0.04132598, -3.65006155],
       [-0.21879166, -1.49182189],
       [-0.73226735, -0.08851797],
       [-0.31630016,  1.82326107],
       [ 1.04251337,  0.74293067]])
print(random(x=0,y=1,shape=(1,2)))
print(normal(x=[0,10],y=[1,1],shape=None))
print(choice(['a','b','c'],1))
[[0.12428328 0.67062441]]
[ 0.35151007 10.90347018]
['c']