Skip to content

Commit cbe3b50

Browse files
author
counterclocker
committed
printing for matrix like objects (except for LLSparseMatrixView)
1 parent aa77520 commit cbe3b50

70 files changed

Lines changed: 43276 additions & 25782 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cysparse/sparse/csc_mat_matrices/csc_mat.cpx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ from cysparse.sparse.s_mat cimport unexposed_value
1212
from cysparse.sparse.s_mat_matrices.s_mat_@index@_@type@ cimport ImmutableSparseMatrix_@index@_@type@
1313
from cysparse.sparse.ll_mat_matrices.ll_mat_@index@_@type@ cimport LLSparseMatrix_@index@_@type@
1414

15+
from cysparse.sparse.sparse_utils.generic.print_@type@ cimport element_to_string_@type@, conjugated_element_to_string_@type@, empty_to_string_@type@
16+
1517
########################################################################################################################
1618
# Cython, NumPy import/cimport
1719
########################################################################################################################
@@ -377,9 +379,41 @@ YOU HAVE TO EXPLICITY CAST YOUR TYPE
377379
####################################################################################################################
378380
# String representations
379381
####################################################################################################################
380-
def __repr__(self):
381-
s = "CSCSparseMatrix of size %d by %d with %d non zero values" % (self.nrow, self.ncol, self.nnz)
382-
return s
382+
def at_to_string(self, @index@ i, @index@ j, int cell_width=10):
383+
"""
384+
Return a string with a given element if it exists or an "empty" string.
385+
386+
387+
"""
388+
cdef:
389+
@index@ k
390+
391+
for k from self.ind[j] <= k < self.ind[j+1]:
392+
if i == self.row[k]:
393+
return element_to_string_@type@(self.val[k], cell_width=cell_width)
394+
395+
# element not found -> return empty cell
396+
return empty_to_string_@type@(cell_width=cell_width)
397+
398+
def at_conj_to_string(self, @index@ i, @index@ j, int cell_width=10):
399+
"""
400+
Return a string with a given element if it exists or an "empty" string.
401+
402+
403+
"""
404+
cdef:
405+
@index@ k
406+
407+
for k from self.ind[j] <= k < self.ind[j+1]:
408+
if i == self.row[k]:
409+
return conjugated_element_to_string_@type@(self.val[k], cell_width=cell_width)
410+
411+
# element not found -> return empty cell
412+
return empty_to_string_@type@(cell_width=cell_width)
413+
414+
#def __repr__(self):
415+
# s = "CSCSparseMatrix of size %d by %d with %d non zero values" % (self.nrow, self.ncol, self.nnz)
416+
# return s
383417

384418
def print_to(self, OUT):
385419
"""

cysparse/sparse/csc_mat_matrices/csc_mat_INT32_t_COMPLEX128_t.c

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

cysparse/sparse/csc_mat_matrices/csc_mat_INT32_t_COMPLEX128_t.pyx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ from cysparse.sparse.s_mat cimport unexposed_value
1212
from cysparse.sparse.s_mat_matrices.s_mat_INT32_t_COMPLEX128_t cimport ImmutableSparseMatrix_INT32_t_COMPLEX128_t
1313
from cysparse.sparse.ll_mat_matrices.ll_mat_INT32_t_COMPLEX128_t cimport LLSparseMatrix_INT32_t_COMPLEX128_t
1414

15+
from cysparse.sparse.sparse_utils.generic.print_COMPLEX128_t cimport element_to_string_COMPLEX128_t, conjugated_element_to_string_COMPLEX128_t, empty_to_string_COMPLEX128_t
16+
1517
########################################################################################################################
1618
# Cython, NumPy import/cimport
1719
########################################################################################################################
@@ -369,9 +371,41 @@ cdef class CSCSparseMatrix_INT32_t_COMPLEX128_t(ImmutableSparseMatrix_INT32_t_CO
369371
####################################################################################################################
370372
# String representations
371373
####################################################################################################################
372-
def __repr__(self):
373-
s = "CSCSparseMatrix of size %d by %d with %d non zero values" % (self.nrow, self.ncol, self.nnz)
374-
return s
374+
def at_to_string(self, INT32_t i, INT32_t j, int cell_width=10):
375+
"""
376+
Return a string with a given element if it exists or an "empty" string.
377+
378+
379+
"""
380+
cdef:
381+
INT32_t k
382+
383+
for k from self.ind[j] <= k < self.ind[j+1]:
384+
if i == self.row[k]:
385+
return element_to_string_COMPLEX128_t(self.val[k], cell_width=cell_width)
386+
387+
# element not found -> return empty cell
388+
return empty_to_string_COMPLEX128_t(cell_width=cell_width)
389+
390+
def at_conj_to_string(self, INT32_t i, INT32_t j, int cell_width=10):
391+
"""
392+
Return a string with a given element if it exists or an "empty" string.
393+
394+
395+
"""
396+
cdef:
397+
INT32_t k
398+
399+
for k from self.ind[j] <= k < self.ind[j+1]:
400+
if i == self.row[k]:
401+
return conjugated_element_to_string_COMPLEX128_t(self.val[k], cell_width=cell_width)
402+
403+
# element not found -> return empty cell
404+
return empty_to_string_COMPLEX128_t(cell_width=cell_width)
405+
406+
#def __repr__(self):
407+
# s = "CSCSparseMatrix of size %d by %d with %d non zero values" % (self.nrow, self.ncol, self.nnz)
408+
# return s
375409

376410
def print_to(self, OUT):
377411
"""

0 commit comments

Comments
 (0)