@@ -19,6 +19,7 @@ from cysparse.sparse.csr_mat_matrices.csr_mat_@index@_@type@ cimport MakeCSRSpar
1919from cysparse.sparse.csc_mat_matrices.csc_mat_@index@_@type@ cimport MakeCSCSparseMatrix_@index@_@type@
2020
2121from 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 """
0 commit comments