27#include "neml2/misc/types.h"
28#include "neml2/tensors/Tensor.h"
33template <std::
size_t N>
37template <std::
size_t N>
39derivative_name(
const std::string & var_name,
const std::array<std::string, N> & arg_names)
41 std::string
name =
"d";
43 name += std::to_string(N);
44 name +=
"(" + var_name +
")/";
45 for (
const auto & arg_name : arg_names)
46 name +=
"d(" + arg_name +
")";
60template <std::
size_t N>
64template <std::
size_t N>
70 const std::array<std::size_t, N + 1> & intrsc_intmd_dims,
71 const std::array<TensorShapeRef, N + 1> &
intmd_sizes,
72 const std::array<TensorShapeRef, N + 1> &
base_sizes,
73 [[maybe_unused]] std::string
var_name =
"",
74 [[maybe_unused]] std::array<std::string, N> arg_names = {});
87 const std::string &
arg_name(std::size_t i)
const;
155 Size _intrsc_intmd_dim = 0;
158 std::array<Size, N + 1> _intrsc_intmd_dims;
161 std::array<TensorShape, N + 1> _intmd_sizes;
164 std::array<TensorShape, N + 1> _base_sizes;
167 std::string _var_name;
168 std::array<std::string, N> _arg_names;
175 Size _cached_intmd_dim = 0;
Derivative wrapper.
Definition Derivative.h:66
Derivative & operator=(const Tensor &val)
Derivative & operator+=(const Derivative< N > &val)
TensorShapeRef arg_intmd_sizes(std::size_t i) const
Derivative(std::size_t intrsc_intmd_dim, const std::array< std::size_t, N+1 > &intrsc_intmd_dims, const std::array< TensorShapeRef, N+1 > &intmd_sizes, const std::array< TensorShapeRef, N+1 > &base_sizes, std::string var_name="", std::array< std::string, N > arg_names={})
std::string name() const
Get the derivative name.
const std::string & var_name() const
Get the variable name.
const Tensor & tensor() const
Get the derivative.
TensorShapeRef intmd_sizes() const
Derivative & operator=(Derivative< N > &&val) noexcept=default
TensorShape base_sizes() const
Size var_base_dim() const
TensorShapeRef var_base_sizes() const
const std::string & arg_name(std::size_t i) const
Get the i-th argument name.
bool defined() const
Whether this derivative contains defined value.
Size arg_base_dim(std::size_t i) const
Derivative & operator+=(const Tensor &val)
TensorShapeRef arg_base_sizes(std::size_t i) const
Size intrsc_intmd_dim() const
Derivative & operator=(const Derivative< N > &val)=default
TensorShapeRef var_intrsc_intmd_sizes() const
Derivative< N > reinterpret(std::size_t additional_intrsc_intmd_dim) const
Reinterpret the derivative to add additional intrinsic intermediate dimensions to the variable and ar...
Derivative(Derivative< N > &&val)=default
Size arg_intrsc_intmd_dim(std::size_t i) const
TensorShapeRef var_intmd_sizes() const
TensorShapeRef intrsc_intmd_sizes() const
void clear()
Clear the derivative.
Size var_intrsc_intmd_dim() const
Derivative(const Derivative< N > &val)=default
bool is_intrsc_intmd_broadcast() const
Whether this derivative represents a broadcast over intrinsic intermediate dimensions.
TensorShapeRef extrsc_intmd_sizes() const
TensorShapeRef arg_intrsc_intmd_sizes(std::size_t i) const
Definition DiagnosticsInterface.h:31
c10::SmallVector< Size, 8 > TensorShape
Definition types.h:72
std::string derivative_name(const std::string &var_name, const std::array< std::string, N > &arg_names)
Pretty print derivative names.
Definition Derivative.h:39
std::string name(ElasticConstant p)
Tensor fullify(const Tensor &t, Size iid, std::array< TensorShape, N > iiss)
int64_t Size
Definition types.h:71
c10::ArrayRef< Size > TensorShapeRef
Definition types.h:73