18#include <initializer_list>
23#include <torch/torch.h>
29template <std::
size_t N,
typename T>
30inline std::array<T, N>
to_array(std::vector<T> &&vector) {
31 std::array<T, N> array;
32 std::move(vector.begin(), vector.end(), array.begin());
37template <
typename T, std::
size_t N>
38inline std::vector<T>
to_vector(std::array<T, N> &&array) {
39 std::vector<T> vector;
40 std::move(array.begin(), array.end(), vector.begin());
46 return std::array<
typename std::common_type<
Args...>::type,
sizeof...(Args)>{
52 return std::vector<
typename std::common_type<
Args...>::type>{
58template <
typename T, std::
size_t N>
61 torch::IntArrayRef
sizes = torch::IntArrayRef{-1},
63 if (options.
device() == torch::kCPU)
64 return torch::from_blob(
const_cast<T *
>(std::data(array)),
65 (
sizes == torch::IntArrayRef{-1}) ? array.size()
72 return torch::from_blob(
const_cast<T *
>(std::data(array)),
73 (
sizes == torch::IntArrayRef{-1}) ? array.size()
75 options.device(torch::
kCPU))
82template <
typename T, std::
size_t N>
85 if (options.
device() == torch::kCPU)
86 return torch::from_blob(
const_cast<T *
>(std::data(array)), array.size(),
92 return torch::from_blob(
const_cast<T *
>(std::data(array)), array.size(),
93 options.
device(torch::kCPU))
106 torch::IntArrayRef
sizes = torch::IntArrayRef{-1},
108 if (options.
device() == torch::kCPU)
109 return torch::from_blob(
110 const_cast<T *
>(std::data(list)),
111 (
sizes == torch::IntArrayRef{-1}) ? list.size() :
sizes, options)
116 return torch::from_blob(
const_cast<T *
>(std::data(list)),
117 (
sizes == torch::IntArrayRef{-1}) ? list.size()
119 options.device(torch::
kCPU))
122 .to(options.device())
129 if (options.
device() == torch::kCPU)
130 return torch::from_blob(
const_cast<T *
>(std::data(list)), list.size(),
136 return torch::from_blob(
const_cast<T *
>(std::data(list)), list.size(),
137 options.
device(torch::kCPU))
150 torch::IntArrayRef
sizes = torch::IntArrayRef{-1},
152 if (options.
device() == torch::kCPU)
153 return torch::from_blob(
const_cast<T *
>(std::data(vector)),
154 (
sizes == torch::IntArrayRef{-1}) ? vector.size()
161 return torch::from_blob(
const_cast<T *
>(std::data(vector)),
162 (
sizes == torch::IntArrayRef{-1}) ? vector.size()
164 options.device(torch::
kCPU))
167 .to(options.device())
174 if (options.
device() == torch::kCPU)
175 return torch::from_blob(
const_cast<T *
>(std::data(vector)), vector.size(),
181 return torch::from_blob(
const_cast<T *
>(std::data(vector)), vector.size(),
182 options.
device(torch::kCPU))
191template <
typename T, std::
size_t N>
193 return at::ArrayRef<T>{array};
198template <
typename T, std::size_t...
N>
200 std::array<T, (
N + ...)>
result;
203 ((std::copy_n(
arrays.begin(),
N,
result.begin() + index), index +=
N), ...);
208template <
typename T, std::size_t...
N>
210 std::array<T, (
N + ...)>
result;
213 ((std::copy_n(std::make_move_iterator(
arrays.begin()),
N,
224template <
typename...
Ts>
226 std::vector<
typename std::common_type<
Ts...>::type>
result;
234 std::vector<
typename std::common_type<
Ts...>::type>
result;
237 std::make_move_iterator(
vectors.end())),
246inline constexpr auto operator+(torch::ArrayRef<T> array, T data) {
247 std::vector<T>
result{array.vec()};
253template <
typename T, std::
size_t N>
254inline constexpr auto operator+(std::array<T, N> array, T data) {
255 std::array<T, N + 1>
result;
256 for (std::size_t
i = 0;
i <
N; ++
i)
264inline constexpr auto operator+(std::vector<T> vector, T data) {
265 std::vector<T>
result{vector};
272inline constexpr auto operator+(T data, torch::ArrayRef<T> array) {
273 std::vector<T>
result{array.vec()};
279template <
typename T, std::
size_t N>
280inline constexpr auto operator+(T data, std::array<T, N> array) {
281 std::array<T, N + 1>
result;
283 for (std::size_t
i = 0;
i <
N; ++
i)
290inline constexpr auto operator+(T data, std::vector<T> vector) {
291 std::vector<T>
result{vector};
297template <
typename T, std::
size_t N>
inline constexpr auto make_array(T value) {
304template <
typename T,
typename U, std::
size_t N>
305inline constexpr std::array<T, N>
make_array(std::array<U, N> array) {
307 for (std::size_t
i = 0;
i <
N; ++
i)
308 result[
i] =
static_cast<T
>(array[
i]);
313template <
typename T, std::
size_t N>
314inline constexpr std::array<T, N>
operator-(std::array<T, N> array) {
316 for (std::size_t
i = 0;
i <
N; ++
i)
322template <
typename T, std::
size_t N>
324 std::array<T, N>
rhs) {
326 for (std::size_t
i = 0;
i <
N; ++
i)
332template <
typename T, std::
size_t N>
334 std::array<T, N>
rhs) {
336 for (std::size_t
i = 0;
i <
N; ++
i)
342template <
typename T, std::
size_t N>
344 std::array<T, N>
rhs) {
346 for (std::size_t
i = 0;
i <
N; ++
i)
352template <
typename T, std::
size_t N>
354 std::array<T, N>
rhs) {
356 for (std::size_t
i = 0;
i <
N; ++
i)
363template <
typename T, std::
size_t N, std::
size_t M = 1>
364inline constexpr std::array<T,
N -
M>
368 for (std::size_t
i = 0;
i <
N -
M; ++
i)
375template <
typename T, std::
size_t N, std::
size_t M = 1>
379 for (std::size_t
i = 0;
i <
N -
M; ++
i)
The Options class handles the automated determination of dtype from the template argument and the sel...
Definition options.hpp:90
torch::Device device() const noexcept
Returns the device property.
Definition options.hpp:123
bool requires_grad() const noexcept
Returns the requires_grad property.
Definition options.hpp:135
auto operator-(const BlockTensor< T, Dims... > &lhs, const BlockTensor< U, Dims... > &rhs)
Subtracts one compile-time block tensor from another and returns a new compile-time block tensor.
Definition blocktensor.hpp:1629
constexpr auto make_array(T value)
Creates an std::array object filled with a constant.
Definition container.hpp:297
auto to_tensor(const std::array< T, N > &array, torch::IntArrayRef sizes=torch::IntArrayRef{-1}, const iganet::Options< T > &options=iganet::Options< T >{})
Converts an std::array to torch::Tensor.
Definition container.hpp:60
auto concat(const std::array< T, N > &...arrays)
Concatenates multiple std::array objects.
Definition container.hpp:199
constexpr std::array< T, N - M > remove_from_front(std::array< T, N > array)
Derives an std::array object from a given std::array object dropping the first M entries.
Definition container.hpp:365
std::array< T, N > to_array(std::vector< T > &&vector)
Converts an std::vector object into std::array.
Definition container.hpp:30
std::vector< T > to_vector(std::array< T, N > &&array)
Converts an std::array object into std::vector.
Definition container.hpp:38
constexpr std::array< T, N > operator/(std::array< T, N > lhs, std::array< T, N > rhs)
Divides one std::array by another std::array.
Definition container.hpp:353
constexpr std::array< T, N - M > remove_from_back(std::array< T, N > array)
Derives an std::array object from a given std::array object dropping the last M entries.
Definition container.hpp:376
auto to_ArrayRef(const std::array< T, N > &array)
Converts an std::array<int64_t, N> to a at::IntArrayRef object.
Definition container.hpp:192
auto operator*(const BlockTensor< T, Rows, Common > &lhs, const BlockTensor< U, Common, Cols > &rhs)
Multiplies one compile-time rank-2 block tensor with another compile-time rank-2 block tensor.
Definition blocktensor.hpp:852
Definition boundary.hpp:22
constexpr auto operator+(deriv lhs, deriv rhs)
Adds two enumerators for specifying the derivative of B-spline evaluation.
Definition bspline.hpp:91
constexpr bool is_SplineType_v
Alias to the value of is_SplineType.
Definition bspline.hpp:3243