Python GenericMatrix.set docstring misleading

Bug #1063868 reported by Charl
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
DOLFIN
New
Undecided
Unassigned

Bug Description

We have a dolfin.cpp.Matrix called foo. The documentation for its set function:

-------------------------------------------
In [349]: foo.set?
Type: instancemethod
Base Class: <type 'instancemethod'>
String Form: <bound method Matrix.GenericMatrix_set of <dolfin.cpp.Matrix; proxy of <Swig Object of type 'boost::shared_ptr< dolfin::Matrix > *' at 0x491f030> >>
Namespace: Interactive
Docstring:
    **Overloaded versions**

    * set\ (block, num_rows, rows)

      Set block of values

    * set\ (block, m, rows, n, cols)

      Set block of values
-------------------------------------------

First, there seems to be no way to invoke the function in the second way: an error is always received about 4 arguments being expected, but 6 supplied.

Secondly, the parameter description 'block, num_rows, rows' is misleading. The role of these arguments appears to be 'target_rows' resp. 'target_cols'.

Example:

-------------------------------------------
In [350]: foo=Matrix(E)

In [351]: foo.zero()

In [352]: foo.set(np.array([[42,43,44],[45,46,47]], dtype='d'), np.array([2,5], dtype='I'), np.array([1,2,3], dtype='I'))

In [353]: foo.apply('add')

In [354]: foo.array()
Out[354]:
array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [ 0., 42., 43., 44., 0., 0., 0., 0., 0., 0., 0.],
       [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [ 0., 45., 46., 47., 0., 0., 0., 0., 0., 0., 0.],
       [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
       [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
-------------------------------------------

Revision history for this message
Johan Hake (johan-hake) wrote :

This is because we automatically generate documentation based on the C++ interface. Here you are actually invoking the last set version, but instead of 5 (or 6 as Python add self) arguments it expects 3, as m and rows, and n and cols are lumped together into one NumPy array argument.

In addition are the autogenerated documentation not taking into account that the first version is really not included in the swig interface, as it is %ignored.

These errors are difficult to fix. I have registered a new bug which more precisely describe the problem.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.