Skip to content

Commit

Permalink
Closes #3430: deprecate array_api/array_manipulation.py (#3629)
Browse files Browse the repository at this point in the history
Co-authored-by: Amanda Potts <ajpotts@users.noreply.github.com>
  • Loading branch information
ajpotts and ajpotts committed Aug 7, 2024
1 parent 92fdfe8 commit 05e2dc6
Show file tree
Hide file tree
Showing 20 changed files with 1,196 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ArrayAPIServerModules.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ArgSortMsg
CastMsg
EfuncMsg
IndexingMsg
# LinalgMsg
#LinalgMsg
LogMsg
ManipulationMsg
OperatorMsg
Expand Down
53 changes: 53 additions & 0 deletions PROTO_tests/tests/array_api/array_creation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import json

import numpy as np
import pytest

import arkouda as ak
import arkouda.array_api as xp

# requires the server to be built with 2D array support
SHAPES = [(), (0,), (0, 0), (1,), (5,), (2, 2), (5, 10)]
SIZES = [1, 0, 0, 1, 5, 4, 50]
DIMS = [0, 1, 2, 1, 1, 2, 2]

def get_server_max_array_dims():
try:
return json.load(open('serverConfig.json', 'r'))['max_array_dims']
except (ValueError, FileNotFoundError, TypeError, KeyError):
return 1

class TestArrayCreation:
@pytest.mark.skipif(get_server_max_array_dims() < 2, reason="test_zeros requires server with 'max_array_dims' >= 2")
def test_zeros(self):
for shape, size, dim in zip(SHAPES, SIZES, DIMS):
for dtype in ak.ScalarDTypes:
a = xp.zeros(shape, dtype=dtype)
assert a.size == size
assert a.ndim == dim
assert a.shape == shape
assert a.dtype == dtype
assert a.tolist() == np.zeros(shape, dtype=dtype).tolist()

@pytest.mark.skipif(get_server_max_array_dims() < 2, reason="test_ones requires server with 'max_array_dims' >= 2")
def test_ones(self):
for shape, size, dim in zip(SHAPES, SIZES, DIMS):
for dtype in ak.ScalarDTypes:
a = xp.ones(shape, dtype=dtype)
assert a.size == size
assert a.ndim == dim
assert a.shape == shape
assert a.dtype == dtype
assert a.tolist() == np.ones(shape, dtype=dtype).tolist()

@pytest.mark.skipif(get_server_max_array_dims() < 2, reason="test_from_numpy requires server with 'max_array_dims' >= 2")
def test_from_numpy(self):
# TODO: support 0D (scalar) arrays
# (need changes to the create0D command from #2967)
for shape in SHAPES[1:]:
a = np.random.randint(0, 10, size=shape, dtype=np.int64)
b = xp.asarray(a)
assert b.size == a.size
assert b.ndim == a.ndim
assert b.shape == a.shape
assert b.tolist() == a.tolist()
Loading

0 comments on commit 05e2dc6

Please sign in to comment.