Skip to content

Commit

Permalink
Fix error/warning forming Tsparse mat w/ Matrix {<,>=}v1.3-0
Browse files Browse the repository at this point in the history
Context:

In the `Matrix` package v1.3-0, `sparseMatrix` was
[updated](https://cran.r-project.org/web/packages/Matrix/news.html) with a new
argument `repr` and deprecation of `giveCsparse=FALSE`.  Commit
9f8fa00 avoided deprecation warnings when using
`Matrix` package versions >= 1.3-0, but generated errors with versions < 1.3-0.

Action:

Avoid both errors for earlier versions and deprecation warnings for later
versions by constructing Tsparse matrices by directly constructing an
appropriate S4 object.
  • Loading branch information
lcbrooks committed Jul 26, 2021
1 parent 9f8fa00 commit 0174dac
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions R-package/quantgen/R/quantile_ensemble.R
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,16 @@ quantile_ensemble_flex = function(qarr, y, tau, weights, tau_groups,
noncross=TRUE, q0=NULL,
lp_solver=c("glpk","gurobi"), time_limit=NULL,
params=list(), verbose=FALSE) {

# Check inputs

if (anyDuplicated(tau) != 0L || is.unsorted(tau) || any(tau < 0 | tau > 1)) {
stop ("Entries of `tau` must be distinct, sorted in increasing order, >=0, and <=1")
}

if (intercept && noncross) {
stop ("using multiple tau groups with intercept=TRUE and noncross=TRUE is currently unsupported")
## (Matrix formation needs to be debugged or verified for this case.)
# (Matrix formation needs to be debugged or verified for this case.)
}

# Set up some basic objects that we will need
Expand Down Expand Up @@ -430,12 +437,11 @@ quantile_ensemble_flex = function(qarr, y, tau, weights, tau_groups,
}

# Build model$A from parts:
model$A = sparseMatrix(
i = do.call(c, A_i_parts[seq_len(A_part_ind)]),
j = do.call(c, A_j_parts[seq_len(A_part_ind)]),
x = do.call(c, A_x_parts[seq_len(A_part_ind)]),
dims = c(A_nrow, A_ncol),
repr = "T" # faster than "C"; solvers might expect Tsparse form
model$A = new("dgTMatrix", # `d`ouble-type entries, `g`eneral structure, `T`sparse (ijx format)
i = as.integer(do.call(c, A_i_parts[seq_len(A_part_ind)])) - 1L,
j = as.integer(do.call(c, A_j_parts[seq_len(A_part_ind)])) - 1L,
x = as.numeric(do.call(c, A_x_parts[seq_len(A_part_ind)])),
Dim = as.integer(c(A_nrow, A_ncol))
)

# Call Gurobi's LP solver, store results
Expand Down

0 comments on commit 0174dac

Please sign in to comment.