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

Upgrade arrow2/convert and use native buffers for the tensor u8 types #1375

Merged
merged 2 commits into from
May 9, 2023
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
328 changes: 83 additions & 245 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ rerun = { path = "crates/rerun", version = "=0.6.0-alpha.0", default-features =

ahash = "0.8"
anyhow = "1.0"
arrow2 = "0.16"
arrow2_convert = "0.4.2"
arrow2 = "0.17"
arrow2_convert = "0.5.0"
bytemuck = { version = "1.11", features = ["extern_crate_alloc"] }
cfg-if = "1.0"
clap = "4.0"
Expand All @@ -82,9 +82,9 @@ mimalloc = "0.1.29"
ndarray = "0.15"
nohash-hasher = "0.2"
parking_lot = "0.12"
polars-core = "0.27.1"
polars-lazy = "0.27.1"
polars-ops = "0.27.1"
polars-core = "0.29"
polars-lazy = "0.29"
polars-ops = "0.29"
puffin = "0.14"
rfd = { version = "0.11.3", default_features = false, features = [
"xdg-portal",
Expand Down
2 changes: 1 addition & 1 deletion crates/re_data_ui/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ pub fn tensor_summary_ui_grid_contents(
re_ui.grid_left_hand_label(ui, "Encoding");
ui.label(format!(
"{} JPEG",
re_format::format_bytes(jpeg_bytes.num_bytes() as _),
re_format::format_bytes(jpeg_bytes.len() as _),
));
ui.end_row();
}
Expand Down
130 changes: 0 additions & 130 deletions crates/re_log_types/src/component_types/arrow_convert_shims.rs

This file was deleted.

5 changes: 2 additions & 3 deletions crates/re_log_types/src/component_types/mesh3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use arrow2_convert::{serialize::ArrowSerialize, ArrowDeserialize, ArrowField, Ar

use crate::Component;

use super::arrow_convert_shims::BinaryBuffer;
use super::{FieldError, Vec4D};

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -262,7 +261,7 @@ pub struct EncodedMesh3D {

pub format: MeshFormat,

pub bytes: BinaryBuffer,
pub bytes: Buffer<u8>,

/// four columns of an affine transformation matrix
pub transform: [[f32; 3]; 4],
Expand All @@ -275,7 +274,7 @@ pub struct EncodedMesh3DArrow {

pub format: MeshFormat,

pub bytes: BinaryBuffer,
pub bytes: Buffer<u8>,

#[arrow_field(type = "arrow2_convert::field::FixedSizeVec<f32, 12>")]
pub transform: Vec<f32>,
Expand Down
1 change: 0 additions & 1 deletion crates/re_log_types/src/component_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use lazy_static::lazy_static;
use crate::Component;

mod arrow;
mod arrow_convert_shims;
mod bbox;
mod class_id;
mod color;
Expand Down
10 changes: 4 additions & 6 deletions crates/re_log_types/src/component_types/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use arrow2_convert::{serialize::ArrowSerialize, ArrowDeserialize, ArrowField, Ar
use crate::Component;
use crate::{TensorDataType, TensorElement};

use super::arrow_convert_shims::BinaryBuffer;

// ----------------------------------------------------------------------------

/// A unique id per [`Tensor`].
Expand Down Expand Up @@ -145,7 +143,7 @@ impl ArrowDeserialize for TensorId {
#[derive(Clone, PartialEq, ArrowField, ArrowSerialize, ArrowDeserialize)]
#[arrow_field(type = "dense")]
pub enum TensorData {
U8(BinaryBuffer),
U8(Buffer<u8>),
U16(Buffer<u16>),
U32(Buffer<u32>),
U64(Buffer<u64>),
Expand All @@ -159,7 +157,7 @@ pub enum TensorData {
//F16(Vec<arrow2::types::f16>),
F32(Buffer<f32>),
F64(Buffer<f64>),
JPEG(BinaryBuffer),
JPEG(Buffer<u8>),
}

impl TensorData {
Expand All @@ -180,7 +178,7 @@ impl TensorData {

pub fn size_in_bytes(&self) -> usize {
match self {
Self::U8(buf) | Self::JPEG(buf) => buf.0.len(),
Self::U8(buf) | Self::JPEG(buf) => buf.len(),
Self::U16(buf) => buf.len(),
Self::U32(buf) => buf.len(),
Self::U64(buf) => buf.len(),
Expand Down Expand Up @@ -979,7 +977,7 @@ impl DecodedTensor {

TensorData::JPEG(buf) => {
use image::io::Reader as ImageReader;
let mut reader = ImageReader::new(std::io::Cursor::new(buf.0.as_slice()));
let mut reader = ImageReader::new(std::io::Cursor::new(buf.as_slice()));
reader.set_format(image::ImageFormat::Jpeg);
let img = {
crate::profile_scope!("decode_jpeg");
Expand Down
12 changes: 6 additions & 6 deletions crates/re_log_types/src/data_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ fn data_table_sizes_basics() {
2_690_064, // expected_num_bytes
);
expect(
DataCell::from_arrow("some_bools".into(), cell.to_arrow().slice(1, 1)),
DataCell::from_arrow("some_bools".into(), cell.to_arrow().sliced(1, 1)),
10_000, // num_rows
2_690_064, // expected_num_bytes
);
Expand All @@ -1182,7 +1182,7 @@ fn data_table_sizes_basics() {
2_840_064, // expected_num_bytes
);
expect(
DataCell::from_arrow("some_u64s".into(), cell.to_arrow().slice(1, 1)),
DataCell::from_arrow("some_u64s".into(), cell.to_arrow().sliced(1, 1)),
10_000, // num_rows
2_680_064, // expected_num_bytes
);
Expand All @@ -1205,7 +1205,7 @@ fn data_table_sizes_basics() {
expect(
DataCell::from_arrow(
crate::component_types::Label::name(),
cell.to_arrow().slice(1, 1),
cell.to_arrow().sliced(1, 1),
),
10_000, // num_rows
2_950_064, // expected_num_bytes
Expand All @@ -1229,7 +1229,7 @@ fn data_table_sizes_basics() {
expect(
DataCell::from_arrow(
crate::component_types::Point2D::name(),
cell.to_arrow().slice(1, 1),
cell.to_arrow().sliced(1, 1),
),
10_000, // num_rows
5_100_064, // expected_num_bytes
Expand All @@ -1253,7 +1253,7 @@ fn data_table_sizes_basics() {
expect(
DataCell::from_arrow(
crate::component_types::Point2D::name(),
cell.to_arrow().slice(1, 1),
cell.to_arrow().sliced(1, 1),
),
10_000, // num_rows
3_920_064, // expected_num_bytes
Expand Down Expand Up @@ -1289,7 +1289,7 @@ fn data_table_sizes_basics() {
expect(
DataCell::from_arrow(
crate::component_types::Point2D::name(),
cell.to_arrow().slice(1, 1),
cell.to_arrow().sliced(1, 1),
),
10_000, // num_rows
5_560_064, // expected_num_bytes
Expand Down
6 changes: 3 additions & 3 deletions crates/re_log_types/src/size_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ fn estimated_bytes_size(array: &dyn Array) -> usize {
estimated_bytes_size(
array
.values()
.slice(values_start, values_end - values_start)
.sliced(values_start, values_end - values_start)
.as_ref(),
) + std::mem::size_of_val(array.offsets().as_slice())
+ validity_size(array.validity())
Expand Down Expand Up @@ -372,7 +372,7 @@ fn estimated_bytes_size(array: &dyn Array) -> usize {
let values_end = offsets[idx_end] as usize;
fields.get(cur_ty as usize).map_or(0, |x| {
estimated_bytes_size(
x.slice(values_start, values_end - values_start).as_ref(),
x.sliced(values_start, values_end - values_start).as_ref(),
)
})
})
Expand All @@ -394,7 +394,7 @@ fn estimated_bytes_size(array: &dyn Array) -> usize {
array
.fields()
.iter()
.map(|x| estimated_bytes_size(x.slice(0, array.len()).as_ref()))
.map(|x| estimated_bytes_size(x.sliced(0, array.len()).as_ref()))
.sum::<usize>()
};

Expand Down
2 changes: 1 addition & 1 deletion crates/re_query/src/entity_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl ComponentWithInstances {

let arrow_ref = self.values.as_arrow_ref();
(arrow_ref.len() > offset)
.then(|| arrow_ref.slice(offset, 1))
.then(|| arrow_ref.sliced(offset, 1))
.or_else(|| {
re_log::error_once!("found corrupt cell -- mismatched number of instances");
None
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/view_bar_chart/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub(crate) fn view_bar_chart(
for ((ent_path, instance_key), tensor) in &scene.charts {
let chart = match &tensor.data {
component_types::TensorData::U8(data) => {
create_bar_chart(ent_path, instance_key, data.0.iter().copied())
create_bar_chart(ent_path, instance_key, data.iter().copied())
}
component_types::TensorData::U16(data) => {
create_bar_chart(ent_path, instance_key, data.iter().copied())
Expand Down