Expand description
Tensors.
use autograph::tensor::{Tensor, TensorView};
use anyhow::Result;
use ndarray::{Array, arr2, linalg::Dot};
// Create a tensor from an array
let a = Tensor::from(arr2(&[
[1f32, 2.],
[3., 4.],
]))
// Moves to device, no copy if device is Device::host().
.into_device(device.clone())?;
// Alternatively, create a tensor from an array view.
let a = arr2(&[
[1f32, 2.],
[3., 4.],
]);
// This will fail if the view is not contiguous.
let a = TensorView::try_from(a.view()).unwrap()
.to_device(device.clone())?;
// Create a tensor from a vec, same as above.
let b = Tensor::from(vec![5f32, 6., 7., 8.]).into_shape([2, 2]).unwrap()
.into_device(device.clone())?;
// Compute a dot product (matrix multiplication) and move back to host.
let c = a.dot(&b)?.into_device(Device::host())?;
// Borrow as an array view.
let c_view = c.as_array().unwrap();
// Move into an array
let c = c.into_array()?;
Structs§
- Scalar
Tensor Base - Dynamically typed multi-dimensional matrix.
- Tensor
Base - Multi-dimensional matrix.
Type Aliases§
- ArcTensor
- Shared Tensor.
- ArcTensor0
- ArcTensor with 1 element.
- ArcTensor1
- ArcTensor with 1 dimension.
- ArcTensor2
- ArcTensor with 2 dimensions.
- ArcTensor3
- ArcTensor with 3 dimensions.
- ArcTensor4
- ArcTensor with 4 dimensions.
- ArcTensor5
- ArcTensor with 5 dimensions.
- ArcTensor6
- ArcTensor with 6 dimensions.
- ArcTensorD
- ArcTensor with dynamic dimensions.
- CowTensor
- Tensor that is either borrowed or owned.
- CowTensor0
- CowTensor with 1 element.
- CowTensor1
- CowTensor with 1 dimension.
- CowTensor2
- CowTensor with 2 dimensions.
- CowTensor3
- CowTensor with 3 dimensions.
- CowTensor4
- CowTensor with 4 dimensions.
- CowTensor5
- CowTensor with 5 dimensions.
- CowTensor6
- CowTensor with 6 dimensions.
- CowTensorD
- CowTensor with dynamic dimensions.
- Scalar
ArcTensor - Shared Scalar Tensor.
- Scalar
ArcTensor0 - ScalarArcTensor with 1 element.
- Scalar
ArcTensor1 - ScalarArcTensor with 1 dimension.
- Scalar
ArcTensor2 - ScalarArcTensor with 2 dimensions.
- Scalar
ArcTensor3 - ScalarArcTensor with 3 dimensions.
- Scalar
ArcTensor4 - ScalarArcTensor with 4 dimensions.
- Scalar
ArcTensor5 - ScalarArcTensor with 5 dimensions.
- Scalar
ArcTensor6 - ScalarArcTensor with 6 dimensions.
- Scalar
ArcTensorD - ScalarArcTensor with dynamic dimensions.
- Scalar
CowTensor - Scalar Tensor that is either borrowed or owned.
- Scalar
CowTensor0 - ScalarCowTensor with 1 element.
- Scalar
CowTensor1 - ScalarCowTensor with 1 dimension.
- Scalar
CowTensor2 - ScalarCowTensor with 2 dimensions.
- Scalar
CowTensor3 - ScalarCowTensor with 3 dimensions.
- Scalar
CowTensor4 - ScalarCowTensor with 4 dimensions.
- Scalar
CowTensor5 - ScalarCowTensor with 5 dimensions.
- Scalar
CowTensor6 - ScalarCowTensor with 6 dimensions.
- Scalar
CowTensorD - ScalarCowTensor with dynamic dimensions.
- Scalar
Tensor - Owned Scalar Tensor.
- Scalar
Tensor0 - ScalarTensor with 1 element.
- Scalar
Tensor1 - ScalarTensor with 1 dimension.
- Scalar
Tensor2 - ScalarTensor with 2 dimensions.
- Scalar
Tensor3 - ScalarTensor with 3 dimensions.
- Scalar
Tensor4 - ScalarTensor with 4 dimensions.
- Scalar
Tensor5 - ScalarTensor with 5 dimensions.
- Scalar
Tensor6 - ScalarTensor with 6 dimensions.
- Scalar
TensorD - ScalarTensor with dynamic dimensions.
- Scalar
Tensor View - Borrowed Scalar Tensor.
- Scalar
Tensor View0 - ScalarTensorView with 1 element.
- Scalar
Tensor View1 - ScalarTensorView with 1 dimension.
- Scalar
Tensor View2 - ScalarTensorView with 2 dimensions.
- Scalar
Tensor View3 - ScalarTensorView with 3 dimensions.
- Scalar
Tensor View4 - ScalarTensorView with 4 dimensions.
- Scalar
Tensor View5 - ScalarTensorView with 5 dimensions.
- Scalar
Tensor View6 - ScalarTensorView with 6 dimensions.
- Scalar
Tensor ViewD - ScalarTensorView with dynamic dimensions.
- Scalar
Tensor View Mut - Mutably borrowed Scalar Tensor.
- Scalar
Tensor View Mut0 - ScalarTensorViewMut with 1 element.
- Scalar
Tensor View Mut1 - ScalarTensorViewMut with 1 dimension.
- Scalar
Tensor View Mut2 - ScalarTensorViewMut with 2 dimensions.
- Scalar
Tensor View Mut3 - ScalarTensorViewMut with 3 dimensions.
- Scalar
Tensor View Mut4 - ScalarTensorViewMut with 4 dimensions.
- Scalar
Tensor View Mut5 - ScalarTensorViewMut with 5 dimensions.
- Scalar
Tensor View Mut6 - ScalarTensorViewMut with 6 dimensions.
- Scalar
Tensor View MutD - ScalarTensorViewMut with dynamic dimensions.
- Tensor
- Owned Tensor.
- Tensor0
- Tensor with 1 element.
- Tensor1
- Tensor with 1 dimension.
- Tensor2
- Tensor with 2 dimensions.
- Tensor3
- Tensor with 3 dimensions.
- Tensor4
- Tensor with 4 dimensions.
- Tensor5
- Tensor with 5 dimensions.
- Tensor6
- Tensor with 6 dimensions.
- TensorD
- Tensor with dynamic dimensions.
- Tensor
View - Borrowed Tensor.
- Tensor
View0 - TensorView with 1 element.
- Tensor
View1 - TensorView with 1 dimension.
- Tensor
View2 - TensorView with 2 dimensions.
- Tensor
View3 - TensorView with 3 dimensions.
- Tensor
View4 - TensorView with 4 dimensions.
- Tensor
View5 - TensorView with 5 dimensions.
- Tensor
View6 - TensorView with 6 dimensions.
- Tensor
ViewD - TensorView with dynamic dimensions.
- Tensor
View Mut - Mutably borrowed Tensor.
- Tensor
View Mut0 - TensorViewMut with 1 element.
- Tensor
View Mut1 - TensorViewMut with 1 dimension.
- Tensor
View Mut2 - TensorViewMut with 2 dimensions.
- Tensor
View Mut3 - TensorViewMut with 3 dimensions.
- Tensor
View Mut4 - TensorViewMut with 4 dimensions.
- Tensor
View Mut5 - TensorViewMut with 5 dimensions.
- Tensor
View Mut6 - TensorViewMut with 6 dimensions.
- Tensor
View MutD - TensorViewMut with dynamic dimensions.