def setUp(self): self.c1 = mls.COONDArray(indices=np.asarray([(9, 5, 4), (7, 6, 5), (2, 2, 4), (7, 9, 4), (2, 2, 6)]), data=np.asarray([3, 4, 5, 3, 1]), shape=np.asarray([10, 11, 12])) self.c2 = mls.COONDArray(indices=np.asarray([(9, 5, 4), (2, 2, 4), (7, 9, 4), (2, 2, 6), (8, 4, 9)]), data=np.asarray([3, 5, 3, 1, 2]), shape=np.asarray([10, 11, 12])) self.c3 = mls.COONDArray(indices=np.asarray( [tuple(i - 1 for i in list(ind)) for ind in self.c1.indices]), data=np.asarray(self.c1.data), shape=np.asarray(self.c1.shape)) # self.s1 = sps.coo_matrix() # create dense numpy arrays with a similar shape and all zero values self.d1 = np.zeros(shape=self.c1.shape) self.d2 = np.zeros(shape=self.c2.shape) self.d3 = np.zeros(shape=self.c3.shape) # assign nnz val to the dense numpy array of each instance. # d stands for dense for i in range(len(self.c1.indices)): self.d1[tuple(self.c1.indices[i])] = self.c1.data[i] for i in range(len(self.c2.indices)): self.d2[tuple(self.c2.indices[i])] = self.c2.data[i] for i in range(len(self.c3.indices)): self.d3[tuple(self.c3.indices[i])] = self.c3.data[i]
def testCooCreation(self): # self.assert(mls.issparse(self.c1)) # type assertion only. REQUIRE: parameter assertion as well s = mls.COONDArray(self.c1) assert (isinstance(s, mls.COONDArray)) assert (isinstance(s, mls.SparseNDArray)) assert (mls.issparse(s)) assert (s.issparse())