Beispiel #1
0
    def test_gram_matrix_sp(self):
        mat2 = gram_matrix_mkl(self.mat1)
        npt.assert_array_almost_equal(mat2.A, self.gram_ut)

        with self.assertRaises(ValueError):
            gram_matrix_mkl(self.mat1,
                            out=np.zeros(
                                (self.mat1.shape[0], self.mat1.shape[0])))
Beispiel #2
0
    def test_gram_matrix_dd_single(self):
        mat2 = gram_matrix_mkl(self.mat1.astype(np.float32).A, dense=True)
        npt.assert_array_almost_equal(mat2, self.gram_ut)

        mat2 = gram_matrix_mkl(self.mat1.astype(np.float32).A,
                               dense=True,
                               out=np.zeros(
                                   (self.mat1.shape[1], self.mat1.shape[1]),
                                   dtype=np.float32),
                               out_scalar=1.)
        npt.assert_array_almost_equal(mat2, self.gram_ut)
Beispiel #3
0
    def test_gram_matrix_d(self):
        mat2 = gram_matrix_mkl(self.mat1, dense=True)
        npt.assert_array_almost_equal(mat2, self.gram_ut)

        mat2 = gram_matrix_mkl(self.mat1,
                               dense=True,
                               out=np.zeros(
                                   (self.mat1.shape[1], self.mat1.shape[1]),
                                   dtype=np.float64),
                               out_scalar=1.)
        mat2[np.tril_indices(mat2.shape[0], k=-1)] = 0.
        npt.assert_array_almost_equal(mat2, self.gram_ut)
Beispiel #4
0
    def test_gram_matrix_dd_double_F(self):
        mat2 = gram_matrix_mkl(np.asarray(self.mat1.A, order="F"), dense=True)
        npt.assert_array_almost_equal(mat2, self.gram_ut)

        mat2 = gram_matrix_mkl(np.asarray(self.mat1.A, order="F"),
                               dense=True,
                               out=np.zeros(
                                   (self.mat1.shape[1], self.mat1.shape[1]),
                                   dtype=np.float64,
                                   order="F"),
                               out_scalar=1.)
        npt.assert_array_almost_equal(mat2, self.gram_ut)
Beispiel #5
0
    def test_gram_matrix_d_single(self):
        mat2 = gram_matrix_mkl(self.mat1.astype(np.float32), dense=True)
        npt.assert_array_almost_equal(mat2, self.gram_ut)

        mat2 = gram_matrix_mkl(self.mat1.astype(np.float32),
                               dense=True,
                               out=np.zeros(
                                   (self.mat1.shape[1], self.mat1.shape[1]),
                                   dtype=np.float32),
                               out_scalar=1.)
        mat2[np.tril_indices(mat2.shape[0], k=-1)] = 0.
        npt.assert_array_almost_equal(mat2, self.gram_ut)

        with self.assertRaises(ValueError):
            mat2 = gram_matrix_mkl(self.mat1.astype(np.float32),
                                   dense=True,
                                   out=np.zeros((self.mat1.shape[1],
                                                 self.mat1.shape[1])),
                                   out_scalar=1.)
Beispiel #6
0
 def test_gram_matrix_csc_d(self):
     mat2 = gram_matrix_mkl(self.mat1.tocsc(), dense=True, cast=True)
     npt.assert_array_almost_equal(mat2, self.gram_ut)
Beispiel #7
0
 def test_gram_matrix_d_t(self):
     mat2 = gram_matrix_mkl(self.mat1, dense=True, transpose=True)
     npt.assert_array_almost_equal(mat2, self.gram_ut_t)
Beispiel #8
0
 def test_gram_matrix_sp_single(self):
     mat2 = gram_matrix_mkl(self.mat1.astype(np.float32))
     npt.assert_array_almost_equal(mat2.A, self.gram_ut)