|
22 | 22 | #include <include/math/dnamatrix_contiguous.hpp>
|
23 | 23 | #include <iomanip>
|
24 | 24 | #include <sstream>
|
| 25 | +#include <cmath> |
| 26 | +#include <limits> |
25 | 27 | #include <include/ide/trace.hpp>
|
26 | 28 |
|
27 | 29 | namespace dynadjust {
|
@@ -411,17 +413,17 @@ void matrix_2d::buy(const UINT32& rows, const UINT32& columns, double** mem_spac
|
411 | 413 |
|
412 | 414 | // an exception will be thrown by out_of_memory_handler
|
413 | 415 | // 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]; |
415 | 418 |
|
416 | 419 | if ((*mem_space) == nullptr) {
|
417 | 420 | std::stringstream ss;
|
418 | 421 | ss << "Insufficient memory for a " << rows << " x " << columns << " matrix.";
|
419 | 422 | throw NetMemoryException(ss.str());
|
420 | 423 | }
|
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)); |
425 | 427 | }
|
426 | 428 |
|
427 | 429 | void matrix_2d::deallocate() {
|
@@ -661,7 +663,7 @@ matrix_2d matrix_2d::cholesky_inverse(bool LOWER_IS_CLEARED /*=false*/) {
|
661 | 663 | return *this;
|
662 | 664 |
|
663 | 665 | 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."); |
665 | 667 |
|
666 | 668 | char uplo(LOWER_TRIANGLE);
|
667 | 669 |
|
|
0 commit comments