コード例 #1
0
ファイル: test_scan.py プロジェクト: GabrielWen/spartan
  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))
コード例 #2
0
    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))
コード例 #3
0
ファイル: test_scan.py プロジェクト: GabrielWen/spartan
 def all_eq_helper(spa, npa, axis=None):
   Assert.all_eq(scan(spa, axis=axis).glom(),
                 np.cumsum(npa, axis).reshape(ARRAY_SIZE))
コード例 #4
0
 def all_eq_helper(spa, npa, axis=None):
     Assert.all_eq(
         scan(spa, axis=axis).glom(),
         np.cumsum(npa, axis).reshape(ARRAY_SIZE))
コード例 #5
0
ファイル: swaption.py プロジェクト: rossparks/spartan
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)
コード例 #6
0
ファイル: swaption.py プロジェクト: rgardner/spartan
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)