- edited description
GenericVector * numpy.float = numpy.array, not GenericVector
Issue #874
resolved
When multiplying a GenericVector
with a float, the result is a GenericVector
. When multiplying a GenericVector
with a numpy.float
, the result is a numpy.array
. Yikes!
This leads to all sorts of unexpected behavior since of course numpy.array
doesn't play well with FEniCS's methods.
It was hard to find this cause of the errors I got since print()
doesn't tell you about the difference between a float
and a numpy.float
.
MWE:
from dolfin import *
import numpy
mesh = UnitSquareMesh(10, 10)
V = FunctionSpace(mesh, 'CG', 1)
u = Function(V)
uvec = u.vector()
a = 1.23
b = numpy.sin(1.23)
print(type(b))
print(type(a * uvec))
print(type(b * uvec))
Output:
<class 'numpy.float64'>
<class 'dolfin.cpp.la.GenericVector'>
<class 'numpy.ndarray'>
Comments (5)
-
reporter -
Fix in next 057f08e
-
- changed milestone to 2017.2
- changed component to python interface
- marked as minor
-
assigned issue to
-
reporter Thanks!
-
- changed status to resolved
- Log in to comment