예제 #1
0
    def testMatmul(self):
        t1 = tensor([[0, 1, 0], [1, 0, 0]], chunk_size=2).tosparse()
        t2 = t1.T

        t3 = matmul(t1, t2, out=empty((2, 2), dtype=t1.dtype, order='F'))
        self.assertEqual(t3.order.value, 'F')

        with self.assertRaises(TypeError):
            matmul(t1, t2, out=1)

        with self.assertRaises(TypeError):
            matmul(t1, t2, out=empty((2, 2), dtype='?'))

        with self.assertRaises(ValueError):
            matmul(t1, t2, out=empty((3, 2), dtype=t1.dtype))

        raw1 = np.asfortranarray(np.random.rand(3, 3))
        raw2 = np.asfortranarray(np.random.rand(3, 3))
        raw3 = np.random.rand(3, 3)

        self.assertEqual(matmul(tensor(raw1), tensor(raw2)).flags['C_CONTIGUOUS'],
                         np.matmul(raw1, raw2).flags['C_CONTIGUOUS'])
        self.assertEqual(matmul(tensor(raw1), tensor(raw2)).flags['F_CONTIGUOUS'],
                         np.matmul(raw1, raw2).flags['F_CONTIGUOUS'])

        self.assertEqual(matmul(tensor(raw1), tensor(raw2), order='A').flags['C_CONTIGUOUS'],
                         np.matmul(raw1, raw2, order='A').flags['C_CONTIGUOUS'])
        self.assertEqual(matmul(tensor(raw1), tensor(raw2), order='A').flags['F_CONTIGUOUS'],
                         np.matmul(raw1, raw2, order='A').flags['F_CONTIGUOUS'])

        self.assertEqual(matmul(tensor(raw1), tensor(raw3), order='A').flags['C_CONTIGUOUS'],
                         np.matmul(raw1, raw3, order='A').flags['C_CONTIGUOUS'])
        self.assertEqual(matmul(tensor(raw1), tensor(raw3), order='A').flags['F_CONTIGUOUS'],
                         np.matmul(raw1, raw3, order='A').flags['F_CONTIGUOUS'])
예제 #2
0
파일: test_linalg.py 프로젝트: haijohn/mars
def test_matmul():
    t1 = tensor([[0, 1, 0], [1, 0, 0]], chunk_size=2).tosparse()
    t2 = t1.T

    t3 = matmul(t1, t2, out=empty((2, 2), dtype=t1.dtype, order='F'))
    assert t3.order.value == 'F'

    with pytest.raises(TypeError):
        matmul(t1, t2, out=1)

    with pytest.raises(TypeError):
        matmul(t1, t2, out=empty((2, 2), dtype='?'))

    with pytest.raises(ValueError):
        matmul(t1, t2, out=empty((3, 2), dtype=t1.dtype))

    raw1 = np.asfortranarray(np.random.rand(3, 3))
    raw2 = np.asfortranarray(np.random.rand(3, 3))
    raw3 = np.random.rand(3, 3)

    assert matmul(tensor(raw1), tensor(raw2)).flags['C_CONTIGUOUS'] == \
           np.matmul(raw1, raw2).flags['C_CONTIGUOUS']
    assert matmul(tensor(raw1), tensor(raw2)).flags['F_CONTIGUOUS'] == \
           np.matmul(raw1, raw2).flags['F_CONTIGUOUS']

    assert matmul(tensor(raw1), tensor(raw2), order='A').flags['C_CONTIGUOUS'] == \
           np.matmul(raw1, raw2, order='A').flags['C_CONTIGUOUS']
    assert matmul(tensor(raw1), tensor(raw2), order='A').flags['F_CONTIGUOUS'] == \
           np.matmul(raw1, raw2, order='A').flags['F_CONTIGUOUS']

    assert matmul(tensor(raw1), tensor(raw3), order='A').flags['C_CONTIGUOUS'] == \
           np.matmul(raw1, raw3, order='A').flags['C_CONTIGUOUS']
    assert matmul(tensor(raw1), tensor(raw3), order='A').flags['F_CONTIGUOUS'] == \
           np.matmul(raw1, raw3, order='A').flags['F_CONTIGUOUS']
예제 #3
0
    def testDot(self):
        t1 = tensor([[0, 1, 0], [1, 0, 0]], chunk_size=2).tosparse()
        t2 = t1.T

        self.assertTrue(t1.dot(t2).issparse())
        self.assertIs(type(t1.dot(t2)), SparseTensor)
        self.assertFalse(t1.dot(t2, sparse=False).issparse())
        self.assertIs(type(t1.dot(t2, sparse=False)), Tensor)

        with self.assertRaises(TypeError):
            dot(t1, t2, out=1)

        with self.assertRaises(ValueError):
            dot(t1, t2, empty((3, 6)))

        with self.assertRaises(ValueError):
            dot(t1, t2, empty((3, 3), dtype='i4'))

        with self.assertRaises(ValueError):
            dot(t1, t2, empty((3, 3), order='F'))

        t1.dot(t2, out=empty((2, 2), dtype=t1.dtype))
예제 #4
0
파일: test_linalg.py 프로젝트: haijohn/mars
def test_dot():
    t1 = tensor([[0, 1, 0], [1, 0, 0]], chunk_size=2).tosparse()
    t2 = t1.T

    assert t1.dot(t2).issparse() is True
    assert type(t1.dot(t2)) is SparseTensor
    assert t1.dot(t2, sparse=False).issparse() is False
    assert type(t1.dot(t2, sparse=False)) is Tensor

    with pytest.raises(TypeError):
        dot(t1, t2, out=1)

    with pytest.raises(ValueError):
        dot(t1, t2, empty((3, 6)))

    with pytest.raises(ValueError):
        dot(t1, t2, empty((3, 3), dtype='i4'))

    with pytest.raises(ValueError):
        dot(t1, t2, empty((3, 3), order='F'))

    t1.dot(t2, out=empty((2, 2), dtype=t1.dtype))