### DeprecationWarning when multiplying function by array

462
views
0
7 months ago by
Dear community.

I just upgraded to FEniCS 2017.2.0.dev0 (using Arch Linux and Python3) and I got the warning that "GenericVector.array() is being deprecated, use GenericVector.get_local()". Fair enough! However, this warning occurs when I'm multiplying a function by a numpy vector of elements like in the following MWE:

from dolfin import *
import numpy as np

mesh = UnitSquareMesh(8,8)
V = FunctionSpace(mesh, 'CG', 1)
u = Function(V)

x = np.ones(u.vector().get_local().shape) # No problem to use get_local() here...
u.vector()[:] *= x # ...but what about here?​

The last line outputs

/usr/lib/python3.6/site-packages/dolfin/cpp/la.py:1331: DeprecationWarning: GenericVector.array() is being deprecated, use GenericVector.get_local()
"use GenericVector.get_local()", DeprecationWarning)
/usr/lib/python3.6/site-packages/dolfin/cpp/la.py:1331: DeprecationWarning: GenericVector.array() is being deprecated, use GenericVector.get_local()
"use GenericVector.get_local()", DeprecationWarning)
/usr/lib/python3.6/site-packages/dolfin/cpp/la.py:1331: DeprecationWarning: GenericVector.array() is being deprecated, use GenericVector.get_local()
"use GenericVector.get_local()", DeprecationWarning)​

The FEniCS tutorial ( https://fenicsproject.org/pub/tutorial/html/._ftut1020.html ) is not yet updated in this respect so I was wondering; What is the correct way to do this now?

Thank you!
Community: FEniCS Project

1
7 months ago by
The problem here is that vector.array() is used by the __getitem__() method. This is all happening in the SWIG interface layer, which is being removed anyway soon, and is not being maintained at this point. The new interface will use pybind11, so should fix this warning. If you have the development version, you should be able to find the new pybind11 interface in the "python" directory at the top level.
This looks like a bug to me. It probably goes through GenericVector.__iter__ which calls self.array(). There is no reason why u.vector()[:] *= a should not be supported.
written 7 months ago by Jan Blechta
Yes it should be supported. Somebody needs to edit the post.i file in dolfin/swig/la to get around this error in the short term. Long term it will be supported by pybind11.
written 7 months ago by Chris Richardson
I wish I was part of your development crew so I could figure out how you guys made all the magic happen.
written 7 months ago by pf4d
Don't be shy with the contributions then. See the contributing guide https://fenicsproject.org/community/ ;)
written 7 months ago by Jan Blechta
Registered as https://bitbucket.org/fenics-project/dolfin/issues/961.
written 7 months ago by Jan Blechta
Fixed in master. [Blah blah at least 20 characters are needed for a comment\$%^&*(]
written 6 months ago by Jan Blechta
0
7 months ago by
I see. So then it'll go away in the future. I'm not sure if I want to spend time on figuring out of pybind11 (no experience with it) but I suppose this means that when I use the [:] operator what actually happens is something similar to this?

u_arr = u.vector().get_local()
u_arr *= x
u.vector().set_local(u_arr)​

If so I can just use that snippet instead.