def test_matvec_multiply_fc_f(self):
     """matrix multiply FORTRAN layout by C layout vector, explicit FORTRAN array output"""
     a = np.asfortranarray(np.random.randint(100, size=(M,N)))
     b = np.ascontiguousarray(np.random.randint(N, size=(N)))
     res = np.zeros(M, order='F')
     gulinalg.matvec_multiply(a,b, out=res)
     ref = np.dot(a,b)
     assert_allclose(res, ref)
 def test_matvec_multiply_fc_f(self):
     """matrix multiply FORTRAN layout by C layout vector, explicit FORTRAN array output"""
     a = np.asfortranarray(np.random.randint(100, size=(M, N)))
     b = np.ascontiguousarray(np.random.randint(N, size=(N)))
     res = np.zeros(M, order='F')
     gulinalg.matvec_multiply(a, b, out=res)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
 def test_matvec_multiply_fv_f(self):
     """Test for explicit FORTRAN array output for F layout input matrix"""
     a = np.asfortranarray(np.random.randn(M, N))
     b = np.ascontiguousarray(np.random.randn(N))
     res = np.zeros(M, order='F')
     gulinalg.matvec_multiply(a, b, out=res)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
 def test_matvec_multiply_fv_f(self):
     """Test for explicit FORTRAN array output for F layout input matrix"""
     a = np.asfortranarray(np.random.randn(M, N))
     b = np.ascontiguousarray(np.random.randn(N))
     res = np.zeros(M, order='F')
     gulinalg.matvec_multiply(a, b, out=res)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
 def test_matvec_multiply_batch_both_out_non_contiguous(self):
     """Multiply C layout stack of matrices and vectors"""
     a = np.random.randn(n_batch, M, N, 2)[..., 0]
     b = np.random.randn(n_batch, N, 2)[..., 0]
     res = np.zeros((n_batch, M, 2), dtype=a.dtype)[..., 0]
     for workers in [1, -1]:
         gulinalg.matvec_multiply(a, b, out=res)
         ref = np.matmul(a, b[:, :, np.newaxis])[..., 0]
         assert_allclose(res, ref)
 def test_input_non_contiguous_2(self):
     """Second input not contiguous"""
     a = np.ascontiguousarray(np.random.randn(M, N))
     b = np.ascontiguousarray(np.random.randn(N, 2))[:, 0]
     res = np.zeros(M, order='C')
     assert not b.flags.c_contiguous and not b.flags.f_contiguous
     gulinalg.matvec_multiply(a, b, out=res)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
 def test_output_non_contiguous(self):
     """Output not contiguous"""
     a = np.ascontiguousarray(np.random.randn(M, N))
     b = np.ascontiguousarray(np.random.randn(N))
     res = np.zeros((M, 2), order='C')[:, 0]
     assert not res.flags.c_contiguous and not res.flags.f_contiguous
     gulinalg.matvec_multiply(a, b, out=res)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
 def test_output_non_contiguous(self):
     """Output not contiguous"""
     a = np.ascontiguousarray(np.random.randn(M, N))
     b = np.ascontiguousarray(np.random.randn(N))
     res = np.zeros((M, 2), order='C')[:, 0]
     assert not res.flags.c_contiguous and not res.flags.f_contiguous
     gulinalg.matvec_multiply(a, b, out=res)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
 def test_input_non_contiguous_2(self):
     """Second input not contiguous"""
     a = np.ascontiguousarray(np.random.randn(M, N))
     b = np.ascontiguousarray(np.random.randn(N, 2))[:, 0]
     res = np.zeros(M, order='C')
     assert not b.flags.c_contiguous and not b.flags.f_contiguous
     gulinalg.matvec_multiply(a, b, out=res)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
示例#10
0
 def test_all_non_contiguous(self):
     """Neither input nor output contiguous"""
     a = np.ascontiguousarray(np.random.randn(M, N, 2))[:, :, 0]
     b = np.ascontiguousarray(np.random.randn(N, 2))[:, 0]
     res = np.zeros((M, 2), order='C')[:, 0]
     assert not a.flags.c_contiguous and not a.flags.f_contiguous
     assert not b.flags.c_contiguous and not b.flags.f_contiguous
     assert not res.flags.c_contiguous and not res.flags.f_contiguous
     gulinalg.matvec_multiply(a, b, out=res)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
 def test_all_non_contiguous(self):
     """Neither input nor output contiguous"""
     a = np.ascontiguousarray(np.random.randn(M, N, 2))[:, :, 0]
     b = np.ascontiguousarray(np.random.randn(N, 2))[:, 0]
     res = np.zeros((M, 2), order='C')[:, 0]
     assert not a.flags.c_contiguous and not a.flags.f_contiguous
     assert not b.flags.c_contiguous and not b.flags.f_contiguous
     assert not res.flags.c_contiguous and not res.flags.f_contiguous
     gulinalg.matvec_multiply(a, b, out=res)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
 def test_matvec_size_zero_vector(self):
     """Test vector of size zero"""
     a = np.random.randn(2, 0)
     b = np.random.randn(0)
     res = gulinalg.matvec_multiply(a, b)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
 def test_matvec_size_zero_matrix(self):
     """Test matrix of size zero"""
     a = np.random.randn(0, 2)
     b = np.random.randn(2)
     res = gulinalg.matvec_multiply(a, b)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
 def test_matvec_multiply_for_complex_numbers(self):
     """Test for complex numbers input."""
     a = np.array([[1 + 2j, 3 + 4j], [5 + 6j, 7 + -8j]])
     b = np.array([1 - 2j, 4 + 5j])
     res = gulinalg.matvec_multiply(a, b)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
 def test_matvec_multiply_f(self):
     """Multiply FORTRAN layout matrix with vector"""
     a = np.asfortranarray(np.random.randn(M, N))
     b = np.random.randn(N)
     res = gulinalg.matvec_multiply(a, b)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
 def test_matvec_multiply_c(self):
     """Multiply C layout matrix with vector"""
     a = np.ascontiguousarray(np.random.randn(M, N))
     b = np.random.randn(N)
     res = gulinalg.matvec_multiply(a, b)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
 def test_infinity_handling(self):
     """Infinity in one output shouldn't contaminate remaining outputs"""
     a = np.eye(2)
     b = np.array([[1.0, 2.0], [np.inf, 1.0]])
     ref = np.array([[1., 2.], [np.inf, np.nan]])
     res = gulinalg.matvec_multiply(a, b)
     assert_allclose(res, ref)
示例#18
0
 def test_matvec_size_one_vector(self):
     """Test vector of size one"""
     a = np.random.randn(1, 1)
     b = np.random.randn(1)
     res = gulinalg.matvec_multiply(a, b)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
 def test_matvec_size_one_vector(self):
     """Test vector of size one"""
     a = np.random.randn(1, 1)
     b = np.random.randn(1)
     res = gulinalg.matvec_multiply(a, b)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
示例#20
0
 def test_matvec_size_zero_vector(self):
     """Test vector of size zero"""
     a = np.random.randn(2, 0)
     b = np.random.randn(0)
     res = gulinalg.matvec_multiply(a, b)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
示例#21
0
 def test_matvec_multiply_for_complex_numbers(self):
     """Test for complex numbers input."""
     a = np.array([[1 + 2j, 3 + 4j], [5 + 6j, 7 + -8j]])
     b = np.array([1 - 2j, 4 + 5j])
     res = gulinalg.matvec_multiply(a, b)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
示例#22
0
 def test_matvec_size_zero_matrix(self):
     """Test matrix of size zero"""
     a = np.random.randn(0, 2)
     b = np.random.randn(2)
     res = gulinalg.matvec_multiply(a, b)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
示例#23
0
 def test_matvec_multiply_f(self):
     """Multiply FORTRAN layout matrix with vector"""
     a = np.asfortranarray(np.random.randn(M, N))
     b = np.random.randn(N)
     res = gulinalg.matvec_multiply(a, b)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
示例#24
0
 def test_infinity_handling(self):
     """Infinity in one output shouldn't contaminate remaining outputs"""
     a = np.eye(2)
     b = np.array([[1.0, 2.0], [np.inf, 1.0]])
     ref = np.array([[1., 2.], [np.inf, np.nan]])
     res = gulinalg.matvec_multiply(a, b)
     assert_allclose(res, ref)
示例#25
0
 def test_matvec_multiply_c(self):
     """Multiply C layout matrix with vector"""
     a = np.ascontiguousarray(np.random.randn(M, N))
     b = np.random.randn(N)
     res = gulinalg.matvec_multiply(a, b)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
示例#26
0
 def test_matvec_multiply_batch_both(self):
     """Multiply C layout stack of matrices and vectors"""
     a = np.ascontiguousarray(np.random.randn(n_batch, M, N))
     b = np.random.randn(n_batch, N)
     for workers in [1, -1]:
         res = gulinalg.matvec_multiply(a, b)
         ref = np.matmul(a, b[:, :, np.newaxis])[..., 0]
         assert_allclose(res, ref)
示例#27
0
 def test_size_one_vector(self):
     """Test broadcasting for vector of size one"""
     a = np.ascontiguousarray(np.random.randn(10, 1, 1))
     b = np.ascontiguousarray(np.random.randn(10, 1))
     res = gulinalg.matvec_multiply(a, b)
     assert res.shape == (10, 1)
     ref = np.stack([np.dot(a[i], b[i]) for i in range(len(a))])
     assert_allclose(res, ref)
示例#28
0
 def test_size_zero_matrix(self):
     """Test broadcasting for matrix of size zero"""
     a = np.ascontiguousarray(np.random.randn(10, 0, 2))
     b = np.ascontiguousarray(np.random.randn(10, 2))
     res = gulinalg.matvec_multiply(a, b)
     assert res.shape == (10, 0)
     ref = np.stack([np.dot(a[i], b[i]) for i in range(len(a))])
     assert_allclose(res, ref)
示例#29
0
 def test_broadcast(self):
     """test broadcast matrix multiply"""
     a = np.ascontiguousarray(np.random.randn(M, N))
     b = np.ascontiguousarray(np.random.randn(10, N))
     res = gulinalg.matvec_multiply(a, b)
     assert res.shape == (10, M)
     ref = np.stack([np.dot(a, b[i]) for i in range(len(b))])
     assert_allclose(res, ref)
 def test_broadcast(self):
     """test broadcast matrix multiply"""
     a = np.ascontiguousarray(np.random.randn(M, N))
     b = np.ascontiguousarray(np.random.randn(10, N))
     res = gulinalg.matvec_multiply(a, b)
     assert res.shape == (10, M)
     ref = np.stack([np.dot(a, b[i]) for i in range(len(b))])
     assert_allclose(res, ref)
 def test_size_zero_matrix(self):
     """Test broadcasting for matrix of size zero"""
     a = np.ascontiguousarray(np.random.randn(10, 0, 2))
     b = np.ascontiguousarray(np.random.randn(10, 2))
     res = gulinalg.matvec_multiply(a, b)
     assert res.shape == (10, 0)
     ref = np.stack([np.dot(a[i], b[i]) for i in range(len(a))])
     assert_allclose(res, ref)
 def test_size_one_vector(self):
     """Test broadcasting for vector of size one"""
     a = np.ascontiguousarray(np.random.randn(10, 1, 1))
     b = np.ascontiguousarray(np.random.randn(10, 1))
     res = gulinalg.matvec_multiply(a, b)
     assert res.shape == (10, 1)
     ref = np.stack([np.dot(a[i], b[i]) for i in range(len(a))])
     assert_allclose(res, ref)
 def test_stride_tricks(self):
     """Test that matrices that are contiguous but have their dimension
     overlapped *copy*, as BLAS does not support them"""
     a = np.ascontiguousarray(np.random.randn(M + N))
     a = np.lib.stride_tricks.as_strided(a,
                                         shape=(M, N),
                                         strides=(a.itemsize, a.itemsize))
     b = np.ascontiguousarray(np.random.randn(N))
     res = gulinalg.matvec_multiply(a, b)
     ref = np.dot(a, b)
     assert_allclose(res, ref)
示例#34
0
 def test_stride_tricks(self):
     """Test that matrices that are contiguous but have their dimension
     overlapped *copy*, as BLAS does not support them"""
     a = np.ascontiguousarray(np.random.randn(M + N))
     a = np.lib.stride_tricks.as_strided(a,
                                         shape=(M, N),
                                         strides=(a.itemsize, a.itemsize))
     b = np.ascontiguousarray(np.random.randn(N))
     res = gulinalg.matvec_multiply(a, b)
     ref = np.dot(a, b)
     assert_allclose(res, ref)