25#include "neml2/tensors/user_tensors/UserFixedDimTensor.h"
29#define USERFIXEDDIMTENSOR_REGISTER(T) register_NEML2_object_alias(User##T, #T)
30FOR_ALL_FIXEDDIMTENSOR(USERFIXEDDIMTENSOR_REGISTER);
43 " from a vector values. The vector will be reshaped according to the specified batch shape.";
45 options.
set<std::vector<Real>>(
"values");
46 options.
set(
"values").doc() =
"Values in this (flattened) tensor";
49 options.
set(
"batch_shape").doc() =
"Batch shape";
59 auto vals = options.
get<std::vector<Real>>(
"values");
61 if (
vals.size() ==
size_t(
this->base_storage()))
62 this->
index_put_({torch::indexing::Ellipsis},
flat.reshape(this->base_sizes()));
64 this->
index_put_({torch::indexing::Ellipsis},
flat.reshape(this->sizes()));
69 " must equal to either the base storage size ",
71 " or the total storage size ",
75#define USERFIXEDDIMTENSOR_INSTANTIATE_FIXEDDIMTENSOR(T) template class UserFixedDimTensor<T>
76FOR_ALL_FIXEDDIMTENSOR(USERFIXEDDIMTENSOR_INSTANTIATE_FIXEDDIMTENSOR);
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
const std::string & doc() const
A readonly reference to the option set's docstring.
Definition OptionSet.h:91
const T & get(const std::string &) const
Definition OptionSet.h:422
T & set(const std::string &)
Definition OptionSet.h:436
UserFixedDimTensor(const OptionSet &options)
Construct a new UserFixedDimTensor object.
Definition UserFixedDimTensor.cxx:55
static OptionSet expected_options()
Definition UserFixedDimTensor.cxx:34
Definition UserTensor.h:33
static OptionSet expected_options()
Definition UserTensor.cxx:30
TorchSize storage_size(TorchShapeRef shape)
The flattened storage size of a tensor with given shape.
Definition utils.cxx:32
std::string demangle(const char *name)
Definition parser_utils.cxx:46
Definition CrossRef.cxx:32
const torch::TensorOptions default_tensor_options()
Definition types.cxx:30
std::vector< TorchSize > TorchShape
Definition types.h:36
void neml_assert(bool assertion, Args &&... args)
Definition error.h:73