Beispiel #1
0
    def test_set_bug_2(self):
        mat = [[0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1], [1, 0, 0, 0]]
        n = 4
        csr = CSR()
        csr.load(mat)

        for i in range(n):
            for j in range(n):
                self.assertEquals(mat[i][j], csr.get(i, j))
        rand = random.random()

        print(mat)
        print(csr)

        mat[1][1] = rand
        csr.set(1, 1, rand)

        print(mat)
        print(csr)
        self.assertEquals(mat[1][0], csr.get(1, 0))

        print(mat)
        print(csr)

        for i in range(n):
            for j in range(n):
                self.assertEquals(mat[i][j], csr.get(i, j))
Beispiel #2
0
    def test_get(self):
        for n in [10, 50, 100, 500]:
            with self.subTest(i=n):
                mat2 = randomizeMatrix(n)
                csr_sci = sparse.csr_matrix(mat2)
                csr = CSR()
                csr.load(mat2)

                for i in range(n):
                    for j in range(n):
                        self.assertEquals(mat2[i][j], csr.get(i, j))
Beispiel #3
0
    def test_load(self):
        for n in [10, 50, 100, 500]:
            with self.subTest(i=n):
                mat2 = randomizeMatrix(n)
                csr_sci = sparse.csr_matrix(mat2)
                csr = CSR()
                csr.load(mat2)

                for index, i in enumerate(csr_sci.data):
                    self.assertEquals(i, csr.val[index])
                    self.assertEquals(csr.col_ind[index],
                                      csr_sci.indices[index])

                for id, j in enumerate(csr_sci.indptr):
                    self.assertEquals(j, csr.row_ptr[id])
Beispiel #4
0
    def test_set_Diag(self):
        for n in [4, 10, 50, 100]:
            mat2 = randomizeMatrix(n)
            csr = CSR()
            csr.load(mat2)
            for i in range(n):
                rand = random.random()
                mat2[i][i] = rand
                csr.set(i, i, rand)
                print(mat2)
                self.assertEquals(rand, csr.get(i, i))

            csr2 = CSR(mat2)
            for i in range(n):
                for j in range(n):
                    self.assertEquals(mat2[i][j], csr2.get(i, j))