def test_init(self): v = np.arange(6) A = lo.linop_from_ndarray(np.outer(v, v), symmetric=True) R = lo.SymmetricallyReducedLinearOperator(A, [1, 2, 3]) self.assertTrue(R.symmetric) self.assertTrue(R.hermitian) A = lo.linop_from_ndarray(np.outer(v, v)) R = lo.SymmetricallyReducedLinearOperator(A, [1, 2, 3]) self.assertFalse(R.symmetric) self.assertTrue(R.shape == (3, 3))
def test_runtime(self): v = np.arange(6) A_mat = np.outer(v, v) A = lo.linop_from_ndarray(A_mat) sym_idx = [1, 2, 3] R = lo.SymmetricallyReducedLinearOperator(A, sym_idx) vmask = np.zeros(v.size) vmask[sym_idx] = 1 assert_equal(R * v[sym_idx], A_mat.dot(v * vmask)[sym_idx])
def test_runtime(self): v = np.arange(6) A_mat = np.outer(v, v) A = lo.linop_from_ndarray(A_mat) row_idx = [2, 4] col_idx = [1, 2, 3] R = lo.ReducedLinearOperator(A, row_idx, col_idx) vmask = np.zeros(v.size) vmask[col_idx] = 1 assert_equal(R * v[col_idx], A_mat.dot(v * vmask)[row_idx])
def test_init(self): A_as_op = lo.linop_from_ndarray(self.A) assert_(isinstance(A_as_op, lo.LinearOperator)) x = np.array([1, 1, 1]) assert_equal(A_as_op * x, self.A.dot(x)) x = np.array([1, 1]) assert_equal(A_as_op.T * x, self.A.T.dot(x)) assert_equal(A_as_op.H * x, self.A.T.dot(x)) def init_Aop(s, h): lo.linop_from_ndarray(self.A, symmetric=s, hermitian=h) assert_raises(ValueError, init_Aop, True, False)
def setUp(self): self.A = lo.IdentityOperator(2) self.B = lo.linop_from_ndarray(np.arange(1, 7).reshape([2, 3])) self.C = lo.DiagonalOperator(np.arange(3)) self.D = lo.linop_from_ndarray(np.arange(6, 0, -1).reshape([3, 2]))
def init_Aop(s, h): lo.linop_from_ndarray(self.A, symmetric=s, hermitian=h)
def test_init(self): v = np.arange(6) A = lo.linop_from_ndarray(np.outer(v, v)) R = lo.ReducedLinearOperator(A, [1, 2, 3], [4, 5]) self.assertFalse(R.symmetric) self.assertTrue(R.shape == (3, 2))