def test_sparse_scan(self): # np.cumsum does not support sparse matrices, so they must be converted # to dense matrices first. np_sparse = sparse.eye(*ARRAY_SIZE).todense() sp_sparse = sparse_diagonal(ARRAY_SIZE, np.float32, tile_hint) Assert.all_eq( scan(sp_sparse, reduce_fn=lambda x, **kw:x.sum(axis=kw['axis']), scan_fn=lambda x, **kw: x.cumsum(axis=kw['axis']), axis=None).glom(), np.cumsum(np_sparse).reshape(ARRAY_SIZE)) for axis in range(len(ARRAY_SIZE)): Assert.all_eq( scan(sp_sparse, reduce_fn=lambda x, **kw:x.sum(axis=kw['axis']), scan_fn=lambda x, **kw: x.cumsum(axis=kw['axis']), axis=axis).glom(), np.cumsum(np_sparse, axis).reshape(ARRAY_SIZE))
def test_sparse_scan(self): # np.cumsum does not support sparse matrices, so they must be converted # to dense matrices first. np_sparse = sparse.eye(*ARRAY_SIZE).todense() sp_sparse = sparse_diagonal(ARRAY_SIZE, np.float32, tile_hint) Assert.all_eq( scan(sp_sparse, reduce_fn=lambda x, **kw: x.sum(axis=kw['axis']), scan_fn=lambda x, **kw: x.cumsum(axis=kw['axis']), axis=None).glom(), np.cumsum(np_sparse).reshape(ARRAY_SIZE)) for axis in range(len(ARRAY_SIZE)): Assert.all_eq( scan(sp_sparse, reduce_fn=lambda x, **kw: x.sum(axis=kw['axis']), scan_fn=lambda x, **kw: x.cumsum(axis=kw['axis']), axis=axis).glom(), np.cumsum(np_sparse, axis).reshape(ARRAY_SIZE))
def all_eq_helper(spa, npa, axis=None): Assert.all_eq(scan(spa, axis=axis).glom(), np.cumsum(npa, axis).reshape(ARRAY_SIZE))
def all_eq_helper(spa, npa, axis=None): Assert.all_eq( scan(spa, axis=axis).glom(), np.cumsum(npa, axis).reshape(ARRAY_SIZE))
def mu(f, lamb): '''Auxiliary function.''' tmp = lamb*(DELTA*f[1:, :]) / (1 + DELTA*f[1:, :]) # Andreasen style return spartan.scan(tmp, np.sum, np.cumsum, axis=0)
def mu(f, lamb): """Auxiliary function.""" tmp = lamb * (DELTA * f[1:, :]) / (1 + DELTA * f[1:, :]) # Andreasen style return spartan.scan(tmp, np.sum, np.cumsum, axis=0)