Navigation Menu

Skip to content

Commit

Permalink
Avoid overflow of int in the flattened array of 2D matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
ttadano committed Sep 28, 2018
1 parent 4a94e41 commit 95845b9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions alm/fitting.cpp
Expand Up @@ -427,7 +427,9 @@ void Fitting::fit_without_constraints(int N,
memory->allocate(S, LMIN);

// transpose matrix A
memory->allocate(amat_mod, M * N);
auto _M = static_cast<unsigned long>(M);
auto _N = static_cast<unsigned long>(N);
memory->allocate(amat_mod, _M * _N);
memory->allocate(fsum2, LMAX);

k = 0;
Expand Down Expand Up @@ -493,6 +495,10 @@ void Fitting::fit_with_constraints(int N,

std::cout << " Entering fitting routine: QRD with constraints" << std::endl;

auto _M = static_cast<unsigned long>(M);
auto _N = static_cast<unsigned long>(N);
auto _P = static_cast<unsigned long>(P);

memory->allocate(fsum2, M);

#ifdef _USE_EIGEN_DISABLED
Expand All @@ -517,7 +523,7 @@ void Fitting::fit_with_constraints(int N,

double *mat_tmp;

memory->allocate(mat_tmp, (M + P) * N);
memory->allocate(mat_tmp, (_M + _P) * _N);

k = 0;

Expand Down Expand Up @@ -560,8 +566,8 @@ void Fitting::fit_with_constraints(int N,
std::cout << " QR-Decomposition has started ...";

double *amat_mod, *cmat_mod;
memory->allocate(amat_mod, M * N);
memory->allocate(cmat_mod, P * N);
memory->allocate(amat_mod, _M * _N);
memory->allocate(cmat_mod, _P * _N);

// transpose matrix A and C
k = 0;
Expand Down

0 comments on commit 95845b9

Please sign in to comment.