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

"resize" attribute of numpy array #8015

Closed
Rinoahu opened this issue Apr 29, 2022 · 8 comments
Closed

"resize" attribute of numpy array #8015

Rinoahu opened this issue Apr 29, 2022 · 8 comments

Comments

@Rinoahu
Copy link

Rinoahu commented Apr 29, 2022

Feature request

Dear Developer Team,

Could you please add the "resize" attribute to numpy arrays? When increasing the size of a numpy array, "resize" seems to be more memory-efficient than creating a new numpy array and deleting the old one.

Best,

R.H.

@czgdp1807
Copy link
Contributor

Maybe I can try working on this? @guilhermeleobas @stuartarchibald

@czgdp1807
Copy link
Contributor

I think both np.resize and array.resize are not present. Should we implement both? I can do that.

@Rinoahu
Copy link
Author

Rinoahu commented Apr 30, 2022

np.resize seems a pure python function. ndarray.resize is different.

@czgdp1807
Copy link
Contributor

Okay. I will prioritise ndarray.resize first then.

@stuartarchibald
Copy link
Contributor

Maybe I can try working on this? @guilhermeleobas @stuartarchibald

@czgdp1807 I don't recall there being/can't find any open PR doing the same, so if it's something you'd like to work on, then patches are welcomed, thanks!

Also, as noted, np.resize and np.ndarray.resize do different things. I think the request here is for the latter.

@czgdp1807
Copy link
Contributor

Great. I am working on it. Will open a PR soon (a couple of days may be).

@czgdp1807
Copy link
Contributor

@Rinoahu N.B. - #8020 (comment)

stuartarchibald added a commit to stuartarchibald/numba that referenced this issue Jun 1, 2022
This patch:

* Updates nrt.c to ensure that allocation routines return NULL if
  the allocation fails. cf. malloc.
* Updates the nrt.context to add a check that wraps any allocation
  routine to check if the allocation failed and if so raises a
  MemoryError.
* Fixes the runtime system allocators to catch invalid allocation
  requests and handle failed allocation requests.
* Adds tests for the above.
* Fixes a storage classifier issue in the C code in the nrt tests.
* Adds the option `--debuginfo` to the `build_ext` command in
  setup.py, on unix systems this will ensure the DSOs Numba
  produces are built with debug symbols.

Fixes numba#8015
(the segfault part).
stuartarchibald added a commit to stuartarchibald/numba that referenced this issue Jun 1, 2022
This patch:

* Updates nrt.c to ensure that allocation routines return NULL if
  the allocation fails. cf. malloc.
* Updates the nrt.context to add a check that wraps any allocation
  routine to check if the allocation failed and if so raises a
  MemoryError.
* Fixes the runtime system allocators to catch invalid allocation
  requests and handle failed allocation requests.
* Adds tests for the above.
* Fixes a storage classifier issue in the C code in the nrt tests.
* Adds the option `--debuginfo` to the `build_ext` command in
  setup.py, on unix systems this will ensure the DSOs Numba
  produces are built with debug symbols.
* Adds an update to the notes in nrt_external.h about the expected
  behaviour of an externally supplied allocation routine.

Fixes numba#8015
(the segfault part).
@stuartarchibald
Copy link
Contributor

Am going to close this as it was established in #8020 that Numba cannot support numpy.ndarray.resize (see notes in that PR as to why). Thanks for your understanding.

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

Successfully merging a pull request may close this issue.

3 participants