def test_operator_pointwise_product(): """Check call and adjoint of operator pointwise multiplication.""" if dom_eq_ran: mat1 = np.random.rand(3, 3) mat2 = np.random.rand(3, 3) else: mat1 = np.random.rand(4, 3) mat2 = np.random.rand(4, 3) op1 = MultiplyAndSquareOp(mat1) op2 = MultiplyAndSquareOp(mat2) x = noise_element(op1.domain) prod_op = odl.OperatorPointwiseProduct(op1, op2) # Evaluate expected = op1(x) * op2(x) check_call(prod_op, x, expected) # Derivative y = noise_element(op1.domain) expected = (op1.derivative(x)(y) * op2(x) + op2.derivative(x)(y) * op1(x)) prod_deriv_op = prod_op.derivative(x) assert prod_deriv_op.is_linear check_call(prod_deriv_op, y, expected) # Derivative Adjoint z = noise_element(op1.range) expected = (op1.derivative(x).adjoint(z * op2(x)) + op2.derivative(x).adjoint(z * op1(x))) prod_deriv_adj_op = prod_deriv_op.adjoint assert prod_deriv_adj_op.is_linear check_call(prod_deriv_adj_op, z, expected)
def test_operator_pointwise_product(): """Test OperatorPointwiseProduct.""" Aop = MultiplyAndSquareOp(np.random.rand(4, 3)) Bop = MultiplyAndSquareOp(np.random.rand(4, 3)) x = noise_element(Aop.domain) prod = odl.OperatorPointwiseProduct(Aop, Bop) # Evaluate expected = Aop(x) * Bop(x) check_call(prod, x, expected) # Derivative y = noise_element(Aop.domain) expected = (Aop.derivative(x)(y) * Bop(x) + Bop.derivative(x)(y) * Aop(x)) derivative = prod.derivative(x) assert derivative.is_linear check_call(derivative, y, expected) # Adjoint z = noise_element(Aop.range) expected = (Aop.derivative(x).adjoint(z * Bop(x)) + Bop.derivative(x).adjoint(z * Aop(x))) adjoint = derivative.adjoint assert adjoint.is_linear check_call(adjoint, z, expected)