https://mooseframework.inl.gov
LibtorchUtils.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #ifdef LIBTORCH_ENABLED
11 
12 #pragma once
13 
14 #include <torch/torch.h>
15 #include "MooseUtils.h"
16 
17 namespace LibtorchUtils
18 {
19 
27 template <typename DataType>
28 void
29 vectorToTensor(std::vector<DataType> & vector, torch::Tensor & tensor, const bool detach = false);
30 
37 template <typename DataType>
38 void tensorToVector(torch::Tensor & tensor, std::vector<DataType> & vector);
39 
40 } // LibtorchUtils namespace
41 
42 #endif
void tensorToVector(torch::Tensor &tensor, std::vector< DataType > &vector)
Utility function that converts a torch::Tensor to a standard vector.
Definition: LibtorchUtils.C:44
void vectorToTensor(std::vector< DataType > &vector, torch::Tensor &tensor, const bool detach=false)
Utility function that converts a standard vector to a torch::Tensor.
Definition: LibtorchUtils.C:19