Example #1
0
 def test_create_sparse(self):
     t = tile.from_shape(ARRAY_SIZE,
                         dtype=np.float32,
                         tile_type=tile.TYPE_SPARSE)
     t._initialize()
     Assert.eq(t.data.shape, ARRAY_SIZE)
     Assert.eq(t.mask, None)
Example #2
0
 def test_update_sparse_to_sparse(self):
   t = tile.from_shape(ARRAY_SIZE, dtype=np.float32, tile_type=tile.TYPE_SPARSE)
   update = sp.lil_matrix(ARRAY_SIZE, dtype=np.float32)
   for i in range(UPDATE_SHAPE[0]):
     update[i,i] = 1
   t.update(UPDATE_SUBSLICE, update, None)
   Assert.eq(sp.issparse(t.data), True)
   print t.data.todense()
Example #3
0
def test_unravel():
    for i in range(100):
        shp = (20, 77)
        ul = (random.randint(0, 19), random.randint(0, 76))
        lr = (random.randint(ul[0] + 1, 20), random.randint(ul[1] + 1, 77))

        a = extent.create(ul, lr, shp)
        ravelled = a.ravelled_pos()
        unravelled = extent.unravelled_pos(ravelled, a.array_shape)
        Assert.eq(a.ul, unravelled)
Example #4
0
 def test_update_sparse_to_sparse(self):
     t = tile.from_shape(ARRAY_SIZE,
                         dtype=np.float32,
                         tile_type=tile.TYPE_SPARSE)
     update = sp.lil_matrix(ARRAY_SIZE, dtype=np.float32)
     for i in range(UPDATE_SHAPE[0]):
         update[i, i] = 1
     t.update(UPDATE_SUBSLICE, update, None)
     Assert.eq(sp.issparse(t.data), True)
     print t.data.todense()
Example #5
0
def test_unravel():
  for i in range(100):
    shp = (20, 77)
    ul = (random.randint(0, 19), random.randint(0, 76))
    lr = (random.randint(ul[0] + 1, 20), random.randint(ul[1] + 1, 77))
                         
    a = extent.create(ul, lr, shp)
    ravelled = a.ravelled_pos()
    unravelled = extent.unravelled_pos(ravelled, a.array_shape)
    Assert.eq(a.ul, unravelled)
Example #6
0
def test_ravelled_pos():
    a = extent.create((2, 2), (7, 7), (10, 10))
    for i in range(0, 10):
        for j in range(0, 10):
            assert extent.ravelled_pos((i, j), a.array_shape) == 10 * i + j

    Assert.eq(a.to_global(0, axis=None), 22)
    Assert.eq(a.to_global(10, axis=None), 42)
    Assert.eq(a.to_global(11, axis=None), 43)
    Assert.eq(a.to_global(20, axis=None), 62)
Example #7
0
def test_ravelled_pos():
  a = extent.create((2, 2), (7, 7), (10, 10))
  for i in range(0, 10):
    for j in range(0, 10):
      assert extent.ravelled_pos((i, j), a.array_shape) == 10 * i + j
      
  Assert.eq(a.to_global(0, axis=None), 22)
  Assert.eq(a.to_global(10, axis=None), 42)
  Assert.eq(a.to_global(11, axis=None), 43)
  Assert.eq(a.to_global(20, axis=None), 62)
Example #8
0
 def test_fio_sparse(self):
   self.create_path()
   t1 = expr.sparse_rand((100, 100)).evaluate()
   Assert.eq(expr.save(t1, "fiotest3", self.test_dir, False), True)
   Assert.all_eq(t1.glom().todense(), expr.load("fiotest3", self.test_dir, False).glom().todense())
   Assert.eq(expr.save(t1, "fiotest3", self.test_dir, True), True)
   Assert.all_eq(t1.glom().todense(), expr.load("fiotest3", self.test_dir, True).glom().todense())
   Assert.eq(expr.pickle(t1, "fiotest4", self.test_dir, False), True)
   Assert.all_eq(t1.glom().todense(), expr.unpickle("fiotest4", self.test_dir, False).glom().todense())
   Assert.eq(expr.pickle(t1, "fiotest4", self.test_dir, True), True)
   Assert.all_eq(t1.glom().todense(), expr.unpickle("fiotest4", self.test_dir, True).glom().todense())
Example #9
0
 def test_fio_dense(self):
   self.create_path()
   t1 = expr.arange((100, 100)).evaluate()
   Assert.eq(expr.save(t1, "fiotest1", self.test_dir, False), True)
   Assert.all_eq(t1.glom(), expr.load("fiotest1", self.test_dir, False).glom())
   Assert.eq(expr.save(t1, "fiotest1", self.test_dir, True), True)
   Assert.all_eq(t1.glom(), expr.load("fiotest1", self.test_dir, True).glom())
   Assert.eq(expr.pickle(t1, "fiotest2", self.test_dir, False), True)
   Assert.all_eq(t1.glom(), expr.unpickle("fiotest2", self.test_dir, False).glom())
   Assert.eq(expr.pickle(t1, "fiotest2", self.test_dir, True), True)
   Assert.all_eq(t1.glom(), expr.unpickle("fiotest2", self.test_dir, True).glom())
Example #10
0
def test_intersection():
    a = extent.create((0, 0), (10, 10), None)
    b = extent.create((5, 5), (6, 6), None)

    Assert.eq(extent.intersection(a, b), extent.create((5, 5), (6, 6), None))
    Assert.eq(extent.intersection(b, a), extent.create((5, 5), (6, 6), None))

    a = extent.create((5, 5), (10, 10), None)
    b = extent.create((4, 6), (6, 8), None)
    Assert.eq(extent.intersection(a, b), extent.create((5, 6), (6, 8), None))

    a = extent.create((5, 5), (5, 5), None)
    b = extent.create((1, 1), (2, 2), None)
    assert extent.intersection(a, b) == None
Example #11
0
def test_intersection():
  a = extent.create((0, 0), (10, 10), None)
  b = extent.create((5, 5), (6, 6), None)
  
  Assert.eq(extent.intersection(a, b),
            extent.create((5,5), (6,6), None))
  Assert.eq(extent.intersection(b, a),
            extent.create((5,5), (6,6), None))
  
  a = extent.create((5, 5), (10, 10), None)
  b = extent.create((4, 6), (6, 8), None)
  Assert.eq(extent.intersection(a, b),
            extent.create((5,6), (6, 8), None))

  a = extent.create((5, 5), (5, 5), None)
  b = extent.create((1, 1), (2, 2), None)
  assert extent.intersection(a, b) == None
Example #12
0
 def test_create_sparse(self):
   t = tile.from_shape(ARRAY_SIZE, dtype=np.float32, tile_type=tile.TYPE_SPARSE)
   t._initialize()
   Assert.eq(t.data.shape, ARRAY_SIZE)
   Assert.eq(t.mask, None) 
Example #13
0
 def test_create_dense(self):
   t = tile.from_shape(ARRAY_SIZE, dtype=np.float32, tile_type=tile.TYPE_DENSE)
   t._initialize()
   Assert.eq(t.mask.shape, ARRAY_SIZE)
Example #14
0
 def test_create_dense(self):
     t = tile.from_shape(ARRAY_SIZE,
                         dtype=np.float32,
                         tile_type=tile.TYPE_DENSE)
     t._initialize()
     Assert.eq(t.mask.shape, ARRAY_SIZE)
Example #15
0
 def test_count_zero(self):
     x = expr.ones((TEST_SIZE, ))
     Assert.eq(expr.count_zero(x).glom(), 0)
     x = expr.zeros((TEST_SIZE, ))
     Assert.eq(expr.count_zero(x).glom(), TEST_SIZE)
Example #16
0
 def test_count_nonzero(self):
   x = expr.ones((TEST_SIZE,))
   Assert.eq(expr.count_nonzero(x).glom(), TEST_SIZE)
   x = expr.zeros((TEST_SIZE,))
   Assert.eq(expr.count_nonzero(x).glom(), 0)