Skip to content

Commit 6f66b67

Browse files
committed
Minor enhancements
1 parent f985c91 commit 6f66b67

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

dynadjust/include/math/dnamatrix_contiguous.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <include/math/dnamatrix_contiguous.hpp>
2323
#include <iomanip>
2424
#include <sstream>
25+
#include <cmath>
26+
#include <limits>
2527
#include <include/ide/trace.hpp>
2628

2729
namespace dynadjust {
@@ -411,17 +413,17 @@ void matrix_2d::buy(const UINT32& rows, const UINT32& columns, double** mem_spac
411413

412414
// an exception will be thrown by out_of_memory_handler
413415
// if memory cannot be allocated
414-
(*mem_space) = new double[static_cast<std::size_t>(rows) * static_cast<std::size_t>(columns)];
416+
std::size_t total_size = static_cast<std::size_t>(rows) * static_cast<std::size_t>(columns);
417+
(*mem_space) = new double[total_size];
415418

416419
if ((*mem_space) == nullptr) {
417420
std::stringstream ss;
418421
ss << "Insufficient memory for a " << rows << " x " << columns << " matrix.";
419422
throw NetMemoryException(ss.str());
420423
}
421-
422-
// an exception will be thrown by out_of_memory_handler
423-
// if memory cannot be allocated
424-
memset(*mem_space, 0, byteSize<double>(static_cast<std::size_t>(rows) * columns)); // initialise to zero
424+
425+
// Initialize memory to zero to prevent uninitialized values
426+
std::memset((*mem_space), 0, total_size * sizeof(double));
425427
}
426428

427429
void matrix_2d::deallocate() {
@@ -661,7 +663,7 @@ matrix_2d matrix_2d::cholesky_inverse(bool LOWER_IS_CLEARED /*=false*/) {
661663
return *this;
662664

663665
if (_rows != _cols)
664-
throw std::runtime_error("choleskyinverse_mkl: Matrix is not square.");
666+
throw std::runtime_error("cholesky_inverse(): Matrix is not square.");
665667

666668
char uplo(LOWER_TRIANGLE);
667669

0 commit comments

Comments
 (0)