Skip to content

Commit

Permalink
Data type functions: astype.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski committed Dec 27, 2023
1 parent 59c94b6 commit 6229ae2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ragged/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
zeros,
zeros_like,
)
from ._datatype import (
astype,
)
from ._obj import array

__all__ = [
Expand All @@ -47,6 +50,8 @@
"triu",
"zeros",
"zeros_like",
# _datatype
"astype",
# _obj
"array",
]
38 changes: 38 additions & 0 deletions src/ragged/common/_datatype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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

from ._obj import array
from ._typing import (
Dtype,
)


def astype(x: array, dtype: Dtype, /, *, copy: bool = True) -> array:
"""
Copies an array to a specified data type irrespective of type promotion rules.
Args:
x: Array to cast.
dtype: Desired data type.
copy: Specifies whether to copy an array when the specified `dtype`
matches the data type of the input array `x`. If `True`, a newly
allocated array is always returned. If `False` and the specified
`dtype` matches the data type of the input array, the input array
is returned; otherwise, a newly allocated array is returned.
Returns:
An array having the specified data type. The returned array has the
same `shape` as `x`.
https://data-apis.org/array-api/latest/API_specification/generated/array_api.astype.html
"""

assert x, "TODO"
assert dtype, "TODO"
assert copy, "TODO"
assert False, "TODO"
5 changes: 5 additions & 0 deletions src/ragged/v202212/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
zeros,
zeros_like,
)
from ._datatype import (
astype,
)
from ._obj import array

__all__ = [
Expand All @@ -49,6 +52,8 @@
"triu",
"zeros",
"zeros_like",
# _datatype
"astype",
# _obj
"array",
]
15 changes: 15 additions & 0 deletions src/ragged/v202212/_datatype.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/2022.12/API_specification/creation_functions.html
"""

from __future__ import annotations

from ..common._datatype import (
astype,
)

__all__ = [
"astype",
]

0 comments on commit 6229ae2

Please sign in to comment.