rust-ndarray / ndarray

ndarray: an N-dimensional array with array views, multidimensional slicing, and efficient operations
https://docs.rs/ndarray/
Apache License 2.0
3.62k stars 307 forks source link

Add `.shrink_to_fit()` for `Array` #1424

Open bluss opened 3 months ago

bluss commented 3 months ago

Add .shrink_to_fit() for owned storage arrays. This initial version does not change array strides, this is to avoid the most tricky part of the implementation (and maybe take it step by step).

Care must be taken since self.ptr points inside the allocation - which for Array is still Vec-allocated, and several Vec methods including its shrink_to_fit can reallocate the array.

bluss commented 3 months ago

This is a new take on #1141. I don't think this is an easy topic, lots of details to work through. That's also why this change (in current state) does not change the Array strides.