From 69e967405bb4e3a6c575c4fece054f5f28fa1da4 Mon Sep 17 00:00:00 2001 From: Thinh Date: Mon, 14 Apr 2025 18:57:25 +0700 Subject: [PATCH 1/3] Add dot product operation --- impl/NotSoBasicLinearAlgebra.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/impl/NotSoBasicLinearAlgebra.h b/impl/NotSoBasicLinearAlgebra.h index 6381d7d..a33c171 100644 --- a/impl/NotSoBasicLinearAlgebra.h +++ b/impl/NotSoBasicLinearAlgebra.h @@ -33,6 +33,18 @@ Matrix<3, Cols, typename ParentTypeA::DType> CrossProduct( return ret; } +template +typename ParentTypeA::DType DotProduct( + const MatrixBase &vecA, + const MatrixBase &vecB) +{ + typename ParentTypeA::DType ret = 0; + for (int i = 0; i < Dim; i++) { + ret += vecA(i) * vecB(i); + } + return ret; +} + template struct LUDecomposition { From 2f6dfc07a7273c142fe1ebc749e9b558229f9793 Mon Sep 17 00:00:00 2001 From: Thinh Pham Date: Tue, 15 Apr 2025 05:56:02 +0700 Subject: [PATCH 2/3] Fix ctest --rerun-failed argument typo. --- .github/workflows/run_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 318d261..b99aba7 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -24,4 +24,4 @@ jobs: - name: Test working-directory: ${{github.workspace}}/build - run: ctest -rerun-failed --output-on-failure -C ${{env.BUILD_TYPE}} + run: ctest --rerun-failed --output-on-failure -C ${{env.BUILD_TYPE}} From b59278e4238f3f2e9df7e1213f77e6680de2804f Mon Sep 17 00:00:00 2001 From: Thinh Pham Date: Wed, 16 Apr 2025 12:44:01 +0700 Subject: [PATCH 3/3] Add unit test for DotProduct. --- test/test_linear_algebra.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/test_linear_algebra.cpp b/test/test_linear_algebra.cpp index f45d9ed..d76b9f1 100644 --- a/test/test_linear_algebra.cpp +++ b/test/test_linear_algebra.cpp @@ -35,6 +35,19 @@ TEST(LinearAlgebra, CrossProduct) } } +TEST(LinearAlgebra, DotProduct) +{ + // Test with Dimension 3, int + Matrix<3, 1, int> A = {2, 3, 4}; + Matrix<3, 1, int> B = {7, 8, 9}; + EXPECT_FLOAT_EQ(DotProduct(A, B), 74); + + // Test with Dimension 4, float + Matrix<4> C = {2.5f, -3.4f, 4.3f, 5.2f}; + Matrix<4> D = {6.7f, 7.6f, -8.5f, 9.4f}; + EXPECT_NEAR(DotProduct(C, D), 3.23999f, 1e-5); +} + TEST(LinearAlgebra, LUDecomposition) { Matrix<7, 7> A = {16, 78, 50, 84, 70, 63, 2, 32, 33, 61, 40, 17, 96, 98, 50, 80, 78, 27, 86, 49, 57, 10, 42, 96, 44,