Skip to content

Commit 528b755

Browse files
committed
Fix linalg_bitset template argument deduction
1 parent 879824a commit 528b755

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

linear_algebra_matrix/linalg_bitset.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#pragma once
22
#include <bitset>
33
#include <cassert>
4+
#include <cstddef>
45
#include <tuple>
56
#include <utility>
67
#include <vector>
78

89
// Gauss-Jordan elimination of n * m matrix M
910
// Complexity: O(nm + nm rank(M) / 64)
1011
// Verified: abc276_h (2000 x 8000)
11-
template <int Wmax>
12+
template <std::size_t Wmax>
1213
std::vector<std::bitset<Wmax>> f2_gauss_jordan(int W, std::vector<std::bitset<Wmax>> M) {
1314
assert(W <= Wmax);
1415
int H = M.size(), c = 0;
@@ -33,7 +34,8 @@ std::vector<std::bitset<Wmax>> f2_gauss_jordan(int W, std::vector<std::bitset<Wm
3334
}
3435

3536
// Rank of Gauss-Jordan eliminated matrix
36-
template <int Wmax> int f2_rank_gauss_jordan(int W, const std::vector<std::bitset<Wmax>> &M) {
37+
template <std::size_t Wmax>
38+
int f2_rank_gauss_jordan(int W, const std::vector<std::bitset<Wmax>> &M) {
3739
assert(W <= Wmax);
3840
for (int h = (int)M.size() - 1; h >= 0; h--) {
3941
int j = 0;
@@ -46,7 +48,7 @@ template <int Wmax> int f2_rank_gauss_jordan(int W, const std::vector<std::bitse
4648
// determinant of F2 matrix.
4749
// Return 0 if the matrix is singular, otherwise return 1.
4850
// Complexity: O(W^3 / 64)
49-
template <int Wmax> int f2_determinant(const std::vector<std::bitset<Wmax>> &M) {
51+
template <std::size_t Wmax> int f2_determinant(const std::vector<std::bitset<Wmax>> &M) {
5052
const int H = M.size();
5153
if (H > Wmax) return 0;
5254

@@ -70,7 +72,7 @@ template <int Wmax> int f2_determinant(const std::vector<std::bitset<Wmax>> &M)
7072
return 1; // nonsingular
7173
}
7274

73-
template <int W1, int W2>
75+
template <std::size_t W1, std::size_t W2>
7476
std::vector<std::bitset<W2>>
7577
f2_matmul(const std::vector<std::bitset<W1>> &A, const std::vector<std::bitset<W2>> &B) {
7678
int H = A.size(), K = B.size();
@@ -83,7 +85,7 @@ f2_matmul(const std::vector<std::bitset<W1>> &A, const std::vector<std::bitset<W
8385
return C;
8486
}
8587

86-
template <int Wmax>
88+
template <std::size_t Wmax>
8789
std::vector<std::bitset<Wmax>> f2_matpower(std::vector<std::bitset<Wmax>> X, long long n) {
8890
int D = X.size();
8991
std::vector<std::bitset<Wmax>> ret(D);
@@ -99,7 +101,7 @@ std::vector<std::bitset<Wmax>> f2_matpower(std::vector<std::bitset<Wmax>> X, lon
99101
// - retval: {true, one of the solutions, {freedoms}} (if solution exists)
100102
// {false, {}, {}} (otherwise)
101103
// Complexity: O(HW + HW rank(A) / 64 + W^2 len(freedoms))
102-
template <int Wmax, class Vec>
104+
template <std::size_t Wmax, class Vec>
103105
std::tuple<bool, std::bitset<Wmax>, std::vector<std::bitset<Wmax>>>
104106
f2_system_of_linear_equations(std::vector<std::bitset<Wmax>> A, Vec b, int W) {
105107
int H = A.size();

linear_algebra_matrix/linalg_bitset.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ vector<bitset<Wmax>> A;
1515
vector<bool> b;
1616

1717
// Solve Ax = b (x: F_2^W)
18-
auto [feasible, x0, freedoms] = f2_system_of_linear_equations<Wmax, vector<bool>>(A, b, W);
18+
auto [feasible, x0, freedoms] = f2_system_of_linear_equations(A, b, W);
1919

2020
// Calc determinant (or check whether A is regular)
21-
int det = f2_determinant<dim>(mat);
21+
int det = f2_determinant(mat);
2222
```
2323

2424
## 問題例

0 commit comments

Comments
 (0)