-
Notifications
You must be signed in to change notification settings - Fork 97
Closes 5170 adding overloads to reshape #5212
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
Open
drculhane
wants to merge
5
commits into
Bears-R-Us:main
Choose a base branch
from
drculhane:Closes-5170
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| from functools import reduce | ||
| from math import ceil | ||
| from sys import modules | ||
| from typing import TYPE_CHECKING, List, Optional, Tuple, Union, cast, overload | ||
| from typing import TYPE_CHECKING, List, Optional, Sequence, Tuple, Union, cast, overload | ||
|
|
||
| import numpy as np | ||
|
|
||
|
|
@@ -2644,7 +2644,17 @@ def bigint_to_uint_arrays(self) -> List[pdarray]: | |
| ret_list = json.loads(generic_msg(cmd=cmd, args={"array": self})) | ||
| return list(reversed([create_pdarray(a) for a in ret_list])) | ||
|
|
||
| def reshape(self, *shape): | ||
| @overload | ||
| def reshape(self, shape: Sequence[int_scalars]) -> pdarray: ... | ||
|
|
||
| @overload | ||
| def reshape(self, *shape: int_scalars) -> pdarray: ... | ||
|
|
||
| @overload | ||
| def reshape(self, shape: pdarray) -> pdarray: ... | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add an In [18]: shape_np = np.array([6, 4], dtype=np.int64)
...: try:
...: a.reshape(shape_np)
...: except Exception as e:
...: print(type(e).__name__, e)
...:
TypeError type of argument "shape"[0] must be one of (int, int8, int16, int32, int64, uint8, uint16, uint32, uint64, Sequence, pdarray); got numpy.ndarray instead
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good idea but it could also be a separate ticket. |
||
|
|
||
| @typechecked | ||
| def reshape(self, *shape: Union[int_scalars, Sequence[int_scalars], pdarray]) -> pdarray: | ||
| """ | ||
| Gives a new shape to an array without changing its data. | ||
|
|
||
|
|
@@ -2678,21 +2688,40 @@ def reshape(self, *shape): | |
| # For example, a.reshape(10, 11) is equivalent to a.reshape((10, 11)) | ||
| # the lenshape variable addresses an error that occurred when a single integer was | ||
| # passed | ||
| from typing import get_args | ||
|
|
||
| from arkouda.client import generic_msg | ||
|
|
||
| shape_seq: Sequence[int_scalars] | ||
|
|
||
| if len(shape) == 1: | ||
| shape = shape[0] | ||
| lenshape = 1 | ||
| if (not isinstance(shape, int)) and (not isinstance(shape, pdarray)): | ||
| shape = [i for i in shape] | ||
| lenshape = len(shape) | ||
| arg = shape[0] | ||
|
|
||
| if isinstance(arg, get_args(int_scalars)): | ||
| shape_seq = (arg,) | ||
|
|
||
| elif isinstance(arg, Sequence): | ||
| shape_seq = tuple(arg) | ||
|
|
||
| elif isinstance(arg, pdarray): | ||
| shape_seq = cast(Sequence[int_scalars], arg.tolist()) | ||
|
|
||
| else: | ||
| raise TypeError(f"Invalid shape argument {shape}") | ||
|
|
||
| else: | ||
| shape_seq = cast(Sequence[int_scalars], shape) | ||
|
|
||
| shape_arg: list[int_scalars] = list(shape_seq) | ||
|
|
||
| lenshape = len(shape_arg) | ||
|
|
||
| return create_pdarray( | ||
| generic_msg( | ||
| cmd=f"reshape<{self.dtype},{self.ndim},{lenshape}>", | ||
| args={ | ||
| "name": self.name, | ||
| "shape": shape, | ||
| "shape": shape_arg, | ||
| }, | ||
| ), | ||
| max_bits=self.max_bits, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.