You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feature request: allow changing ndarray WRITABLE flag after ndarray construction #171
I want to write a function which creates, fills, and returns an ndarray in C++. The ndarray owns its memory, but should be non-writable for the user. I would therefore like to clear the WRITABLE flag after I finished filling it in my function. I studied the header and I see no way of doing this right now, because flags are not writable after creating an ndarray. For most flags this makes sense, the WRITABLE flag seems to be the only one which you may want to change manually.
This would be the generic solution, right, but it may open possibilities to wreck havoc with the internal consistency of the array. We could document this with a "use at your own peril" or something.
I'd rather not hand-hold users of the API. So if this is possible in the NumPy C API, I'm inclined to make it accessible in Boost.Python directly. But of course, proper documentation (including warning signs) would be helpful.
Activity
HDembinski commentedon Aug 1, 2018
Any chance that this will be implemented? Would you review a PR if I prepare one?
stefanseefeld commentedon Aug 1, 2018
Yes, it looks like a simple
ndarray::set_flags()method is missing, right ?HDembinski commentedon Aug 1, 2018
This would be the generic solution, right, but it may open possibilities to wreck havoc with the internal consistency of the array. We could document this with a "use at your own peril" or something.
When I look through the list of flags of the C-API
https://docs.scipy.org/doc/numpy/reference/c-api.array.html#c.NPY_ARRAY_C_CONTIGUOUS
I think only
NPY_ARRAY_WRITEABLEshould ever be changed after construction of the array. So perhaps a methodndarray::set_writeable(bool on)is sufficient.stefanseefeld commentedon Aug 1, 2018
I'd rather not hand-hold users of the API. So if this is possible in the NumPy C API, I'm inclined to make it accessible in Boost.Python directly. But of course, proper documentation (including warning signs) would be helpful.
HDembinski commentedon Aug 1, 2018
Ok!
HDembinski commentedon Aug 3, 2018
I submitted a PR. Some tests are failing, but this seems unrelated to the new code...