def test_basicSD(self): for mtype in _mtypes: x = as_sparse_variable(mtype((500, 3))) x.data[(10, 1)] = 1 x.data[(20, 2)] = 2 self.assertTrue(_is_sparse_variable(x)) y = tensor.as_tensor_variable([[1., 2], [3, 4], [2, 1]]) self.assertTrue(_is_dense_variable(y)) zop = true_dot(x, y) self.assertTrue(_is_sparse_variable(zop)) z = eval_outputs([zop]) self.assertTrue(_is_sparse(z)) self.assertTrue(z.shape == (500, 2)) self.assertTrue(type(z) is mtype) w = mtype((500, 2)) w[(10, 0)] = 3. w[(20, 0)] = 4 w[(10, 1)] = 4 w[(20, 1)] = 2 self.assertTrue(z.shape == w.shape) self.assertTrue(type(z) == type(w)) self.assertTrue(z.dtype == w.dtype) #self.assertTrue(z == w) self.assertTrue(abs(z - w).nnz == 0) z = z.todense() w = w.todense() self.assertTrue((z == w).all() == True)
def test_basicSS(self): for mtype in _mtypes: x = as_sparse_variable(mtype((500, 3))) x.data[(10, 1)] = 1 x.data[(20, 2)] = 2 self.assertTrue(_is_sparse_variable(x)) xT = x.T self.assertTrue(_is_sparse_variable(xT)) zop = true_dot(x, xT) self.assertTrue(_is_sparse_variable(zop)) z = eval_outputs([zop]) self.assertTrue(_is_sparse(z)) self.assertTrue(z.shape == (500, 500)) self.assertTrue(type(z) is mtype) w = mtype((500, 500)) w[(10, 10)] = 1 w[(20, 20)] = 4 self.assertTrue(z.shape == w.shape) self.assertTrue(type(z) == type(w)) self.assertTrue(z.dtype == w.dtype) #self.assertTrue(z == w) self.assertTrue(abs(z - w).nnz == 0) z = z.todense() w = w.todense() self.assertTrue((z == w).all() == True)
def test_basicSS(self): for mtype in _mtypes: x = as_sparse_variable(mtype((500,3))) x.data[(10, 1)] = 1 x.data[(20, 2)] = 2 self.assertTrue(_is_sparse_variable(x)) xT = x.T self.assertTrue(_is_sparse_variable(xT)) zop = true_dot(x,xT) self.assertTrue(_is_sparse_variable(zop)) z = eval_outputs([zop]) self.assertTrue(_is_sparse(z)) self.assertTrue(z.shape == (500,500)) self.assertTrue(type(z) is mtype) w = mtype((500,500)) w[(10, 10)] = 1 w[(20, 20)] = 4 self.assertTrue(z.shape == w.shape) self.assertTrue(type(z) == type(w)) self.assertTrue(z.dtype == w.dtype) #self.assertTrue(z == w) self.assertTrue(abs(z-w).nnz == 0) z = z.todense() w = w.todense() self.assertTrue((z == w).all() == True)
def test_basicSD(self): for mtype in _mtypes: x = as_sparse_variable(mtype((500,3))) x.data[(10, 1)] = 1 x.data[(20, 2)] = 2 self.assertTrue(_is_sparse_variable(x)) y = tensor.as_tensor_variable([[1., 2], [3, 4], [2, 1]]) self.assertTrue(_is_dense_variable(y)) zop = true_dot(x,y) self.assertTrue(_is_sparse_variable(zop)) z = eval_outputs([zop]) self.assertTrue(_is_sparse(z)) self.assertTrue(z.shape == (500,2)) self.assertTrue(type(z) is mtype) w = mtype((500,2)) w[(10, 0)] = 3. w[(20, 0)] = 4 w[(10, 1)] = 4 w[(20, 1)] = 2 self.assertTrue(z.shape == w.shape) self.assertTrue(type(z) == type(w)) self.assertTrue(z.dtype == w.dtype) #self.assertTrue(z == w) self.assertTrue(abs(z-w).nnz == 0) z = z.todense() w = w.todense() self.assertTrue((z == w).all() == True)
def test_basicDS(self): for mtype in _mtypes: x = as_sparse_variable(mtype((500, 3))) x.data[(10, 1)] = 1 x.data[(20, 2)] = 2 self.assertTrue(_is_sparse_variable(x)) y = tensor.as_tensor_variable([[1., 2], [3, 4], [2, 1]]) self.assertTrue(_is_dense_variable(y)) x.data = x.data.T y.data = y.data.T zop = true_dot(y, x) zop = transpose(true_dot(y, x)) self.assertTrue(_is_sparse_variable(zop)) z = eval_outputs([zop]) self.assertTrue(_is_sparse(z)) self.assertTrue(z.shape == (500, 2)) # self.assertTrue(type(z) is mtype) w = mtype((500, 2)) w[(10, 0)] = 3. w[(20, 0)] = 4 w[(10, 1)] = 4 w[(20, 1)] = 2 self.assertTrue(z.shape == w.shape) # Type should switch from csr to csc and vice-versa, so don't perform this test #self.assertTrue(type(z) == type(w)) self.assertTrue(z.dtype == w.dtype) # Type should switch from csr to csc and vice-versa, so don't perform this test #self.assertTrue(z == w) self.assertTrue(abs(z - w).nnz == 0) z = z.todense() w = w.todense() self.assertTrue((z == w).all() == True)
def test_basicDS(self): for mtype in _mtypes: x = as_sparse_variable(mtype((500,3))) x.data[(10, 1)] = 1 x.data[(20, 2)] = 2 self.assertTrue(_is_sparse_variable(x)) y = tensor.as_tensor_variable([[1., 2], [3, 4], [2, 1]]) self.assertTrue(_is_dense_variable(y)) x.data = x.data.T y.data = y.data.T zop = true_dot(y, x) zop = transpose(true_dot(y, x)) self.assertTrue(_is_sparse_variable(zop)) z = eval_outputs([zop]) self.assertTrue(_is_sparse(z)) self.assertTrue(z.shape == (500,2)) # self.assertTrue(type(z) is mtype) w = mtype((500,2)) w[(10, 0)] = 3. w[(20, 0)] = 4 w[(10, 1)] = 4 w[(20, 1)] = 2 self.assertTrue(z.shape == w.shape) # Type should switch from csr to csc and vice-versa, so don't perform this test #self.assertTrue(type(z) == type(w)) self.assertTrue(z.dtype == w.dtype) # Type should switch from csr to csc and vice-versa, so don't perform this test #self.assertTrue(z == w) self.assertTrue(abs(z-w).nnz == 0) z = z.todense() w = w.todense() self.assertTrue((z == w).all() == True)