Skip to content

Commit

Permalink
Merge pull request #39 from eddelbuettel/master
Browse files Browse the repository at this point in the history
Update insert_rows() (and _cols()) to two-argument signatures
  • Loading branch information
aalfons authored Jan 18, 2023
2 parents 33de0a0 + a08ea6e commit 7e39a96
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/fastGrplars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ uvec fastGrplars(const mat& x, const vec& y, const uword& sMax,
}
// update correlations (adjustment for unequal group size is taken
// care of by update formula)
r.insert_rows(k, 1, false); // do not initialize new memory
r.insert_rows(k, 1); // do not initialize new memory
r(k) = (r(k-1) - gamma * a) / sigma;
corY.shed_row(whichMin);
corU.shed_row(whichMin);
Expand All @@ -265,7 +265,7 @@ uvec fastGrplars(const mat& x, const vec& y, const uword& sMax,
}
}
// update active set
active.insert_rows(k, 1, false); // do not initialize new memory
active.insert_rows(k, 1); // do not initialize new memory
active(k) = inactive(whichMin);
// update inactive set
inactive.shed_row(whichMin);
Expand Down
6 changes: 3 additions & 3 deletions src/fastLars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ uvec fastLars(const mat& x, const vec& y, const uword& sMax,
double minGammaMinus, minGammaPlus, gamma;
minGammaMinus = gammaMinus.min(whichMinus);
minGammaPlus = gammaPlus.min(whichPlus);
signs.insert_rows(k, 1, false); // do not initialize new memory
signs.insert_rows(k, 1); // do not initialize new memory
if(minGammaMinus < minGammaPlus) {
whichMin = whichMinus;
gamma = minGammaMinus;
Expand All @@ -182,13 +182,13 @@ uvec fastLars(const mat& x, const vec& y, const uword& sMax,
signs(k) = -1;
}
// update correlations
r.insert_rows(k, 1, false); // do not initialize new memory
r.insert_rows(k, 1); // do not initialize new memory
r(k) = r(k-1) - gamma * a;
corY.shed_row(whichMin);
corU.shed_row(whichMin);
corY = corY - gamma * corU;
// update active set
active.insert_rows(k, 1, false); // do not initialize new memory
active.insert_rows(k, 1); // do not initialize new memory
active(k) = inactive(whichMin);
// update inactive set
inactive.shed_row(whichMin);
Expand Down
14 changes: 7 additions & 7 deletions src/fastLasso.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ void fastLasso(const mat& x, const vec& y, const double& lambda,
// correct way
// insert row and column without initializing memory
// (set_size() and reshape() have strange behavior)
L.insert_rows(k, 1, false);
L.insert_cols(k, 1, false);
L.insert_rows(k, 1);
L.insert_cols(k, 1);
// fill new parts of the matrix
for(uword j = 0; j < k; j++) {
L(k, j) = l(j);
Expand All @@ -300,7 +300,7 @@ void fastLasso(const mat& x, const vec& y, const double& lambda,
// in case of singularity
if(rank == k) {
// singularity: drop variable for good
ignores.insert_rows(s, 1, false); // do not initialize new memory
ignores.insert_rows(s, 1); // do not initialize new memory
ignores(s) = newJ;
s++; // increase number of ignored variables
p--; // decrease number of variables
Expand All @@ -310,10 +310,10 @@ void fastLasso(const mat& x, const vec& y, const double& lambda,
}
} else {
// no singularity: add variable to active set
active.insert_rows(k, 1, false); // do not initialize new memory
active.insert_rows(k, 1); // do not initialize new memory
active(k) = newJ;
// keep track of sign of correlation for new active variable
signs.insert_rows(k, 1, false); // do not initialize new memory
signs.insert_rows(k, 1); // do not initialize new memory
signs(k) = sign(corY(newJ));
k++; // increase number of active variables
}
Expand Down Expand Up @@ -436,7 +436,7 @@ void fastLasso(const mat& x, const vec& y, const double& lambda,
L = symmatu(L);
// add dropped variables to inactive set and make sure
// coefficients are 0
inactive.insert_rows(m, drops.n_elem, false);
inactive.insert_rows(m, drops.n_elem);
for(uword j = 0; j < drops.n_elem; j++) {
uword newInactive = active(drops(j));
inactive(m + j) = newInactive;
Expand Down Expand Up @@ -529,7 +529,7 @@ SEXP R_fastLasso(SEXP R_x, SEXP R_y, SEXP R_lambda, SEXP R_useSubset,
useGram, false, intercept, coefficients, residuals, crit);
if(useIntercept) {
// prepend intercept
coefficients.insert_rows(0, 1, false);
coefficients.insert_rows(0, 1);
coefficients(0) = intercept;
}
return List::create(
Expand Down
6 changes: 3 additions & 3 deletions src/fastSparseLTS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ SEXP R_testLasso(SEXP R_x, SEXP R_y, SEXP R_lambda, SEXP R_initial,
vec coefficients = subset.coefficients;
if(useIntercept) {
// prepend intercept
coefficients.insert_rows(0, 1, false);
coefficients.insert_rows(0, 1);
coefficients(0) = subset.intercept;
}
return List::create(
Expand Down Expand Up @@ -196,7 +196,7 @@ SEXP R_testCStep(SEXP R_x, SEXP R_y, SEXP R_lambda, SEXP R_subset,
vec coefficients = subset.coefficients;
if(useIntercept) {
// prepend intercept
coefficients.insert_rows(0, 1, false);
coefficients.insert_rows(0, 1);
coefficients(0) = subset.intercept;
}
return List::create(
Expand Down Expand Up @@ -422,7 +422,7 @@ SEXP R_fastSparseLTS(SEXP R_x, SEXP R_y, SEXP R_lambda, SEXP R_initial,
vec coefficients = best.coefficients;
if(useIntercept) {
// prepend intercept
coefficients.insert_rows(0, 1, false);
coefficients.insert_rows(0, 1);
coefficients(0) = best.intercept;
}
return List::create(
Expand Down

0 comments on commit 7e39a96

Please sign in to comment.