chumpy
Advanced tools
+12
-12
@@ -1,10 +0,10 @@ | ||
| from ch import * | ||
| from logic import * | ||
| from .ch import * | ||
| from .logic import * | ||
| from optimization import minimize | ||
| import extras | ||
| import testing | ||
| from version import version as __version__ | ||
| from .optimization import minimize | ||
| from . import extras | ||
| from . import testing | ||
| from .version import version as __version__ | ||
| from version import version as __version__ | ||
| from .version import version as __version__ | ||
@@ -110,10 +110,10 @@ from numpy import bool, int, float, complex, object, unicode, str, nan, inf | ||
| if which not in demos: | ||
| print 'Please indicate which demo you want, as follows:' | ||
| print('Please indicate which demo you want, as follows:') | ||
| for key in demos: | ||
| print "\tdemo('%s')" % (key,) | ||
| print("\tdemo('%s')" % (key,)) | ||
| return | ||
| print '- - - - - - - - - - - <CODE> - - - - - - - - - - - -' | ||
| print demos[which] | ||
| print '- - - - - - - - - - - </CODE> - - - - - - - - - - - -\n' | ||
| print('- - - - - - - - - - - <CODE> - - - - - - - - - - - -') | ||
| print(demos[which]) | ||
| print('- - - - - - - - - - - </CODE> - - - - - - - - - - - -\n') | ||
| exec('global np\n' + demos[which], globals(), locals()) |
@@ -8,9 +8,9 @@ """ | ||
| import ch | ||
| from . import ch | ||
| import numpy as np | ||
| from os.path import join, split | ||
| from StringIO import StringIO | ||
| from six import StringIO | ||
| import numpy | ||
| import chumpy | ||
| import cPickle as pickle | ||
| from six.moves import cPickle as pickle | ||
@@ -75,3 +75,3 @@ src = '' | ||
| if isinstance(args_req, dict): | ||
| fn(**dict(args_req.items() + args_opt.items())) | ||
| fn(**dict(list(args_req.items()) + list(args_opt.items()))) | ||
| else: | ||
@@ -113,3 +113,3 @@ fn(*args_req, **args_opt) | ||
| print '%s: %s, %s' % (a,b,c) | ||
| print('%s: %s, %s' % (a,b,c)) | ||
| make_row(a, b, c, b_color, c_color) | ||
@@ -530,3 +530,3 @@ | ||
| print 'passed %d, not passed %d' % (num_passed, num_not_passed) | ||
| print('passed %d, not passed %d' % (num_passed, num_not_passed)) | ||
@@ -538,2 +538,2 @@ | ||
| main() | ||
| print ' '.join(which_passed) | ||
| print(' '.join(which_passed)) |
+26
-24
@@ -47,9 +47,11 @@ #!/usr/bin/env python | ||
| import ch | ||
| from .ch import Ch | ||
| import six | ||
| import numpy as np | ||
| import warnings | ||
| import cPickle as pickle | ||
| from six.moves import cPickle as pickle | ||
| import scipy.sparse as sp | ||
| from utils import row, col | ||
| from .utils import row, col | ||
| from copy import copy as copy_copy | ||
| from functools import reduce | ||
@@ -70,3 +72,3 @@ __all__ += ['pi', 'set_printoptions'] | ||
| for rtn in numpy_array_creation_routines: | ||
| exec('def %s(*args, **kwargs) : return ch.Ch(np.%s(*args, **kwargs))' % (rtn, rtn)) | ||
| exec('def %s(*args, **kwargs) : return Ch(np.%s(*args, **kwargs))' % (rtn, rtn)) | ||
@@ -88,3 +90,3 @@ | ||
| return a | ||
| return ch.Ch(np.asarray(a, dtype, order)) | ||
| return Ch(np.asarray(a, dtype, order)) | ||
@@ -103,3 +105,3 @@ # Everythign is always c-contiguous | ||
| class Simpleton(ch.Ch): | ||
| class Simpleton(Ch): | ||
| dterms = 'x' | ||
@@ -118,3 +120,3 @@ def compute_dr_wrt(self, wrt): | ||
| class Cross(ch.Ch): | ||
| class Cross(Ch): | ||
| dterms = 'a', 'b' | ||
@@ -191,3 +193,3 @@ terms = 'axisa', 'axisb', 'axisc', 'axis' | ||
| class cumsum(ch.Ch): | ||
| class cumsum(Ch): | ||
| dterms = 'a' | ||
@@ -223,3 +225,3 @@ terms = 'axis' | ||
| class UnaryElemwise(ch.Ch): | ||
| class UnaryElemwise(Ch): | ||
| dterms = 'x' | ||
@@ -299,3 +301,3 @@ | ||
| class clip(ch.Ch): | ||
| class clip(Ch): | ||
| dterms = 'a' | ||
@@ -313,3 +315,3 @@ terms = 'a_min', 'a_max' | ||
| class sum(ch.Ch): | ||
| class sum(Ch): | ||
| dterms = 'x', | ||
@@ -348,3 +350,3 @@ terms = 'axis', | ||
| class mean(ch.Ch): | ||
| class mean(Ch): | ||
| dterms = 'x', | ||
@@ -394,3 +396,3 @@ terms = 'axis', | ||
| class SumOfSquares(ch.Ch): | ||
| class SumOfSquares(Ch): | ||
| dterms = 'x', | ||
@@ -406,3 +408,3 @@ | ||
| class divide (ch.Ch): | ||
| class divide (Ch): | ||
| dterms = 'x1', 'x2' | ||
@@ -556,3 +558,3 @@ | ||
| class add(ch.Ch): | ||
| class add(Ch): | ||
| dterms = 'a', 'b' | ||
@@ -573,3 +575,3 @@ | ||
| class subtract(ch.Ch): | ||
| class subtract(Ch): | ||
| dterms = 'a', 'b' | ||
@@ -591,3 +593,3 @@ | ||
| class power (ch.Ch): | ||
| class power (Ch): | ||
| """Given vector \f$x\f$, computes \f$x^2\f$ and \f$\frac{dx^2}{x}\f$""" | ||
@@ -626,3 +628,3 @@ dterms = 'x', 'pow' | ||
| class A_extremum(ch.Ch): | ||
| class A_extremum(Ch): | ||
| """Superclass for various min and max subclasses""" | ||
@@ -664,4 +666,4 @@ dterms = 'a' | ||
| mn = np.amin(idxs, axis=axis) | ||
| stride = np.array(mtx.strides) | ||
| stride /= np.min(stride) # go from bytes to num elements | ||
| mtx_strides = np.array(mtx.strides) | ||
| stride = mtx_strides / np.min(mtx_strides) # go from bytes to num elements | ||
| stride = stride[axis] | ||
@@ -692,3 +694,3 @@ return mn, stride | ||
| class Extremum(ch.Ch): | ||
| class Extremum(Ch): | ||
| dterms = 'a','b' | ||
@@ -720,3 +722,3 @@ | ||
| class multiply(ch.Ch): | ||
| class multiply(Ch): | ||
| dterms = 'a', 'b' | ||
@@ -744,3 +746,3 @@ | ||
| class dot(ch.Ch): | ||
| class dot(Ch): | ||
| dterms = 'a', 'b' | ||
@@ -784,3 +786,3 @@ | ||
| class BinaryElemwiseNoDrv(ch.Ch): | ||
| class BinaryElemwiseNoDrv(Ch): | ||
| dterms = 'x1', 'x2' | ||
@@ -787,0 +789,0 @@ |
@@ -8,3 +8,3 @@ """ | ||
| import numpy.random | ||
| from ch import Ch | ||
| from .ch import Ch | ||
@@ -11,0 +11,0 @@ api_not_implemented = ['choice','bytes','shuffle','permutation'] |
+69
-67
@@ -21,9 +21,9 @@ #!/usr/bin/env python | ||
| from scipy.sparse.linalg.interface import LinearOperator | ||
| import utils | ||
| from utils import row, col | ||
| from .utils import row, col, timer, convert_inputs_to_sparse_if_necessary | ||
| import collections | ||
| from copy import deepcopy | ||
| from utils import timer | ||
| from functools import reduce | ||
| # Turn this on if you want the profiler injected | ||
@@ -106,3 +106,3 @@ DEBUG = False | ||
| for name, default_val in cls._default_kwargs.items(): | ||
| for name, default_val in list(cls._default_kwargs.items()): | ||
| object.__setattr__(result, '_%s' % name, kwargs.get(name, default_val)) | ||
@@ -195,6 +195,6 @@ if name in kwargs: | ||
| def reshape(self, *args): | ||
| return reordering.reshape(a=self, newshape=args if len(args)>1 else args[0]) | ||
| return reshape(a=self, newshape=args if len(args)>1 else args[0]) | ||
| def ravel(self): | ||
| return reordering.reshape(a=self, newshape=(-1)) | ||
| return reshape(a=self, newshape=(-1)) | ||
@@ -299,3 +299,3 @@ def __hash__(self): | ||
| inner = wrt | ||
| while issubclass(inner.__class__, reordering.Permute): | ||
| while issubclass(inner.__class__, Permute): | ||
| inner = inner.a | ||
@@ -332,3 +332,3 @@ if inner is self: | ||
| def minimize(self, *args, **kwargs): | ||
| import optimization | ||
| from . import optimization | ||
| return optimization.minimize(self, *args, **kwargs) | ||
@@ -347,3 +347,3 @@ | ||
| def copy(self): | ||
| return ch_ops.copy(self) | ||
| return copy(self) | ||
@@ -417,3 +417,3 @@ def __getstate__(self): | ||
| nameset = set(names) | ||
| for func_name, v in self._depends_on_deps.items(): | ||
| for func_name, v in list(self._depends_on_deps.items()): | ||
| if len(nameset.intersection(v['deps'])) > 0: | ||
@@ -437,3 +437,3 @@ v['out_of_date'] = True | ||
| for parent, parent_dict in next._parents.items(): | ||
| for parent, parent_dict in list(next._parents.items()): | ||
| object.__setattr__(parent, '_dirty_vars', parent._dirty_vars.union(parent_dict['varnames'])) | ||
@@ -447,3 +447,3 @@ parent._invalidate_cacheprop_names(parent_dict['varnames']) | ||
| def clear_cache_wrt(self, wrt, itr=None): | ||
| if self._cache['drs'].has_key(wrt): | ||
| if wrt in self._cache['drs']: | ||
| self._cache['drs'][wrt] = None | ||
@@ -455,3 +455,3 @@ | ||
| if itr is None or itr != self._itr: | ||
| for parent, parent_dict in self._parents.items(): | ||
| for parent, parent_dict in list(self._parents.items()): | ||
| if wrt in parent._cache['drs'] or (hasattr(parent, 'dr_cached') and wrt in parent.dr_cached): | ||
@@ -514,3 +514,3 @@ parent.clear_cache_wrt(wrt=wrt, itr=itr) | ||
| newshape = tmp.shape | ||
| return reordering.Select(a=self, idxs=idxs, preferred_shape=newshape) | ||
| return Select(a=self, idxs=idxs, preferred_shape=newshape) | ||
@@ -540,3 +540,3 @@ def __setitem__(self, key, value, itr=None): | ||
| while not inner.is_ch_baseclass(): | ||
| if issubclass(inner.__class__, reordering.Permute): | ||
| if issubclass(inner.__class__, Permute): | ||
| inner = inner.a | ||
@@ -578,15 +578,15 @@ else: | ||
| def T(self): | ||
| return reordering.transpose(self) | ||
| return transpose(self) | ||
| def transpose(self, *axes): | ||
| return reordering.transpose(self, *axes) | ||
| return transpose(self, *axes) | ||
| def squeeze(self, axis=None): | ||
| return ch_ops.squeeze(self, axis) | ||
| return squeeze(self, axis) | ||
| def mean(self, axis=None): | ||
| return ch_ops.mean(self, axis=axis) | ||
| return mean(self, axis=axis) | ||
| def sum(self, axis=None): | ||
| return ch_ops.sum(self, axis=axis) | ||
| return sum(self, axis=axis) | ||
@@ -645,3 +645,3 @@ def _call_on_changed(self): | ||
| tm_maybe_sparse = timer() | ||
| lhs, rhs = utils.convert_inputs_to_sparse_if_necessary(lhs, rhs) | ||
| lhs, rhs = convert_inputs_to_sparse_if_necessary(lhs, rhs) | ||
| if tm_maybe_sparse() > 0.1: | ||
@@ -679,3 +679,3 @@ pif('convert_inputs_to_sparse_if_necessary in {}sec'.format(tm_maybe_sparse())) | ||
| if not isinstance(p, Ch): | ||
| print 'BROKEN!' | ||
| print('BROKEN!') | ||
| raise Exception('Broken Should be Ch object') | ||
@@ -835,3 +835,3 @@ | ||
| # on average. | ||
| if len(self._parents.keys()) != 1: | ||
| if len(list(self._parents.keys())) != 1: | ||
| self._cache['drs'][wrt] = result | ||
@@ -912,5 +912,5 @@ | ||
| color = 'blue' | ||
| if isinstance(dtval, reordering.Concatenate) and len(dtval.dr_cached) > 0: | ||
| if isinstance(dtval, Concatenate) and len(dtval.dr_cached) > 0: | ||
| s = 'dr_cached\n' | ||
| for k, v in dtval.dr_cached.iteritems(): | ||
| for k, v in dtval.dr_cached.items(): | ||
| if v is not None: | ||
@@ -933,3 +933,3 @@ issparse = sp.issparse(v) | ||
| for k, v in dtval._cache['drs'].iteritems(): | ||
| for k, v in dtval._cache['drs'].items(): | ||
| if v is not None: | ||
@@ -1050,4 +1050,4 @@ issparse = sp.issparse(v) | ||
| if cachelim != np.inf and hasattr(self, '_cache') and 'drs' in self._cache: | ||
| import cPickle as pickle | ||
| for dtval, jac in self._cache['drs'].items(): | ||
| from six.moves import cPickle as pickle | ||
| for dtval, jac in list(self._cache['drs'].items()): | ||
| # child_label = getattr(dtval, 'label') if hasattr(dtval, 'label') else dterm | ||
@@ -1132,18 +1132,18 @@ # child_label = '%s (%s)' % (child_label, str(dtval.__class__.__name__)) | ||
| def floor(self): | ||
| return ch_ops.floor(self) | ||
| return floor(self) | ||
| def ceil(self): | ||
| return ch_ops.ceil(self) | ||
| return ceil(self) | ||
| def dot(self, other): | ||
| return ch_ops.dot(self, other) | ||
| return dot(self, other) | ||
| def cumsum(self, axis=None): | ||
| return ch_ops.cumsum(a=self, axis=axis) | ||
| return cumsum(a=self, axis=axis) | ||
| def min(self, axis=None): | ||
| return ch_ops.amin(a=self, axis=axis) | ||
| return amin(a=self, axis=axis) | ||
| def max(self, axis=None): | ||
| return ch_ops.amax(a=self, axis=axis) | ||
| return amax(a=self, axis=axis) | ||
@@ -1154,33 +1154,34 @@ ######################################################## | ||
| def __pos__(self): return self | ||
| def __neg__(self): return ch_ops.negative(self) | ||
| def __neg__(self): return negative(self) | ||
| def __add__ (self, other): return ch_ops.add(a=self, b=other) | ||
| def __radd__(self, other): return ch_ops.add(a=other, b=self) | ||
| def __add__ (self, other): return add(a=self, b=other) | ||
| def __radd__(self, other): return add(a=other, b=self) | ||
| def __sub__ (self, other): return ch_ops.subtract(a=self, b=other) | ||
| def __rsub__(self, other): return ch_ops.subtract(a=other, b=self) | ||
| def __sub__ (self, other): return subtract(a=self, b=other) | ||
| def __rsub__(self, other): return subtract(a=other, b=self) | ||
| def __mul__ (self, other): return ch_ops.multiply(a=self, b=other) | ||
| def __rmul__(self, other): return ch_ops.multiply(a=other, b=self) | ||
| def __mul__ (self, other): return multiply(a=self, b=other) | ||
| def __rmul__(self, other): return multiply(a=other, b=self) | ||
| def __div__ (self, other): return ch_ops.divide(x1=self, x2=other) | ||
| def __rdiv__(self, other): return ch_ops.divide(x1=other, x2=self) | ||
| def __div__ (self, other): return divide(x1=self, x2=other) | ||
| def __truediv__ (self, other): return divide(x1=self, x2=other) | ||
| def __rdiv__(self, other): return divide(x1=other, x2=self) | ||
| def __pow__ (self, other): return ch_ops.power(x=self, pow=other) | ||
| def __rpow__(self, other): return ch_ops.power(x=other, pow=self) | ||
| def __pow__ (self, other): return power(x=self, pow=other) | ||
| def __rpow__(self, other): return power(x=other, pow=self) | ||
| def __rand__(self, other): return self.__and__(other) | ||
| def __abs__ (self): return ch_ops.abs(self) | ||
| def __abs__ (self): return abs(self) | ||
| def __gt__(self, other): return ch_ops.greater(self, other) | ||
| def __ge__(self, other): return ch_ops.greater_equal(self, other) | ||
| def __gt__(self, other): return greater(self, other) | ||
| def __ge__(self, other): return greater_equal(self, other) | ||
| def __lt__(self, other): return ch_ops.less(self, other) | ||
| def __le__(self, other): return ch_ops.less_equal(self, other) | ||
| def __lt__(self, other): return less(self, other) | ||
| def __le__(self, other): return less_equal(self, other) | ||
| def __ne__(self, other): return ch_ops.not_equal(self, other) | ||
| def __ne__(self, other): return not_equal(self, other) | ||
| # not added yet because of weak key dict conflicts | ||
| #def __eq__(self, other): return ch_ops.equal(self, other) | ||
| #def __eq__(self, other): return equal(self, other) | ||
@@ -1227,3 +1228,3 @@ | ||
| def with_caching(self, *args, **kwargs): | ||
| func_name = func.func_name | ||
| func_name = func.__name__ | ||
| sdf = self._depends_on_deps[func_name] | ||
@@ -1273,3 +1274,3 @@ if sdf['out_of_date'] == True: | ||
| result = lmb(**args) | ||
| for argname, arg in args.items(): | ||
| for argname, arg in list(args.items()): | ||
| if result.is_dr_wrt(arg.x): | ||
@@ -1315,4 +1316,4 @@ self.add_dterm(argname, arg.x) | ||
| def __init__(self, result, args): | ||
| self.args = { argname: ChHandle(x=arg) for argname, arg in args.items() } | ||
| for argname, arg in self.args.items(): | ||
| self.args = { argname: ChHandle(x=arg) for argname, arg in list(args.items()) } | ||
| for argname, arg in list(self.args.items()): | ||
| setattr(result, argname, arg) | ||
@@ -1332,13 +1333,14 @@ if result.is_dr_wrt(arg.x): | ||
| import ch_ops | ||
| from ch_ops import * | ||
| __all__ += ch_ops.__all__ | ||
| from .ch_ops import * | ||
| from .ch_ops import __all__ as all_ch_ops | ||
| __all__ += all_ch_ops | ||
| import reordering | ||
| from reordering import * | ||
| __all__ += reordering.__all__ | ||
| from .reordering import * | ||
| from .reordering import Permute | ||
| from .reordering import __all__ as all_reordering | ||
| __all__ += all_reordering | ||
| import linalg | ||
| import ch_random as random | ||
| from . import linalg | ||
| from . import ch_random as random | ||
| __all__ += ['linalg', 'random'] | ||
@@ -1367,3 +1369,3 @@ | ||
| tmp = ChLambda(lambda x, y, z: Ch(1) + Ch(2) * Ch(3) + 4) | ||
| print tmp.dr_wrt(tmp.x) | ||
| print(tmp.dr_wrt(tmp.x)) | ||
| import pdb; pdb.set_trace() | ||
@@ -1374,6 +1376,6 @@ #a(b(c(d(e(f),g),h))) | ||
| print blah.r | ||
| print(blah.r) | ||
| print foo | ||
| print(foo) | ||
@@ -1380,0 +1382,0 @@ import pdb; pdb.set_trace() |
+2
-2
| __author__ = 'matt' | ||
| import ch | ||
| from . import ch | ||
| import numpy as np | ||
| from utils import row, col | ||
| from .utils import row, col | ||
| import scipy.sparse as sp | ||
@@ -7,0 +7,0 @@ import scipy.special |
+20
-15
@@ -15,9 +15,14 @@ #!/usr/bin/env python | ||
| import scipy.sparse as sp | ||
| from ch import Ch, depends_on, NanDivide | ||
| from utils import row, col | ||
| import ch | ||
| from .ch import Ch, depends_on | ||
| from .ch_ops import NanDivide | ||
| from .ch_ops import asarray as ch_asarray | ||
| from .ch_ops import sqrt as ch_sqrt | ||
| from .ch_ops import sum as ch_sum | ||
| from .reordering import concatenate as ch_concatenate | ||
| from .ch_random import randn as ch_random_randn | ||
| from .utils import row, col | ||
| try: | ||
| asarray = ch.asarray | ||
| asarray = ch_asarray | ||
| import inspect | ||
@@ -32,3 +37,3 @@ exec(''.join(inspect.getsourcelines(np.linalg.tensorinv)[0])) | ||
| return ch.sqrt(ch.sum(x**2)) | ||
| return ch_sqrt(ch_sum(x**2)) | ||
@@ -39,3 +44,3 @@ # This version works but derivatives are too slow b/c of nested loop in Svd implementation. | ||
| # x = (v.T / s).dot(u.T.dot(b)) | ||
| # residuals = NotImplementedError # ch.sum((a.dot(x) - b)**2, axis=0) | ||
| # residuals = NotImplementedError # ch_sum((a.dot(x) - b)**2, axis=0) | ||
| # rank = NotImplementedError | ||
@@ -52,3 +57,3 @@ # s = NotImplementedError | ||
| x.b = b | ||
| residuals = ch.sum( (x.a.dot(x) - x.b) **2 , axis=0) | ||
| residuals = ch_sum( (x.a.dot(x) - x.b) **2 , axis=0) | ||
| rank = NotImplementedError | ||
@@ -285,3 +290,3 @@ s = NotImplementedError | ||
| r1 = [SignLogAbsDet(r) for r in r2] | ||
| r2 = ch.concatenate(r2) | ||
| r2 = ch_concatenate(r2) | ||
| return r1, r2 | ||
@@ -291,5 +296,5 @@ | ||
| tmp = ch.random.randn(100).reshape((10,10)) | ||
| print 'chumpy version: ' + str(slogdet(tmp)[1].r) | ||
| print 'old version:' + str(np.linalg.slogdet(tmp.r)[1]) | ||
| tmp = ch_random_randn(100).reshape((10,10)) | ||
| print('chumpy version: ' + str(slogdet(tmp)[1].r)) | ||
| print('old version:' + str(np.linalg.slogdet(tmp.r)[1])) | ||
@@ -299,7 +304,7 @@ eps = 1e-10 | ||
| diff_reshaped = diff.reshape((10,10)) | ||
| print np.linalg.slogdet(tmp.r+diff_reshaped)[1] - np.linalg.slogdet(tmp.r)[1] | ||
| print slogdet(tmp)[1].dr_wrt(tmp).dot(diff) | ||
| print(np.linalg.slogdet(tmp.r+diff_reshaped)[1] - np.linalg.slogdet(tmp.r)[1]) | ||
| print(slogdet(tmp)[1].dr_wrt(tmp).dot(diff)) | ||
| print np.linalg.slogdet(tmp.r)[0] | ||
| print slogdet(tmp)[0] | ||
| print(np.linalg.slogdet(tmp.r)[0]) | ||
| print(slogdet(tmp)[0]) | ||
@@ -306,0 +311,0 @@ if __name__ == '__main__': |
+5
-5
@@ -12,4 +12,4 @@ """ | ||
| import ch | ||
| from ch import Ch | ||
| from . import ch | ||
| from .ch import Ch | ||
| import numpy as np | ||
@@ -38,4 +38,4 @@ | ||
| if __name__ == '__main__': | ||
| import ch | ||
| print all(np.array([1,2,3])) | ||
| print isinf(np.array([0,2,3])) | ||
| from . import ch | ||
| print(all(np.array([1,2,3]))) | ||
| print(isinf(np.array([0,2,3]))) |
@@ -12,3 +12,3 @@ ''' | ||
| import numpy as np | ||
| import reordering | ||
| from . import reordering | ||
@@ -22,3 +22,3 @@ _TWO_20 = float(2 **20) | ||
| def pdb_mem(): | ||
| from monitor import get_current_memory | ||
| from .monitor import get_current_memory | ||
| mem = get_current_memory() | ||
@@ -68,6 +68,6 @@ if mem > 7000: | ||
| if isinstance(ch_node, reordering.Concatenate) and hasattr(ch_node, 'dr_cached') and len(ch_node.dr_cached) > 0: | ||
| for k, v in ch_node.dr_cached.iteritems(): | ||
| for k, v in ch_node.dr_cached.items(): | ||
| build_cache_info(k, v, result) | ||
| elif len(ch_node._cache['drs']) > 0: | ||
| for k, v in ch_node._cache['drs'].iteritems(): | ||
| for k, v in ch_node._cache['drs'].items(): | ||
| build_cache_info(k, v, result) | ||
@@ -150,4 +150,4 @@ | ||
| def harvest(self): | ||
| print 'collecting and dump to file %s' % self.path | ||
| print('collecting and dump to file %s' % self.path) | ||
| with open(self.path, 'w') as f: | ||
| json.dump(self.history, f, indent=4) |
@@ -5,5 +5,5 @@ import sys | ||
| import scipy.sparse as sp | ||
| import ch, utils | ||
| from ch import pif | ||
| from utils import timer | ||
| from . import ch, utils | ||
| from .ch import pif | ||
| from .utils import timer | ||
@@ -119,6 +119,6 @@ | ||
| return sparse_solver | ||
| elif isinstance(sparse_solver, str) and sparse_solver in _solver_fns.keys(): | ||
| elif isinstance(sparse_solver, str) and sparse_solver in list(_solver_fns.keys()): | ||
| return _solver_fns[sparse_solver] | ||
| else: | ||
| raise Exception('sparse_solver argument must be either a string in the set (%s) or have the api of scipy.sparse.linalg.spsolve.' % ', '.join(_solver_fns.keys())) | ||
| raise Exception('sparse_solver argument must be either a string in the set (%s) or have the api of scipy.sparse.linalg.spsolve.' % ', '.join(list(_solver_fns.keys()))) | ||
@@ -143,3 +143,3 @@ | ||
| labels = obj | ||
| obj = ch.concatenate([f.ravel() for f in obj.values()]) | ||
| obj = ch.concatenate([f.ravel() for f in list(obj.values())]) | ||
| # build objective | ||
@@ -154,3 +154,3 @@ x = np.concatenate([freevar.r.ravel() for freevar in free_variables]) | ||
| report_line = ['%.2e' % (np.sum(obj.r**2),)] | ||
| for label, objective in sorted(labels.items(), key=lambda x: x[0]): | ||
| for label, objective in sorted(list(labels.items()), key=lambda x: x[0]): | ||
| report_line.append('%s: %.2e' % (label, np.sum(objective.r**2))) | ||
@@ -157,0 +157,0 @@ report_line = " | ".join(report_line) + '\n' |
@@ -12,7 +12,7 @@ #!/usr/bin/env python | ||
| import numpy as np | ||
| import ch | ||
| from . import ch | ||
| import scipy.sparse as sp | ||
| import scipy.optimize | ||
| from optimization_internal import minimize_dogleg | ||
| from .optimization_internal import minimize_dogleg | ||
@@ -47,3 +47,3 @@ #from memory_profiler import profile, memory_usage | ||
| if isinstance(fun, dict): | ||
| fun = ch.concatenate([f.ravel() for f in fun.values()]) | ||
| fun = ch.concatenate([f.ravel() for f in list(fun.values())]) | ||
| obj = fun | ||
@@ -53,3 +53,3 @@ free_variables = x0 | ||
| from ch import SumOfSquares | ||
| from .ch import SumOfSquares | ||
@@ -56,0 +56,0 @@ hessp = None |
@@ -7,5 +7,5 @@ """ | ||
| import ch | ||
| from .ch import Ch | ||
| import numpy as np | ||
| from utils import row, col | ||
| from .utils import row, col | ||
| import scipy.sparse as sp | ||
@@ -19,3 +19,3 @@ import weakref | ||
| # Classes deriving from "Permute" promise to only reorder/reshape | ||
| class Permute(ch.Ch): | ||
| class Permute(Ch): | ||
| pass | ||
@@ -26,3 +26,3 @@ | ||
| if isinstance (a, np.ndarray): | ||
| self = ch.Ch(a) | ||
| self = Ch(a) | ||
@@ -190,3 +190,3 @@ return reshape(a=a, newshape=(-1,)) | ||
| # class And(ch.Ch): | ||
| # class And(Ch): | ||
| # dterms = 'x1', 'x2' | ||
@@ -309,3 +309,3 @@ # | ||
| class AtleastNd(ch.Ch): | ||
| class AtleastNd(Ch): | ||
| dterms = 'x' | ||
@@ -362,3 +362,3 @@ terms = 'ndims' | ||
| class Concatenate(ch.Ch): | ||
| class Concatenate(Ch): | ||
@@ -421,3 +421,3 @@ def on_changed(self, which): | ||
| if len(self._parents.keys()) != 1: | ||
| if len(list(self._parents.keys())) != 1: | ||
| self.dr_cached[wrt] = res | ||
@@ -424,0 +424,0 @@ else: |
+13
-13
@@ -15,3 +15,3 @@ #!/usr/bin/env python | ||
| import ch | ||
| from . import ch | ||
@@ -207,5 +207,5 @@ class TestCh(unittest.TestCase): | ||
| self.assertTrue(y.r[0] == 105) | ||
| a.__setitem__(range(0,1), np.array(200), 2) | ||
| a.__setitem__(list(range(0,1)), np.array(200), 2) | ||
| self.assertTrue(y.r[0] == 105) | ||
| a.__setitem__(range(0,1), np.array(200), 3) | ||
| a.__setitem__(list(range(0,1)), np.array(200), 3) | ||
| self.assertTrue(y.r[0] == 205) | ||
@@ -262,3 +262,3 @@ | ||
| def test_transpose(self): | ||
| from utils import row, col | ||
| from .utils import row, col | ||
| from copy import deepcopy | ||
@@ -307,3 +307,3 @@ for which in ('C', 'F'): # test in fortran and contiguous mode | ||
| # at root, and verify that both children have parentage. | ||
| import cPickle as pickle | ||
| from six.moves import cPickle as pickle | ||
| tmp = ch.Ch(10) + ch.Ch(20) | ||
@@ -313,4 +313,4 @@ tmp = pickle.loads(pickle.dumps(tmp)) | ||
| self.assertTrue(tmp.r[0] == 40) | ||
| self.assertTrue(tmp.a._parents.keys()[0] == tmp) | ||
| self.assertTrue(tmp.a._parents.keys()[0] == tmp.b._parents.keys()[0]) | ||
| self.assertTrue(list(tmp.a._parents.keys())[0] == tmp) | ||
| self.assertTrue(list(tmp.a._parents.keys())[0] == list(tmp.b._parents.keys())[0]) | ||
@@ -349,3 +349,3 @@ def test_chlambda1(self): | ||
| def test_amax(self): | ||
| from ch import amax | ||
| from .ch import amax | ||
| import numpy as np | ||
@@ -363,4 +363,4 @@ arr = np.empty((5,2,3,7)) | ||
| def test_maximum(self): | ||
| from utils import row, col | ||
| from ch import maximum | ||
| from .utils import row, col | ||
| from .ch import maximum | ||
@@ -441,3 +441,3 @@ # Make sure that when we compare the max of two *identical* numbers, | ||
| def test_matmatmult(self): | ||
| from ch import dot | ||
| from .ch import dot | ||
| mtx1 = ch.Ch(np.arange(6).reshape((3,2))) | ||
@@ -605,5 +605,5 @@ mtx2 = ch.Ch(np.arange(8).reshape((2,4))*10) | ||
| theano_fn = function(Ts, theano_grad) | ||
| print theano_fn(*vals) | ||
| print(theano_fn(*vals)) | ||
| C_result_grad = ch.SumOfSquares(C_result).dr_wrt(Cs[which]) | ||
| print C_result_grad | ||
| print(C_result_grad) | ||
@@ -610,0 +610,0 @@ # if True: |
@@ -10,3 +10,3 @@ #!/usr/bin/env python | ||
| import unittest | ||
| from ch import Ch, depends_on | ||
| from .ch import Ch, depends_on | ||
@@ -13,0 +13,0 @@ class TestInnerComposition(unittest.TestCase): |
+11
-11
@@ -12,3 +12,3 @@ #!/usr/bin/env python | ||
| from ch import Ch | ||
| from .ch import Ch | ||
@@ -25,3 +25,3 @@ | ||
| def test_slogdet(self): | ||
| import ch | ||
| from . import ch | ||
| tmp = ch.random.randn(100).reshape((10,10)) | ||
@@ -52,3 +52,3 @@ # print 'chumpy version: ' + str(slogdet(tmp)[1].r) | ||
| def test_lstsq(self): | ||
| from linalg import lstsq | ||
| from .linalg import lstsq | ||
@@ -80,3 +80,3 @@ shapes = ([10, 3], [3, 10]) | ||
| def test_pinv(self): | ||
| from linalg import Pinv | ||
| from .linalg import Pinv | ||
@@ -109,3 +109,3 @@ data = (np.random.rand(12)-.5).reshape((3, 4)) | ||
| def test_svd(self): | ||
| from linalg import Svd | ||
| from .linalg import Svd | ||
| eps = 1e-3 | ||
@@ -153,3 +153,3 @@ idx = 10 | ||
| def test_det(self): | ||
| from linalg import Det | ||
| from .linalg import Det | ||
@@ -179,3 +179,3 @@ mtx1 = Ch(np.sin(2**np.arange(9)).reshape((3,3))) | ||
| def test_inv1(self): | ||
| from linalg import Inv | ||
| from .linalg import Inv | ||
@@ -202,3 +202,3 @@ mtx1 = Ch(np.sin(2**np.arange(9)).reshape((3,3))) | ||
| def test_inv2(self): | ||
| from linalg import Inv | ||
| from .linalg import Inv | ||
@@ -226,3 +226,3 @@ eps = 1e-8 | ||
| from linalg import Inv | ||
| from .linalg import Inv | ||
@@ -270,4 +270,4 @@ mtx1 = Ch(np.sin(2**np.arange(12)).reshape((3,2,2))) | ||
| #print diff_pred | ||
| print diff_emp / diff_pred | ||
| print diff_emp - diff_pred | ||
| print(diff_emp / diff_pred) | ||
| print(diff_emp - diff_pred) | ||
@@ -274,0 +274,0 @@ parm.x = backed_up |
@@ -12,8 +12,8 @@ #!/usr/bin/env python | ||
| import unittest | ||
| import ch | ||
| from optimization import minimize | ||
| from ch import Ch | ||
| from . import ch | ||
| from .optimization import minimize | ||
| from .ch import Ch | ||
| import numpy as np | ||
| from scipy.optimize import rosen, rosen_der | ||
| from utils import row, col | ||
| from .utils import row, col | ||
@@ -100,4 +100,4 @@ | ||
| residuals = np.sum(self.r**2) | ||
| print '------> RESIDUALS %.2e' % (residuals,) | ||
| print '------> CURRENT GUESS %s' % (str(self.x.r),) | ||
| print('------> RESIDUALS %.2e' % (residuals,)) | ||
| print('------> CURRENT GUESS %s' % (str(self.x.r),)) | ||
| plt.figure(123) | ||
@@ -139,3 +139,3 @@ | ||
| def test_bfgs_rosen(self): | ||
| from optimization import minimize_bfgs_lsq | ||
| from .optimization import minimize_bfgs_lsq | ||
| obj, freevars = Rosen() | ||
@@ -147,3 +147,3 @@ minimize_bfgs_lsq(obj=obj, niters=421, verbose=False, free_variables=freevars) | ||
| def test_bfgs_madsen(self): | ||
| from ch import SumOfSquares | ||
| from .ch import SumOfSquares | ||
| import scipy.optimize | ||
@@ -150,0 +150,0 @@ obj = Ch(lambda x : SumOfSquares(Madsen(x = x)) ) |
@@ -1,2 +0,2 @@ | ||
| import ch | ||
| from . import ch | ||
| import numpy as np | ||
@@ -3,0 +3,0 @@ |
@@ -1,3 +0,3 @@ | ||
| version = '0.67.6' | ||
| version = '0.68' | ||
| short_version = version | ||
| full_version = version |
+6
-2
| all: | ||
| upload: | ||
| python setup.py register sdist upload | ||
| python setup.py sdist | ||
| twine upload dist/* | ||
| #sdist: | ||
@@ -14,3 +15,6 @@ # python setup.py sdist && rsync -avz dist/chumpy-0.5.tar.gz files:~/chumpy/latest.tgz && python ./api_compatibility.py && rsync -avz ./api_compatibility.html files:~/chumpy/ | ||
| qtest: all | ||
| python -m unittest discover -s chumpy | ||
| # For some reason the import changes for Python 3 caused the Python 2 test | ||
| # loader to give up without loading any tests. So we discover them ourselves. | ||
| # python -m unittest | ||
| find chumpy -name 'test_*.py' | sed -e 's/\.py$$//' -e 's/\//./' | xargs python -m unittest | ||
@@ -17,0 +21,0 @@ coverage: clean qcov |
+1
-1
| Metadata-Version: 1.1 | ||
| Name: chumpy | ||
| Version: 0.67.6 | ||
| Version: 0.68 | ||
| Summary: chumpy | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/mattloper/chumpy |
+1
-0
| numpy>=1.8.1 | ||
| scipy>=0.13.0 | ||
| six>=1.11.0 |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
195518
0.37%4560
0.18%