Skip to content

Commit

Permalink
[Numerics] Fix invalid memory access in DenseMatrix increment
Browse files Browse the repository at this point in the history
This method now works for rectangular matrices
  • Loading branch information
speth committed Apr 14, 2016
1 parent bd24aeb commit 7af1b4b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/numerics/DenseMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void multiply(const DenseMatrix& A, const double* const b, double* const prod)
void increment(const DenseMatrix& A, const double* b, double* prod)
{
ct_dgemv(ctlapack::ColMajor, ctlapack::NoTranspose,
static_cast<int>(A.nRows()), static_cast<int>(A.nRows()), 1.0,
static_cast<int>(A.nRows()), static_cast<int>(A.nColumns()), 1.0,
A.ptrColumn(0), static_cast<int>(A.nRows()), b, 1, 1.0, prod, 1);
}

Expand Down
21 changes: 21 additions & 0 deletions test/general/test_matrices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,24 @@ TEST_F(DenseMatrixTest, matrix_times_matrix)
A2.mult(A3, c);
EXPECT_DOUBLE_EQ(4014, special_sum(c));
}

TEST_F(DenseMatrixTest, increment)
{
vector_fp c(b1.size(), 3.0);
increment(A1, x4.data(), c.data());
for (size_t i = 0; i < 4; i++) {
EXPECT_DOUBLE_EQ(3.0 + b1[i], c[i]);
}

c.assign(b2.size(), 3.0);
increment(A2, x3.data(), c.data());
for (size_t i = 0; i < 4; i++) {
EXPECT_DOUBLE_EQ(3.0 + b2[i], c[i]);
}

c.assign(b3.size(), 3.0);
increment(A3, x4.data(), c.data());
for (size_t i = 0; i < 3; i++) {
EXPECT_DOUBLE_EQ(3.0 + b3[i], c[i]);
}
}

0 comments on commit 7af1b4b

Please sign in to comment.