- edited description
Type dolfin.Vector unhashable
Hi All,
I recently installed fenics 2017.1.0.dev0 (with python 3.5.2), as well as CBC-Block (used 2to3 tool for conversion), and found that applying the boundary conditions to a block_mat
object failed because an object of type dolfin.Vector
is not hashable. Thus, this Vector object cannot be added to the set of objects in object_pool
since it must be hashable. On the other hand, dolfin.Matrix
does not have this issue. Here is an example with minimal code:
import dolfin as dlf
A = dlf.Matrix()
b = dlf.Vector()
hash(A) # Works fine
hash(b) # Raises exception
I tried the above code with dolfin 2016.1.0 and 2016.2.0.dev0 (both with python 2.7.12), and this issue is not present.
I believe python 3 requires a __hash__
function when __eq__
is overwritten, which is the case for GenericVector
.
Comments (6)
-
reporter -
reporter - edited description
-
How should a hash be computed? (I can see that changing numerical values of a matrix does not influence its hash.) Maybe we can just hash
Variable::id()
? -
First question is how/why it works for
Matrix
types. -
reporter The
GenericVector
class in the swig-generated file./site-packages/dolfin/cpp/la.py
contains the__eq__
without a__hash__
function, but theGenericMatrix
andMatrix
classes do not. I looked at the cpp header files, but I can't tell what is causing__eq__
to be generated since there is nooperator==
defined (and I am also not too familiar with swig).As for the hash not being influenced by the numerical values of a matrix; isn't the point of hash to "tag" a particular value even if they are different objects? I realize
dolfin.Matrix
anddolfin.Vector
objects are really proxies of swig objects, and thus their "value" might mean something different here. -
- removed milestone
- Log in to comment