use ndarray::{Array, ArrayD, Dimension, IxDyn};
use crate::Tensor;
impl<D: Dimension> From<Array<f32, D>> for Tensor {
fn from(a: Array<f32, D>) -> Self {
Tensor::from(&a)
}
}
impl<D: Dimension> From<&Array<f32, D>> for Tensor {
fn from(a: &Array<f32, D>) -> Self {
let dims = a.shape().to_vec();
let data: Vec<f32> = a.iter().copied().collect();
Tensor::from_vec(data, dims)
}
}
#[cfg(feature = "eval")]
impl Tensor {
pub fn to_ndarray(&self) -> ArrayD<f32> {
let dims = self.dims();
let data = self.to_vec();
ArrayD::from_shape_vec(IxDyn(&dims), data)
.expect("to_ndarray: realized data does not match shape")
}
}