def func(op1, op2): op = op1(op2) attr = {} attr.update(op2.attrout) attr.update(op1.attrout) assert_equal(op.attrout, attr) assert_is(op.classout, op1.classout) if op1.flags.linear: assert_is_type(op, ZeroOperator) assert_same(op.todense(shapein=3, shapeout=4), np.zeros((4, 3))) return if op1.flags.shape_output == 'unconstrained' or \ op1.flags.shape_input != 'explicit' and \ op2.flags.shape_output != 'explicit': assert_is_type(op, CompositionOperator) else: assert_is_type(op, ConstantOperator) if op1.flags.shape_input == 'unconstrained' and \ op2.flags.shape_output == 'unconstrained': return with rule_manager(none=True): op_ref = op1(op2) assert_same(op.todense(shapein=3, shapeout=4), op_ref.todense(shapein=3, shapeout=4))
def func(op_, id_): op = op_(id_) assert_is_type(op, type(op_)) attr = {} assert_is(op.classout, op_.classout) attr.update(id_.attrout) attr.update(op_.attrout) assert_eq(op.attrout, attr) assert_eq(op.flags.linear, op_.flags.linear) assert_eq(op.flags.contiguous_input, op_.flags.contiguous_input)
def func(s1, s2, s3, o1, o2, ref): rule = BinaryRule(s1 + ',' + s2, s3) result = rule(o1, o2) assert_is_not_none(result) assert_is_instance(result, Operator) if s3 == '1': assert_is_instance(result, IdentityOperator) return o3 = eval('ref.'+s3) if s3 != '.' else ref assert_is(result, o3)
def test_homothety_operator(): s = HomothetyOperator(1) assert s.C is s.T is s.H is s.I is s s = HomothetyOperator(-1) assert s.C is s.T is s.H is s.I is s s = HomothetyOperator(2.) assert s.C is s.T is s.H is s assert_is_not(s.I, s) def func(o): assert_is_instance(o, HomothetyOperator) for o in (s.I, s.I.C, s.I.T, s.I.H, s.I.I): yield func, o s = HomothetyOperator(complex(1, 1)) assert_is(s.T, s) assert_is(s.H, s.C) assert_not_in(s.I, (s, s.C)) assert_not_in(s.I.C, (s, s.C)) assert_is_instance(s.C, HomothetyOperator) for o in (s.I, s.I.C, s.I.T, s.I.H, s.I.I): yield func, o
def test_dtype(): assert_is(Quantity(1).dtype, np.dtype(float)) assert_is(Quantity(1, dtype='float32').dtype, np.dtype(np.float32)) assert_is(Quantity(1.).dtype, np.dtype(float)) assert_is(Quantity(complex(1, 0)).dtype, np.dtype(np.complex128)) assert_is(Quantity(1., dtype=np.complex64).dtype, np.dtype(np.complex64)) assert_is(Quantity(1., dtype=np.complex128).dtype, np.dtype(np.complex128)) assert_is(Quantity(1., dtype=np.complex256).dtype, np.dtype(np.complex256)) assert_is(Quantity(np.array(complex(1, 0))).dtype, np.dtype(complex)) assert_is(Quantity(np.array(np.complex64(1.))).dtype, np.dtype(np.complex64)) assert_is(Quantity(np.array(np.complex128(1.))).dtype, np.dtype(complex))
def func(s, p): r = UnaryRule(s, p) if p == '.': assert_is(r(op1), op1) else: assert_is_instance(r(op1), IdentityOperator)