def setUp(self): row = np.array([0, 1, 4, 1, 2, 7, 2, 3, 5, 3, 4, 5, 4, 7, 5, 6, 6, 7]) col = np.array([0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 7]) data = np.array([ 27, 5, 12, 56, 66, 34, 94, 31, 41, 7, 98, 72, 24, 33, 78, 47, 98, 41 ]) off_diagonal_mask = row != col new_row = np.concatenate([row, col[off_diagonal_mask]]) new_col = np.concatenate([col, row[off_diagonal_mask]]) new_data = np.concatenate([data, data[off_diagonal_mask]]) m = coo_matrix((new_data, (new_row, new_col)), shape=(8, 8)) self.block00 = m row = np.array([0, 3, 1, 0]) col = np.array([0, 3, 1, 2]) data = np.array([4, 5, 7, 9]) m = coo_matrix((data, (row, col)), shape=(4, 8)) self.block10 = m row = np.array([0, 1, 2, 3]) col = np.array([0, 1, 2, 3]) data = np.array([1, 1, 1, 1]) m = coo_matrix((data, (row, col)), shape=(4, 4)) self.block11 = m
def test_isin(self): bv = self.bv test_bv = BlockVector(2) a = np.array([1.1, 3.3]) b = np.array([5.5, 7.7]) test_bv.set_block(0, a) test_bv.set_block(1, b) res = pn.isin(bv, test_bv) for bid, blk in enumerate(bv): self.assertEqual(blk.size, res.get_block(bid).size) res_flat = np.isin(blk, test_bv.get_block(bid)) self.assertTrue(np.allclose(res.get_block(bid), res_flat)) c = np.concatenate([a, b]) res = pn.isin(bv, c) for bid, blk in enumerate(bv): self.assertEqual(blk.size, res.get_block(bid).size) res_flat = np.isin(blk, c) self.assertTrue(np.allclose(res.get_block(bid), res_flat)) res = pn.isin(bv, test_bv, invert=True) for bid, blk in enumerate(bv): self.assertEqual(blk.size, res.get_block(bid).size) res_flat = np.isin(blk, test_bv.get_block(bid), invert=True) self.assertTrue(np.allclose(res.get_block(bid), res_flat)) c = np.concatenate([a, b]) res = pn.isin(bv, c, invert=True) for bid, blk in enumerate(bv): self.assertEqual(blk.size, res.get_block(bid).size) res_flat = np.isin(blk, c, invert=True) self.assertTrue(np.allclose(res.get_block(bid), res_flat))
def test_flatten(self): v = BlockVector(2) a = np.arange(5) b = np.arange(9) c = np.concatenate([a, b]) v.set_block(0, a) v.set_block(1, b) self.assertListEqual(v.flatten().tolist(), c.tolist())
def test_min(self): self.assertEqual(self.ones.min(), 1) v = BlockVector(2) a = np.arange(5) b = np.arange(9) c = np.concatenate([a, b]) v.set_block(0, a) v.set_block(1, b) self.assertEqual(v.min(), c.min())
def test_std(self): v = BlockVector(2) a = np.arange(5) b = np.arange(9) v.set_block(0, a) v.set_block(1, b) vv = np.concatenate([a, b]) self.assertEqual(vv.std(), v.std())