This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Trying to understand the get() method in the GenericMatrix class

0 votes

Hello,

The first argument of the method get() is documented as 'block'. Can anyone tell me what this refers to? Why isn't it sufficient to tell it the rows and columns to 'get' ?

Thanks,
Ben

asked May 2, 2016 by brk888 FEniCS Novice (990 points)

1 Answer

0 votes

The block argument is a preallocated array where get() will store the result (so as to keep memory management in the hands of the user of GenericMatrix). Basically you just create an empty numpy.ndarray with the right size beforehand and use that as argument.

The other arguments can be more confusing: There is a long standing bug with the python documentation automatically generated by SWIG, which has trouble with overloaded functions and ignores %typemaps defined in the interface files. You need to call

  get(block, row_indices, col_indices)

where row_indices and col_indices are of type numpy.ndarray with dtype=numpy.intc and block is a numpy.ndarray of type numpy.float and shape (len(row_indices), len(col_indices)).

set() behaves analogously.

answered Mar 11, 2017 by mdbenito FEniCS User (4,530 points)

I know it's a "bit" late for the answer, but I though it might be useful for other people struggling with these functions.

...