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§
sourcefn try_tensor(&self, src: Src) -> Result<Tensor<S, E, Self>, Self::Err>
fn try_tensor(&self, src: Src) -> Result<Tensor<S, E, Self>, Self::Err>
Fallible version of TensorFrom::tensor
Provided Methods§
sourcefn tensor(&self, src: Src) -> Tensor<S, E, Self>
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]));