Skip to content
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

Infer partition size for FixedSizeList-backed components #9210

Merged
merged 20 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/build/re_types_builder/src/codegen/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2649,8 +2649,8 @@ fn quote_columnar_methods(reporter: &Reporter, obj: &Object, objects: &Objects)
for batch in batches:
arrow_array = batch.as_arrow_array()

# For primitive arrays, we infer partition size from the input shape.
if pa.types.is_primitive(arrow_array.type):
# For primitive arrays and fixed size list arrays, we infer partition size from the input shape.
if pa.types.is_primitive(arrow_array.type) or pa.types.is_fixed_size_list(arrow_array.type):
param = kwargs[batch.component_descriptor().archetype_field_name] # type: ignore[index]
shape = np.shape(param) # type: ignore[arg-type]

Expand Down
22 changes: 22 additions & 0 deletions docs/content/howto/logging/send-columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,31 @@ snippet: archetypes/points3d_column_updates
<img src="https://static.rerun.io/points3d_row_updates/fba056871b1ec3fc6978ab605d9a63e44ef1f6de/full.png">
</picture>


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

### Updating a fixed number of arrows over time, in a single operation

Consider this snippet, using the row-oriented `log` API:

snippet: archetypes/arrows3d_row_updates

which can be translated to the column-oriented `send_columns` API as such:

snippet: archetypes/arrows3d_column_updates

<picture data-inline-viewer="snippets/arrows3d_column_updates">
<img src="https://static.rerun.io/arrows3d_column_updates/3e14b35aac709e3f1352426bd905c635b1e13879/full.png" alt="">
<source media="(max-width: 480px)" srcset="https://static.rerun.io/arrows3d_column_updates/3e14b35aac709e3f1352426bd905c635b1e13879/480w.png">
<source media="(max-width: 768px)" srcset="https://static.rerun.io/arrows3d_column_updates/3e14b35aac709e3f1352426bd905c635b1e13879/768w.png">
<source media="(max-width: 1024px)" srcset="https://static.rerun.io/arrows3d_column_updates/3e14b35aac709e3f1352426bd905c635b1e13879/1024w.png">
<source media="(max-width: 1200px)" srcset="https://static.rerun.io/arrows3d_column_updates/3e14b35aac709e3f1352426bd905c635b1e13879/1200w.png">
</picture>

Each row in the component column can be a batch of data, e.g. a batch of positions.
This lets you log the evolution of a set of arrows over time efficiently.


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

Expand Down
3 changes: 3 additions & 0 deletions docs/snippets/INDEX.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions docs/snippets/all/archetypes/arrows3d_column_updates.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Update a set of vectors over time, in a single operation.
//
// This is semantically equivalent to the `arrows3d_row_updates` example, albeit much faster.

#include <rerun.hpp>
#include <rerun/demo_utils.hpp>

#include <algorithm>
#include <vector>

using namespace std::chrono_literals;

int main() {
const auto rec = rerun::RecordingStream("rerun_example_arrows3d_column_updates");
rec.spawn().exit_on_failure();

// Prepare a fixed sequence of arrows over 5 timesteps.
// Origins stay constant, vectors change magnitude and direction, and each timestep has a unique color.
std::vector<std::array<float, 3>> origins;
std::vector<std::array<float, 3>> vectors;

for (size_t i = 0; i < 5; i++) {
float fi = static_cast<float>(i);

auto xs = rerun::demo::linspace(-1.f, 1.f, 5);
auto zs = rerun::demo::linspace(fi / 10.f, fi, 5);
for (size_t j = 0; j < 5; j++) {
std::array<float, 3> origin = {xs[j], xs[j], 0.0};
std::array<float, 3> vector = {xs[j], xs[j], zs[j]};

origins.emplace_back(origin);
vectors.emplace_back(vector);
}
}

// At each timestep, all arrows share the same but changing color.
std::vector<uint32_t> colors = {0xFF0000FF, 0x00FF00FF, 0x0000FFFF, 0xFFFF00FF, 0x00FFFFFF};

// Log at seconds 10-14
auto times = rerun::Collection{10s, 11s, 12s, 13s, 14s};
auto time_column = rerun::TimeColumn::from_durations("time", std::move(times));

auto arrows =
rerun::Arrows3D().with_origins(origins).with_vectors(vectors).columns({5, 5, 5, 5, 5});

rec.send_columns(
"arrows",
time_column,
arrows,
rerun::Arrows3D::update_fields().with_colors(colors).columns()
);
}
28 changes: 28 additions & 0 deletions docs/snippets/all/archetypes/arrows3d_column_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Update a set of vectors over time, in a single operation.

This is semantically equivalent to the `arrows3d_row_updates` example, albeit much faster.
"""

import numpy as np
import rerun as rr

rr.init("rerun_example_arrows3d_column_updates", spawn=True)

# Prepare a fixed sequence of arrows over 5 timesteps.
# Origins stay constant, vectors change magnitude and direction, and each timestep has a unique color.
times = np.arange(10, 15, 1.0)

# At each time step, all arrows maintain their origin.
origins = [np.linspace((-1, -1, 0), (1, 1, 0), 5)] * 5
vectors = [np.linspace((1, 1, i / 10), (1, 1, i), 5) for i in range(5)]


# At each timestep, all arrows share the same but changing color.
colors = [0xFF0000FF, 0x00FF00FF, 0x0000FFFF, 0xFFFF00FF, 0x00FFFFFF]

rr.send_columns(
"arrows",
indexes=[rr.IndexColumn("time", timedelta=times)],
columns=[*rr.Arrows3D.columns(origins=origins, vectors=vectors, colors=colors)],
)
40 changes: 40 additions & 0 deletions docs/snippets/all/archetypes/arrows3d_column_updates.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! Update a set of vectors over time, in a single operation.
//!
//! This is semantically equivalent to the `arrows3d_row_updates` example, albeit much faster.

use rerun::demo_util::linspace;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let rec =
rerun::RecordingStreamBuilder::new("rerun_example_arrows3d_column_updates").spawn()?;
let times = rerun::TimeColumn::new_duration_seconds("time", 10..15);

// Prepare a fixed sequence of arrows over 5 timesteps.
// Origins stay constant, vectors change magnitude and direction, and each timestep has a unique color.
let (origins, vectors): (Vec<_>, Vec<_>) = (0..5)
.map(|i| {
let i = i as f32;
(
linspace(-1., 1., 5).map(move |x| (x, x, 0.)),
linspace(-1., 1., 5)
.zip(linspace(i / 10., i, 5))
.map(|(x, z)| (x, x, z)),
)
})
.collect();

// At each timestep, all arrows share the same but changing color.
let colors = [0xFF0000FF, 0x00FF00FF, 0x0000FFFF, 0xFFFF00FF, 0x00FFFFFF];

let arrows = rerun::Arrows3D::update_fields()
.with_origins(origins.into_iter().flatten())
.with_vectors(vectors.into_iter().flatten())
.columns([5, 5, 5, 5, 5])?;
let color = rerun::Arrows3D::update_fields()
.with_colors(colors)
.columns_of_unit_batches()?;

rec.send_columns("arrows", [times], arrows.chain(color))?;

Ok(())
}
49 changes: 49 additions & 0 deletions docs/snippets/all/archetypes/arrows3d_row_updates.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Update a set of vectors over time.
//
// See also the `arrows3d_column_updates` example, which achieves the same thing in a single operation.

#include <rerun.hpp>
#include <rerun/demo_utils.hpp>

#include <algorithm>
#include <vector>

int main() {
const auto rec = rerun::RecordingStream("rerun_example_arrows3d_row_updates");
rec.spawn().exit_on_failure();

// Prepare a fixed sequence of arrows over 5 timesteps.
// Origins stay constant, vectors change magnitude and direction, and each timestep has a unique color.
std::vector<std::array<std::array<float, 3>, 5>> origins;
std::vector<std::array<std::array<float, 3>, 5>> vectors;

for (size_t i = 0; i < 5; i++) {
float fi = static_cast<float>(i);

auto xs = rerun::demo::linspace(-1.f, 1.f, 5);
auto zs = rerun::demo::linspace(fi / 10.f, fi, 5);

std::array<std::array<float, 3>, 5> origin;
std::array<std::array<float, 3>, 5> vector;
for (size_t j = 0; j < 5; j++) {
origin[j] = {xs[j], xs[j], 0.0};
vector[j] = {xs[j], xs[j], zs[j]};
}

origins.emplace_back(origin);
vectors.emplace_back(vector);
}

// At each timestep, all arrows share the same but changing color.
std::vector<uint32_t> colors = {0xFF0000FF, 0x00FF00FF, 0x0000FFFF, 0xFFFF00FF, 0x00FFFFFF};

for (size_t i = 0; i < 5; i++) {
rec.set_index_duration_secs("time", 10.0 + static_cast<double>(i));
rec.log(
"arrows",
rerun::Arrows3D::from_vectors(vectors[i])
.with_origins(origins[i])
.with_colors(colors[i])
);
}
}
26 changes: 26 additions & 0 deletions docs/snippets/all/archetypes/arrows3d_row_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Update a set of vectors over time.

See also the `arrows3d_column_updates` example, which achieves the same thing in a single operation.
"""

import numpy as np
import rerun as rr

rr.init("rerun_example_arrows3d_row_updates", spawn=True)

# Prepare a fixed sequence of arrows over 5 timesteps.
# Origins stay constant, vectors change magnitude and direction, and each timestep has a unique color.
times = np.arange(10, 15, 1.0)

# At each time step, all arrows maintain their origin.
origins = np.linspace((-1, -1, 0), (1, 1, 0), 5)
vectors = [np.linspace((1, 1, i / 10), (1, 1, i), 5) for i in range(5)]


# At each timestep, all arrows share the same but changing color.
colors = [0xFF0000FF, 0x00FF00FF, 0x0000FFFF, 0xFFFF00FF, 0x00FFFFFF]

for i in range(5):
rr.set_index("time", timedelta=10 + i)
rr.log("arrows", rr.Arrows3D(vectors=vectors[i], origins=origins, colors=colors[i]))
38 changes: 38 additions & 0 deletions docs/snippets/all/archetypes/arrows3d_row_updates.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! Update a set of vectors over time.
//!
//! See also the `arrows3d_column_updates` example, which achieves the same thing in a single operation.

use rerun::demo_util::linspace;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let rec = rerun::RecordingStreamBuilder::new("rerun_example_arrows3d_row_updates").spawn()?;

// Prepare a fixed sequence of arrows over 5 timesteps.
// Origins stay constant, vectors change magnitude and direction, and each timestep has a unique color.
let (origins, vectors): (Vec<_>, Vec<_>) = (0..5)
.map(|i| {
let i = i as f32;
(
linspace(-1., 1., 5).map(move |x| (x, x, 0.)),
linspace(-1., 1., 5)
.zip(linspace(i / 10., i, 5))
.map(|(x, z)| (x, x, z)),
)
})
.collect();

// At each timestep, all arrows share the same but changing color.
let colors = [0xFF0000FF, 0x00FF00FF, 0x0000FFFF, 0xFFFF00FF, 0x00FFFFFF];

for (time, origins, vectors, color) in itertools::izip!(10..15, origins, vectors, colors) {
rec.set_duration_seconds("time", time);

let arrows = rerun::Arrows3D::from_vectors(vectors)
.with_origins(origins)
.with_colors([color]);

rec.log("arrows", &arrows)?;
}

Ok(())
}
2 changes: 2 additions & 0 deletions docs/snippets/snippets.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ features = [
[
"Update rows",
[
"archetypes/arrows3d_row_updates",
"archetypes/scalar_row_updates",
"archetypes/points3d_row_updates",
"archetypes/transform3d_row_updates",
Expand All @@ -28,6 +29,7 @@ features = [
[
"Update columns",
[
"archetypes/arrows3d_row_columns",
"archetypes/scalar_column_updates",
"archetypes/points3d_column_updates",
"archetypes/transform3d_column_updates",
Expand Down
24 changes: 6 additions & 18 deletions lychee.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,10 @@ exclude = [
# '^file:///', # Ignore local file links. They need to be tested, but it's useful for external links we have to ping.

# Snippets that haven't been released yet.
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_column_updates.rs',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.cpp',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.py',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates.rs',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.cpp',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.py',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/points3d_partial_updates_legacy.rs',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/transform3d_partial_updates.cpp',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/transform3d_partial_updates.py',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/transform3d_partial_updates.rs',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/howto/any_batch_value_column_updates.cpp',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/howto/any_batch_value_column_updates.rs',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/howto/any_values_column_updates.cpp',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/howto/any_values_column_updates.rs',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/tutorials/any_values.cpp',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/tutorials/any_values.rs',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/tutorials/extra_values.cpp',
'https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/tutorials/extra_values.rs',
"https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/arrows3d_row_updates.rs",
"https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/arrows3d_column_updates.rs",
"https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/arrows3d_column_updates.cpp",
"https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/arrows3d_row_updates.cpp",
"https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/arrows3d_row_updates.py",
"https://github.com/rerun-io/rerun/blob/main/docs/snippets/all/archetypes/arrows3d_column_updates.py",
]
Loading
Loading