Skip to content

Commit fb6241e

Browse files
oxkitsuneWumpf
authored andcommitted
Infer partition size for FixedSizeList-backed components (#9210)
### Related Closes #9171 ### What This lets the user do: ```py rr.send_columns( "random_3d_points", indexes=[times], columns=rr.Points3D.columns(positions=np.random.random((len(times), 21, 3))), ) ``` --------- Co-authored-by: Andreas Reich <r_andreas2@web.de>
1 parent b216be6 commit fb6241e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+414
-102
lines changed

crates/build/re_types_builder/src/codegen/python/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2649,8 +2649,8 @@ fn quote_columnar_methods(reporter: &Reporter, obj: &Object, objects: &Objects)
26492649
for batch in batches:
26502650
arrow_array = batch.as_arrow_array()
26512651
2652-
# For primitive arrays, we infer partition size from the input shape.
2653-
if pa.types.is_primitive(arrow_array.type):
2652+
# For primitive arrays and fixed size list arrays, we infer partition size from the input shape.
2653+
if pa.types.is_primitive(arrow_array.type) or pa.types.is_fixed_size_list(arrow_array.type):
26542654
param = kwargs[batch.component_descriptor().archetype_field_name] # type: ignore[index]
26552655
shape = np.shape(param) # type: ignore[arg-type]
26562656

docs/content/howto/logging/send-columns.md

+22
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,31 @@ snippet: archetypes/points3d_column_updates
6363
<img src="https://static.rerun.io/points3d_row_updates/fba056871b1ec3fc6978ab605d9a63e44ef1f6de/full.png">
6464
</picture>
6565

66+
6667
Each row in the component column can be a batch of data, e.g. a batch of positions.
6768
This lets you log the evolution of a point cloud over time efficiently.
6869

70+
### Updating a fixed number of arrows over time, in a single operation
71+
72+
Consider this snippet, using the row-oriented `log` API:
73+
74+
snippet: archetypes/arrows3d_row_updates
75+
76+
which can be translated to the column-oriented `send_columns` API as such:
77+
78+
snippet: archetypes/arrows3d_column_updates
79+
80+
<picture data-inline-viewer="snippets/arrows3d_column_updates">
81+
<img src="https://static.rerun.io/arrows3d_column_updates/3e14b35aac709e3f1352426bd905c635b1e13879/full.png" alt="">
82+
<source media="(max-width: 480px)" srcset="https://static.rerun.io/arrows3d_column_updates/3e14b35aac709e3f1352426bd905c635b1e13879/480w.png">
83+
<source media="(max-width: 768px)" srcset="https://static.rerun.io/arrows3d_column_updates/3e14b35aac709e3f1352426bd905c635b1e13879/768w.png">
84+
<source media="(max-width: 1024px)" srcset="https://static.rerun.io/arrows3d_column_updates/3e14b35aac709e3f1352426bd905c635b1e13879/1024w.png">
85+
<source media="(max-width: 1200px)" srcset="https://static.rerun.io/arrows3d_column_updates/3e14b35aac709e3f1352426bd905c635b1e13879/1200w.png">
86+
</picture>
87+
88+
Each row in the component column can be a batch of data, e.g. a batch of positions.
89+
This lets you log the evolution of a set of arrows over time efficiently.
90+
6991

7092
### Updating a transform over time, in a single operation
7193

docs/snippets/INDEX.md

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Update a set of vectors over time, in a single operation.
2+
//
3+
// This is semantically equivalent to the `arrows3d_row_updates` example, albeit much faster.
4+
5+
#include <rerun.hpp>
6+
#include <rerun/demo_utils.hpp>
7+
8+
#include <algorithm>
9+
#include <vector>
10+
11+
using namespace std::chrono_literals;
12+
13+
int main() {
14+
const auto rec = rerun::RecordingStream("rerun_example_arrows3d_column_updates");
15+
rec.spawn().exit_on_failure();
16+
17+
// Prepare a fixed sequence of arrows over 5 timesteps.
18+
// Origins stay constant, vectors change magnitude and direction, and each timestep has a unique color.
19+
std::vector<std::array<float, 3>> origins;
20+
std::vector<std::array<float, 3>> vectors;
21+
22+
for (size_t i = 0; i < 5; i++) {
23+
float fi = static_cast<float>(i);
24+
25+
auto xs = rerun::demo::linspace(-1.f, 1.f, 5);
26+
auto zs = rerun::demo::linspace(fi / 10.f, fi, 5);
27+
for (size_t j = 0; j < 5; j++) {
28+
std::array<float, 3> origin = {xs[j], xs[j], 0.0};
29+
std::array<float, 3> vector = {xs[j], xs[j], zs[j]};
30+
31+
origins.emplace_back(origin);
32+
vectors.emplace_back(vector);
33+
}
34+
}
35+
36+
// At each timestep, all arrows share the same but changing color.
37+
std::vector<uint32_t> colors = {0xFF0000FF, 0x00FF00FF, 0x0000FFFF, 0xFFFF00FF, 0x00FFFFFF};
38+
39+
// Log at seconds 10-14
40+
auto times = rerun::Collection{10s, 11s, 12s, 13s, 14s};
41+
auto time_column = rerun::TimeColumn::from_durations("time", std::move(times));
42+
43+
auto arrows =
44+
rerun::Arrows3D().with_origins(origins).with_vectors(vectors).columns({5, 5, 5, 5, 5});
45+
46+
rec.send_columns(
47+
"arrows",
48+
time_column,
49+
arrows,
50+
rerun::Arrows3D::update_fields().with_colors(colors).columns()
51+
);
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
Update a set of vectors over time, in a single operation.
3+
4+
This is semantically equivalent to the `arrows3d_row_updates` example, albeit much faster.
5+
"""
6+
7+
import numpy as np
8+
import rerun as rr
9+
10+
rr.init("rerun_example_arrows3d_column_updates", spawn=True)
11+
12+
# Prepare a fixed sequence of arrows over 5 timesteps.
13+
# Origins stay constant, vectors change magnitude and direction, and each timestep has a unique color.
14+
times = np.arange(10, 15, 1.0)
15+
16+
# At each time step, all arrows maintain their origin.
17+
origins = [np.linspace((-1, -1, 0), (1, 1, 0), 5)] * 5
18+
vectors = [np.linspace((1, 1, i / 10), (1, 1, i), 5) for i in range(5)]
19+
20+
21+
# At each timestep, all arrows share the same but changing color.
22+
colors = [0xFF0000FF, 0x00FF00FF, 0x0000FFFF, 0xFFFF00FF, 0x00FFFFFF]
23+
24+
rr.send_columns(
25+
"arrows",
26+
indexes=[rr.IndexColumn("time", timedelta=times)],
27+
columns=[*rr.Arrows3D.columns(origins=origins, vectors=vectors, colors=colors)],
28+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//! Update a set of vectors over time, in a single operation.
2+
//!
3+
//! This is semantically equivalent to the `arrows3d_row_updates` example, albeit much faster.
4+
5+
use rerun::demo_util::linspace;
6+
7+
fn main() -> Result<(), Box<dyn std::error::Error>> {
8+
let rec =
9+
rerun::RecordingStreamBuilder::new("rerun_example_arrows3d_column_updates").spawn()?;
10+
let times = rerun::TimeColumn::new_duration_seconds("time", 10..15);
11+
12+
// Prepare a fixed sequence of arrows over 5 timesteps.
13+
// Origins stay constant, vectors change magnitude and direction, and each timestep has a unique color.
14+
let (origins, vectors): (Vec<_>, Vec<_>) = (0..5)
15+
.map(|i| {
16+
let i = i as f32;
17+
(
18+
linspace(-1., 1., 5).map(move |x| (x, x, 0.)),
19+
linspace(-1., 1., 5)
20+
.zip(linspace(i / 10., i, 5))
21+
.map(|(x, z)| (x, x, z)),
22+
)
23+
})
24+
.collect();
25+
26+
// At each timestep, all arrows share the same but changing color.
27+
let colors = [0xFF0000FF, 0x00FF00FF, 0x0000FFFF, 0xFFFF00FF, 0x00FFFFFF];
28+
29+
let arrows = rerun::Arrows3D::update_fields()
30+
.with_origins(origins.into_iter().flatten())
31+
.with_vectors(vectors.into_iter().flatten())
32+
.columns([5, 5, 5, 5, 5])?;
33+
let color = rerun::Arrows3D::update_fields()
34+
.with_colors(colors)
35+
.columns_of_unit_batches()?;
36+
37+
rec.send_columns("arrows", [times], arrows.chain(color))?;
38+
39+
Ok(())
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Update a set of vectors over time.
2+
//
3+
// See also the `arrows3d_column_updates` example, which achieves the same thing in a single operation.
4+
5+
#include <rerun.hpp>
6+
#include <rerun/demo_utils.hpp>
7+
8+
#include <algorithm>
9+
#include <vector>
10+
11+
int main() {
12+
const auto rec = rerun::RecordingStream("rerun_example_arrows3d_row_updates");
13+
rec.spawn().exit_on_failure();
14+
15+
// Prepare a fixed sequence of arrows over 5 timesteps.
16+
// Origins stay constant, vectors change magnitude and direction, and each timestep has a unique color.
17+
std::vector<std::array<std::array<float, 3>, 5>> origins;
18+
std::vector<std::array<std::array<float, 3>, 5>> vectors;
19+
20+
for (size_t i = 0; i < 5; i++) {
21+
float fi = static_cast<float>(i);
22+
23+
auto xs = rerun::demo::linspace(-1.f, 1.f, 5);
24+
auto zs = rerun::demo::linspace(fi / 10.f, fi, 5);
25+
26+
std::array<std::array<float, 3>, 5> origin;
27+
std::array<std::array<float, 3>, 5> vector;
28+
for (size_t j = 0; j < 5; j++) {
29+
origin[j] = {xs[j], xs[j], 0.0};
30+
vector[j] = {xs[j], xs[j], zs[j]};
31+
}
32+
33+
origins.emplace_back(origin);
34+
vectors.emplace_back(vector);
35+
}
36+
37+
// At each timestep, all arrows share the same but changing color.
38+
std::vector<uint32_t> colors = {0xFF0000FF, 0x00FF00FF, 0x0000FFFF, 0xFFFF00FF, 0x00FFFFFF};
39+
40+
for (size_t i = 0; i < 5; i++) {
41+
rec.set_index_duration_secs("time", 10.0 + static_cast<double>(i));
42+
rec.log(
43+
"arrows",
44+
rerun::Arrows3D::from_vectors(vectors[i])
45+
.with_origins(origins[i])
46+
.with_colors(colors[i])
47+
);
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Update a set of vectors over time.
3+
4+
See also the `arrows3d_column_updates` example, which achieves the same thing in a single operation.
5+
"""
6+
7+
import numpy as np
8+
import rerun as rr
9+
10+
rr.init("rerun_example_arrows3d_row_updates", spawn=True)
11+
12+
# Prepare a fixed sequence of arrows over 5 timesteps.
13+
# Origins stay constant, vectors change magnitude and direction, and each timestep has a unique color.
14+
times = np.arange(10, 15, 1.0)
15+
16+
# At each time step, all arrows maintain their origin.
17+
origins = np.linspace((-1, -1, 0), (1, 1, 0), 5)
18+
vectors = [np.linspace((1, 1, i / 10), (1, 1, i), 5) for i in range(5)]
19+
20+
21+
# At each timestep, all arrows share the same but changing color.
22+
colors = [0xFF0000FF, 0x00FF00FF, 0x0000FFFF, 0xFFFF00FF, 0x00FFFFFF]
23+
24+
for i in range(5):
25+
rr.set_index("time", timedelta=10 + i)
26+
rr.log("arrows", rr.Arrows3D(vectors=vectors[i], origins=origins, colors=colors[i]))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//! Update a set of vectors over time.
2+
//!
3+
//! See also the `arrows3d_column_updates` example, which achieves the same thing in a single operation.
4+
5+
use rerun::demo_util::linspace;
6+
7+
fn main() -> Result<(), Box<dyn std::error::Error>> {
8+
let rec = rerun::RecordingStreamBuilder::new("rerun_example_arrows3d_row_updates").spawn()?;
9+
10+
// Prepare a fixed sequence of arrows over 5 timesteps.
11+
// Origins stay constant, vectors change magnitude and direction, and each timestep has a unique color.
12+
let (origins, vectors): (Vec<_>, Vec<_>) = (0..5)
13+
.map(|i| {
14+
let i = i as f32;
15+
(
16+
linspace(-1., 1., 5).map(move |x| (x, x, 0.)),
17+
linspace(-1., 1., 5)
18+
.zip(linspace(i / 10., i, 5))
19+
.map(|(x, z)| (x, x, z)),
20+
)
21+
})
22+
.collect();
23+
24+
// At each timestep, all arrows share the same but changing color.
25+
let colors = [0xFF0000FF, 0x00FF00FF, 0x0000FFFF, 0xFFFF00FF, 0x00FFFFFF];
26+
27+
for (time, origins, vectors, color) in itertools::izip!(10..15, origins, vectors, colors) {
28+
rec.set_duration_seconds("time", time);
29+
30+
let arrows = rerun::Arrows3D::from_vectors(vectors)
31+
.with_origins(origins)
32+
.with_colors([color]);
33+
34+
rec.log("arrows", &arrows)?;
35+
}
36+
37+
Ok(())
38+
}

docs/snippets/snippets.toml

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ features = [
2020
[
2121
"Update rows",
2222
[
23+
"archetypes/arrows3d_row_updates",
2324
"archetypes/scalar_row_updates",
2425
"archetypes/points3d_row_updates",
2526
"archetypes/transform3d_row_updates",
@@ -28,6 +29,7 @@ features = [
2829
[
2930
"Update columns",
3031
[
32+
"archetypes/arrows3d_row_columns",
3133
"archetypes/scalar_column_updates",
3234
"archetypes/points3d_column_updates",
3335
"archetypes/transform3d_column_updates",

lychee.toml

+6-18
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,10 @@ exclude = [
157157
# '^file:///', # Ignore local file links. They need to be tested, but it's useful for external links we have to ping.
158158

159159
# Snippets that haven't been released yet.
160-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_column_updates.rs',
161-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.cpp',
162-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.py',
163-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.rs',
164-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.cpp',
165-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.py',
166-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.rs',
167-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/transform3d_partial_updates.cpp',
168-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/transform3d_partial_updates.py',
169-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/transform3d_partial_updates.rs',
170-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/howto/any_batch_value_column_updates.cpp',
171-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/howto/any_batch_value_column_updates.rs',
172-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/howto/any_values_column_updates.cpp',
173-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/howto/any_values_column_updates.rs',
174-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/tutorials/any_values.cpp',
175-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/tutorials/any_values.rs',
176-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/tutorials/extra_values.cpp',
177-
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/tutorials/extra_values.rs',
160+
"https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/arrows3d_row_updates.rs",
161+
"https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/arrows3d_column_updates.rs",
162+
"https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/arrows3d_column_updates.cpp",
163+
"https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/arrows3d_row_updates.cpp",
164+
"https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/arrows3d_row_updates.py",
165+
"https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/arrows3d_column_updates.py",
178166
]

0 commit comments

Comments
 (0)