From 8e57746d75a9e65436db6e8b589fc553c4a4989b Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Mon, 7 Mar 2016 15:39:42 -0500 Subject: be more defensive with the dimensions --- R/distrib.R | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/R/distrib.R b/R/distrib.R index c6dc609..eeb1796 100644 --- a/R/distrib.R +++ b/R/distrib.R @@ -281,7 +281,11 @@ lossdistC <- function(p, w, S, N, defaultflag=FALSE){ } lossdistCZ <- function(p, w, S, N, defaultflag=FALSE, rho, Z){ - #S is of size (length(p), length(Z)) + ##S is of size (length(p), length(Z)) + stopifnot(length(rho)==length(p), + length(rho)==length(w), + nrow(S)==length(p), + ncol(S)==length(Z)) .C("lossdistrib_Z", as.double(p), as.integer(length(p)), as.double(w), as.double(S), as.integer(N), as.logical(defaultflag), as.double(rho), as.double(Z), as.integer(length(Z)), @@ -553,11 +557,12 @@ BClossdist <- function(defaultprob, issuerweights, recov, rho, Z, w, BClossdistC <- function(defaultprob, issuerweights, recov, rho, Z, w, N=length(issuerweights)+1, defaultflag=FALSE){ - stopifnot(length(Z)==length(w), - nrow(defaultprob)==length(issuerweights)) if(is.null(dim(defaultprob))){ dim(defaultprob) <- c(length(defaultprob),1) } + stopifnot(length(Z)==length(w), + nrow(defaultprob)==length(issuerweights), + nrow(defaultprob)==length(recov)) L <- matrix(0, N, ncol(defaultprob)) R <- matrix(0, N, ncol(defaultprob)) rho <- rep(rho, length(issuerweights)) -- cgit v1.2.3-70-g09d2