12#include <Eigen/Sparse>
21template <
class SpMat,
class MaskVec>
24 using row_iter_t =
typename SpMat::InnerIterator;
27 static constexpr auto proj_row = [](
const row_iter_t &it) {
28 return static_cast<typename MaskVec::value_type
>(it.row());
32 std::move(col_range), std::move(mask), std::less{}, proj_row);
34 auto extract_eigen_iter = []<
class T>(T &&tup) ->
decltype(
auto) {
35 return std::get<0>(std::forward<T>(tup));
37 return std::views::transform(std::move(intersection), extract_eigen_iter);
42template <
class SpMat,
class MaskVec>
45 using row_iter_t =
typename SpMat::InnerIterator;
48 static constexpr auto proj_row = [](
const row_iter_t &it) {
49 return static_cast<typename MaskVec::value_type
>(it.row());
54 static constexpr auto proj_mask = [](
const auto &tup) ->
decltype(
auto) {
55 return std::get<1>(tup);
60 std::less{}, proj_row, proj_mask);
62 auto extract_eigen_iter_and_index = []<
class T>(T && tup)
63 requires(std::is_rvalue_reference_v<T &&>)
65 auto &[eigen_iter, enum_tup] = tup;
66 auto &mask_index = std::get<0>(enum_tup);
67 return std::tuple{std::move(eigen_iter), std::move(mask_index)};
69 return std::views::transform(std::move(intersection),
70 extract_eigen_iter_and_index);
76template <
class SpMat,
class Mat,
class MaskVec>
82 R(ri, ci) += r.value();
86template <
class SpMat,
class Mat,
class MaskVec>
88 using index_t =
typename SpMat::Index;
90 for (
index_t c = 0; c < S_full.cols(); ++c)
93 S(ri, c) += r.value();
97template <
class SpMat,
class CVec,
class Vec,
class MaskVec>
99 Vec &&out,
const MaskVec &mask_J,
100 const MaskVec &mask_K) {
103 for (
auto c : mask_K)
105 for (
auto &&[r, ri] : select_rows_in_col_iota(R, mask_J, c))
106 out(ri) += r.value() * v(c);
110template <
class SpMat,
class CVec,
class Vec,
class MaskVec>
112 Vec &&out,
const MaskVec &mask) {
113 using index_t =
typename SpMat::Index;
115 for (
index_t c = 0; c < S.cols(); ++c)
118 out(c) += r.value() * v(r.row());
auto select_rows_in_col(const SpMat &sp_mat, MaskVec mask, auto column)
Returns a range over the row indices in the given column of sp_mat that are also in mask.
auto select_rows_in_col_iota(const SpMat &sp_mat, MaskVec mask, auto column)
Like select_rows_in_col, but returns a range of tuples containing the Eigen InnerIterator and a linea...
void sparse_matvec_add_masked_rows_cols(const SpMat &R, const CVec &v, Vec &&out, const MaskVec &mask_J, const MaskVec &mask_K)
out += R(mask_J,mask_K) * v(mask_K);
void sparse_add_masked_rows(const SpMat &S_full, Mat &&S, const MaskVec &mask)
S += S_full(mask,:)
auto enumerate(Rng &&rng)
void sparse_add_masked(const SpMat &R_full, Mat &&R, const MaskVec &mask)
R += R_full(mask,mask)
void sparse_matvec_add_transpose_masked_rows(const SpMat &S, const CVec &v, Vec &&out, const MaskVec &mask)
out += S(mask,:)ᵀ * v(mask);
set_intersection_iterable< std::ranges::views::all_t< R1 >, std::ranges::views::all_t< R2 >, Comp, Proj1, Proj2 > iter_set_intersection(R1 &&r1, R2 &&r2, Comp comp={}, Proj1 proj1={}, Proj2 proj2={})
typename Conf::index_t index_t