0

Say I have a matrix M:

>>> print type(M)
<class 'pyop2.petsc_base.Mat'>
>>> dir(M)
['Snapshot', '_Assembly', '_Versioned__version', '__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__iter__', '__module__', '__mul__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slotnames__', '__str__', '__subclasshook__', '__weakref__', '_argtype', '_assemble', '_blocks', '_cow_actual_copy', '_datatype', '_force_evaluation', '_globalcount', '_init', '_init_block', '_init_monolithic', '_init_nest', '_is_scalar_field', '_is_vector_field', '_modes', '_name', '_needs_assembly', '_sparsity', '_version', '_version_before_zero', '_version_bump', '_version_set_zero', 'addto_values', 'assemble', 'blocks', 'cdim', 'create_snapshot', 'ctype', 'dim', 'dims', 'dtype', 'dump', 'duplicate', 'handle', 'name', 'nblock_cols', 'nblock_rows', 'nbytes', 'ncols', 'nrows', 'set_diagonal', 'set_local_diagonal_entries', 'set_values', 'sparsity', 'values', 'zero', 'zero_rows']

Documentation https://op2.github.io/PyOP2/user.html says, that M.sparsity.colidx holds "Column indices array of CSR data structure", while M.sparsity.rowptr holds "Row pointer array of CSR data structure", ok, so I have all needed coordinates to reconstruct the CSR matrix, but where does this CSR data structure live?

Moonwalker
  • 2,180
  • 1
  • 29
  • 48
  • I would create a small `M`, and compare the size and values of `M.values` with those `.colidx` and `rowptr` attributes. The sparsity attributes sound like they would match the attributes (and one input style) for `scipy.sparse.csr_matrix`. But that's just a guess. – hpaulj Oct 20 '15 at 16:41
  • @hpaulj thank you, but values contains all data (with zeros). But I found the solution -- one must use sp.csr_matrix(M.handle.getValuesCSR()[::-1]) which gives exactly what I need. – Moonwalker Oct 20 '15 at 22:24

0 Answers0