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

Enable resizing n-dimensional arrays in addition one-dimensional ones. #312

Merged
merged 1 commit into from
Apr 6, 2022

Conversation

adamreichold
Copy link
Member

No description provided.

@adamreichold adamreichold force-pushed the n-dimensional-resize branch 3 times, most recently from bbd9c45 to 656eb2b Compare April 5, 2022 18:52
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement! Worth including in the CHANGELOG?

EDIT: sorry I see you already did! 🙂🎉

/// Extends or truncates the dimensions of an array.
///
/// This method works only on [contiguous][`Self::is_contiguous`] arrays.
/// Missing elements will be initialized as if calling [`zeros`][Self::zeros].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity what does this do for object? Fill with null references?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the doc comments of PyArray::zeros:

For elements with DATA_TYPE == DataType::Object, this will fill the array with valid pointers to zero-valued Python integer objects.

So more specifically

>>> a = np.zeros(1, dtype=object)
>>> a[0]
0
>>> type(a[0])
<class 'int'>

(PyArray::new correspoding to np.empty will put zero pointers into object arrays (instead of uninitialized values for primitives like integers), so these arrays are always safe to drop, but not to use.)

((I noticed this still references Element::DATA_TYPE which does not actually exist any more. Will resolve this as part of the copy-editing done for #309.))

Copy link
Member Author

@adamreichold adamreichold Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This behaviour is yet another reason why PyArray<PyObject, D> works, but PyArray<Py<T>, D> with arbitrary T is really problematic.)

@adamreichold adamreichold force-pushed the n-dimensional-resize branch from 656eb2b to a31367d Compare April 6, 2022 08:25
@adamreichold adamreichold merged commit 2c99dfa into main Apr 6, 2022
@adamreichold adamreichold deleted the n-dimensional-resize branch April 6, 2022 08:49
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

Successfully merging this pull request may close these issues.

2 participants