Esempio n. 1
0
    def testcopy_from_mat(self):
        for i in range(10):
            rows, cols = 10 * i, 5 * i
            A = Matrix(rows, cols)
            A.set_randn_()
            B = CuMatrix.new_from_size(*A.shape)
            B.copy_from_mat(A)
            self.assertAlmostEqual(A.sum(), B.sum(), places=4)

            A = CuMatrix.new_from_size(rows, cols)
            A.set_randn()
            B = CuMatrix.new_from_size(rows, cols)
            B.copy_from_cu_mat(A)
            self.assertAlmostEqual(A.sum(), B.sum(), places=4)
Esempio n. 2
0
    def testSwap(self):
        for i in range(10):
            dim = (10 * i, 4 * i)
            M = Matrix(np.random.random(dim))
            A = CuMatrix.new_from_matrix(M)
            B = CuMatrix.new_from_size(A.num_rows(), A.num_cols())
            B.Swap(A)
            self.assertAlmostEqual(A.sum(), B.sum(), places = 4) #Kaldi's precision is aweful
            self.assertAlmostEqual(M.sum(), B.sum(), places = 4) #Kaldi's precision is aweful

            C = CuMatrix.new_from_size(M.shape[0], M.shape[1])
            C.SwapWithMatrix(M)
            self.assertAlmostEqual(B.sum(), C.sum(), places = 4) #Kaldi's precision is aweful
Esempio n. 3
0
    def test__init__(self):
        m = Matrix()
        sb = SubMatrix(m)

        m = Matrix(5, 5)
        sb = SubMatrix(m)

        for i in range(100):
            m.set_randn_()
            self.assertAlmostEqual(m.sum(), sb.sum())

        m = DoubleMatrix()
        sb = SubMatrix(m)