Skip to content

Commit

Permalink
Fixed a bug in Matrix class
Browse files Browse the repository at this point in the history
  • Loading branch information
hosseinmoein committed Nov 29, 2024
1 parent d667788 commit bc7f381
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
4 changes: 2 additions & 2 deletions include/DataFrame/Utils/Matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ operator * (const Matrix<T, MO1> &lhs, const Matrix<T, MO2> &rhs) {
assert(lhs_cols == rhs.rows());
#endif // HMDF_SANITY_EXCEPTIONS

Matrix<T, MO1> result { lhs_rows, rhs_cols };
Matrix<T, MO1> result { lhs_rows, rhs_cols, 0 };
const long thread_level =
(lhs_cols >= 400L || rhs_cols >= 400L)
? ThreadGranularity::get_thread_level() : 0;
Expand All @@ -1125,7 +1125,7 @@ operator * (const Matrix<T, MO1> &lhs, const Matrix<T, MO2> &rhs) {
for (long c = begin; c < end; ++c)
for (long r = 0; r < lhs_rows; ++r)
for (long k = 0; k < lhs_cols; ++k)
result(r, c) += lhs(k, r) * rhs(c, k);
result(r, c) += lhs(r, k) * rhs(k, c);
};
auto row_lbd =
[lhs_cols, rhs_cols, &result,
Expand Down
8 changes: 4 additions & 4 deletions test/dataframe_tester_4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1979,10 +1979,10 @@ static void test_PartialAutoCorrVisitor() {
assert(pacf.get_result().size() == 50);
assert(std::fabs(pacf.get_result()[0] - 1.0) < 0.000001);
assert(std::fabs(pacf.get_result()[1] - 0.999915) < 0.000001);
assert(std::fabs(pacf.get_result()[10] - 0.094446) < 0.000001);
assert(std::fabs(pacf.get_result()[30] - 0.004907) < 0.000001);
assert(std::fabs(pacf.get_result()[48] - 0.004338) < 0.000001);
assert(std::fabs(pacf.get_result()[49] - 0.045952) < 0.000001);
assert(std::fabs(pacf.get_result()[10] - 0.982959) < 0.000001);
assert(std::fabs(pacf.get_result()[30] - 0.983226) < 0.000001);
assert(std::fabs(pacf.get_result()[48] - 0.98751) < 0.000001);
assert(std::fabs(pacf.get_result()[49] - 0.987886) < 0.000001);
}

// ----------------------------------------------------------------------------
Expand Down
25 changes: 22 additions & 3 deletions test/matrix_tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,29 @@ int main(int, char *[]) {

// ThreadGranularity::set_optimum_thread_level();

row_mat_t row_mata { 3, 3 };
col_mat_t col_mata { 3, 3 };
std::size_t value { 0 };

for (long r = 0; r < row_mata.rows(); ++r)
for (long c = 0; c < row_mata.cols(); ++c) {
row_mata(r, c) = ++value;
col_mata(r, c) = value;
}

row_mat_t row_matb = row_mata * row_mata;
col_mat_t col_matb = col_mata * col_mata;

assert((row_matb(0, 0) == col_matb(0, 0) && row_matb(0, 0) == 30));
assert((row_matb(0, 2) == col_matb(0, 2) && row_matb(0, 2) == 42));
assert((row_matb(1, 1) == col_matb(1, 1) && row_matb(1, 1) == 81));
assert((row_matb(2, 1) == col_matb(2, 1) && row_matb(2, 1) == 126));
assert((row_matb(2, 2) == col_matb(2, 2) && row_matb(2, 2) == 150));

row_mat_t row_mat { ROWS, COLS };
col_mat_t col_mat { ROWS, COLS };
std::size_t value { 0 };

value = 0;
for (long r = 0; r < row_mat.rows(); ++r)
for (long c = 0; c < row_mat.cols(); ++c)
row_mat(r, c) = value++;
Expand Down Expand Up @@ -184,8 +203,8 @@ int main(int, char *[]) {

assert(big_multi_mat(0, 0) == 5050);
assert(big_multi_mat(99, 99) == 505000);
assert(big_multi_mat(98, 2) == 499950);
assert(big_multi_mat(2, 5) == 15150);
assert(big_multi_mat(98, 2) == 15150);
assert(big_multi_mat(2, 5) == 30300);

//
// Test inverse
Expand Down

0 comments on commit bc7f381

Please sign in to comment.