spacepaste

  1.  
  2. import numy as np
  3. a = np.arange(24, dtype='f8').reshape(2, 3, 4).T
  4. it = np.nditer(a, [],[['readwrite', 'updateifcopy']],casting='same_kind',op_dtypes=[np.dtype('f4')])
  5. op = it.operands[0]
  6. x = op[1:-1] # x is a view into op
  7. x[...] = 14
  8. assert x.base.flags.writebackifcopy is True
  9. assert (x.base.base is a) is True
  10. it.resolve_writeback() # new method to resolve writebacks
  11. it.operands[0][0] #segfaults
  12. assert op.ctypes.data == 0 # writeback has finished, op is no longer a valid ndarray
  13. x.base # segfault
  14.