Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: allow changing ndarray WRITABLE flag after ndarray construction #171

Open
HDembinski opened this issue Nov 1, 2017 · 6 comments

Comments

@HDembinski
Copy link

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.

Is it possible to add this feature? Best regards!

@HDembinski
Copy link
Author

Any chance that this will be implemented? Would you review a PR if I prepare one?

@stefanseefeld
Copy link
Member

Yes, it looks like a simple ndarray::set_flags() method is missing, right ?

@HDembinski
Copy link
Author

HDembinski commented 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_WRITEABLE should ever be changed after construction of the array. So perhaps a method ndarray::set_writeable(bool on) is sufficient.

@stefanseefeld
Copy link
Member

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
Copy link
Author

Ok!

@HDembinski
Copy link
Author

I submitted a PR. Some tests are failing, but this seems unrelated to the new code...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants