def testEtreeRowColCounts(self): parent, rowcnt, colcnt = cppsparse.ivec(), cppsparse.ivec(), cppsparse.ivec() self.A.etree_row_column_counts(parent, rowcnt, colcnt) self.assertEqual(self.parent, list(parent)[1:-1]) self.assertEqual(self.rowcounts, list(rowcnt)) self.assertEqual(self.colcounts, list(colcnt))
def testFirstDescenentLevel(self): etree = self.A.etree_liu() post = self.A.postorder(etree) first = cppsparse.ivec() level = cppsparse.ivec() self.A.first_descendent(etree, post, first, level) self.assertEqual([0, 5, 1, 1, 6, 3, 5, 5, 1, 5, 1, 1], list(first)) self.assertEqual([0, 5, 4, 3, 5, 3, 4, 3, 2, 2, 1, 0], list(level))
def testEtreeRowColCounts(self): parent, rowcnt, colcnt = cppsparse.ivec(), cppsparse.ivec( ), cppsparse.ivec() self.A.etree_row_column_counts(parent, rowcnt, colcnt) self.assertEqual(self.parent, list(parent)[1:-1]) self.assertEqual(self.rowcounts, list(rowcnt)) self.assertEqual(self.colcounts, list(colcnt))
def vect(n): v = None if n.dtype == np.float64: v = c.dvec() for elem in n: v.push_back(float(elem)) elif n.dtype == np.int32 or n.dtype == np.int64: v = c.ivec() for elem in n: v.push_back(int(elem)) else: raise RuntimeError("Array must be float or integer") return v
def vect(n): v = None if n.dtype == np.float64: v = c.dvec(); for elem in n: v.push_back(float(elem)) elif n.dtype == np.int32 or n.dtype == np.int64: v = c.ivec() for elem in n: v.push_back(int(elem)) else: raise RuntimeError("Array must be float or integer") return v
import cppsparse as c ##import numpyinterface as n m = 15 conn = [(1, 3), (3, 5), (3, 8), (5, 8), (8, 10), (6, 9), (6, 10), (2, 4), (2, 7), (2, 9), (4, 9), (6, 9), (6, 10), (7, 10), (7, 11), (8, 10), (9, 12), (9, 13), (10, 11), (10, 13), (10, 14), (11, 12), (11, 13), (12, 13), (13, 14)] trip = c.dtrp(m, m, 2 * m) for i in range(m): trip.push_back(i, i, 1.0) for i, j in conn: trip.push_back(i, j, 1.0) G = c.dcsc(trip).transpose() print(G) #G.to_graph("tim.dot", True) rhs = c.dtrp(15, 1, 4) rhs.push_back(4, 0, 1.0) rhs.push_back(6, 0, 1.0) B = c.dcsc(rhs) top = G.reach(B, 0, c.ivec(m), c.ivec(m))
(8, 10), (9, 12), (9, 13), (10, 11), (10, 13), (10, 14), (11, 12), (11, 13), (12, 13), (13, 14), ] trip = c.dtrp(m, m, 2 * m) for i in range(m): trip.push_back(i, i, 1.0) for i, j in conn: trip.push_back(i, j, 1.0) G = c.dcsc(trip).transpose() print(G) # G.to_graph("tim.dot", True) rhs = c.dtrp(15, 1, 4) rhs.push_back(4, 0, 1.0) rhs.push_back(6, 0, 1.0) B = c.dcsc(rhs) top = G.reach(B, 0, c.ivec(m), c.ivec(m))
def vect(n): v = c.ivec() for elem in n: v.push_back(int(elem)) return v
import cppsparse as c x = c.dtrp("data.txt") print(x) row = c.ivec(5) print(row.size()) col = c.ivec(5) nnz = c.dvec(25) for i in range(5): row[i] = i col[i] = i for i in range(25): nnz[i] = i x.push_back(row, col, nnz) print(x)