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

Improve QOL when reshaping array symbols #218

Merged
merged 5 commits into from
Jan 31, 2025

Conversation

arcondello
Copy link
Member

@arcondello arcondello commented Jan 30, 2025

Adds flattening array, reshaping non-contiguous arrays, the Copy symbol (see #16), and allows reshaped arrays to be used as indexers.

@arcondello arcondello added bug Something isn't working enhancement New feature or request labels Jan 30, 2025
@arcondello arcondello linked an issue Jan 30, 2025 that may be closed by this pull request
@arcondello arcondello requested a review from wbernoudy January 30, 2025 02:09
@arcondello arcondello marked this pull request as ready for review January 30, 2025 02:09
x_ptr->grow(state);
graph.propagate(state, graph.descendants(state, {x_ptr}));

THEN("c has the same shape as y and the same values") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the shape check captured implicitly by the state check? Here and in commit/revert below

Copy link
Member Author

Choose a reason for hiding this comment

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

copy and paste error for the message itself. The size is checked implicitly, and the shape does not vary.

// Check if there are any -1s, and if not fallback to other input checking.
auto it = std::ranges::find(shape, -1);
if (it == shape.end()) return shape;

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Ensure there is at most one -1
if (++it != shape.end()) {
// Same error message as NumPy
throw std::invalid_argument("can only specify one unknown dimension");
}

Copy link
Member Author

Choose a reason for hiding this comment

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

This actually gets checked by the ArrayOutputMixin because that doesn't allow any -1. So I am deferring the error to there. The error message is slightly less explicit, but IMO it's OK.

Copy link
Member

Choose a reason for hiding this comment

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

I think it checks that it's not dynamic, i.e. the first index is not negative, but that won't catch the case of multiple -1s...

Copy link
Member

Choose a reason for hiding this comment

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

Actually, I don't think it gets checked at all. Just returns DYNAMIC_SIZE if the first index is negative. So then the this->dynamic() check below would return true and throw an error if there are an even number of -1s in the shape, but not if there are an odd number

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me add a test case

Copy link
Member Author

Choose a reason for hiding this comment

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

4442ba1 adds a test case, it does correctly throw.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's because it results in a negative or otherwise non-matching shape. So it fails on the check for consistency between Reshape's shape and its predecessor's shape.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I found an edge case, ReshapeNode(&A, {12, -1, -1}. Will fix.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed by 6439503

@arcondello arcondello merged commit a000537 into dwavesystems:main Jan 31, 2025
35 checks passed
@arcondello arcondello deleted the feature/ArraySymbol.flatten branch January 31, 2025 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CopyNode or similar
3 participants