From 2cb90c206762358798352f117dfc3d026b2c8054 Mon Sep 17 00:00:00 2001 From: Clement Rey Date: Sun, 11 Jun 2023 23:11:37 +0200 Subject: [PATCH] autogenerated python code --- rerun_py/rerun2/__init__.py | 3 + rerun_py/rerun2/archetypes/__init__.py | 8 ++ rerun_py/rerun2/archetypes/points2d.py | 112 +++++++++++++++++++++ rerun_py/rerun2/components/__init__.py | 33 ++++++ rerun_py/rerun2/components/class_id.py | 70 +++++++++++++ rerun_py/rerun2/components/color.py | 78 ++++++++++++++ rerun_py/rerun2/components/draw_order.py | 76 ++++++++++++++ rerun_py/rerun2/components/instance_key.py | 68 +++++++++++++ rerun_py/rerun2/components/keypoint_id.py | 77 ++++++++++++++ rerun_py/rerun2/components/label.py | 69 +++++++++++++ rerun_py/rerun2/components/point2d.py | 70 +++++++++++++ rerun_py/rerun2/components/radius.py | 68 +++++++++++++ rerun_py/rerun2/datatypes/__init__.py | 8 ++ rerun_py/rerun2/datatypes/vec2d.py | 70 +++++++++++++ 14 files changed, 810 insertions(+) create mode 100644 rerun_py/rerun2/__init__.py create mode 100644 rerun_py/rerun2/archetypes/__init__.py create mode 100644 rerun_py/rerun2/archetypes/points2d.py create mode 100644 rerun_py/rerun2/components/__init__.py create mode 100644 rerun_py/rerun2/components/class_id.py create mode 100644 rerun_py/rerun2/components/color.py create mode 100644 rerun_py/rerun2/components/draw_order.py create mode 100644 rerun_py/rerun2/components/instance_key.py create mode 100644 rerun_py/rerun2/components/keypoint_id.py create mode 100644 rerun_py/rerun2/components/label.py create mode 100644 rerun_py/rerun2/components/point2d.py create mode 100644 rerun_py/rerun2/components/radius.py create mode 100644 rerun_py/rerun2/datatypes/__init__.py create mode 100644 rerun_py/rerun2/datatypes/vec2d.py diff --git a/rerun_py/rerun2/__init__.py b/rerun_py/rerun2/__init__.py new file mode 100644 index 000000000000..4af2ecbe18f2 --- /dev/null +++ b/rerun_py/rerun2/__init__.py @@ -0,0 +1,3 @@ +# NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +from rerun2.archetypes import Points2D # noqa: F401 diff --git a/rerun_py/rerun2/archetypes/__init__.py b/rerun_py/rerun2/archetypes/__init__.py new file mode 100644 index 000000000000..3394020c5059 --- /dev/null +++ b/rerun_py/rerun2/archetypes/__init__.py @@ -0,0 +1,8 @@ +# NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +# NOTE: +# - we use fully qualified paths to prevent lazy circular imports +# - `noqa F401` (unused import) everywhere because, while not strictly necessary, +# these imports are very nice for end users. + +from rerun2.archetypes.points2d import Points2D # noqa: F401 diff --git a/rerun_py/rerun2/archetypes/points2d.py b/rerun_py/rerun2/archetypes/points2d.py new file mode 100644 index 000000000000..513e2cadeb9a --- /dev/null +++ b/rerun_py/rerun2/archetypes/points2d.py @@ -0,0 +1,112 @@ +# NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Optional + +from rerun2 import components + + +@dataclass +class Points2D: + """A 2D point cloud with positions and optional colors, radii, labels, etc.""" + + points: components.Point2DArray + """ + All the actual 2D points that make up the point cloud. + """ + + radii: Optional[components.RadiusArray] = None + """ + Optional radii for the points, effectively turning them into circles. + """ + + colors: Optional[components.ColorArray] = None + """ + Optional colors for the points. + + The colors are interpreted as RGB or RGBA in sRGB gamma-space, + As either 0-1 floats or 0-255 integers, with separate alpha. + """ + + labels: Optional[components.LabelArray] = None + """ + Optional text labels for the points. + """ + + draw_order: Optional[components.DrawOrderArray] = None + """ + An optional floating point value that specifies the 2D drawing order. + Objects with higher values are drawn on top of those with lower values. + + The default for 2D points is 30.0. + """ + + class_ids: Optional[components.ClassIdArray] = None + """ + Optional class Ids for the points. + + The class ID provides colors and labels if not specified explicitly. + """ + + keypoint_ids: Optional[components.KeypointIdArray] = None + """ + Optional keypoint IDs for the points, identifying them within a class. + + If keypoint IDs are passed in but no class IDs were specified, the class ID will + default to 0. + This is useful to identify points within a single classification (which is identified + with `class_id`). + E.g. the classification might be 'Person' and the keypoints refer to joints on a + detected skeleton. + """ + + instance_keys: Optional[components.InstanceKeyArray] = None + """ + Unique identifiers for each individual point in the batch. + """ + + def __str__(self): + s = f"rr.{type(self).__name__}(\n" + + from dataclasses import fields + + for field in fields(self): + data = getattr(self, field.name) + datatype = getattr(data, "type", None) + if datatype: + name = datatype.extension_name + typ = datatype.storage_type + s += f" {name}<{typ}>(\n {data.to_pylist()}\n )\n" + + s += ")" + + return s + + def __repr__(self): + return str(self) + + def __init__( + self, + points: components.Point2DArrayLike, + *, + radii: Optional[components.RadiusArrayLike] = None, + colors: Optional[components.ColorArrayLike] = None, + labels: Optional[components.LabelArrayLike] = None, + draw_order: Optional[components.DrawOrderLike] = None, + class_ids: Optional[components.ClassIdArrayLike] = None, + keypoint_ids: Optional[components.KeypointIdArrayLike] = None, + instance_keys: Optional[components.InstanceKeyArrayLike] = None, + ) -> None: + # Required components + self.points = components.Point2DArray.from_similar(points) + + # Optional components + self.radii = components.RadiusArray.from_similar(radii) + self.colors = components.ColorArray.from_similar(colors) + self.labels = components.LabelArray.from_similar(labels) + self.draw_order = components.DrawOrderArray.from_similar(draw_order) + self.class_ids = components.ClassIdArray.from_similar(class_ids) + self.keypoint_ids = components.KeypointIdArray.from_similar(keypoint_ids) + self.instance_keys = components.InstanceKeyArray.from_similar(instance_keys) diff --git a/rerun_py/rerun2/components/__init__.py b/rerun_py/rerun2/components/__init__.py new file mode 100644 index 000000000000..47e85a20362e --- /dev/null +++ b/rerun_py/rerun2/components/__init__.py @@ -0,0 +1,33 @@ +# NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +# NOTE: +# - we use fully qualified paths to prevent lazy circular imports +# - `noqa F401` (unused import) everywhere because, while not strictly necessary, +# these imports are very nice for end users. + +from rerun2.components.class_id import ClassId, ClassIdArray, ClassIdArrayLike, ClassIdLike, ClassIdType # noqa: F401 +from rerun2.components.color import Color, ColorArray, ColorArrayLike, ColorLike, ColorType # noqa: F401 +from rerun2.components.draw_order import ( # noqa: F401 + DrawOrder, + DrawOrderArray, + DrawOrderArrayLike, + DrawOrderLike, + DrawOrderType, +) +from rerun2.components.instance_key import ( # noqa: F401 + InstanceKey, + InstanceKeyArray, + InstanceKeyArrayLike, + InstanceKeyLike, + InstanceKeyType, +) +from rerun2.components.keypoint_id import ( # noqa: F401 + KeypointId, + KeypointIdArray, + KeypointIdArrayLike, + KeypointIdLike, + KeypointIdType, +) +from rerun2.components.label import Label, LabelArray, LabelArrayLike, LabelLike, LabelType # noqa: F401 +from rerun2.components.point2d import Point2D, Point2DArray, Point2DArrayLike, Point2DLike, Point2DType # noqa: F401 +from rerun2.components.radius import Radius, RadiusArray, RadiusArrayLike, RadiusLike, RadiusType # noqa: F401 diff --git a/rerun_py/rerun2/components/class_id.py b/rerun_py/rerun2/components/class_id.py new file mode 100644 index 000000000000..bcab3bfd9468 --- /dev/null +++ b/rerun_py/rerun2/components/class_id.py @@ -0,0 +1,70 @@ +# NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Any, Optional, Sequence, Union + +import numpy as np +import numpy.typing as npt +import pyarrow as pa + + +@dataclass +class ClassId: + """A 16-bit ID representing a type of semantic class.""" + + id: int + + def __array__(self): + return np.asarray(self.id) + + +ClassIdLike = Union[ClassId, float] + +ClassIdArrayLike = Union[ + ClassIdLike, Sequence[ClassIdLike], npt.NDArray[np.uint8], npt.NDArray[np.uint16], npt.NDArray[np.uint32] +] + + +# --- Arrow support --- + +from rerun2.components.class_id_ext import ClassIdArrayExt # noqa: E402 + + +class ClassIdType(pa.ExtensionType): + def __init__(self: type[pa.ExtensionType]) -> None: + pa.ExtensionType.__init__(self, pa.uint16(), "rerun.components.ClassId") + + def __arrow_ext_serialize__(self: type[pa.ExtensionType]) -> bytes: + # since we don't have a parameterized type, we don't need extra metadata to be deserialized + return b"" + + @classmethod + def __arrow_ext_deserialize__( + cls: type[pa.ExtensionType], storage_type: Any, serialized: Any + ) -> type[pa.ExtensionType]: + # return an instance of this subclass given the serialized metadata. + return ClassIdType() + + def __arrow_ext_class__(self: type[pa.ExtensionType]) -> type[pa.ExtensionArray]: + return ClassIdArray + + +pa.register_extension_type(ClassIdType()) + + +class ClassIdArray(pa.ExtensionArray, ClassIdArrayExt): # type: ignore[misc] + @staticmethod + def from_similar(data: Optional[ClassIdArrayLike]): + if data is None: + return ClassIdType().wrap_array(pa.array([], type=ClassIdType().storage_type)) + else: + return ClassIdArrayExt.from_similar( + data, + mono=ClassId, + mono_aliases=ClassIdLike, + many=ClassIdArray, + many_aliases=ClassIdArrayLike, + arrow=ClassIdType, + ) diff --git a/rerun_py/rerun2/components/color.py b/rerun_py/rerun2/components/color.py new file mode 100644 index 000000000000..39d4f2a7e388 --- /dev/null +++ b/rerun_py/rerun2/components/color.py @@ -0,0 +1,78 @@ +# NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Any, Optional, Sequence, Union + +import numpy as np +import numpy.typing as npt +import pyarrow as pa + + +@dataclass +class Color: + """An RGBA color tuple with unmultiplied/separate alpha, in sRGB gamma space with linear alpha.""" + + rgba: int + + def __array__(self): + return np.asarray(self.rgba) + + +ColorLike = Union[ + Color, Sequence[int], Sequence[float], npt.NDArray[np.uint8], npt.NDArray[np.float32], npt.NDArray[np.float64] +] + +ColorArrayLike = Union[ + ColorLike, + Sequence[ColorLike], + Sequence[int], + Sequence[float], + npt.NDArray[np.uint8], + npt.NDArray[np.float32], + npt.NDArray[np.float64], +] + + +# --- Arrow support --- + +from rerun2.components.color_ext import ColorArrayExt # noqa: E402 + + +class ColorType(pa.ExtensionType): + def __init__(self: type[pa.ExtensionType]) -> None: + pa.ExtensionType.__init__(self, pa.uint32(), "rerun.components.Color") + + def __arrow_ext_serialize__(self: type[pa.ExtensionType]) -> bytes: + # since we don't have a parameterized type, we don't need extra metadata to be deserialized + return b"" + + @classmethod + def __arrow_ext_deserialize__( + cls: type[pa.ExtensionType], storage_type: Any, serialized: Any + ) -> type[pa.ExtensionType]: + # return an instance of this subclass given the serialized metadata. + return ColorType() + + def __arrow_ext_class__(self: type[pa.ExtensionType]) -> type[pa.ExtensionArray]: + return ColorArray + + +pa.register_extension_type(ColorType()) + + +class ColorArray(pa.ExtensionArray, ColorArrayExt): # type: ignore[misc] + @staticmethod + def from_similar(data: Optional[ColorArrayLike]): + if data is None: + return ColorType().wrap_array(pa.array([], type=ColorType().storage_type)) + else: + return ColorArrayExt.from_similar( + data, + mono=Color, + mono_aliases=ColorLike, + many=ColorArray, + many_aliases=ColorArrayLike, + arrow=ColorType, + ) diff --git a/rerun_py/rerun2/components/draw_order.py b/rerun_py/rerun2/components/draw_order.py new file mode 100644 index 000000000000..0e3252f5e586 --- /dev/null +++ b/rerun_py/rerun2/components/draw_order.py @@ -0,0 +1,76 @@ +# NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Any, Optional, Sequence, Union + +import numpy as np +import numpy.typing as npt +import pyarrow as pa + + +@dataclass +class DrawOrder: + """ + Draw order used for the display order of 2D elements. + + Higher values are drawn on top of lower values. + An entity can have only a single draw order component. + Within an entity draw order is governed by the order of the components. + + Draw order for entities with the same draw order is generally undefined. + """ + + value: float + + def __array__(self): + return np.asarray(self.value) + + +DrawOrderLike = Union[DrawOrder, float] + +DrawOrderArrayLike = Union[DrawOrderLike, Sequence[DrawOrderLike], npt.NDArray[np.float32]] + + +# --- Arrow support --- + +from rerun2.components.draw_order_ext import DrawOrderArrayExt # noqa: E402 + + +class DrawOrderType(pa.ExtensionType): + def __init__(self: type[pa.ExtensionType]) -> None: + pa.ExtensionType.__init__(self, pa.float32(), "rerun.components.DrawOrder") + + def __arrow_ext_serialize__(self: type[pa.ExtensionType]) -> bytes: + # since we don't have a parameterized type, we don't need extra metadata to be deserialized + return b"" + + @classmethod + def __arrow_ext_deserialize__( + cls: type[pa.ExtensionType], storage_type: Any, serialized: Any + ) -> type[pa.ExtensionType]: + # return an instance of this subclass given the serialized metadata. + return DrawOrderType() + + def __arrow_ext_class__(self: type[pa.ExtensionType]) -> type[pa.ExtensionArray]: + return DrawOrderArray + + +pa.register_extension_type(DrawOrderType()) + + +class DrawOrderArray(pa.ExtensionArray, DrawOrderArrayExt): # type: ignore[misc] + @staticmethod + def from_similar(data: Optional[DrawOrderArrayLike]): + if data is None: + return DrawOrderType().wrap_array(pa.array([], type=DrawOrderType().storage_type)) + else: + return DrawOrderArrayExt.from_similar( + data, + mono=DrawOrder, + mono_aliases=DrawOrderLike, + many=DrawOrderArray, + many_aliases=DrawOrderArrayLike, + arrow=DrawOrderType, + ) diff --git a/rerun_py/rerun2/components/instance_key.py b/rerun_py/rerun2/components/instance_key.py new file mode 100644 index 000000000000..3d997f353dce --- /dev/null +++ b/rerun_py/rerun2/components/instance_key.py @@ -0,0 +1,68 @@ +# NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Any, Optional, Sequence, Union + +import numpy as np +import numpy.typing as npt +import pyarrow as pa + + +@dataclass +class InstanceKey: + """A unique numeric identifier for each individual instance within a batch.""" + + value: int + + def __array__(self): + return np.asarray(self.value) + + +InstanceKeyLike = Union[InstanceKey, int] + +InstanceKeyArrayLike = Union[InstanceKeyLike, Sequence[InstanceKeyLike], npt.NDArray[np.uint64]] + + +# --- Arrow support --- + +from rerun2.components.instance_key_ext import InstanceKeyArrayExt # noqa: E402 + + +class InstanceKeyType(pa.ExtensionType): + def __init__(self: type[pa.ExtensionType]) -> None: + pa.ExtensionType.__init__(self, pa.uint64(), "rerun.components.InstanceKey") + + def __arrow_ext_serialize__(self: type[pa.ExtensionType]) -> bytes: + # since we don't have a parameterized type, we don't need extra metadata to be deserialized + return b"" + + @classmethod + def __arrow_ext_deserialize__( + cls: type[pa.ExtensionType], storage_type: Any, serialized: Any + ) -> type[pa.ExtensionType]: + # return an instance of this subclass given the serialized metadata. + return InstanceKeyType() + + def __arrow_ext_class__(self: type[pa.ExtensionType]) -> type[pa.ExtensionArray]: + return InstanceKeyArray + + +pa.register_extension_type(InstanceKeyType()) + + +class InstanceKeyArray(pa.ExtensionArray, InstanceKeyArrayExt): # type: ignore[misc] + @staticmethod + def from_similar(data: Optional[InstanceKeyArrayLike]): + if data is None: + return InstanceKeyType().wrap_array(pa.array([], type=InstanceKeyType().storage_type)) + else: + return InstanceKeyArrayExt.from_similar( + data, + mono=InstanceKey, + mono_aliases=InstanceKeyLike, + many=InstanceKeyArray, + many_aliases=InstanceKeyArrayLike, + arrow=InstanceKeyType, + ) diff --git a/rerun_py/rerun2/components/keypoint_id.py b/rerun_py/rerun2/components/keypoint_id.py new file mode 100644 index 000000000000..4165291e310c --- /dev/null +++ b/rerun_py/rerun2/components/keypoint_id.py @@ -0,0 +1,77 @@ +# NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Any, Optional, Sequence, Union + +import numpy as np +import numpy.typing as npt +import pyarrow as pa + + +@dataclass +class KeypointId: + """ + A 16-bit ID representing a type of semantic keypoint within a class. + + `KeypointId`s are only meaningful within the context of a [`rerun.components.ClassDescription`][]. + + Used to look up an [`rerun.components.AnnotationInfo`][] for a Keypoint within the + [`rerun.components.AnnotationContext`]. + """ + + id: int + + def __array__(self): + return np.asarray(self.id) + + +KeypointIdLike = Union[KeypointId, float] + +KeypointIdArrayLike = Union[ + KeypointIdLike, Sequence[KeypointIdLike], npt.NDArray[np.uint8], npt.NDArray[np.uint16], npt.NDArray[np.uint32] +] + + +# --- Arrow support --- + +from rerun2.components.keypoint_id_ext import KeypointIdArrayExt # noqa: E402 + + +class KeypointIdType(pa.ExtensionType): + def __init__(self: type[pa.ExtensionType]) -> None: + pa.ExtensionType.__init__(self, pa.uint16(), "rerun.components.KeypointId") + + def __arrow_ext_serialize__(self: type[pa.ExtensionType]) -> bytes: + # since we don't have a parameterized type, we don't need extra metadata to be deserialized + return b"" + + @classmethod + def __arrow_ext_deserialize__( + cls: type[pa.ExtensionType], storage_type: Any, serialized: Any + ) -> type[pa.ExtensionType]: + # return an instance of this subclass given the serialized metadata. + return KeypointIdType() + + def __arrow_ext_class__(self: type[pa.ExtensionType]) -> type[pa.ExtensionArray]: + return KeypointIdArray + + +pa.register_extension_type(KeypointIdType()) + + +class KeypointIdArray(pa.ExtensionArray, KeypointIdArrayExt): # type: ignore[misc] + @staticmethod + def from_similar(data: Optional[KeypointIdArrayLike]): + if data is None: + return KeypointIdType().wrap_array(pa.array([], type=KeypointIdType().storage_type)) + else: + return KeypointIdArrayExt.from_similar( + data, + mono=KeypointId, + mono_aliases=KeypointIdLike, + many=KeypointIdArray, + many_aliases=KeypointIdArrayLike, + arrow=KeypointIdType, + ) diff --git a/rerun_py/rerun2/components/label.py b/rerun_py/rerun2/components/label.py new file mode 100644 index 000000000000..066ee6fe4bc1 --- /dev/null +++ b/rerun_py/rerun2/components/label.py @@ -0,0 +1,69 @@ +# NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Any, Optional, Sequence, Union + +import pyarrow as pa + + +@dataclass +class Label: + """A String label component.""" + + value: str + + def __str__(self): + return self.value + + +LabelLike = Union[Label, str] + +LabelArrayLike = Union[ + LabelLike, + Sequence[LabelLike], +] + + +# --- Arrow support --- + +from rerun2.components.label_ext import LabelArrayExt # noqa: E402 + + +class LabelType(pa.ExtensionType): + def __init__(self: type[pa.ExtensionType]) -> None: + pa.ExtensionType.__init__(self, pa.utf8(), "rerun.components.Label") + + def __arrow_ext_serialize__(self: type[pa.ExtensionType]) -> bytes: + # since we don't have a parameterized type, we don't need extra metadata to be deserialized + return b"" + + @classmethod + def __arrow_ext_deserialize__( + cls: type[pa.ExtensionType], storage_type: Any, serialized: Any + ) -> type[pa.ExtensionType]: + # return an instance of this subclass given the serialized metadata. + return LabelType() + + def __arrow_ext_class__(self: type[pa.ExtensionType]) -> type[pa.ExtensionArray]: + return LabelArray + + +pa.register_extension_type(LabelType()) + + +class LabelArray(pa.ExtensionArray, LabelArrayExt): # type: ignore[misc] + @staticmethod + def from_similar(data: Optional[LabelArrayLike]): + if data is None: + return LabelType().wrap_array(pa.array([], type=LabelType().storage_type)) + else: + return LabelArrayExt.from_similar( + data, + mono=Label, + mono_aliases=LabelLike, + many=LabelArray, + many_aliases=LabelArrayLike, + arrow=LabelType, + ) diff --git a/rerun_py/rerun2/components/point2d.py b/rerun_py/rerun2/components/point2d.py new file mode 100644 index 000000000000..16915ada861a --- /dev/null +++ b/rerun_py/rerun2/components/point2d.py @@ -0,0 +1,70 @@ +# NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Any, Optional, Sequence, Tuple, Union + +import numpy as np +import numpy.typing as npt +import pyarrow as pa + + +@dataclass +class Point2D: + """A point in 2D space.""" + + position: npt.ArrayLike + + def __array__(self): + return np.asarray(self.position) + + +Point2DLike = Union[Point2D, npt.NDArray[np.float32], Sequence[float], Tuple[float, float]] + +Point2DArrayLike = Union[Point2DLike, Sequence[Point2DLike], npt.NDArray[np.float32], Sequence[float]] + + +# --- Arrow support --- + +from rerun2.components.point2d_ext import Point2DArrayExt # noqa: E402 + + +class Point2DType(pa.ExtensionType): + def __init__(self: type[pa.ExtensionType]) -> None: + pa.ExtensionType.__init__( + self, pa.list_(pa.field("item", pa.float32(), False, {}), 2), "rerun.components.Point2D" + ) + + def __arrow_ext_serialize__(self: type[pa.ExtensionType]) -> bytes: + # since we don't have a parameterized type, we don't need extra metadata to be deserialized + return b"" + + @classmethod + def __arrow_ext_deserialize__( + cls: type[pa.ExtensionType], storage_type: Any, serialized: Any + ) -> type[pa.ExtensionType]: + # return an instance of this subclass given the serialized metadata. + return Point2DType() + + def __arrow_ext_class__(self: type[pa.ExtensionType]) -> type[pa.ExtensionArray]: + return Point2DArray + + +pa.register_extension_type(Point2DType()) + + +class Point2DArray(pa.ExtensionArray, Point2DArrayExt): # type: ignore[misc] + @staticmethod + def from_similar(data: Optional[Point2DArrayLike]): + if data is None: + return Point2DType().wrap_array(pa.array([], type=Point2DType().storage_type)) + else: + return Point2DArrayExt.from_similar( + data, + mono=Point2D, + mono_aliases=Point2DLike, + many=Point2DArray, + many_aliases=Point2DArrayLike, + arrow=Point2DType, + ) diff --git a/rerun_py/rerun2/components/radius.py b/rerun_py/rerun2/components/radius.py new file mode 100644 index 000000000000..3a106cd14649 --- /dev/null +++ b/rerun_py/rerun2/components/radius.py @@ -0,0 +1,68 @@ +# NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Any, Optional, Sequence, Union + +import numpy as np +import numpy.typing as npt +import pyarrow as pa + + +@dataclass +class Radius: + """A Radius component.""" + + value: float + + def __array__(self): + return np.asarray(self.value) + + +RadiusLike = Union[Radius, float] + +RadiusArrayLike = Union[RadiusLike, Sequence[RadiusLike], npt.NDArray[np.float32]] + + +# --- Arrow support --- + +from rerun2.components.radius_ext import RadiusArrayExt # noqa: E402 + + +class RadiusType(pa.ExtensionType): + def __init__(self: type[pa.ExtensionType]) -> None: + pa.ExtensionType.__init__(self, pa.float32(), "rerun.components.Radius") + + def __arrow_ext_serialize__(self: type[pa.ExtensionType]) -> bytes: + # since we don't have a parameterized type, we don't need extra metadata to be deserialized + return b"" + + @classmethod + def __arrow_ext_deserialize__( + cls: type[pa.ExtensionType], storage_type: Any, serialized: Any + ) -> type[pa.ExtensionType]: + # return an instance of this subclass given the serialized metadata. + return RadiusType() + + def __arrow_ext_class__(self: type[pa.ExtensionType]) -> type[pa.ExtensionArray]: + return RadiusArray + + +pa.register_extension_type(RadiusType()) + + +class RadiusArray(pa.ExtensionArray, RadiusArrayExt): # type: ignore[misc] + @staticmethod + def from_similar(data: Optional[RadiusArrayLike]): + if data is None: + return RadiusType().wrap_array(pa.array([], type=RadiusType().storage_type)) + else: + return RadiusArrayExt.from_similar( + data, + mono=Radius, + mono_aliases=RadiusLike, + many=RadiusArray, + many_aliases=RadiusArrayLike, + arrow=RadiusType, + ) diff --git a/rerun_py/rerun2/datatypes/__init__.py b/rerun_py/rerun2/datatypes/__init__.py new file mode 100644 index 000000000000..862df0e03401 --- /dev/null +++ b/rerun_py/rerun2/datatypes/__init__.py @@ -0,0 +1,8 @@ +# NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +# NOTE: +# - we use fully qualified paths to prevent lazy circular imports +# - `noqa F401` (unused import) everywhere because, while not strictly necessary, +# these imports are very nice for end users. + +from rerun2.datatypes.vec2d import Vec2D, Vec2DArray, Vec2DArrayLike, Vec2DLike, Vec2DType # noqa: F401 diff --git a/rerun_py/rerun2/datatypes/vec2d.py b/rerun_py/rerun2/datatypes/vec2d.py new file mode 100644 index 000000000000..e3712df10c20 --- /dev/null +++ b/rerun_py/rerun2/datatypes/vec2d.py @@ -0,0 +1,70 @@ +# NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Any, Optional, Sequence, Union + +import numpy as np +import numpy.typing as npt +import pyarrow as pa + + +@dataclass +class Vec2D: + """A vector in 2D space.""" + + xy: npt.ArrayLike + + def __array__(self): + return np.asarray(self.xy) + + +Vec2DLike = Vec2D +Vec2DArrayLike = Union[ + Vec2DLike, + Sequence[Vec2DLike], +] + + +# --- Arrow support --- + +from rerun2.datatypes.vec2d_ext import Vec2DArrayExt # noqa: E402 + + +class Vec2DType(pa.ExtensionType): + def __init__(self: type[pa.ExtensionType]) -> None: + pa.ExtensionType.__init__(self, pa.list_(pa.field("item", pa.float32(), False, {}), 2), "rerun.datatypes.Vec2D") + + def __arrow_ext_serialize__(self: type[pa.ExtensionType]) -> bytes: + # since we don't have a parameterized type, we don't need extra metadata to be deserialized + return b"" + + @classmethod + def __arrow_ext_deserialize__( + cls: type[pa.ExtensionType], storage_type: Any, serialized: Any + ) -> type[pa.ExtensionType]: + # return an instance of this subclass given the serialized metadata. + return Vec2DType() + + def __arrow_ext_class__(self: type[pa.ExtensionType]) -> type[pa.ExtensionArray]: + return Vec2DArray + + +pa.register_extension_type(Vec2DType()) + + +class Vec2DArray(pa.ExtensionArray, Vec2DArrayExt): # type: ignore[misc] + @staticmethod + def from_similar(data: Optional[Vec2DArrayLike]): + if data is None: + return Vec2DType().wrap_array(pa.array([], type=Vec2DType().storage_type)) + else: + return Vec2DArrayExt.from_similar( + data, + mono=Vec2D, + mono_aliases=Vec2DLike, + many=Vec2DArray, + many_aliases=Vec2DArrayLike, + arrow=Vec2DType, + )