Browse Source

Made conversion generic (#908)

tags/v0.3.11-rc1
Haixuan Xavier Tao GitHub 10 months ago
parent
commit
1bbbc4b428
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 4 deletions
  1. +1
    -0
      Cargo.lock
  2. +1
    -0
      libraries/arrow-convert/Cargo.toml
  3. +12
    -2
      libraries/arrow-convert/src/lib.rs
  4. +2
    -2
      node-hub/dora-rerun/src/series.rs

+ 1
- 0
Cargo.lock View File

@@ -2586,6 +2586,7 @@ dependencies = [
"chrono",
"eyre",
"half",
"num",
]

[[package]]


+ 1
- 0
libraries/arrow-convert/Cargo.toml View File

@@ -13,4 +13,5 @@ repository.workspace = true
arrow = { workspace = true }
eyre = "0.6.8"
half = "2.5.0"
num = "0.4.3"
chrono = "0.4.39"

+ 12
- 2
libraries/arrow-convert/src/lib.rs View File

@@ -1,6 +1,7 @@
use arrow::array::{Array, Float32Array, Float64Array, Int32Array, Int64Array, UInt32Array};
use arrow::datatypes::DataType;
use eyre::{eyre, ContextCompat, Result};
use num::NumCast;
use std::ops::{Deref, DerefMut};

mod from_impls;
@@ -31,7 +32,10 @@ impl DerefMut for ArrowData {

macro_rules! register_array_handlers {
($(($variant:path, $array_type:ty, $type_name:expr)),* $(,)?) => {
pub fn into_vec_f64(data: &ArrowData) -> Result<Vec<f64>> {
pub fn into_vec<T>(data: &ArrowData) -> Result<Vec<T>>
where
T: Copy + NumCast + 'static,
{
match data.data_type() {
$(
$variant => {
@@ -39,7 +43,13 @@ macro_rules! register_array_handlers {
.as_any()
.downcast_ref()
.context(concat!("series is not ", $type_name))?;
Ok(buffer.values().iter().map(|&v| v as f64).collect())

let mut result = Vec::with_capacity(buffer.len());
for &v in buffer.values() {
let converted = NumCast::from(v).context(format!("Failed to cast value from {} to target type",$type_name))?;
result.push(converted);
}
Ok(result)
}
),*
// Error handling for unsupported types


+ 2
- 2
node-hub/dora-rerun/src/series.rs View File

@@ -1,9 +1,9 @@
use dora_node_api::{dora_core::config::DataId, into_vec_f64, ArrowData};
use dora_node_api::{dora_core::config::DataId, into_vec, ArrowData};
use eyre::{Context, Result};
use rerun::RecordingStream;

pub fn update_series(rec: &RecordingStream, id: DataId, data: ArrowData) -> Result<()> {
let series = into_vec_f64(&data).context("could not cast values")?;
let series = into_vec::<f64>(&data).context("could not cast values")?;
for (i, value) in series.iter().enumerate() {
rec.log(
format!("{}_{}", id.as_str(), i),


Loading…
Cancel
Save