tensorlogic_scirs_backend/
conversion.rs1use scirs2_core::ndarray::{Array, IxDyn};
4use tensorlogic_infer::ExecutorError;
5
6use crate::{Scirs2Exec, Scirs2Tensor};
7
8impl Scirs2Exec {
9 pub fn from_vec(data: Vec<f64>, shape: Vec<usize>) -> Result<Scirs2Tensor, ExecutorError> {
11 let total_size: usize = shape.iter().product();
12 if total_size != data.len() {
13 return Err(ExecutorError::ShapeMismatch(format!(
14 "Data length {} doesn't match shape {:?} (total: {})",
15 data.len(),
16 shape,
17 total_size
18 )));
19 }
20
21 Array::from_shape_vec(IxDyn(&shape), data)
22 .map_err(|e| ExecutorError::ShapeMismatch(e.to_string()))
23 }
24
25 pub fn zeros(shape: Vec<usize>) -> Scirs2Tensor {
27 Array::zeros(IxDyn(&shape))
28 }
29
30 pub fn ones(shape: Vec<usize>) -> Scirs2Tensor {
32 Array::ones(IxDyn(&shape))
33 }
34}