pub struct Tensor<T> { /* private fields */ }
Expand description

A multidimensional array with copy-on-write semantics.

Implementations

Get the Tensor’s dimensions.

The number of dimensions this Tensor has.

Get an immutable reference to the underlying elements in this Tensor.

Get a mutable reference to the underlying elements in this Tensor.

Try to get a contiguous sub-slice of this tensor.

Note

Due to the way tensors are laid out in memory, you can only slice off the leading dimensions.

In order to be well-formed, this requires that RANK + leading_indices.len() equals Tensor::rank(), and that each of the indices are within bounds.

Examples

Say you have a [3, 4, 2] tensor, passing in [0, 1] would give you a 1D TensorView that views the 3 elements at [0, 1, ..].

let input = [
    [[0, 1], [2, 3], [4, 5], [6, 7]],
    [[8, 9], [10, 11], [12, 13], [14, 15]],
    [[16, 17], [18, 19], [20, 21], [22, 23]],
];
let tensor: Tensor<i32> = input.into();

let got = tensor.slice::<1>(&[0, 1]).unwrap();

assert_eq!(got.dimensions(), [2]);
assert_eq!(got.elements(), &input[0][1]);

A mutable version of Tensor::slice().

Try to reinterpret this tensor as a RANK-D tensor.

The mutable version of Tensor::view().

Create a new Tensor by applying a function to every element in the current tensor.

This is often an expensive operation.

Get a reference to the element with this particular index.

Get a mutable reference to the element with this particular index.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Creates a value from an iterator. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Get an array containing the Shape for each Tensor in this tuple.

Get an array containing pointers to the elements of each Tensor in this tuple. Read more

Create a new set of empty tensors with the specified shape. Read more

Get a set of mutable pointers into each tensor’s backing buffer.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.