Exemple #1
0
def test_fsc_error():
    data = np.zeros((3, 4), [('index', int), ('value', float)])
    data_wrong1 = np.empty((3, 4), [('index_', int), ('value', float)])
    data_wrong2 = np.empty((3, 4), [('value', float), ('index', int)])
    assert_raises(TypeError, FSCMatrix, 3)
    assert_raises(ValueError, FSCMatrix, (2, 3, 4))
    assert_raises(ValueError, FSCMatrix, (3, 8), data=data)
    assert_raises(TypeError, FSCMatrix, (8, 3), data=data_wrong1)
    assert_raises(TypeError, FSCMatrix, (8, 3), data=data_wrong2)
    assert_raises(ValueError, FSCMatrix, (8, 3), 5, data=data)
    FSCMatrix((8, 3), 4, data=data)
    assert_raises(ValueError, FSCMatrix, (8, 3))
    mat = FSCMatrix((8, 3), data=data)
    mat._matvec(np.ones(3))
    assert_raises(ValueError, mat._matvec, np.ones(7))
    assert_raises(TypeError, mat._matvec, np.ones(3), out=1)
    assert_raises(ValueError, mat._matvec, np.ones(3), out=np.zeros(7))
Exemple #2
0
 def func(itype, ftype, vtype, block_size):
     if np.dtype(itype).kind != 'u':
         ind = index
         exp = expected
     else:
         ind = index_u
         exp = expected_u
     input_ = np.array(input, vtype)
     if block_size == 2:
         input_ = np.array([input_, input_]).T.ravel()
         exp = np.array([exp, exp]).T.ravel()
     dtype = [('index', itype), ('value', ftype)]
     matrix = np.recarray((6, 1), dtype=dtype)
     matrix[..., 0].index = ind
     matrix[..., 0].value = value
     op = FSCMatrix((4, 6), data=matrix)
     out = op * np.array(input_, vtype)
     assert_same(out, exp)
     out[...] = 0
     op._matvec(np.array(input_, vtype), out=out)
     assert_same(out, exp)