Exemplo n.º 1
0
def spcolvec(x):
    y = c.dtrp(len(x), 1)
    for i in range(len(x)):
        y.push_back(i, 0, float(x[i]))
    z = c.dcsc(y)
    z.keep()
    return z
Exemplo n.º 2
0
def spcolvec(x):
    y = c.dtrp(len(x), 1)
    for i in range(len(x)):
        y.push_back(i, 0, float(x[i]))
    z = c.dcsc(y)
    z.keep()
    return z
Exemplo n.º 3
0
def random_col_vector(m, nnz):
    irn = numpy.random.random_integers(0, m-1, nnz).astype(numpy.uint64)
    irn = numpy.random.permutation(numpy.unique(irn));
    nzv = numpy.random.rand(nnz)    
    triplet_matrix = c.dtrp(m, 1, nnz)

    for ir, nz in zip(irn, nzv):
        triplet_matrix.push_back(int(ir), 0, nz)

    return c.dcsc(triplet_matrix)
Exemplo n.º 4
0
def random_col_vector(m, nnz):
    irn = numpy.random.random_integers(0, m - 1, nnz).astype(numpy.uint64)
    irn = numpy.random.permutation(numpy.unique(irn))
    nzv = numpy.random.rand(nnz)
    triplet_matrix = c.dtrp(m, 1, nnz)

    for ir, nz in zip(irn, nzv):
        triplet_matrix.push_back(int(ir), 0, nz)

    return c.dcsc(triplet_matrix)
Exemplo n.º 5
0
def build_matrix():
    N = 12;
    t = c.dtrp(N, N ,4*N)
    for row in range(N):
        t.push_back(int(row), int(row), 5.0);

    for row, col in trips:
        t.push_back(int(row), int(col), 2.0);
        t.push_back(int(col), int(row), 2.0);

    return c.dcsc(t)
Exemplo n.º 6
0
def build_matrix():
    N = 12
    t = c.dtrp(N, N, 4 * N)
    for row in range(N):
        t.push_back(int(row), int(row), 5.0)

    for row, col in trips:
        t.push_back(int(row), int(col), 2.0)
        t.push_back(int(col), int(row), 2.0)

    return c.dcsc(t)
Exemplo n.º 7
0
def sprand(m, n, s):
    nnz = int(m * n * s)
    row_idx = vect(np.random.random_integers(0, m - 1, nnz))
    col_idx = vect(np.random.random_integers(0, n - 1, nnz))
    vals = vect(np.random.rand(nnz))

    for d in range(0, min(m, n)):
        row_idx.push_back(int(d))
        col_idx.push_back(int(d))
        vals.push_back(float(1.0))

    tr = c.dtrp(m, n)

    for i, j, v in zip(row_idx, col_idx, vals):
        tr.push_back(i, j, v)

    return c.dcsc(tr)
Exemplo n.º 8
0
def sprand(m, n, s):
    nnz = int(m * n * s)
    row_idx = vect(np.random.random_integers(0, m - 1, nnz))
    col_idx = vect(np.random.random_integers(0, n - 1, nnz))
    vals    = vect(np.random.rand(nnz))
    
    for d in range(0, min(m, n)):
        row_idx.push_back(int(d))
        col_idx.push_back(int(d))
        vals.push_back(float(1.0))

    tr = c.dtrp(m, n)

    for i, j, v in zip(row_idx, col_idx, vals):
        tr.push_back(i, j, v)
    
    return c.dcsc(tr)
Exemplo n.º 9
0
import cppsparse as c

x = c.dtrp("fem.dat")
y = c.dcsc(x)
y.sum_duplicates()
m = y.n_rows()
n = y.n_cols()
print m, n
cs = c.dvec(n, 2.0)
rs = c.dvec(m, 3.0)
print (y.find())
y.scale(rs, cs)
print (y.find())
Exemplo n.º 10
0
def upper_tri_full(m, n):
    u = c.dtrp(m, n)
    for col in range(n):
        for row in range(col, m):
            u.push_back(col, row, float(row + col * m))
    return c.dcsc(u)
Exemplo n.º 11
0
def lower_tri_full(m, n):
    l = c.dtrp(m, n)
    for col in range(n):
        for row in range(col, m):
            l.push_back(row, col, float(row + col * m))
    return c.dcsc(l)
Exemplo n.º 12
0
import cppsparse as c

def random_triplet (m, n, nnz):
    import numpy as np
    row_idx = np.random.random_integers(0, m-1, nnz)
    col_idx = np.random.random_integers(0, n-1, nnz)
    nz__val = np.random.rand(10)

    trip = c.dtrp(m, n, nnz)
    
    for i,j,v in zip(row_idx, col_idx, nz__val):
        print i, j, v
        trip.push_back(int(i), int(j), float(v))

    return trip


x = c.dcsc(random_triplet(8, 8, 20))
##print(x)
#print(x.find())
x.sort()
##print(x.find())








Exemplo n.º 13
0
def upper_tri_full(m, n):
    u = c.dtrp(m, n)
    for col in range(n):
        for row in range(col, m):
            u.push_back(col, row, float(row + col * m))
    return c.dcsc(u)
Exemplo n.º 14
0
def lower_tri_full(m, n):
    l = c.dtrp(m, n)
    for col in range(n):
        for row in range(col, m):
            l.push_back(row, col, float(row + col * m))
    return c.dcsc(l)
Exemplo n.º 15
0
import cppsparse as cp
x = cp.dcsc(cp.dtrp("fem.dat"))
x.sum_duplicates()
print(x)
Exemplo n.º 16
0
import cppsparse as c


def random_triplet(m, n, nnz):
    import numpy as np
    row_idx = np.random.random_integers(0, m - 1, nnz)
    col_idx = np.random.random_integers(0, n - 1, nnz)
    nz__val = np.random.rand(10)

    trip = c.dtrp(m, n, nnz)

    for i, j, v in zip(row_idx, col_idx, nz__val):
        print i, j, v
        trip.push_back(int(i), int(j), float(v))

    return trip


x = c.dcsc(random_triplet(8, 8, 20))
##print(x)
#print(x.find())
x.sort()
##print(x.find())
Exemplo n.º 17
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))
Exemplo n.º 18
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))
Exemplo n.º 19
0
    for i in range(len(x)):
        y.push_back(i, 0, float(x[i]))
    z = c.dcsc(y)
    z.keep()
    return z


lower_tri = c.dtrp(5, 5)
full_sym = c.dtrp(5, 5)
upper_tri = c.dtrp(5, 5)
y = c.dtrp(5, 1)

for col in range(5):
    for row in range(col, 5):
        lower_tri.push_back(row, col, float(row + col * 5.0))
        full_sym.push_back(row, col, float(row + col * 5.0))
        upper_tri.push_back(col, row, float(row + col * 5.0))
        if row != col:
            full_sym.push_back(col, row, float(row + col * 5.0))

lower_tri = c.dcsc(lower_tri)
upper_tri = c.dcsc(upper_tri)
full_sym = c.dcsc(full_sym)

b = spcolvec(n.array([3.0, 4.0, 0, 0, 2.0]))
z = lower_tri.multiply2(upper_tri)
print(z)
B = nfull(b)
print(n.dot(nfull(lower_tri), nfull(upper_tri)))
print(nfull(z))
Exemplo n.º 20
0
        y.push_back(i, 0, float(x[i]))
    z = c.dcsc(y)
    z.keep()
    return z

lower_tri = c.dtrp(5, 5)
full_sym  = c.dtrp(5, 5)
upper_tri = c.dtrp(5, 5)
y         = c.dtrp(5, 1)

for col in range(5):
    for row in range(col, 5):
        lower_tri.push_back(row, col, float(row + col * 5.0))
        full_sym.push_back (row, col, float(row + col * 5.0))
        upper_tri.push_back (col, row, float(row + col * 5.0))
        if row != col:
            full_sym.push_back (col, row, float(row + col * 5.0))


lower_tri = c.dcsc(lower_tri)
upper_tri = c.dcsc(upper_tri)
full_sym  = c.dcsc(full_sym)


b = spcolvec(n.array([3.0,4.0,0,0,2.0]))
z = lower_tri.multiply2(upper_tri)
print(z)
B = nfull(b)
print(n.dot(nfull(lower_tri), nfull(upper_tri)))
print(nfull(z))
Exemplo n.º 21
0
import cppsparse as c
x = c.dtrp("data.txt")
print(x)
y = c.dcsc(x)
print(y)
print(y == y)
t = y.transpose()
print(t)
u = t.transpose()
print(u)
v = u.transpose()
print(v.find())