> On Feb 11, 2020, at 13:24, HOUSSEN Franck <fghous...@gmail.com> wrote: > > Finally able to reproduce the "real" problem with a "dummy" example : seems > that, at python side, when you use "np.append" C++ get screwed data ?!... > (note that with or without "np.append" all is OK at python side). > Can somebody help here ? Known problem ? Possible workaround or fix ? Should > I open a bug for that ? (if yes where)
This is a side-effect of how np.append() broadcasts its arguments to find a common type. You've asked it to append a Python float (which is secretly a double) to an array of np.float32. The only safe way to do that is to cast both to numpy.float64, which np.append() happily does for you. Before you reinterpret_cast the data pointer of an ndarray to a given type, you need to check whether the dtype is compatible (and also, strictly speaking, whether the flags are CARRAY or CARRAY_RO). There's a whole lot more background information in the Numpy C API docs: https://docs.scipy.org/doc/numpy/reference/c-api.html Cheers, Jakob _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org https://mail.python.org/mailman/listinfo/cplusplus-sig