Skip to content

Commit

Permalink
feat: initial array object implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski committed Dec 26, 2023
1 parent 1071217 commit 651e781
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 17 deletions.
11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ classifiers = [
"Typing :: Typed",
]
dynamic = ["version"]
dependencies = []
dependencies = [
"awkward",
]

[project.optional-dependencies]
test = [
Expand Down Expand Up @@ -100,6 +102,13 @@ module = "ragged.*"
disallow_untyped_defs = true
disallow_incomplete_defs = true

[[tool.mypy.overrides]]
module = "numpy.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "awkward.*"
ignore_missing_imports = true

[tool.ruff]
src = ["src"]
Expand Down
10 changes: 3 additions & 7 deletions src/ragged/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
"""
Copyright (c) 2023 Jim Pivarski. All rights reserved.
ragged: Ragged array library, complying with Python API specification.
"""

# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

from __future__ import annotations

from ._version import version as __version__
from .api_2022_12 import array

__all__ = ["__version__"]
__all__ = ["array", "__version__"]
9 changes: 9 additions & 0 deletions src/ragged/api_2022_12/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

from __future__ import annotations

from ..common import array as common_array


class array(common_array):
pass
25 changes: 25 additions & 0 deletions src/ragged/common/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

from __future__ import annotations

import awkward as ak

from ._typing import Device, Dtype, NestedSequence, SupportsDLPack


class array:
def __init__(
self,
array_like: (
array
| ak.Array
| SupportsDLPack
| bool
| int
| float
| NestedSequence[bool | int | float]
),
dtype: None | Dtype = None,
device: None | Device = None,
):
...
47 changes: 47 additions & 0 deletions src/ragged/common/_typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

from __future__ import annotations

import warnings
from typing import Any, Literal, Protocol, TypeVar, Union

import numpy as np

with warnings.catch_warnings():
warnings.simplefilter("ignore")

T_co = TypeVar("T_co", covariant=True)


class NestedSequence(Protocol[T_co]):
def __getitem__(self, key: int, /) -> T_co | NestedSequence[T_co]:
...

def __len__(self, /) -> int:
...


PyCapsule = Any


class SupportsDLPack(Protocol):
def __dlpack__(self, /, *, stream: None = ...) -> PyCapsule:
...


Device = Union[Literal["cpu"], Literal["cuda"]]

Dtype = np.dtype[
(
np.int8,
np.int16,
np.int32,
np.int64,
np.uint8,
np.uint16,
np.uint32,
np.uint64,
np.float32,
np.float64,
)
]
9 changes: 9 additions & 0 deletions tests/test_0001_initial_array_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/ragged/blob/main/LICENSE

from __future__ import annotations

# import ragged


# def test():
# a = ragged.array([1, 2, 3])
9 changes: 0 additions & 9 deletions tests/test_package.py

This file was deleted.

0 comments on commit 651e781

Please sign in to comment.