asnp() strange behavior
Issue #63
new
the asnp() function has always been 'dangerous', in that the returned object does not own the data that it refers to. However, some change in swig or numpy seems to have broken the returned numpy objects. The following code shows that a simple subtraction does not work as intended with an asnp() object:
#python
import PyCA.Common as common
import numpy as np
sz = [128,120,1]
imarr = np.random.rand(*sz)
I = common.ImFromNPArr(imarr)
# I = common.RandImage(self.sz, nSig=1.0, gSig=4.0,
# mType = MEM_HOST)
Iarr = I.asnp()
Iarrcopy = I.asnp().copy()
diff = Iarr-Iarrcopy
diff2 = Iarrcopy-imarr
print 'difference of asnp() and asnp().copy(): ', np.sum(np.abs(diff))
print 'difference of asnp().copy() and original array: ', np.sum(np.abs(diff2))
gives the output
difference of asnp() and asnp().copy(): 5143.09
difference of asnp().copy() and original array: 0.00015343035454
This seems very strange, the asnp().copy() version seems correct, but the asnp() alone does not. I'd like to verify this behavior on a different installation to see if it's numpy/swig version specific.
Comments (2)
-
reporter -
reporter Tested with SWIG 3.0.7 and numpy 1.8.0, do not see this behavior any longer:
difference of asnp() and asnp().copy(): 0.0 difference of asnp().copy() and original array: 0.000152864641595
- Log in to comment
some updates to PyCAIO, allow use of PIL if available, also remove some unsafe asnp() calls, see issue #63
→ <<cset b2594ecfbe4a>>