From 528b7558d51ddd0310144a2aaa0be1bf7a717098 Mon Sep 17 00:00:00 2001 From: ShengRang Date: Tue, 13 Aug 2024 17:35:20 +0800 Subject: [PATCH] Fix linalg_bitset template argument deduction --- linear_algebra_matrix/linalg_bitset.hpp | 14 ++++++++------ linear_algebra_matrix/linalg_bitset.md | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/linear_algebra_matrix/linalg_bitset.hpp b/linear_algebra_matrix/linalg_bitset.hpp index 5292096e..cec19cb6 100644 --- a/linear_algebra_matrix/linalg_bitset.hpp +++ b/linear_algebra_matrix/linalg_bitset.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include #include #include @@ -8,7 +9,7 @@ // Gauss-Jordan elimination of n * m matrix M // Complexity: O(nm + nm rank(M) / 64) // Verified: abc276_h (2000 x 8000) -template +template std::vector> f2_gauss_jordan(int W, std::vector> M) { assert(W <= Wmax); int H = M.size(), c = 0; @@ -33,7 +34,8 @@ std::vector> f2_gauss_jordan(int W, std::vector int f2_rank_gauss_jordan(int W, const std::vector> &M) { +template +int f2_rank_gauss_jordan(int W, const std::vector> &M) { assert(W <= Wmax); for (int h = (int)M.size() - 1; h >= 0; h--) { int j = 0; @@ -46,7 +48,7 @@ template int f2_rank_gauss_jordan(int W, const std::vector int f2_determinant(const std::vector> &M) { +template int f2_determinant(const std::vector> &M) { const int H = M.size(); if (H > Wmax) return 0; @@ -70,7 +72,7 @@ template int f2_determinant(const std::vector> &M) return 1; // nonsingular } -template +template std::vector> f2_matmul(const std::vector> &A, const std::vector> &B) { int H = A.size(), K = B.size(); @@ -83,7 +85,7 @@ f2_matmul(const std::vector> &A, const std::vector +template std::vector> f2_matpower(std::vector> X, long long n) { int D = X.size(); std::vector> ret(D); @@ -99,7 +101,7 @@ std::vector> f2_matpower(std::vector> X, lon // - retval: {true, one of the solutions, {freedoms}} (if solution exists) // {false, {}, {}} (otherwise) // Complexity: O(HW + HW rank(A) / 64 + W^2 len(freedoms)) -template +template std::tuple, std::vector>> f2_system_of_linear_equations(std::vector> A, Vec b, int W) { int H = A.size(); diff --git a/linear_algebra_matrix/linalg_bitset.md b/linear_algebra_matrix/linalg_bitset.md index 68614a9f..f5699a8b 100644 --- a/linear_algebra_matrix/linalg_bitset.md +++ b/linear_algebra_matrix/linalg_bitset.md @@ -15,10 +15,10 @@ vector> A; vector b; // Solve Ax = b (x: F_2^W) -auto [feasible, x0, freedoms] = f2_system_of_linear_equations>(A, b, W); +auto [feasible, x0, freedoms] = f2_system_of_linear_equations(A, b, W); // Calc determinant (or check whether A is regular) -int det = f2_determinant(mat); +int det = f2_determinant(mat); ``` ## 問題例