src/lalg/ds/matsp/lib.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "../../../fast/rsort32/lib.hpp" | ||
| 4 | |||
| 5 | namespace tifa_libs { | ||
| 6 | |||
| 7 | template <class T> | ||
| 8 | class matsp { | ||
| 9 | using node = std::pair<u32, T>; | ||
| 10 | using data_t = vvec<node>; | ||
| 11 | |||
| 12 | u32 r, c; | ||
| 13 | data_t d; | ||
| 14 | |||
| 15 | public: | ||
| 16 | using val_t = T; | ||
| 17 | |||
| 18 |
12/24tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_bd_tag<13l> > >::matsp(unsigned int, unsigned int):
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_bs_tag<998244353ul> > >::matsp(unsigned int, unsigned int):
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_md64_tag<13l> > >::matsp(unsigned int, unsigned int):
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_md_tag<13l> > >::matsp(unsigned int, unsigned int):
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms64_tag<998244353ul> > >::matsp(unsigned int, unsigned int):
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms_tag<998244353ul> > >::matsp(unsigned int, unsigned int):
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
|
432 | CEXP matsp(u32 row, u32 col) NE : r(row), c(col), d(r) { assert(row > 0 && col > 0); } |
| 19 | |||
| 20 | 622404 | ND CEXP u32 CR row() CNE { return r; } | |
| 21 | 622404 | ND CEXP u32 CR col() CNE { return c; } | |
| 22 | CEXP data_t CR data() CNE { return d; } | ||
| 23 | CEXP data_t& data() NE { return d; } | ||
| 24 | 841116 | CEXP T& operator()(u32 r, u32 c) NE { | |
| 25 |
12/12tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_bd_tag<13l> > >::operator()(unsigned int, unsigned int):
✓ Branch 8 taken 4876997 times.
✓ Branch 9 taken 140186 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_bs_tag<998244353ul> > >::operator()(unsigned int, unsigned int):
✓ Branch 8 taken 4876997 times.
✓ Branch 9 taken 140186 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_md64_tag<13l> > >::operator()(unsigned int, unsigned int):
✓ Branch 8 taken 4876997 times.
✓ Branch 9 taken 140186 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_md_tag<13l> > >::operator()(unsigned int, unsigned int):
✓ Branch 8 taken 4876997 times.
✓ Branch 9 taken 140186 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms64_tag<998244353ul> > >::operator()(unsigned int, unsigned int):
✓ Branch 8 taken 4876997 times.
✓ Branch 9 taken 140186 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms_tag<998244353ul> > >::operator()(unsigned int, unsigned int):
✓ Branch 8 taken 4876997 times.
✓ Branch 9 taken 140186 times.
|
30103098 | for (auto& [c_, v] : d[r]) |
| 26 |
6/12tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_bd_tag<13l> > >::operator()(unsigned int, unsigned int):
✗ Branch 0 not taken.
✓ Branch 1 taken 4876997 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_bs_tag<998244353ul> > >::operator()(unsigned int, unsigned int):
✗ Branch 0 not taken.
✓ Branch 1 taken 4876997 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_md64_tag<13l> > >::operator()(unsigned int, unsigned int):
✗ Branch 0 not taken.
✓ Branch 1 taken 4876997 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_md_tag<13l> > >::operator()(unsigned int, unsigned int):
✗ Branch 0 not taken.
✓ Branch 1 taken 4876997 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms64_tag<998244353ul> > >::operator()(unsigned int, unsigned int):
✗ Branch 0 not taken.
✓ Branch 1 taken 4876997 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms_tag<998244353ul> > >::operator()(unsigned int, unsigned int):
✗ Branch 0 not taken.
✓ Branch 1 taken 4876997 times.
|
29261982 | if (c == c_) return v; |
| 27 | 841116 | d[r].emplace_back(c, T{}); | |
| 28 | 841116 | return d[r].back().second; | |
| 29 | } | ||
| 30 | CEXP T CR operator()(u32 r, u32 c) CNE { | ||
| 31 | for (auto& [c_, v] : d[r]) | ||
| 32 | if (c == c_) return v; | ||
| 33 | return T{}; | ||
| 34 | } | ||
| 35 | CEXP void shrink_row(u32 r) NE { | ||
| 36 | d[r].erase(remove_if(begin(d[r]), end(d[r]), [](cT_(node) x) NE { return x.second == T{}; }), end(d[r])); | ||
| 37 | } | ||
| 38 | CEXP void sort_row(u32 r) NE { tifa_libs::sort(d[r]); } | ||
| 39 | template <class F> | ||
| 40 | CEXP void apply(F f) NE { | ||
| 41 | flt_ (u32, i, 0, r) | ||
| 42 | for (auto& [j, v] : d[i]) f(i, j, v); | ||
| 43 | } | ||
| 44 | template <class F> | ||
| 45 | friend CEXP matsp merge(matsp l, matsp r, F f) NE { | ||
| 46 | cu32 r_ = l.row(), c_ = l.col(); | ||
| 47 | assert(r_ == r.row() && c_ == r.col()); | ||
| 48 | matsp ret(r_, c_); | ||
| 49 | flt_ (u32, i, 0, r_) { | ||
| 50 | if (i >= r_ || (i < r_ && l[i].empty())) { | ||
| 51 | if (!r[i].empty()) ret[i] = r[i]; | ||
| 52 | continue; | ||
| 53 | } | ||
| 54 | if (i >= r_ || (i < r_ && r[i].empty())) { | ||
| 55 | if (!l[i].empty()) ret[i] = l[i]; | ||
| 56 | continue; | ||
| 57 | } | ||
| 58 | l.sort_row(i), r.sort_row(i); | ||
| 59 | auto f1 = begin(l.data()), l1 = end(l.data()), f2 = begin(r.data()), l2 = end(r.data()), d = begin(ret.d[i]); | ||
| 60 | for (; f1 != l1; ++d) { | ||
| 61 | if (f2 == l2) copy(f1, l1, d); | ||
| 62 | if (*f2 < *f1) *d = *f2, ++f2; | ||
| 63 | else if (*f1 < *f2) *d = *f1, ++f1; | ||
| 64 | else { | ||
| 65 | u32 j = u32(f1 - begin(l.data())); | ||
| 66 | *d = f(i, j, *f1, *f2), ++f1, ++f2; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | copy(f2, l2, d); | ||
| 70 | } | ||
| 71 | return ret; | ||
| 72 | } | ||
| 73 | CEXP matsp operator-() CNE { | ||
| 74 | matsp ret = *this; | ||
| 75 | ret.apply([](u32, u32, T& v) NE { v = -v; }); | ||
| 76 | return ret; | ||
| 77 | } | ||
| 78 | friend CEXP matsp operator+(matsp l, cT_(T) v) NE { return l += v; } | ||
| 79 | friend CEXP matsp operator+(cT_(T) v, matsp l) NE { return l += v; } | ||
| 80 | CEXP matsp& operator+=(cT_(T) v) NE { | ||
| 81 | apply([&v](u32, u32, T& val) NE { val += v; }); | ||
| 82 | return *this; | ||
| 83 | } | ||
| 84 | friend CEXP matsp operator-(matsp l, cT_(T) v) NE { return l -= v; } | ||
| 85 | friend CEXP matsp operator-(cT_(T) v, matsp l) NE { return l -= v; } | ||
| 86 | CEXP matsp& operator-=(cT_(T) v) NE { | ||
| 87 | apply([&v](u32, u32, T& val) NE { val -= v; }); | ||
| 88 | return *this; | ||
| 89 | } | ||
| 90 | friend CEXP matsp operator*(matsp l, cT_(T) v) NE { return l *= v; } | ||
| 91 | friend CEXP matsp operator*(cT_(T) v, matsp l) NE { return l *= v; } | ||
| 92 | CEXP matsp& operator*=(cT_(T) v) NE { | ||
| 93 | apply([&v](u32, u32, T& val) NE { val *= v; }); | ||
| 94 | return *this; | ||
| 95 | } | ||
| 96 | friend CEXP matsp operator+(matsp CR l, matsp CR r) NE { | ||
| 97 | return merge(l, r, [](u32, u32, cT_(T) lv, cT_(T) rv) NE { return lv + rv; }); | ||
| 98 | } | ||
| 99 | CEXP matsp& operator+=(matsp CR r) NE { return *this = *this + r; } | ||
| 100 | friend CEXP matsp operator-(matsp l, matsp CR r) NE { return l + (-r); } | ||
| 101 | CEXP matsp& operator-=(matsp CR r) NE { return *this = *this - r; } | ||
| 102 | friend CEXP matsp operator*(matsp l, matsp CR r) NE { | ||
| 103 | cu32 i_ = l.row(), j_ = l.col(), k_ = r.col(); | ||
| 104 | assert(j_ == r.row()); | ||
| 105 | matsp ret(i_, k_); | ||
| 106 | flt_ (u32, i, 0, i_) { | ||
| 107 | if (l.d[i].empty()) continue; | ||
| 108 | flt_ (u32, j, 0, j_) { | ||
| 109 | if (r.d[j].empty()) continue; | ||
| 110 | flt_ (u32, k, 0, k_) ret(i, k) += l(i, j) * r(j, k); | ||
| 111 | } | ||
| 112 | ret.shrink_row(i); | ||
| 113 | } | ||
| 114 | return ret; | ||
| 115 | } | ||
| 116 | CEXP matsp& operator*=(matsp CR r) NE { return *this = *this - r; } | ||
| 117 | 622260 | CEXP vec<T> lproj(spn<T> x) CNE { | |
| 118 | 622260 | cu32 r_ = row(), c_ = col(); | |
| 119 |
6/12tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_bd_tag<13l> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_bd_tag<13l> > const, 18446744073709551615ul>) const:
✗ Branch 1 not taken.
✓ Branch 2 taken 103710 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_bs_tag<998244353ul> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_bs_tag<998244353ul> > const, 18446744073709551615ul>) const:
✗ Branch 1 not taken.
✓ Branch 2 taken 103710 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_md64_tag<13l> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_md64_tag<13l> > const, 18446744073709551615ul>) const:
✗ Branch 1 not taken.
✓ Branch 2 taken 103710 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_md_tag<13l> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_md_tag<13l> > const, 18446744073709551615ul>) const:
✗ Branch 1 not taken.
✓ Branch 2 taken 103710 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms64_tag<998244353ul> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms64_tag<998244353ul> > const, 18446744073709551615ul>) const:
✗ Branch 1 not taken.
✓ Branch 2 taken 103710 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms_tag<998244353ul> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms_tag<998244353ul> > const, 18446744073709551615ul>) const:
✗ Branch 1 not taken.
✓ Branch 2 taken 103710 times.
|
622260 | assert(r_ == x.size()); |
| 120 | 622260 | vec<T> ret(c_); | |
| 121 |
12/12tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_bd_tag<13l> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_bd_tag<13l> > const, 18446744073709551615ul>) const:
✓ Branch 0 taken 294133594 times.
✓ Branch 1 taken 103710 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_bs_tag<998244353ul> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_bs_tag<998244353ul> > const, 18446744073709551615ul>) const:
✓ Branch 0 taken 294133594 times.
✓ Branch 1 taken 103710 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_md64_tag<13l> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_md64_tag<13l> > const, 18446744073709551615ul>) const:
✓ Branch 0 taken 294133594 times.
✓ Branch 1 taken 103710 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_md_tag<13l> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_md_tag<13l> > const, 18446744073709551615ul>) const:
✓ Branch 0 taken 294133594 times.
✓ Branch 1 taken 103710 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms64_tag<998244353ul> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms64_tag<998244353ul> > const, 18446744073709551615ul>) const:
✓ Branch 0 taken 294133594 times.
✓ Branch 1 taken 103710 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms_tag<998244353ul> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms_tag<998244353ul> > const, 18446744073709551615ul>) const:
✓ Branch 0 taken 294133594 times.
✓ Branch 1 taken 103710 times.
|
1765423824 | flt_ (u32, i, 0, c_) |
| 122 |
12/12tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_bd_tag<13l> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_bd_tag<13l> > const, 18446744073709551615ul>) const:
✓ Branch 12 taken 747487970 times.
✓ Branch 13 taken 294133594 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_bs_tag<998244353ul> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_bs_tag<998244353ul> > const, 18446744073709551615ul>) const:
✓ Branch 12 taken 747487970 times.
✓ Branch 13 taken 294133594 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_md64_tag<13l> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_md64_tag<13l> > const, 18446744073709551615ul>) const:
✓ Branch 12 taken 747487970 times.
✓ Branch 13 taken 294133594 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_md_tag<13l> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_md_tag<13l> > const, 18446744073709551615ul>) const:
✓ Branch 12 taken 747487970 times.
✓ Branch 13 taken 294133594 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms64_tag<998244353ul> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms64_tag<998244353ul> > const, 18446744073709551615ul>) const:
✓ Branch 12 taken 747487970 times.
✓ Branch 13 taken 294133594 times.
tifa_libs::matsp<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms_tag<998244353ul> > >::lproj(std::span<tifa_libs::mint_impl_::mint<tifa_libs::mint_ms_tag<998244353ul> > const, 18446744073709551615ul>) const:
✓ Branch 12 taken 747487970 times.
✓ Branch 13 taken 294133594 times.
|
6249729384 | for (auto&& [pos, v] : d[i]) ret[i] += x[pos] * v; |
| 123 | 622260 | return ret; | |
| 124 | } | ||
| 125 | }; | ||
| 126 | |||
| 127 | } // namespace tifa_libs | ||
| 128 |