File size: 2,079 Bytes
9ff4bea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/python/mod.rs
# Based on "crates/build/re_type_definitions/rerun/encodings/float32.def.rs".

# You can extend this class by creating a "Float32Ext" class in "float32_ext.py".

from __future__ import annotations

from collections.abc import Sequence
from typing import TYPE_CHECKING, Any

import numpy as np
import numpy.typing as npt
import pyarrow as pa
from attrs import define, field

from .._baseclasses import (
    BaseBatch,
)
from .._numpy_compatibility import asarray

__all__ = ["Float32", "Float32ArrayLike", "Float32Batch", "Float32Like"]


@define(init=False)
class Float32:
    """**Encoding**: A single-precision 32-bit IEEE 754 floating point number."""

    def __init__(self: Any, value: Float32Like) -> None:
        """Create a new instance of the Float32 encoding."""

        # You can define your own __init__ function as a member of Float32Ext in float32_ext.py
        self.__attrs_init__(value=value)

    value: float = field(converter=float)

    def __array__(self, dtype: npt.DTypeLike = None, copy: bool | None = None) -> npt.NDArray[Any]:
        # You can define your own __array__ function as a member of Float32Ext in float32_ext.py
        return asarray(self.value, dtype=dtype, copy=copy)

    def __float__(self) -> float:
        return float(self.value)

    def __hash__(self) -> int:
        return hash(self.value)


if TYPE_CHECKING:
    Float32Like = Float32 | float
    """A type alias for any Float32-like object."""
else:
    Float32Like = Any

Float32ArrayLike = (
    Float32 | Sequence[Float32Like] | npt.NDArray[Any] | npt.ArrayLike | Sequence[Sequence[float]] | Sequence[float]
)
"""A type alias for any Float32-like array object."""


class Float32Batch(BaseBatch[Float32ArrayLike]):
    _ARROW_DATATYPE = pa.float32()

    @staticmethod
    def _native_to_pa_array(data: Float32ArrayLike, data_type: pa.DataType) -> pa.Array:
        array = np.asarray(data, dtype=np.float32).flatten()
        return pa.array(array, type=data_type)