-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Codegen/IDL 7: handwritten Python tests and extensions for Points2D
#2410
Changes from all commits
6b18956
1dd116a
cc3e464
4424160
d02415a
d3feee9
3064e4c
241a667
fb7f248
386a62e
f7f97c9
2ad0695
d4bf7c5
8138d62
22f6677
70220db
e23c608
75251a7
f394106
8634406
1f269c6
ce2e4a2
cf684ce
c5e53b0
41728fe
bc35933
c1447b7
019aa55
8361e0a
a816bdf
18ee660
d9d2363
6c4f1cb
28b9354
ed59c9a
a857211
48df2d5
a440e4e
72e4ce9
c767df7
5aa37ae
6fbe9f9
969a65f
b967a1b
e1aab5d
1bb25df
02201ae
9a3853b
8c281e0
9ec1edf
872cfe4
2fa5283
d156759
2fd016d
246fb8b
497b368
df4eb93
cc4f910
e3d5be3
14aa58b
0bada80
7bdcbc7
39951aa
e676518
231a146
f758038
d0524b6
6529880
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# This is a sha256 hash for all direct and indirect dependencies of this crate's build script. | ||
# It can be safely removed at anytime to force the build script to run again. | ||
# Check out build.rs to see how it's computed. | ||
2d611d0d686a6314da94b1797472e7690413465d16a611aae3560a847668d53d | ||
184f79acfe7c0608f9ec2bb5f6a6783dc2270f5cae0edb147ad08ad4ee89c825 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from __future__ import annotations | ||
|
||
__all__ = ["ClassIdArrayExt"] | ||
|
||
from typing import Any, Sequence | ||
|
||
import numpy as np | ||
import pyarrow as pa | ||
|
||
|
||
class ClassIdArrayExt: | ||
@staticmethod | ||
def _from_similar( | ||
data: Any | None, *, mono: type, mono_aliases: Any, many: type, many_aliases: Any, arrow: type | ||
) -> pa.Array: | ||
if isinstance(data, Sequence) and (len(data) > 0 and isinstance(data[0], mono)): | ||
teh-cmc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
array = np.asarray([class_id.id for class_id in data], np.uint16) | ||
else: | ||
array = np.asarray(data, dtype=np.uint16).flatten() | ||
|
||
return arrow().wrap_array(pa.array(array, type=arrow().storage_type)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from __future__ import annotations | ||
|
||
__all__ = ["ColorArrayExt"] | ||
|
||
from typing import Any, Sequence | ||
|
||
import numpy as np | ||
import pyarrow as pa | ||
from rerun.color_conversion import u8_array_to_rgba | ||
|
||
|
||
class ColorArrayExt: | ||
@staticmethod | ||
def _from_similar( | ||
data: Any | None, *, mono: type, mono_aliases: Any, many: type, many_aliases: Any, arrow: type | ||
) -> pa.Array: | ||
""" | ||
Normalize flexible colors arrays. | ||
|
||
Float colors are assumed to be in 0-1 gamma sRGB space. | ||
All other colors are assumed to be in 0-255 gamma sRGB space. | ||
|
||
If there is an alpha, we assume it is in linear space, and separate (NOT pre-multiplied). | ||
""" | ||
Comment on lines
+17
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to surface this comment somehow to the user where appropriate. Here it won't be all that useful There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add this blurb as tagged docs. Though again, this is just an alpha preview, we'll give the doc much more love when backporting. |
||
if isinstance(data, Sequence) and len(data) == 0: | ||
array = np.array([], np.uint32) | ||
elif isinstance(data, Sequence) and (len(data) > 0 and isinstance(data[0], mono)): | ||
array = np.asarray([color.rgba for color in data], np.uint32) | ||
elif isinstance(data, Sequence) and (len(data) > 0 and isinstance(data[0], int)): | ||
array = np.asarray(data, np.uint32) | ||
else: | ||
array = np.asarray(data) | ||
# Rust expects colors in 0-255 uint8 | ||
if array.dtype.type in [np.float32, np.float64]: | ||
# Assume gamma-space colors | ||
array = u8_array_to_rgba(np.asarray(np.round(np.asarray(data).reshape((-1, 4)) * 255.0), np.uint8)) | ||
elif array.dtype.type == np.uint32: | ||
array = np.asarray(data).flatten() | ||
else: | ||
array = u8_array_to_rgba(np.asarray(data, dtype=np.uint8).reshape((-1, 4))) | ||
|
||
return arrow().wrap_array(pa.array(array, type=arrow().storage_type)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from __future__ import annotations | ||
|
||
__all__ = ["DrawOrderArrayExt"] | ||
|
||
from typing import Any, Sequence | ||
|
||
import numpy as np | ||
import pyarrow as pa | ||
|
||
|
||
class DrawOrderArrayExt: | ||
@staticmethod | ||
def _from_similar( | ||
data: Any | None, *, mono: type, mono_aliases: Any, many: type, many_aliases: Any, arrow: type | ||
) -> pa.Array: | ||
if isinstance(data, Sequence) and (len(data) > 0 and isinstance(data[0], mono)): | ||
array = np.asarray([draw_order.value for draw_order in data], np.float32) | ||
else: | ||
array = np.require(np.asarray(data), np.float32).flatten() | ||
|
||
return arrow().wrap_array(pa.array(array, type=arrow().storage_type)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what error are se suppressing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some non-sense about inheriting
Any
or something.I don't remember exactly and didn't bother any further because this is just a verbatim port of what we already do today.