Skip to content

Commit

Permalink
Closes Bears-R-Us#3300: shape function
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpotts committed Nov 15, 2024
1 parent 0f5f0a3 commit 4e50331
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions arkouda/numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@
from arkouda.numpy.rec import *

from ._numeric import *
from ._from_numeric import *
from ._manipulation_functions import *

44 changes: 44 additions & 0 deletions arkouda/numpy/_from_numeric.py
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
15 changes: 15 additions & 0 deletions tests/numpy/from_numeric_test.py
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)

0 comments on commit 4e50331

Please sign in to comment.