use scirs2_core::ndarray::{Array, IxDyn};
use tensorlogic_infer::ExecutorError;
use crate::{Scirs2Exec, Scirs2Tensor};
impl Scirs2Exec {
pub fn from_vec(data: Vec<f64>, shape: Vec<usize>) -> Result<Scirs2Tensor, ExecutorError> {
let total_size: usize = shape.iter().product();
if total_size != data.len() {
return Err(ExecutorError::ShapeMismatch(format!(
"Data length {} doesn't match shape {:?} (total: {})",
data.len(),
shape,
total_size
)));
}
Array::from_shape_vec(IxDyn(&shape), data)
.map_err(|e| ExecutorError::ShapeMismatch(e.to_string()))
}
pub fn zeros(shape: Vec<usize>) -> Scirs2Tensor {
Array::zeros(IxDyn(&shape))
}
pub fn ones(shape: Vec<usize>) -> Scirs2Tensor {
Array::ones(IxDyn(&shape))
}
}