Ejemplo n.º 1
0
    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))
Ejemplo n.º 2
0
    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))
Ejemplo n.º 3
0
    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))
Ejemplo n.º 4
0
    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))
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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))
Ejemplo n.º 8
0
    (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))
Ejemplo n.º 9
0
def vect(n):
    v = c.ivec()
    for elem in n:
        v.push_back(int(elem))
    return v
Ejemplo n.º 10
0
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)