Beispiel #1
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))
 def test_90PrecentZerosAll(self):
     for i in [10, 50, 100, 500, 1000, 5000]:
         with self.subTest(i == i):
             randMat = randomizeMatrix(i)
             nonZerosCount = 0
             total = 0
             for row in randMat:
                 nonZeros = [1 for i in row if i != 0.0]
                 nonZerosCount += sum(nonZeros)
                 total += len(row)
             self.assertEquals(
                 90.0, floor((total - nonZerosCount) * 100.0 / total))
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))
Beispiel #5
0
    def test_set(self):
        for n in [4, 10, 50, 100]:
            mat2 = randomizeMatrix(n)
            csr = CSR(mat2)

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

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