re_types/blueprint/datatypes/
tensor_dimension_index_slider.rs1#![allow(unused_imports)]
5#![allow(unused_parens)]
6#![allow(clippy::clone_on_copy)]
7#![allow(clippy::cloned_instead_of_copied)]
8#![allow(clippy::map_flatten)]
9#![allow(clippy::needless_question_mark)]
10#![allow(clippy::new_without_default)]
11#![allow(clippy::redundant_closure)]
12#![allow(clippy::too_many_arguments)]
13#![allow(clippy::too_many_lines)]
14
15use ::re_types_core::try_serialize_field;
16use ::re_types_core::SerializationResult;
17use ::re_types_core::{ComponentBatch as _, SerializedComponentBatch};
18use ::re_types_core::{ComponentDescriptor, ComponentName};
19use ::re_types_core::{DeserializationError, DeserializationResult};
20
21#[derive(Clone, Debug, Default, Copy, Hash, PartialEq, Eq)]
25pub struct TensorDimensionIndexSlider {
26 pub dimension: u32,
28}
29
30::re_types_core::macros::impl_into_cow!(TensorDimensionIndexSlider);
31
32impl ::re_types_core::Loggable for TensorDimensionIndexSlider {
33 #[inline]
34 fn arrow_datatype() -> arrow::datatypes::DataType {
35 #![allow(clippy::wildcard_imports)]
36 use arrow::datatypes::*;
37 DataType::Struct(Fields::from(vec![Field::new(
38 "dimension",
39 DataType::UInt32,
40 false,
41 )]))
42 }
43
44 fn to_arrow_opt<'a>(
45 data: impl IntoIterator<Item = Option<impl Into<::std::borrow::Cow<'a, Self>>>>,
46 ) -> SerializationResult<arrow::array::ArrayRef>
47 where
48 Self: Clone + 'a,
49 {
50 #![allow(clippy::wildcard_imports)]
51 #![allow(clippy::manual_is_variant_and)]
52 use ::re_types_core::{arrow_helpers::as_array_ref, Loggable as _, ResultExt as _};
53 use arrow::{array::*, buffer::*, datatypes::*};
54 Ok({
55 let fields = Fields::from(vec![Field::new("dimension", DataType::UInt32, false)]);
56 let (somes, data): (Vec<_>, Vec<_>) = data
57 .into_iter()
58 .map(|datum| {
59 let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into);
60 (datum.is_some(), datum)
61 })
62 .unzip();
63 let validity: Option<arrow::buffer::NullBuffer> = {
64 let any_nones = somes.iter().any(|some| !*some);
65 any_nones.then(|| somes.into())
66 };
67 as_array_ref(StructArray::new(
68 fields,
69 vec![{
70 let (somes, dimension): (Vec<_>, Vec<_>) = data
71 .iter()
72 .map(|datum| {
73 let datum = datum.as_ref().map(|datum| datum.dimension.clone());
74 (datum.is_some(), datum)
75 })
76 .unzip();
77 let dimension_validity: Option<arrow::buffer::NullBuffer> = {
78 let any_nones = somes.iter().any(|some| !*some);
79 any_nones.then(|| somes.into())
80 };
81 as_array_ref(PrimitiveArray::<UInt32Type>::new(
82 ScalarBuffer::from(
83 dimension
84 .into_iter()
85 .map(|v| v.unwrap_or_default())
86 .collect::<Vec<_>>(),
87 ),
88 dimension_validity,
89 ))
90 }],
91 validity,
92 ))
93 })
94 }
95
96 fn from_arrow_opt(
97 arrow_data: &dyn arrow::array::Array,
98 ) -> DeserializationResult<Vec<Option<Self>>>
99 where
100 Self: Sized,
101 {
102 #![allow(clippy::wildcard_imports)]
103 use ::re_types_core::{arrow_zip_validity::ZipValidity, Loggable as _, ResultExt as _};
104 use arrow::{array::*, buffer::*, datatypes::*};
105 Ok({
106 let arrow_data = arrow_data
107 .as_any()
108 .downcast_ref::<arrow::array::StructArray>()
109 .ok_or_else(|| {
110 let expected = Self::arrow_datatype();
111 let actual = arrow_data.data_type().clone();
112 DeserializationError::datatype_mismatch(expected, actual)
113 })
114 .with_context("rerun.blueprint.datatypes.TensorDimensionIndexSlider")?;
115 if arrow_data.is_empty() {
116 Vec::new()
117 } else {
118 let (arrow_data_fields, arrow_data_arrays) =
119 (arrow_data.fields(), arrow_data.columns());
120 let arrays_by_name: ::std::collections::HashMap<_, _> = arrow_data_fields
121 .iter()
122 .map(|field| field.name().as_str())
123 .zip(arrow_data_arrays)
124 .collect();
125 let dimension = {
126 if !arrays_by_name.contains_key("dimension") {
127 return Err(DeserializationError::missing_struct_field(
128 Self::arrow_datatype(),
129 "dimension",
130 ))
131 .with_context("rerun.blueprint.datatypes.TensorDimensionIndexSlider");
132 }
133 let arrow_data = &**arrays_by_name["dimension"];
134 arrow_data
135 .as_any()
136 .downcast_ref::<UInt32Array>()
137 .ok_or_else(|| {
138 let expected = DataType::UInt32;
139 let actual = arrow_data.data_type().clone();
140 DeserializationError::datatype_mismatch(expected, actual)
141 })
142 .with_context(
143 "rerun.blueprint.datatypes.TensorDimensionIndexSlider#dimension",
144 )?
145 .into_iter()
146 };
147 ZipValidity::new_with_validity(
148 ::itertools::izip!(dimension),
149 arrow_data.nulls(),
150 )
151 .map(|opt| {
152 opt
153 .map(|(dimension)| Ok(Self {
154 dimension: dimension
155 .ok_or_else(DeserializationError::missing_data)
156 .with_context(
157 "rerun.blueprint.datatypes.TensorDimensionIndexSlider#dimension",
158 )?,
159 }))
160 .transpose()
161 })
162 .collect::<DeserializationResult<Vec<_>>>()
163 .with_context(
164 "rerun.blueprint.datatypes.TensorDimensionIndexSlider",
165 )?
166 }
167 })
168 }
169}
170
171impl From<u32> for TensorDimensionIndexSlider {
172 #[inline]
173 fn from(dimension: u32) -> Self {
174 Self { dimension }
175 }
176}
177
178impl From<TensorDimensionIndexSlider> for u32 {
179 #[inline]
180 fn from(value: TensorDimensionIndexSlider) -> Self {
181 value.dimension
182 }
183}
184
185impl ::re_byte_size::SizeBytes for TensorDimensionIndexSlider {
186 #[inline]
187 fn heap_size_bytes(&self) -> u64 {
188 self.dimension.heap_size_bytes()
189 }
190
191 #[inline]
192 fn is_pod() -> bool {
193 <u32>::is_pod()
194 }
195}