Source code for qualia2

# -*- coding: utf-8 -*- 
import gzip
from .core import * 
from .autograd import *
from .functions import * 
from .util import *
from .util import _mul
from .nn import * 
from .data import *
from .vision import *
#from .rl import *

pi = np.pi
e = np.e

[docs]def save(state_dict, filename, protocol=-1): '''Saves parameters to qla format.\n Args: state_dict (dict): state dict to save filename (str): specify the filename as well as the saving path without the file extension. (ex) path/to/filename protocol (int): pickle protocol ''' with gzip.open(filename+'.qla', 'wb') as f: pickle.dump(state_dict, f, protocol)
[docs]def load(filename): '''Loads parameters saved in qla format.\n Args: filename (str): specify the filename as well as the path to the file without the file extension. (ex) path/to/filename ''' with gzip.open(filename+'.qla', 'rb') as f: return pickle.load(f)
[docs]def seed(seed=None): np.random.seed(seed)
[docs]def copy(tensor): return Tensor(np.copy(tensor.data), tensor.requires_grad, tensor.dtype)
[docs]def numel(obj): return _mul(*obj.shape)
[docs]def array(obj, dtype='float64'): return Tensor(obj, dtype=dtype)
[docs]def arange(*args, dtype='float64'): return Tensor(np.arange(*args), dtype=dtype)
[docs]def empty(shape, dtype='float64'): return Tensor(np.empty(shape), dtype=dtype)
[docs]def empty_like(obj, dtype='float64'): return Tensor(np.empty(obj.shape), dtype=dtype)
[docs]def zeros(shape, dtype='int64'): return Tensor(np.zeros(shape), dtype=dtype)
[docs]def zeros_like(obj, dtype='int64'): return Tensor(np.zeros(obj.shape), dtype=dtype)
[docs]def ones(shape, dtype='int64'): return Tensor(np.ones(shape), dtype=dtype)
[docs]def ones_like(obj, dtype='int64'): return Tensor(np.ones(obj.shape), dtype=dtype)
[docs]def rand(*args, dtype='float64'): return Tensor(np.random.rand(*args), dtype=dtype)
[docs]def rand_like(obj, dtype='float64'): return Tensor(np.random.rand(*obj.shape), dtype=dtype)
[docs]def randn(*args, dtype='float64'): return Tensor(np.random.randn(*args), dtype=dtype)
[docs]def randn_like(obj, dtype='float64'): return Tensor(np.random.randn(*obj.shape), dtype=dtype)
[docs]def uniform(low=0.0, high=1.0, shape=None, dtype='float64'): return Tensor(np.random.uniform(low, high, shape), dtype=dtype)
[docs]def uniform_like(obj, low=0.0, high=1.0, dtype='float64'): return Tensor(np.random.uniform(low, high, *obj.shape), dtype=dtype)
[docs]def normal(mean=0, std=1, shape=None, dtype='float64'): return Tensor(np.random.normal(mean, std, shape), dtype=dtype)
[docs]def normal_like(obj, mean=0, std=1, dtype='float64'): return Tensor(np.random.normal(mean, std, *obj.shape), dtype=dtype)
[docs]def randint(low, high=None, shape=None, dtype='float64'): return Tensor(np.random.randint(low, high, shape), dtype=dtype)
[docs]def randint_like(obj, low, high=None, dtype='float64'): return Tensor(np.random.randint(low, high, *obj.shape), dtype=dtype)
[docs]def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype='float64'): return Tensor(np.linspace(start, stop, num, endpoint, retstep), dtype=dtype)