Skip to content

Commit

Permalink
refactor: organize submodules and tests by spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski committed Dec 28, 2023
1 parent 62594fc commit 4c9a613
Show file tree
Hide file tree
Showing 19 changed files with 288 additions and 62 deletions.
13 changes: 13 additions & 0 deletions src/ragged/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

from __future__ import annotations

from ._const import (
e,
inf,
nan,
newaxis,
pi,
)
from ._creation import (
arange,
asarray,
Expand Down Expand Up @@ -149,6 +156,12 @@
)

__all__ = [
# _const
"e",
"inf",
"nan",
"newaxis",
"pi",
# _creation
"arange",
"asarray",
Expand Down
13 changes: 13 additions & 0 deletions src/ragged/v202212/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@

__array_api_version__ = "2022.12"

from ._const import (
e,
inf,
nan,
newaxis,
pi,
)
from ._creation import (
arange,
asarray,
Expand Down Expand Up @@ -154,6 +161,12 @@

__all__ = [
"__array_api_version__",
# _const
"e",
"inf",
"nan",
"newaxis",
"pi",
# _creation
"arange",
"asarray",
Expand Down
13 changes: 13 additions & 0 deletions tests/test_spec_array_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/array_object.html
"""

from __future__ import annotations

import ragged


def test_existence():
assert ragged.array is not None
11 changes: 11 additions & 0 deletions tests/test_spec_broadcasting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/broadcasting.html
"""

from __future__ import annotations


def test():
pass
20 changes: 20 additions & 0 deletions tests/test_spec_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/constants.html
"""

from __future__ import annotations

import math

import ragged


def test_values():
assert ragged.e == math.e
assert not math.isfinite(ragged.inf)
assert ragged.inf > 0
assert math.isnan(ragged.nan)
assert ragged.newaxis is None
assert ragged.pi == math.pi
28 changes: 28 additions & 0 deletions tests/test_spec_creation_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/creation_functions.html
"""

from __future__ import annotations

import ragged


def test_existence():
assert ragged.arange is not None
assert ragged.asarray is not None
assert ragged.empty is not None
assert ragged.empty_like is not None
assert ragged.eye is not None
assert ragged.from_dlpack is not None
assert ragged.full is not None
assert ragged.full_like is not None
assert ragged.linspace is not None
assert ragged.meshgrid is not None
assert ragged.ones is not None
assert ragged.ones_like is not None
assert ragged.tril is not None
assert ragged.triu is not None
assert ragged.zeros is not None
assert ragged.zeros_like is not None
18 changes: 18 additions & 0 deletions tests/test_spec_data_type_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/data_type_functions.html
"""

from __future__ import annotations

import ragged


def test_existence():
assert ragged.astype is not None
assert ragged.can_cast is not None
assert ragged.finfo is not None
assert ragged.iinfo is not None
assert ragged.isdtype is not None
assert ragged.result_type is not None
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/elementwise_functions.html
"""

from __future__ import annotations

import ragged


def test():
assert ragged.__array_api_version__ == "2022.12"

a = ragged.array([[1, 2], [3]])
assert a is not None

assert ragged.arange is not None
assert ragged.asarray is not None
assert ragged.empty is not None
assert ragged.empty_like is not None
assert ragged.eye is not None
assert ragged.from_dlpack is not None
assert ragged.full is not None
assert ragged.full_like is not None
assert ragged.linspace is not None
assert ragged.meshgrid is not None
assert ragged.ones is not None
assert ragged.ones_like is not None
assert ragged.tril is not None
assert ragged.triu is not None
assert ragged.zeros is not None
assert ragged.zeros_like is not None
assert ragged.astype is not None
assert ragged.can_cast is not None
assert ragged.finfo is not None
assert ragged.iinfo is not None
assert ragged.isdtype is not None
assert ragged.result_type is not None
def test_existence():
assert ragged.abs is not None
assert ragged.acos is not None
assert ragged.acosh is not None
Expand Down Expand Up @@ -92,37 +69,3 @@ def test():
assert ragged.tan is not None
assert ragged.tanh is not None
assert ragged.trunc is not None
assert ragged.take is not None
assert ragged.matmul is not None
assert ragged.matrix_transpose is not None
assert ragged.tensordot is not None
assert ragged.vecdot is not None
assert ragged.broadcast_arrays is not None
assert ragged.broadcast_to is not None
assert ragged.concat is not None
assert ragged.expand_dims is not None
assert ragged.flip is not None
assert ragged.permute_dims is not None
assert ragged.reshape is not None
assert ragged.roll is not None
assert ragged.squeeze is not None
assert ragged.stack is not None
assert ragged.argmax is not None
assert ragged.argmin is not None
assert ragged.nonzero is not None
assert ragged.where is not None
assert ragged.unique_all is not None
assert ragged.unique_counts is not None
assert ragged.unique_inverse is not None
assert ragged.unique_values is not None
assert ragged.argsort is not None
assert ragged.sort is not None
assert ragged.max is not None
assert ragged.mean is not None
assert ragged.min is not None
assert ragged.prod is not None
assert ragged.std is not None
assert ragged.sum is not None
assert ragged.var is not None
assert ragged.all is not None
assert ragged.any is not None
11 changes: 11 additions & 0 deletions tests/test_spec_indexing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/indexing.html
"""

from __future__ import annotations


def test():
pass
13 changes: 13 additions & 0 deletions tests/test_spec_indexing_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/indexing_functions.html
"""

from __future__ import annotations

import ragged


def test_existence():
assert ragged.take is not None
16 changes: 16 additions & 0 deletions tests/test_spec_linear_algebra_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/linear_algebra_functions.html
"""

from __future__ import annotations

import ragged


def test_existence():
assert ragged.matmul is not None
assert ragged.matrix_transpose is not None
assert ragged.tensordot is not None
assert ragged.vecdot is not None
22 changes: 22 additions & 0 deletions tests/test_spec_manipulation_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/manipulation_functions.html
"""

from __future__ import annotations

import ragged


def test_existence():
assert ragged.broadcast_arrays is not None
assert ragged.broadcast_to is not None
assert ragged.concat is not None
assert ragged.expand_dims is not None
assert ragged.flip is not None
assert ragged.permute_dims is not None
assert ragged.reshape is not None
assert ragged.roll is not None
assert ragged.squeeze is not None
assert ragged.stack is not None
16 changes: 16 additions & 0 deletions tests/test_spec_searching_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/searching_functions.html
"""

from __future__ import annotations

import ragged


def test_existence():
assert ragged.argmax is not None
assert ragged.argmin is not None
assert ragged.nonzero is not None
assert ragged.where is not None
16 changes: 16 additions & 0 deletions tests/test_spec_set_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/set_functions.html
"""

from __future__ import annotations

import ragged


def test_existence():
assert ragged.unique_all is not None
assert ragged.unique_counts is not None
assert ragged.unique_inverse is not None
assert ragged.unique_values is not None
14 changes: 14 additions & 0 deletions tests/test_spec_sorting_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/sorting_functions.html
"""

from __future__ import annotations

import ragged


def test_existence():
assert ragged.argsort is not None
assert ragged.sort is not None
19 changes: 19 additions & 0 deletions tests/test_spec_statistical_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/statistical_functions.html
"""

from __future__ import annotations

import ragged


def test_existence():
assert ragged.max is not None
assert ragged.mean is not None
assert ragged.min is not None
assert ragged.prod is not None
assert ragged.std is not None
assert ragged.sum is not None
assert ragged.var is not None
14 changes: 14 additions & 0 deletions tests/test_spec_utility_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/utility_functions.html
"""

from __future__ import annotations

import ragged


def test_existence():
assert ragged.all is not None
assert ragged.any is not None
15 changes: 15 additions & 0 deletions tests/test_spec_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

"""
https://data-apis.org/array-api/latest/API_specification/version.html
"""

from __future__ import annotations

import ragged


def test_values():
assert ragged.v202212.__array_api_version__ == "2022.12"

assert ragged.__array_api_version__ == "2022.12"
Loading

0 comments on commit 4c9a613

Please sign in to comment.