forked from Bears-R-Us/arkouda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes Bears-R-Us#3300: shape function
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from arkouda.numpy.dtypes import isSupportedNumber, numeric_scalars | ||
from arkouda.pdarrayclass import pdarray | ||
from typing import Union, Tuple | ||
|
||
__all__ = ["shape"] | ||
|
||
|
||
def shape(a: Union[pdarray, numeric_scalars]) -> Tuple: | ||
""" | ||
Return the shape of an array. | ||
Parameters | ||
---------- | ||
a : pdarray | ||
Input array. | ||
Returns | ||
------- | ||
shape : tuple of ints | ||
The elements of the shape tuple give the lengths of the | ||
corresponding array dimensions. | ||
Examples | ||
-------- | ||
>>> import arkouda as ak | ||
>>> ak.shape(ak.eye(3,2)) | ||
(3, 2) | ||
>>> ak.shape([[1, 3]]) | ||
(1, 2) | ||
>>> ak.shape([0]) | ||
(1,) | ||
>>> ak.shape(0) | ||
() | ||
""" | ||
if isSupportedNumber(a): | ||
return () | ||
try: | ||
result = a.shape | ||
except AttributeError: | ||
from arkouda import array | ||
|
||
result = array(a).shape | ||
return result |
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pytest | ||
|
||
import arkouda as ak | ||
|
||
|
||
class TestFromNumericFunctions: | ||
|
||
def test_shape(self): | ||
assert ak.shape([[1, 3]]) == (1, 2) | ||
assert ak.shape([0]) == (1,) | ||
assert ak.shape(0) == () | ||
|
||
@pytest.mark.skip_if_max_rank_less_than(2) | ||
def test_shape_multidim(self): | ||
assert ak.shape(ak.eye(3, 2)) == (3, 2) |