14 #include "libmesh/libmesh_common.h" 31 std::vector<std::vector<T>> computeMatrix()
const;
34 std::vector<T> computeRow(std::size_t row)
const;
37 T computeValue(std::size_t row, std::size_t col)
const;
40 std::size_t
numRows()
const {
return _n_rows; }
43 std::size_t
numCols()
const {
return _n_cols; }
53 const std::vector<std::vector<T>>
_items;
60 static std::size_t computeRowCount(
const std::vector<std::vector<T>> & items);
65 : _n_rows(computeRowCount(items)), _n_cols(items.size()), _items(items)
68 for (
typename std::vector<std::vector<T>>::const_reverse_iterator iter = _items.rbegin();
69 iter != _items.rend();
72 std::size_t n = iter->size();
73 _denomenators.push_front(
d);
74 _moduli.push_front(n);
80 std::vector<std::vector<T>>
83 std::vector<std::vector<T>> output(_n_rows, std::vector<T>(_n_cols));
84 for (std::size_t row = 0; row < _n_rows; ++row)
85 for (std::size_t col = 0; col < _n_cols; ++col)
86 output[row][col] = computeValue(row, col);
94 std::vector<T> output(_n_cols);
95 for (std::size_t col = 0; col < _n_cols; ++col)
96 output[col] = computeValue(row, col);
100 template <
typename T>
104 mooseAssert(row < _n_rows,
"Row index out of range.");
105 mooseAssert(col < _n_cols,
"Column index out of range.");
106 return _items[col][(row / _denomenators[col]) % _moduli[col]];
109 template <
typename T>
113 std::size_t n_rows = 1;
114 for (
const auto & inner : items)
115 n_rows *= inner.size();
122 template <
class T,
class W>
127 const std::vector<std::vector<W>> & weights);
130 std::vector<W> computeWeightVector()
const;
133 W computeWeight(std::size_t row)
const;
140 template <
typename T,
typename W>
142 const std::vector<std::vector<T>> & items,
const std::vector<std::vector<W>> & weights)
145 mooseAssert(items.size() == weights.size(),
146 "The supplied items and weights must be the same size.");
147 for (std::size_t i = 0; i < items.size(); ++i)
148 mooseAssert(items[i].size() == weights[i].size(),
149 "Internal vector of the supplied items and weights must be the same size.");
152 template <
typename T,
typename W>
156 std::vector<W> output(this->_n_rows);
157 for (std::size_t i = 0; i < output.size(); ++i)
158 output[i] = computeWeight(i);
162 template <
typename T,
typename W>
166 std::vector<W> vec = _weight.computeRow(row);
167 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...