Struct tch::Tensor[][src]

pub struct Tensor { /* fields omitted */ }
Expand description

A tensor object.

Implementations

Creates a new tensor.

Creates a new tensor from the pointer to an existing C++ tensor.

Safety

The caller must ensures that the pointer outlives the Rust object.

Creates a new tensor from the pointer to an existing C++ tensor.

Safety

A shallow copy of the pointer is made so there is no need for this pointer to remain valid for the whole lifetime of the Rust object.

Returns a pointer to the underlying C++ tensor.

The caller must ensures that the Rust tensor object outlives this pointer.

Returns a mutable pointer to the underlying C++ tensor.

The caller must ensures that the Rust tensor object outlives this pointer.

Returns the number of dimension of the tensor.

Returns the shape of the input tensor.

Returns the tensor size for single dimension tensors.

Returns the tensor sizes for two dimension tensors.

Returns the tensor sizes for three dimension tensors.

Returns the tensor sizes for four dimension tensors.

Returns the tensor sizes for five dimension tensors.

Returns the tensor sizes for six dimension tensors.

Returns the stride of the input tensor.

Returns the tensor strides for single dimension tensors.

Returns the tensor strides for two dimension tensors.

Returns the tensor strides for three dimension tensors.

Returns the tensor strides for four dimension tensors.

Returns the tensor strides for five dimension tensors.

Returns the tensor strides for six dimension tensors.

Returns the kind of elements stored in the input tensor. Returns an error on undefined tensors and unsupported data types.

Returns the kind of elements stored in the input tensor. Panics an error on undefined tensors and unsupported data types.

Returns the device on which the input tensor is located.

Prints the input tensor.

Caution: this uses the C++ printer which prints the whole tensor even if it is very large.

Returns a double value on tensors holding a single element. An error is returned otherwise.

Returns an int value on tensors holding a single element. An error is returned otherwise.

Returns a double value on tensors holding a single element. Panics otherwise.

Returns an int value on tensors holding a single element. Panics otherwise.

Returns true if gradient are currently tracked for this tensor.

Returns the address of the first element of this tensor.

Returns true if the tensor is defined.

Returns true if the tensor is compatible with MKL-DNN (oneDNN).

Returns true if the tensor is sparse.

Zeroes the gradient tensor attached to this tensor if defined.

Runs the backward pass, populating the gradient tensors for tensors which gradients are tracked.

Gradients tracking can be turned on via set_requires_grad.

Runs the backward pass, populating the gradient tensors for tensors which gradients are tracked.

Gradients tracking can be turned on via set_requires_grad. Panics if the C++ api returns an exception.

Copies numel elements from self to dst.

Unscale tensor while checking for infinities.

found_inf is a singleton tensor that is used to record the presence of infinite values. inv_scale is a scalar containing the inverse scaling factor. This method is only available for CUDA tensors.

Unscale tensor while checking for infinities.

found_inf is a singleton tensor that is used to record the presence of infinite values. inv_scale is a scalar containing the inverse scaling factor. This method is only available for CUDA tensors.

Copies numel elements from self to dst.

Copies numel elements from self to dst.

Copies numel elements from self to dst.

Returns the total number of elements stored in a tensor.

Converts a slice to a tensor.

Converts a slice to a tensor.

Converts some byte data to a tensor with some specified kind and shape.

Creates a tensor from data that is assumed to be initialized. Resize operations are now allowed on this tensor without copying the data first.

Safety

This will panic if data points to invalid data.

Creates a tensor from data that is assumed to be initialized. Resize operations are now allowed on this tensor without copying the data first.

Safety

This will panic if data points to invalid data.

Converts some byte data to a tensor with some specified kind and shape.

Returns a new tensor that share storage with the input tensor.

Gets the sub-tensor at the given index.

Gets the sub-tensor at the given index.

Copies values from the argument tensor to the input tensor.

Copies values from the argument tensor to the input tensor.

Loads a tensor from a file.

The file format is the same as the one used by the PyTorch C++ API.

Saves a tensor to a file.

The file format is the same as the one used by the PyTorch C++ API.

Saves some named tensors to a file

The file format is the same as the one used by the PyTorch C++ API.

Loads some named tensors from a file

The file format is the same as the one used by the PyTorch C++ API.

Loads some named tensors from a file to a given device

The file format is the same as the one used by the PyTorch C++ API.

Returns a string representation for the tensor.

The representation will contain all the tensor element hence may be huge for large tensors.

Reads a npy file and return the stored tensor.

Reads a npz file and returns some named tensors.

Writes a tensor in the npy format so that it can be read using python.

Casts a tensor to a specified kind.

Computes the cross-entropy loss based on some logits and targets.

Returns the average accuracy for some given logits assuming that targets represent ground-truth.

Moves a tensor to a specified device.

Flattens a tensor.

This returns a flattened version of the given tensor. The first dimension is preserved as it is assumed to be the mini-batch dimension.

Converts a tensor to a one-hot encoded version.

If the input has a size [N1, N2, …, Nk], the returned tensor has a size [N1, …, Nk, labels]. The returned tensor uses float values. Elements of the input vector are expected to be between 0 and labels-1.

Copies a tensor to a newly allocated tensor using the same shape and device.

Re-initializes the tensor using the specified initialization.

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Performs the += operation. Read more

Performs the conversion.

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

The resulting type after applying the / operator.

Performs the / operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

Performs the /= operation. Read more

Executes the destructor for this type. 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.

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.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

The resulting type after applying the * operator.

Performs the * operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

Performs the *= operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

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

This method tests for !=.

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

Performs the -= operation. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. 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.

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.

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.

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

Performs the conversion.

Performs the conversion.

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.