Skip to content

Commit a78412a

Browse files
committed
make submatrix return view of views
1 parent c1575f8 commit a78412a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

cp-algo/linalg/matrix.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ namespace cp_algo::linalg {
109109
}
110110
return res;
111111
}
112-
matrix submatrix(auto viewx, auto viewy) const {
113-
return from(*this | viewx | std::views::transform([&](auto const& y) {
112+
auto submatrix(auto viewx, auto viewy) const {
113+
return *this | viewx | std::views::transform([viewy](auto const& y) {
114114
return y | viewy;
115-
}));
115+
});
116116
}
117117

118118
matrix T() const {
@@ -214,7 +214,7 @@ namespace cp_algo::linalg {
214214
det *= b[i][i];
215215
b[i] *= base(1) / b[i][i];
216216
}
217-
return {det, b.submatrix(std::views::all, std::views::drop(n()))};
217+
return {det, from(b.submatrix(std::views::all, std::views::drop(n())))};
218218
}
219219

220220
// Can also just run gauss on T() | eye(m)
@@ -238,15 +238,15 @@ namespace cp_algo::linalg {
238238
// [solution, basis], transposed
239239
std::optional<std::array<matrix, 2>> solve(matrix t) const {
240240
matrix sols = (*this | t).kernel();
241-
if(sols.n() < t.m() || sols.submatrix(
241+
if(sols.n() < t.m() || from(sols.submatrix(
242242
std::views::drop(sols.n() - t.m()),
243243
std::views::drop(m())
244-
) != -eye(t.m())) {
244+
)) != -eye(t.m())) {
245245
return std::nullopt;
246246
} else {
247247
return std::array{
248-
sols.submatrix(std::views::drop(sols.n() - t.m()), std::views::take(m())),
249-
sols.submatrix(std::views::take(sols.n() - t.m()), std::views::take(m()))
248+
from(sols.submatrix(std::views::drop(sols.n() - t.m()), std::views::take(m()))),
249+
from(sols.submatrix(std::views::take(sols.n() - t.m()), std::views::take(m())))
250250
};
251251
}
252252
}

0 commit comments

Comments
 (0)