LibtorchUtils Namespace

MOOSE includes a number of C++ utility classes and functions that may be useful for Manipulating Libtorch tensors and interfacing them with MOOSE-based objects.

Standard Vector To Tensor and Tensor to Standard Vector conversion

The utility classes streamline the two-way conversion between standard vectors and Libtorch tensors.

/**
 * Utility function that converts a standard vector to a `torch::Tensor`.
 * @tparam DataType The type of data (float,double, etc.) which the vector is filled with
 * @param vector The vector that needs to be converted
 * @param tensor The output tensor
 * @param detach If the gradient information needs to be detached during the conversion
 */
template <typename DataType>
void
vectorToTensor(std::vector<DataType> & vector, torch::Tensor & tensor, const bool detach = false);

/**
 * Utility function that converts a `torch::Tensor` to a standard vector.
 * @tparam DataType The type of data (float,double, etc.) which the vector is filled with
 * @param tensor The tensor which needs to be converted
 * @param vector The output vector
 */
template <typename DataType>
void tensorToVector(torch::Tensor & tensor, std::vector<DataType> & vector);
(../moose/framework/include/libtorch/utils/LibtorchUtils.h)