1 #ifndef MEDUSA_BITS_OPERATORS_SHAPESTORAGE_HPP_
2 #define MEDUSA_BITS_OPERATORS_SHAPESTORAGE_HPP_
14 template <
typename Derived,
typename vec_t,
typename OpFamilies>
16 assert_msg(0 <= node && node <= domain_size_,
"Node index %d out or range [0, %d).",
18 assert_msg(0 <= j && j < supportSize(node),
"Support index %d out of range [0, %d).",
19 j, supportSize(node));
20 assert_msg(access(support_, node)[j] != -1,
"Attempted access to shapes and support for node "
21 "%d, which were not computed.", node);
22 return access(support_, node)[j];
25 template <
typename Derived,
typename vec_t,
typename OpFamilies>
26 Eigen::Map<const Eigen::Matrix<int, Eigen::Dynamic, 1>>
28 assert_msg(0 <= node && node <= domain_size_,
"Node index %d out or range [0, %d).",
30 assert_msg(*access(support_, node) != -1,
"Attempted access to shapes and support for node "
31 "%d, which were not computed.", node);
32 return {access(support_, node), supportSize(node)};
35 template <
typename Derived,
typename vec_t,
typename OpFamilies>
38 for (
int i = 0; i < domain_size_; ++i) {
39 sizes[i] = supportSize(i);
44 template <
typename Derived,
typename vec_t,
typename OpFamilies>
48 for (
int d = 0; d <
dim; ++d) res.
append(sizes);
49 for (
int& i : res) i *=
dim;
53 template <
typename Derived,
typename vec_t,
typename OpFamilies>
56 assert_msg(0 <= node && node <= domain_size_,
"Node index %d out or range [0, %d).",
58 assert_msg(0 <= j && j < supportSize(node),
"Support index %d out of range [0, %d).",
59 j, supportSize(node));
60 return get<Lap<vec_t::dim>>(node, j);
63 template <
typename Derived,
typename vec_t,
typename OpFamilies>
66 assert_msg(0 <= node && node <= domain_size_,
"Node index %d out or range [0, %d).",
68 assert_msg(0 <= j && j < supportSize(node),
"Support index %d out of range [0, %d).",
69 j, supportSize(node));
70 assert_msg(0 <= var && var <
dim,
"Variable index %d out of bounds [%d, %d).", var, 0,
dim);
74 template <
typename Derived,
typename vec_t,
typename OpFamilies>
77 int varmin,
int varmax,
int node,
int j)
const {
78 assert_msg(0 <= node && node <= domain_size_,
"Node index %d out or range [0, %d).",
80 assert_msg(0 <= j && j < supportSize(node),
"Support index %d out of range [0, %d).",
81 j, supportSize(node));
83 "Variable varmin %d out of bounds [%d, %d).", varmin, 0,
dim);
85 "Variable varmax %d out of bounds [%d, %d).", varmax, 0,
dim);
86 assert_msg(varmin <= varmax,
"Varmin (%d) must be smaller than varmax (%d).",
91 template <
typename Derived,
typename vec_t,
typename OpFamilies>
95 assert_msg(0 <= node && node <= domain_size_,
"Node index %d out or range [0, %d).",
97 return getShape<Lap<vec_t::dim>>(node);
100 template <
typename Derived,
typename vec_t,
typename OpFamilies>
104 assert_msg(0 <= node && node <= domain_size_,
"Node index %d out or range [0, %d).",
106 assert_msg(0 <= var && var <
dim,
"Variable index %d out of bounds [%d, %d).", var, 0,
dim);
110 template <
typename Derived,
typename vec_t,
typename OpFamilies>
114 assert_msg(0 <= node && node <= domain_size_,
"Node index %d out or range [0, %d).",
117 "Variable varmin %d out of bounds [%d, %d).", varmin, 0,
dim);
119 "Variable varmax %d out of bounds [%d, %d).", varmax, 0,
dim);
120 assert_msg(varmin <= varmax,
"Varmin (%d) must be smaller than varmax (%d).",
125 template <
typename Derived,
typename vec_t,
typename OpFamilies>
127 int node,
const std::vector<int>& support) {
128 assert_msg(0 <= node && node <= domain_size_,
"Node index %d out or range [0, %d).",
130 assert_msg(
static_cast<int>(support.size()) == supportSize(node),
"Support of unexpected "
131 "length %d, expected %d.", support.size(), supportSize(node));
132 std::memcpy(access(support_, node), support.data(),
133 support.size()*
sizeof(
int));
136 template <
typename Derived,
typename vec_t,
typename OpFamilies>
138 int node,
const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>& shape) {
139 assert_msg(0 <= node && node <= domain_size_,
"Node index %d out or range [0, %d).",
141 assert_msg(shape.size() == supportSize(node),
"Laplace shape of unexpected length %d, "
142 "expected %d.", shape.size(), supportSize(node));
143 setShape<Lap<vec_t::dim>>(node, shape);
146 template <
typename Derived,
typename vec_t,
typename OpFamilies>
148 int var,
int node,
const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>& shape) {
149 assert_msg(0 <= node && node <= domain_size_,
"Node index %d out or range [0, %d).",
151 assert_msg(0 <= var && var <
dim,
"Variable index %d out of bounds [%d, %d).", var, 0,
dim);
152 assert_msg(shape.size() == supportSize(node),
"D1 shape of unexpected length %d, expected %d.",
153 shape.size(), supportSize(node));
154 setShape<Der1s<dim>>(var, node, shape);
157 template <
typename Derived,
typename vec_t,
typename OpFamilies>
159 int varmin,
int varmax,
int node,
const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>& shape) {
160 assert_msg(0 <= node && node <= domain_size_,
"Node index %d out or range [0, %d).",
163 "Variable varmin %d out of bounds [%d, %d).", varmin, 0,
dim);
165 "Variable varmax %d out of bounds [%d, %d).", varmax, 0,
dim);
166 assert_msg(varmin <= varmax,
"Varmin (%d) must be smaller than varmax (%d).",
168 assert_msg(shape.size() == supportSize(node),
"D2 shape of unexpected length %d, expected %d.",
169 shape.size(), supportSize(node));
170 int idx = varmax*(varmax+1)/2 + varmin;
171 setShape<Der2s<dim>>(idx, node, shape);
175 template <
typename D,
typename V,
typename O>
177 os <<
"Shape storage:\n";
178 return shapes_internal::printShapes(shapes, os);
181 template <
typename Derived,
typename vec_t,
typename OpFamilies>
183 size_t size =
sizeof(*this);
184 for (
int i = 0; i < num_operators; ++i) {
191 namespace resize_internal {
195 template <
typename OpFamilies,
size_t i>
196 struct resize_storage_ {
197 template <
typename Shapes>
198 static void resize(Shapes& shapes,
int base_size) {
199 resize_storage_<OpFamilies, i-1>::template resize<Shapes>(shapes, base_size);
200 std::get<i-1>(shapes).resize(
201 base_size*std::tuple_element<i-1, OpFamilies>::type::size(),
NaN);
206 template <
typename OpFamilies>
207 struct resize_storage_<OpFamilies, 0> {
208 template <
typename Shapes>
static void resize(Shapes&,
int) {}
216 #endif // MEDUSA_BITS_OPERATORS_SHAPESTORAGE_HPP_