Skip to content

Commit 43538ef

Browse files
author
counterclocker
committed
decent printing: refactoring xxx_to_string()
1 parent 7caf910 commit 43538ef

93 files changed

Lines changed: 82318 additions & 39731 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/ll_mat_matrices/ll_mat.cpx

Lines changed: 7 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ from cysparse.sparse.csr_mat_matrices.csr_mat_@index@_@type@ cimport MakeCSRSpar
1919
from cysparse.sparse.csc_mat_matrices.csc_mat_@index@_@type@ cimport MakeCSCSparseMatrix_@index@_@type@
2020

2121
from cysparse.sparse.sparse_utils.generic.generate_indices_@index@ cimport create_c_array_indices_from_python_object_@index@
22+
from cysparse.sparse.sparse_utils.generic.print_@type@ cimport element_to_string_@type@, empty_to_string_@type@
2223

2324
########################################################################################################################
2425
# CySparse include
@@ -2392,7 +2393,7 @@ YOU HAVE TO CAST YOUR NEW TYPE HERE
23922393
####################################################################################################################
23932394
# String representations
23942395
####################################################################################################################
2395-
def at_to_string(self, @index@ i, @index@ j, @index@ cell_width=10):
2396+
def at_to_string(self, @index@ i, @index@ j, int cell_width=10):
23962397
"""
23972398
Return a string with a given element if it exists or an "empty" string.
23982399

@@ -2409,67 +2410,15 @@ YOU HAVE TO CAST YOUR NEW TYPE HERE
24092410
next_col = self.col[k]
24102411
if next_col >= j:
24112412
if next_col == j:
2412-
v = self.val[k]
2413-
{% if type in integer_list %}
2414-
exp = log(fabs(<FLOAT64_t> self.val[k]))
2415-
{% elif type == 'FLOAT32_t' %}
2416-
exp = log(fabsf(self.val[k]))
2417-
{% elif type == 'FLOAT64_t' %}
2418-
exp = log(fabs(self.val[k]))
2419-
{% elif type == 'FLOAT128_t' %}
2420-
exp = log(fabsl(self.val[k]))
2421-
{% elif type == 'COMPLEX64_t' %}
2422-
exp = log(cabsf(self.val[k]))
2423-
{% elif type == 'COMPLEX128_t' %}
2424-
exp = log(cabs(self.val[k]))
2425-
{% elif type == 'COMPLEX256_t' %}
2426-
exp = log(cabsl(self.val[k]))
2427-
{% else %}
2428-
YOU HAVE TO CAST YOUR NEW TYPE HERE
2429-
{% endif %}
2430-
if abs(exp) <= 4:
2431-
if exp < 0:
2432-
{% if type == 'COMPLEX64_t' %}
2433-
return ("%9.6f" % crealf(v)).ljust(cell_width) + '+' + ("%9.6fj" % cimagf(v)).ljust(cell_width)
2434-
{% elif type == 'COMPLEX128_t' %}
2435-
return ("%9.6f" % creal(v)).ljust(cell_width) + '+' + ("%9.6fj" % cimag(v)).ljust(cell_width)
2436-
{% elif type == 'COMPLEX256_t' %}
2437-
return ("%9.6f" % creall(v)).ljust(cell_width) + '+' + ("%9.6fj" % cimagl(v)).ljust(cell_width)
2438-
{% else %}
2439-
return ("%9.6f" % v).ljust(cell_width)
2440-
{% endif %}
2441-
2442-
else:
2443-
{% if type == 'COMPLEX64_t' %}
2444-
return ("%9.*f" % (6,crealf(v))).ljust(cell_width) + '+' + ("%9.*fj" % (6,cimagf(v))).ljust(cell_width)
2445-
{% elif type == 'COMPLEX128_t' %}
2446-
return ("%9.*f" % (6,creal(v))).ljust(cell_width) + '+' + ("%9.*fj" % (6,cimag(v))).ljust(cell_width)
2447-
{% elif type == 'COMPLEX256_t' %}
2448-
return ("%9.*f" % (6,creall(v))).ljust(cell_width) + '+' + ("%9.*fj" % (6,cimagl(v))).ljust(cell_width)
2449-
{% else %}
2450-
return ("%9.*f" % (6,v)).ljust(cell_width)
2451-
{% endif %}
2452-
2453-
else:
2454-
{% if type == 'COMPLEX64_t' %}
2455-
return ("%9.2e" % crealf(v)).ljust(cell_width) + '+' + ("%9.2ej" % cimagf(v)).ljust(cell_width)
2456-
{% elif type == 'COMPLEX128_t' %}
2457-
return ("%9.2e" % creal(v)).ljust(cell_width) + '+' + ("%9.2ej" % cimag(v)).ljust(cell_width)
2458-
{% elif type == 'COMPLEX256_t' %}
2459-
return ("%9.2e" % creall(v)).ljust(cell_width) + '+' + ("%9.2ej" % cimagl(v)).ljust(cell_width)
2460-
{% else %}
2461-
return ("%9.2e" % v).ljust(cell_width)
2462-
{% endif %}
2463-
2413+
#v = self.val[k]
2414+
return element_to_string_@type@(self.val[k], cell_width=cell_width)
24642415
else: # value not found
24652416
break
24662417

24672418
k = self.link[k]
2468-
{% if type in complex_list %}
2469-
return "---".center(cell_width) + ' ' + "---".center(cell_width)
2470-
{% else %}
2471-
return "---".center(cell_width)
2472-
{% endif %}
2419+
2420+
# element not found -> return empty cell
2421+
return empty_to_string_@type@(cell_width=cell_width)
24732422

24742423
def print_to(self, OUT, width=9, print_big_matrices=False, transposed=False):
24752424
"""

cysparse/sparse/ll_mat_matrices/ll_mat_INT32_t_COMPLEX128_t.c

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

cysparse/sparse/ll_mat_matrices/ll_mat_INT32_t_COMPLEX128_t.pyx

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ from cysparse.sparse.csr_mat_matrices.csr_mat_INT32_t_COMPLEX128_t cimport MakeC
1919
from cysparse.sparse.csc_mat_matrices.csc_mat_INT32_t_COMPLEX128_t cimport MakeCSCSparseMatrix_INT32_t_COMPLEX128_t
2020

2121
from cysparse.sparse.sparse_utils.generic.generate_indices_INT32_t cimport create_c_array_indices_from_python_object_INT32_t
22+
from cysparse.sparse.sparse_utils.generic.print_COMPLEX128_t cimport element_to_string_COMPLEX128_t, empty_to_string_COMPLEX128_t
2223

2324
########################################################################################################################
2425
# CySparse include
@@ -2218,7 +2219,7 @@ cdef class LLSparseMatrix_INT32_t_COMPLEX128_t(MutableSparseMatrix_INT32_t_COMPL
22182219
####################################################################################################################
22192220
# String representations
22202221
####################################################################################################################
2221-
def at_to_string(self, INT32_t i, INT32_t j, INT32_t cell_width=10):
2222+
def at_to_string(self, INT32_t i, INT32_t j, int cell_width=10):
22222223
"""
22232224
Return a string with a given element if it exists or an "empty" string.
22242225
@@ -2235,33 +2236,15 @@ cdef class LLSparseMatrix_INT32_t_COMPLEX128_t(MutableSparseMatrix_INT32_t_COMPL
22352236
next_col = self.col[k]
22362237
if next_col >= j:
22372238
if next_col == j:
2238-
v = self.val[k]
2239-
2240-
exp = log(cabs(self.val[k]))
2241-
2242-
if abs(exp) <= 4:
2243-
if exp < 0:
2244-
2245-
return ("%9.6f" % creal(v)).ljust(cell_width) + '+' + ("%9.6fj" % cimag(v)).ljust(cell_width)
2246-
2247-
2248-
else:
2249-
2250-
return ("%9.*f" % (6,creal(v))).ljust(cell_width) + '+' + ("%9.*fj" % (6,cimag(v))).ljust(cell_width)
2251-
2252-
2253-
else:
2254-
2255-
return ("%9.2e" % creal(v)).ljust(cell_width) + '+' + ("%9.2ej" % cimag(v)).ljust(cell_width)
2256-
2257-
2239+
#v = self.val[k]
2240+
return element_to_string_COMPLEX128_t(self.val[k], cell_width=cell_width)
22582241
else: # value not found
22592242
break
22602243

22612244
k = self.link[k]
22622245

2263-
return "---".center(cell_width) + ' ' + "---".center(cell_width)
2264-
2246+
# element not found -> return empty cell
2247+
return empty_to_string_COMPLEX128_t(cell_width=cell_width)
22652248

22662249
def print_to(self, OUT, width=9, print_big_matrices=False, transposed=False):
22672250
"""

0 commit comments

Comments
 (0)