Skip to content

Commit 5855e96

Browse files
author
counterclocker
committed
added NonZeros context manager, memory indicators
1 parent c2c9280 commit 5855e96

9 files changed

Lines changed: 3324 additions & 1296 deletions

File tree

examples/mul.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
2222
print "*" * 80
2323

2424
RC = R * C
25-
print RC
25+
print RC
26+
RC.print_to(sys.stdout)

examples/umfpack.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from sparse_lib.sparse.ll_mat import MakeLLSparseMatrix
22
import sparse_lib.solvers.suitesparse.umfpack as umfpack
33

4+
import sys
5+
46
import numpy
57

68
A = MakeLLSparseMatrix(size=4)
@@ -43,7 +45,9 @@
4345
(L, U, P, Q, D, do_recip, R) = solver.get_LU()
4446

4547
print L
48+
L.print_to(sys.stdout)
4649
print U
50+
U.print_to(sys.stdout)
4751
print P
4852
print Q
4953
print D
@@ -55,7 +59,18 @@
5559
LU = L * U
5660

5761

58-
print "heheh"
62+
print "heheh" * 20
5963
print LU
6064
import sys
65+
LU.print_to(sys.stdout)
66+
67+
print LU.memory_virtual()
68+
print LU.memory_element()
69+
print LU.memory_real()
70+
71+
LU.compress()
72+
73+
print "new matrix:"
74+
75+
print LU.memory_real()
6176
LU.print_to(sys.stdout)

sparse_lib/sparse/csr_mat.c

Lines changed: 65 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sparse_lib/sparse/csr_mat.pyx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,19 @@ cdef LLSparseMatrix multiply_csr_mat_by_csc_mat(CSRSparseMatrix A, CSCSparseMatr
393393
int i, j, k
394394
int sum
395395

396-
for i from 0 <= i < A.nrow:
397-
for j from 0 <= j < A.ncol:
396+
# don't keep zeros, no matter what
397+
cdef bint old_store_zeros = store_zeros
398+
C.store_zeros = 0
399+
400+
for i from 0 <= i < C_nrow:
401+
for j from 0 <= j < C_ncol:
398402
sum = 0
399403

400-
for k from 0 <= k < A.ncol:
401-
sum += A[i, k] * B[k, j]
404+
for k from 0 <= k < A_ncol:
405+
sum += (A[i, k] * B[k, j])
402406

403407
C.put(i, j, sum)
404408

409+
C.store_zeros = old_store_zeros
405410

406411
return C

0 commit comments

Comments
 (0)