Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix measure bottlenecks #337

Merged
merged 17 commits into from
Nov 20, 2023
29 changes: 24 additions & 5 deletions R/MeasureSurvRCLL.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,34 @@ MeasureSurvRCLL = R6::R6Class("MeasureSurvRCLL",
# Bypass distr6 construction if underlying distr represented by array
if (inherits(prediction$data$distr, "array")) {
surv = prediction$data$distr
if (length(dim(surv)) == 3) {
bblodfon marked this conversation as resolved.
Show resolved Hide resolved
# survival 3d array, extract median
surv = .ext_surv_mat(arr = surv, which.curve = 0.5)
}
times = as.numeric(colnames(surv))
pdf = distr6:::cdfpdf(1 - surv)
bblodfon marked this conversation as resolved.
Show resolved Hide resolved

if (any(!event)) {
out[!event] = diag(t(distr6:::C_Vec_WeightedDiscreteCdf(
cens_times, times, t(1 - surv), FALSE, FALSE)))
if (sum(!event) == 1) { # fix subsetting issue in case of 1 censored
bblodfon marked this conversation as resolved.
Show resolved Hide resolved
cdf = t(1 - surv)
} else {
cdf = t(1 - surv[!event, ])
}

out[!event] = diag(
bblodfon marked this conversation as resolved.
Show resolved Hide resolved
distr6:::C_Vec_WeightedDiscreteCdf(cens_times, times, cdf = cdf, FALSE, FALSE)
)
}
if (any(event)) {
out[event] = diag(t(distr6:::C_Vec_WeightedDiscretePdf(
event_times, times, t(pdf))))
pdf = distr6:::cdfpdf(1 - surv)
if (sum(event) == 1) { # fix subsetting issue in case of 1 event
pdf = t(pdf)
} else {
pdf = t(pdf[event, ])
}

out[event] = diag(
distr6:::C_Vec_WeightedDiscretePdf(event_times, times, pdf = pdf)
)
}
bblodfon marked this conversation as resolved.
Show resolved Hide resolved
} else {
distr = prediction$distr
Expand Down