Skip to content

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

Open

Description

@HDembinski

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!

Activity

  1. HDembinski commented on Aug 1, 2018

    @HDembinski
    Author

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

  2. stefanseefeld commented on Aug 1, 2018

    @stefanseefeld
    Member

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

  3. HDembinski commented on Aug 1, 2018

    @HDembinski
    Author

    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.

  4. stefanseefeld commented on Aug 1, 2018

    @stefanseefeld
    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.

  5. HDembinski commented on Aug 1, 2018

    @HDembinski
    Author

    Ok!

  6. HDembinski commented on Aug 3, 2018

    @HDembinski
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions