try_mdarray_to_tensor

Function try_mdarray_to_tensor 

Source
pub fn try_mdarray_to_tensor<T: Scalar>(
    array: Array<T, DynRank>,
) -> Result<Tensor<T>>
Expand description

Fallibly converts an mdarray Array<T, DynRank> into a tenferro Tensor<T>.

This conversion copies all element data from the mdarray array into a newly allocated tenferro tensor on the CPU. The shape is preserved.

§Examples

use mdarray::{Array, DynRank};
use tenferro_tensor::Tensor;
use tenferro_ext_mdarray::try_mdarray_to_tensor;

let md: Array<f64, DynRank> = mdarray::tensor![1.0, 2.0, 3.0].into_dyn();
let t: Tensor<f64> = try_mdarray_to_tensor(md).unwrap();