Trait dfdx::tensor::TensorFrom

source ·
pub trait TensorFrom<Src, S: Shape, E>: Storage<E> {
    // Required method
    fn try_tensor(&self, src: Src) -> Result<Tensor<S, E, Self>, Self::Err>;

    // Provided method
    fn tensor(&self, src: Src) -> Tensor<S, E, Self> { ... }
}
Expand description

Construct tensors from rust data

Required Methods§

source

fn try_tensor(&self, src: Src) -> Result<Tensor<S, E, Self>, Self::Err>

Fallible version of TensorFrom::tensor

Provided Methods§

source

fn tensor(&self, src: Src) -> Tensor<S, E, Self>

Create a tensor from rust data

let _: Tensor<Rank2<2, 3>, f32, Cpu> = dev.tensor([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]);
let _: Tensor<Rank2<2, 3>, f32, Cpu> = dev.tensor(vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
// Note: arguments are in a tuple, and this syntax should only be used when creating
// tensors with a dynamic shape
let _ = dev.tensor((vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0], [2, 3]));

Implementors§

source§

impl<E, D: TensorFromVec<E>> TensorFrom<E, (), E> for D

source§

impl<E, S: ConstShape, D: TensorFromVec<E>> TensorFrom<Vec<E, Global>, S, E> for D

source§

impl<E, S: Shape, D: TensorFromVec<E>> TensorFrom<(Vec<E, Global>, S), S, E> for D

source§

impl<E: Copy, const M: usize, D: TensorFromVec<E>> TensorFrom<&[E; M], (Const<M>,), E> for D

source§

impl<E: Copy, const M: usize, D: TensorFromVec<E>> TensorFrom<[E; M], (Const<M>,), E> for D

source§

impl<E: Copy, const M: usize, const N: usize, D: TensorFromVec<E>> TensorFrom<[[E; N]; M], (Const<M>, Const<N>), E> for D

source§

impl<E: Copy, const M: usize, const N: usize, const O: usize, D: TensorFromVec<E>> TensorFrom<[[[E; O]; N]; M], (Const<M>, Const<N>, Const<O>), E> for D

source§

impl<E: Copy, const M: usize, const N: usize, const O: usize, const P: usize, D: TensorFromVec<E>> TensorFrom<[[[[E; P]; O]; N]; M], (Const<M>, Const<N>, Const<O>, Const<P>), E> for D