Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
12 changes: 12 additions & 0 deletions impl/NotSoBasicLinearAlgebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ Matrix<3, Cols, typename ParentTypeA::DType> CrossProduct(
return ret;
}

template <typename ParentTypeA, typename ParentTypeB, int Dim>
typename ParentTypeA::DType DotProduct(
const MatrixBase<ParentTypeA, Dim, 1, typename ParentTypeA::DType> &vecA,
const MatrixBase<ParentTypeB, Dim, 1, typename ParentTypeA::DType> &vecB)
{
typename ParentTypeA::DType ret = 0;
for (int i = 0; i < Dim; i++) {
ret += vecA(i) * vecB(i);
}
return ret;
}

template <typename ParentType>
struct LUDecomposition
{
Expand Down
13 changes: 13 additions & 0 deletions test/test_linear_algebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down