#![allow(dead_code)] use candle::{Result, Tensor}; pub fn to_vec0_round(t: &Tensor, digits: i32) -> Result { let b = 10f32.powi(digits); let t = t.to_vec0::()?; Ok(f32::round(t * b) / b) } pub fn to_vec1_round(t: &Tensor, digits: i32) -> Result> { let b = 10f32.powi(digits); let t = t.to_vec1::()?; let t = t.iter().map(|t| f32::round(t * b) / b).collect(); Ok(t) } pub fn to_vec2_round(t: &Tensor, digits: i32) -> Result>> { let b = 10f32.powi(digits); let t = t.to_vec2::()?; let t = t .iter() .map(|t| t.iter().map(|t| f32::round(t * b) / b).collect()) .collect(); Ok(t) } pub fn to_vec3_round(t: Tensor, digits: i32) -> Result>>> { let b = 10f32.powi(digits); let t = t.to_vec3::()?; let t = t .iter() .map(|t| { t.iter() .map(|t| t.iter().map(|t| f32::round(t * b) / b).collect()) .collect() }) .collect(); Ok(t) }