Module tensor

Source
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§

ScalarTensorBase
Dynamically typed multi-dimensional matrix.
TensorBase
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.
ScalarArcTensor
Shared Scalar Tensor.
ScalarArcTensor0
ScalarArcTensor with 1 element.
ScalarArcTensor1
ScalarArcTensor with 1 dimension.
ScalarArcTensor2
ScalarArcTensor with 2 dimensions.
ScalarArcTensor3
ScalarArcTensor with 3 dimensions.
ScalarArcTensor4
ScalarArcTensor with 4 dimensions.
ScalarArcTensor5
ScalarArcTensor with 5 dimensions.
ScalarArcTensor6
ScalarArcTensor with 6 dimensions.
ScalarArcTensorD
ScalarArcTensor with dynamic dimensions.
ScalarCowTensor
Scalar Tensor that is either borrowed or owned.
ScalarCowTensor0
ScalarCowTensor with 1 element.
ScalarCowTensor1
ScalarCowTensor with 1 dimension.
ScalarCowTensor2
ScalarCowTensor with 2 dimensions.
ScalarCowTensor3
ScalarCowTensor with 3 dimensions.
ScalarCowTensor4
ScalarCowTensor with 4 dimensions.
ScalarCowTensor5
ScalarCowTensor with 5 dimensions.
ScalarCowTensor6
ScalarCowTensor with 6 dimensions.
ScalarCowTensorD
ScalarCowTensor with dynamic dimensions.
ScalarTensor
Owned Scalar Tensor.
ScalarTensor0
ScalarTensor with 1 element.
ScalarTensor1
ScalarTensor with 1 dimension.
ScalarTensor2
ScalarTensor with 2 dimensions.
ScalarTensor3
ScalarTensor with 3 dimensions.
ScalarTensor4
ScalarTensor with 4 dimensions.
ScalarTensor5
ScalarTensor with 5 dimensions.
ScalarTensor6
ScalarTensor with 6 dimensions.
ScalarTensorD
ScalarTensor with dynamic dimensions.
ScalarTensorView
Borrowed Scalar Tensor.
ScalarTensorView0
ScalarTensorView with 1 element.
ScalarTensorView1
ScalarTensorView with 1 dimension.
ScalarTensorView2
ScalarTensorView with 2 dimensions.
ScalarTensorView3
ScalarTensorView with 3 dimensions.
ScalarTensorView4
ScalarTensorView with 4 dimensions.
ScalarTensorView5
ScalarTensorView with 5 dimensions.
ScalarTensorView6
ScalarTensorView with 6 dimensions.
ScalarTensorViewD
ScalarTensorView with dynamic dimensions.
ScalarTensorViewMut
Mutably borrowed Scalar Tensor.
ScalarTensorViewMut0
ScalarTensorViewMut with 1 element.
ScalarTensorViewMut1
ScalarTensorViewMut with 1 dimension.
ScalarTensorViewMut2
ScalarTensorViewMut with 2 dimensions.
ScalarTensorViewMut3
ScalarTensorViewMut with 3 dimensions.
ScalarTensorViewMut4
ScalarTensorViewMut with 4 dimensions.
ScalarTensorViewMut5
ScalarTensorViewMut with 5 dimensions.
ScalarTensorViewMut6
ScalarTensorViewMut with 6 dimensions.
ScalarTensorViewMutD
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.
TensorView
Borrowed Tensor.
TensorView0
TensorView with 1 element.
TensorView1
TensorView with 1 dimension.
TensorView2
TensorView with 2 dimensions.
TensorView3
TensorView with 3 dimensions.
TensorView4
TensorView with 4 dimensions.
TensorView5
TensorView with 5 dimensions.
TensorView6
TensorView with 6 dimensions.
TensorViewD
TensorView with dynamic dimensions.
TensorViewMut
Mutably borrowed Tensor.
TensorViewMut0
TensorViewMut with 1 element.
TensorViewMut1
TensorViewMut with 1 dimension.
TensorViewMut2
TensorViewMut with 2 dimensions.
TensorViewMut3
TensorViewMut with 3 dimensions.
TensorViewMut4
TensorViewMut with 4 dimensions.
TensorViewMut5
TensorViewMut with 5 dimensions.
TensorViewMut6
TensorViewMut with 6 dimensions.
TensorViewMutD
TensorViewMut with dynamic dimensions.