Hi,
I tend to write too many things on the same line in Python and this caused an unexpected behavior for the numpy vnl bridge. It occurred in a different context but I have the following minimal example
Any clue what’s going on and if this can and should be corrected? It seems to be some memory release before the deep copy of the numpy array but I could not see what was wrong in the bridge code.
Thanks in advance!
Simon
No idea, but it is worth the look. Interestingly enough, since the implementation between images and VNL matrices are similar for the NumPy bridge, this problem could potentially arise with images…
This PR solves the problem on my computer. @simon.rit: Could you test it on your machine? It is not the solution I wanted to implement (I wanted to use a SWIG typemap), but I couldn’t get the other solution to work. So I think that for now this could be a reasonable patch.
If this works for you, would you mind improving the PR with a test?
Great, thanks a lot for your efforts. Yes, I’ll test and provide a test. I now understand the reference issue and can provide a simpler example for the problem, without some one line operation:
>>> m = itk.Matrix[itk.D,3,3]()
>>> m.SetIdentity()
>>> v = m.GetVnlMatrix()
>>> del m
>>> print(itk.GetArrayFromVnlMatrix(v.as_matrix()))
[[4.65884433e-310 0.00000000e+000 0.00000000e+000]
[0.00000000e+000 1.00000000e+000 0.00000000e+000]
[0.00000000e+000 0.00000000e+000 1.00000000e+000]]
I’ll base my test on this, just the time to recompile the wrapping with your master branch and your PR.