Functions | |
| template<typename DataType > | |
| void | vectorToTensor (const std::vector< DataType > &vector, torch::Tensor &tensor, const bool detach=false) |
Utility function that converts a standard vector to a torch::Tensor. More... | |
| template<typename DataType > | |
| torch::Tensor | vectorToTensorCopy (const std::vector< DataType > &vector, c10::IntArrayRef sizes) |
| Utility function that creates an owning tensor copy of a standard vector. More... | |
| template<typename DataType > | |
| torch::Tensor | vectorToTensorView (std::vector< DataType > &vector, c10::IntArrayRef sizes) |
| Utility function that creates a non-owning tensor view of a standard vector. More... | |
| void | moveToLibtorchDevice (torch::Tensor &tensor, const torch::DeviceType device_type) |
| Move a tensor to the configured libtorch device. More... | |
| torch::Tensor | toCPUContiguous (const torch::Tensor &tensor) |
| Return a detached contiguous CPU copy of a tensor. More... | |
| template<typename DataType > | |
| void | tensorToVector (torch::Tensor &tensor, std::vector< DataType > &vector) |
Utility function that converts a torch::Tensor to a standard vector. More... | |
| template torch::Tensor | vectorToTensorCopy< Real > (const std::vector< Real > &vector, c10::IntArrayRef sizes) |
| template void | vectorToTensor< Real > (const std::vector< Real > &vector, torch::Tensor &tensor, const bool detach) |
| template torch::Tensor | vectorToTensorView< Real > (std::vector< Real > &vector, c10::IntArrayRef sizes) |
| template void | tensorToVector< Real > (torch::Tensor &tensor, std::vector< Real > &vector) |
| void LibtorchUtils::moveToLibtorchDevice | ( | torch::Tensor & | tensor, |
| const torch::DeviceType | device_type | ||
| ) |
Move a tensor to the configured libtorch device.
| tensor | The tensor to move |
| device_type | The target torch device type |
Definition at line 100 of file LibtorchUtils.C.
| void LibtorchUtils::tensorToVector | ( | torch::Tensor & | tensor, |
| std::vector< DataType > & | vector | ||
| ) |
Utility function that converts a torch::Tensor to a standard vector.
| DataType | The type of data (float,double, etc.) which the vector is filled with |
| tensor | The tensor which needs to be converted |
| vector | The output vector |
Definition at line 114 of file LibtorchUtils.C.
| template void LibtorchUtils::tensorToVector< Real > | ( | torch::Tensor & | tensor, |
| std::vector< Real > & | vector | ||
| ) |
| torch::Tensor LibtorchUtils::toCPUContiguous | ( | const torch::Tensor & | tensor | ) |
Return a detached contiguous CPU copy of a tensor.
This is for call sites that read tensor storage through CPU accessors or data_ptr(). Moving a tensor to CPU does not guarantee that logical tensor order is backed by a dense linear memory layout; contiguous() makes that invariant explicit.
| tensor | The tensor to copy to CPU |
Definition at line 106 of file LibtorchUtils.C.
Referenced by dataStore().
| void LibtorchUtils::vectorToTensor | ( | const std::vector< DataType > & | vector, |
| torch::Tensor & | tensor, | ||
| const bool | detach = false |
||
| ) |
Utility function that converts a standard vector to a torch::Tensor.
| DataType | The type of data (float,double, etc.) which the vector is filled with |
| vector | The vector that needs to be converted |
| tensor | The output tensor |
| detach | If the gradient information needs to be detached during the conversion |
Definition at line 71 of file LibtorchUtils.C.
Referenced by LibtorchNeuralNetControl::prepareInputTensor().
| template void LibtorchUtils::vectorToTensor< Real > | ( | const std::vector< Real > & | vector, |
| torch::Tensor & | tensor, | ||
| const bool | detach | ||
| ) |
| torch::Tensor LibtorchUtils::vectorToTensorCopy | ( | const std::vector< DataType > & | vector, |
| c10::IntArrayRef | sizes | ||
| ) |
Utility function that creates an owning tensor copy of a standard vector.
| DataType | The vector element type |
| vector | The vector that needs to be copied |
| sizes | The desired tensor shape |
Definition at line 52 of file LibtorchUtils.C.
Referenced by vectorToTensor().
| template torch::Tensor LibtorchUtils::vectorToTensorCopy< Real > | ( | const std::vector< Real > & | vector, |
| c10::IntArrayRef | sizes | ||
| ) |
| torch::Tensor LibtorchUtils::vectorToTensorView | ( | std::vector< DataType > & | vector, |
| c10::IntArrayRef | sizes | ||
| ) |
Utility function that creates a non-owning tensor view of a standard vector.
The returned tensor shares the mutable storage of the provided vector, so the vector must outlive the tensor and may be modified through the tensor.
| DataType | The vector element type |
| vector | The vector that needs to be wrapped |
| sizes | The desired tensor shape |
Definition at line 85 of file LibtorchUtils.C.
| template torch::Tensor LibtorchUtils::vectorToTensorView< Real > | ( | std::vector< Real > & | vector, |
| c10::IntArrayRef | sizes | ||
| ) |
1.8.14