예제 #1
0
 def func2(itype, ftype, shapein):
     mat = get_mat(itype, ftype)
     op = SparseOperator(mat)
     todense = op.todense(shapein=(6,) + shapein)
     assert_same(todense.T, op.T.todense(shapeout=(6,) + shapein))
     op2 = SparseOperator(mat, shapeout=(2, 2) + shapein,
                          shapein=(3, 2) + shapein)
     assert_same(op2.todense(), todense)
예제 #2
0
    def func1(itype, ftype, inner_block_shape):
        if inner_block_shape == (1, 1):
            return
        mat_fsr, dense = get_mat(itype, ftype, inner_block_shape,
                                 [index1, index2])
        mat_fsc = mat_fsr._transpose()
        input_fsc = np.random.random_sample(mat_fsc.shape[1])
        input_fsr = np.random.random_sample(mat_fsr.shape[1])

        assert_same(mat_fsr.block_shape, inner_block_shape)
        assert_same(mat_fsc.block_shape, inner_block_shape[::-1])
        op = SparseOperator(mat_fsc)
        assert_equal(op.matrix.dtype, ftype)
        assert_equal(op.dtype, ftype)
        assert_same(op.todense(), dense.T)
        assert_same(op.T.todense(), dense)
        ref = mat_fsc._matvec(input_fsc.astype(np.float128))
        for ftype2 in ftypes[:-1]:
            out = np.zeros_like(ref, ftype2)
            mat_fsc._matvec(input_fsc.astype(ftype2), out)
            assert_same(out, ref.astype(min_dtype(ftype, ftype2)), atol=10)
        ref = (2 * (mat_fsc * input_fsc)).astype(ftype)
        assert_same((mat_fsc * 2) * input_fsc, ref, atol=10)
        assert_same((2 * mat_fsc) * input_fsc, ref, atol=10)
        assert_same(input_fsr * mat_fsc, mat_fsr * input_fsr, atol=10)

        op = SparseOperator(mat_fsr)
        assert_equal(op.matrix.dtype, ftype)
        assert_equal(op.dtype, ftype)
        assert_same(op.todense(), dense)
        assert_same(op.T.todense(), dense.T)
        ref = mat_fsr._matvec(input_fsr.astype(np.float128))
        for ftype2 in ftypes[:-1]:
            out = np.zeros_like(ref, ftype2)
            mat_fsr._matvec(input_fsr.astype(ftype2), out)
            assert_same(out, ref.astype(min_dtype(ftype, ftype2)), atol=10)
        ref = (2 * (mat_fsr * input_fsr)).astype(ftype)
        assert_same((mat_fsr * 2) * input_fsr, ref, atol=10)
        assert_same((2 * mat_fsr) * input_fsr, ref, atol=10)
        assert_same(input_fsc * mat_fsr, mat_fsc * input_fsc, atol=10)
예제 #3
0
    def func1(itype, ftype):
        array = np.recarray((6, 2), dtype=[('index', itype), ('r11', ftype),
                                           ('r22', ftype), ('r32', ftype)])
        dense = np.zeros((6*3, 4*3), dtype=ftype)
        fill(array, dense, index1, value1, angle1, 0)
        fill(array, dense, index2, value2, angle2, 1)

        mat_fsc = FSCRotation3dMatrix(dense.shape[::-1], data=array)
        mat_fsr = FSRRotation3dMatrix(dense.shape, data=array)

        op = SparseOperator(mat_fsc)
        assert_equal(op.matrix.dtype, ftype)
        assert_equal(op.dtype, ftype)
        assert_same(op.todense(), dense.T)
        assert_same(op.T.todense(), dense)
        ref = mat_fsc._matvec(input_fsc.astype(np.float128))
        for ftype2 in ftypes[:-1]:
            out = np.zeros_like(ref, ftype2)
            mat_fsc._matvec(input_fsc.astype(ftype2), out)
            assert_same(out, ref.astype(min_dtype(ftype, ftype2)))
        ref = (3 * (mat_fsc * input_fsc)).astype(ftype)
        assert_same((mat_fsc * 3) * input_fsc, ref)
        assert_same((3 * mat_fsc) * input_fsc, ref)
        assert_same(input_fsr * mat_fsc, mat_fsr * input_fsr)

        op = SparseOperator(mat_fsr)
        assert_equal(op.matrix.dtype, ftype)
        assert_equal(op.dtype, ftype)
        assert_same(op.todense(), dense)
        assert_same(op.T.todense(), dense.T)
        ref = mat_fsr._matvec(input_fsr.astype(np.float128))
        for ftype2 in ftypes[:-1]:
            out = np.zeros_like(ref, ftype2)
            mat_fsr._matvec(input_fsr.astype(ftype2), out)
            assert_same(out, ref.astype(min_dtype(ftype, ftype2)))
        ref = (3 * (mat_fsr * input_fsr)).astype(ftype)
        assert_same((mat_fsr * 3) * input_fsr, ref)
        assert_same((3 * mat_fsr) * input_fsr, ref)
        assert_same(input_fsc * mat_fsr, mat_fsc * input_fsc)
예제 #4
0
 def func2(itype, ftype):
     mat = get_mat(itype, ftype)
     op = SparseOperator(mat, shapein=4)
     todense = op.todense()
     pTp = op.T * op
     if (itype, ftype) not in ((np.int32, np.float32),
                               (np.int32, np.float64),
                               (np.int64, np.float32),
                               (np.int64, np.float64)):
         assert_is_type(pTp, CompositionOperator)
         return
     assert_is_type(pTp, DiagonalOperator)
     assert_same(pTp.todense(), np.dot(todense.T, todense))