def test_mat_lin(self): mat = numpy.identity(3) lin = linearize_matrix(mat) exp = numpy.array([[1., 0., 0.], [0., 0., 1.], [0., 0., 2.], [0., 1., 0.], [1., 1., 1.], [0., 1., 2.], [0., 2., 0.], [0., 2., 1.], [1., 2., 2.]]) self.assertEqual(exp, lin)
def test_mat_lin_sparse3(self): mat = numpy.identity(3) mat[0, 1] = 8 mat[2, 1] = 7 mat = scipy.sparse.csr_matrix(mat) lin = linearize_matrix(mat) exp = numpy.array([[1., 0., 0.], [8., 0., 1.], [1., 1., 1.], [7., 2., 1.], [1., 2., 2.]]) self.assertEqual(exp, lin)
def test_mat_lin_add(self): mat = numpy.identity(3) mat2 = numpy.identity(3) * 3 lin = linearize_matrix(mat, mat2) exp = numpy.array([[1., 0., 0., 3.], [0., 0., 1., 0.], [0., 0., 2., 0.], [0., 1., 0., 0.], [1., 1., 1., 3.], [0., 1., 2., 0.], [0., 2., 0., 0.], [0., 2., 1., 0.], [1., 2., 2., 3.]]) self.assertEqual(exp, lin)
def test_mat_lin_sparse_add(self): mat = numpy.identity(3) mat[0, 2] = 8 mat[1, 2] = 5 mat[2, 1] = 7 mat2 = numpy.identity(3) * 3 mat = scipy.sparse.csr_matrix(mat) mat2 = scipy.sparse.csr_matrix(mat2) lin = linearize_matrix(mat, mat2) exp = numpy.array([[1., 0., 0., 3.], [8., 0., 2., 0.], [1., 1., 1., 3.], [5., 1., 2., 0.], [7., 2., 1., 0.], [1., 2., 2., 3.]]) self.assertEqual(exp, lin)