Skip to content

Commit c2cb66d

Browse files
ConchylicultorThe dataclass_array Authors
authored andcommitted
Add dca.typing alias for array types (alias of enp.typing)
Rational: This allow to use `dataclass_array` in a self-contained fashion, without importing 2 different packages PiperOrigin-RevId: 469692004
1 parent c0c8308 commit c2cb66d

File tree

10 files changed

+48
-13
lines changed

10 files changed

+48
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ To release a new version (e.g. from `1.0.0` -> `2.0.0`):
2323

2424
## [Unreleased]
2525

26+
## [1.1.0] - 2022-08-15
27+
28+
* Added: Array types can be imported directly from `dataclass_array.typing`
2629
* Added: Syntax to specify the shape of the DataclassArray (e.g. `MyRay['h
2730
w']`).
2831
* Fixed: Correctly forward non-init fields in `.replace`, `tree_map`,
@@ -32,6 +35,7 @@ To release a new version (e.g. from `1.0.0` -> `2.0.0`):
3235

3336
* Initial release
3437

35-
[Unreleased]: https://github.com/google-research/dataclass_array/compare/v1.0.0...HEAD
38+
[Unreleased]: https://github.com/google-research/dataclass_array/compare/v1.1.0...HEAD
39+
[1.1.0]: https://github.com/google-research/dataclass_array/compare/v1.0.0...v1.1.0
3640
[1.0.0]: https://github.com/google-research/dataclass_array/compare/v0.1.0...v1.0.0
3741
[0.1.0]: https://github.com/google-research/dataclass_array/releases/tag/v0.1.0

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ To view an example of dataclass arrays used in practice, see
2020
To create a `dca.DataclassArray`, take a frozen dataclass and:
2121

2222
* Inherit from `dca.DataclassArray`
23-
* Annotate the fields with `etils.array_types` to specify the inner shape and
24-
dtype of the array (see below for static or nested dataclass fields).
23+
* Annotate the fields with `dataclass_array.typing` to specify the inner shape
24+
and dtype of the array (see below for static or nested dataclass fields).
25+
The array types are an alias from
26+
[`etils.array_types`](https://github.com/google/etils/blob/main/etils/array_types/README.md).
2527

2628
```python
2729
import dataclass_array as dca
28-
from etils.array_types import FloatArray
30+
from dataclass_array.typing import FloatArray
2931

3032

3133
@dataclasses.dataclass(frozen=True)
@@ -145,8 +147,8 @@ For example, with `__matmul__(self, x: T) -> T`:
145147
(a, *x) @ (b, *x) -> Error: Incompatible a != b
146148
```
147149

148-
To test on Colab, see the `visu3d`
149-
dataclass [Colab tutorial](https://colab.research.google.com/github/google-research/visu3d/blob/main/docs/dataclass.ipynb).
150+
To test on Colab, see the `visu3d` dataclass
151+
[Colab tutorial](https://colab.research.google.com/github/google-research/visu3d/blob/main/docs/dataclass.ipynb).
150152

151153
## Motivating examples
152154

dataclass_array/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@
4343

4444
# A new PyPI release will be pushed everytime `__version__` is increased
4545
# When changing this, also update the CHANGELOG.md
46-
__version__ = '1.0.0'
46+
__version__ = '1.1.0'
4747

4848
del sys, pytest

dataclass_array/array_dataclass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from dataclass_array import field_utils
2424
from dataclass_array import shape_parsing
2525
from dataclass_array import type_parsing
26+
from dataclass_array.typing import Array
2627
from dataclass_array.typing import Axes, DcOrArray, DcOrArrayT, DTypeArg, DynamicShape, Shape # pylint: disable=g-multiple-import
2728
from dataclass_array.utils import np_utils
2829
from dataclass_array.utils import py_utils
@@ -31,7 +32,6 @@
3132
from etils import edc
3233
from etils import enp
3334
from etils import epy
34-
from etils.array_types import Array
3535
import numpy as np
3636
import typing_extensions
3737
from typing_extensions import Annotated, Literal, TypeAlias # pylint: disable=g-multiple-import

dataclass_array/array_dataclass_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
from typing import Any, Callable
2121

2222
import dataclass_array as dca
23+
from dataclass_array.typing import FloatArray, IntArray, f32, i32 # pylint: disable=g-multiple-import
2324
from dataclass_array.typing import Shape # pylint: disable=g-multiple-import
2425
from etils import enp
25-
from etils.array_types import FloatArray, IntArray, f32, i32 # pylint: disable=g-multiple-import
2626
import numpy as np
2727
import pytest
2828
import tensorflow as tf

dataclass_array/shape_parsing_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from __future__ import annotations
1818

1919
from dataclass_array import shape_parsing
20-
from etils.array_types import f32
20+
from dataclass_array.typing import f32
2121
import pytest
2222

2323

dataclass_array/testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from typing import Any, Optional
2222

2323
from dataclass_array import array_dataclass
24-
from etils.array_types import FloatArray # pylint: disable=g-multiple-import
24+
from dataclass_array.typing import FloatArray # pylint: disable=g-multiple-import
2525
from etils.etree import jax as etree
2626
from etils.etree import Tree
2727
import numpy as np

dataclass_array/type_parsing_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import dataclass_array as dca
2323
from dataclass_array import type_parsing
24-
from etils.array_types import f32, FloatArray # pylint: disable=g-multiple-import
24+
from dataclass_array.typing import f32, FloatArray # pylint: disable=g-multiple-import
2525
import pytest
2626

2727

dataclass_array/typing.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,40 @@
1919
import typing
2020
from typing import Any, Optional, Tuple, Type, TypeVar, Union
2121

22+
from etils import enp
2223
from etils.array_types import FloatArray
2324

2425
if typing.TYPE_CHECKING:
2526
from dataclass_array import array_dataclass
2627

28+
# ======== Array types (alias of `enp.typing`) ========
29+
30+
ArrayAliasMeta = enp.typing.ArrayAliasMeta
31+
ArrayLike = enp.typing.ArrayLike
32+
33+
Array = enp.typing.Array
34+
FloatArray = enp.typing.FloatArray
35+
IntArray = enp.typing.IntArray
36+
BoolArray = enp.typing.BoolArray
37+
StrArray = enp.typing.StrArray
38+
39+
ui8 = enp.typing.ui8
40+
ui16 = enp.typing.ui16
41+
ui32 = enp.typing.ui32
42+
ui64 = enp.typing.ui64
43+
i8 = enp.typing.i8
44+
i16 = enp.typing.i16
45+
i32 = enp.typing.i32
46+
i64 = enp.typing.i64
47+
f16 = enp.typing.f16
48+
f32 = enp.typing.f32
49+
f64 = enp.typing.f64
50+
complex64 = enp.typing.complex64
51+
complex128 = enp.typing.complex128
52+
bool_ = enp.typing.bool_
53+
54+
# ======== Dataclass array specific types ========
55+
2756
TypeAlias = Any
2857

2958
Shape = Tuple[int, ...]

dataclass_array/vectorization_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
import dataclass_array as dca
2222
from dataclass_array import vectorization
23+
from dataclass_array.typing import FloatArray
2324
from dataclass_array.utils import inspect_utils
2425
from dataclass_array.utils import np_utils
2526
from etils import enp
26-
from etils.array_types import FloatArray
2727
import jax
2828
import pytest
2929
import tensorflow.experimental.numpy as tnp

0 commit comments

Comments
 (0)