15 #include "libmesh/libmesh_common.h" 32 std::vector<std::vector<T>> computeMatrix()
const;
35 std::vector<T> computeRow(std::size_t row)
const;
38 T computeValue(std::size_t row, std::size_t col)
const;
41 std::size_t
numRows()
const {
return _n_rows; }
44 std::size_t
numCols()
const {
return _n_cols; }
54 const std::vector<std::vector<T>>
_items;
61 static std::size_t computeRowCount(
const std::vector<std::vector<T>> & items);
66 : _n_rows(computeRowCount(items)), _n_cols(items.size()), _items(items)
69 for (
typename std::vector<std::vector<T>>::const_reverse_iterator iter = _items.rbegin();
70 iter != _items.rend();
73 std::size_t n = iter->size();
74 _denomenators.push_front(
d);
75 _moduli.push_front(n);
81 std::vector<std::vector<T>>
84 std::vector<std::vector<T>> output(_n_rows, std::vector<T>(_n_cols));
85 for (std::size_t row = 0; row < _n_rows; ++row)
86 for (std::size_t col = 0; col < _n_cols; ++col)
87 output[row][col] = computeValue(row, col);
95 std::vector<T> output(_n_cols);
96 for (std::size_t col = 0; col < _n_cols; ++col)
97 output[col] = computeValue(row, col);
101 template <
typename T>
105 mooseAssert(row < _n_rows,
"Row index out of range.");
106 mooseAssert(col < _n_cols,
"Column index out of range.");
107 return _items[col][(row / _denomenators[col]) % _moduli[col]];
110 template <
typename T>
114 std::size_t n_rows = 1;
115 for (
const auto & inner : items)
116 n_rows *= inner.size();
123 template <
class T,
class W>
128 const std::vector<std::vector<W>> & weights);
131 std::vector<W> computeWeightVector()
const;
134 W computeWeight(std::size_t row)
const;
141 template <
typename T,
typename W>
143 const std::vector<std::vector<T>> & items,
const std::vector<std::vector<W>> & weights)
146 mooseAssert(items.size() == weights.size(),
147 "The supplied items and weights must be the same size.");
148 for (std::size_t i = 0; i < items.size(); ++i)
149 mooseAssert(items[i].size() == weights[i].size(),
150 "Internal vector of the supplied items and weights must be the same size.");
153 template <
typename T,
typename W>
157 std::vector<W> output(this->_n_rows);
158 for (std::size_t i = 0; i < output.size(); ++i)
159 output[i] = computeWeight(i);
163 template <
typename T,
typename W>
167 std::vector<W> vec = _weight.computeRow(row);
168 return std::accumulate(vec.begin(), vec.end(),
static_cast<W
>(1), std::multiplies<W>());
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...