[Distr-commits] r1273 - in branches/distr-2.8/pkg/distr: R inst

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Aug 11 16:33:45 CEST 2018


Author: ruckdeschel
Date: 2018-08-11 16:33:45 +0200 (Sat, 11 Aug 2018)
New Revision: 1273

Modified:
   branches/distr-2.8/pkg/distr/R/solve.R
   branches/distr-2.8/pkg/distr/inst/NEWS
Log:
[distr] branch 2.8.0
+ in distr::solve only try base::solve if arg "a" has no dim or if it has then 
  if nrow(a)==nrow(b); otherwise directly use MASS::ginv


Modified: branches/distr-2.8/pkg/distr/R/solve.R
===================================================================
--- branches/distr-2.8/pkg/distr/R/solve.R	2018-08-11 13:41:43 UTC (rev 1272)
+++ branches/distr-2.8/pkg/distr/R/solve.R	2018-08-11 14:33:45 UTC (rev 1273)
@@ -1,21 +1,26 @@
 setMethod("solve", signature(a = "ANY", b = "ANY"), function(a,b, 
              generalized = getdistrOption("use.generalized.inverse.by.default"),
-          tol = .Machine$double.eps, ...) {
-                 if(!generalized) return(base::solve(a,b, tol = tol, ...))
-                 else if(is(try({
-                            ab <- base::solve(a,b, tol = tol, ...)
-                            if(missing(b))
-                                 dimnames(ab) <-  rev(dimnames(a))
-                            else names(ab) <-  colnames(a)
-                            return(ab)
-                            }, silent = TRUE), "try-error")){
-             if (!missing(b))
-                if(!(length(b)==nrow(a))) stop("non-conformable arguments")
-             a.m <- MASS::ginv(a)
-             dimnames(a.m) <- rev(dimnames(a))             
-             if (missing(b)) return(a.m) 
-             else return(a.m %*% b)
-             }})
+             tol = .Machine$double.eps, ...) {
+          if(!generalized|is.null(dim(a))) return(base::solve(a,b, tol = tol, ...))
+          else if(nrow(a)==ncol(a)){
+             abtry <- try({
+                 ab <- base::solve(a,b, tol = tol, ...)
+                 if(missing(b)){
+                    dimnames(ab) <-  rev(dimnames(a))
+                 }else{
+                    names(ab) <-  colnames(a)
+                 }
+                 return(ab)
+             }, silent = TRUE)
+             if(!is(abtry, "try-error")) return(abtry)
+          }
+          if (!missing(b))
+              if(!(length(b)==nrow(a))) stop("non-conformable arguments")
+          a.m <- MASS::ginv(a)
+          dimnames(a.m) <- rev(dimnames(a))
+          if (missing(b)) return(a.m)
+              else return(a.m %*% b)
+          })
 
 setMethod("solve", signature(a = "PosSemDefSymmMatrix", b = "ANY"), 
            function(a,b, 

Modified: branches/distr-2.8/pkg/distr/inst/NEWS
===================================================================
--- branches/distr-2.8/pkg/distr/inst/NEWS	2018-08-11 13:41:43 UTC (rev 1272)
+++ branches/distr-2.8/pkg/distr/inst/NEWS	2018-08-11 14:33:45 UTC (rev 1273)
@@ -28,6 +28,8 @@
   the upper bound is finite)
 + changed definition of q(DExp(..)) in initialize method in AllInitialize.R 
   from ifelse expressions to index operations  to avoid warnings 
++ in distr::solve only try base::solve if arg "a" has no dim or if it has then 
+  if nrow(a)==nrow(b); otherwise directly use MASS::ginv
 
 bug fixes
 + fixed a (newly introduced) bug in exp() for DiscreteDistribution -- forgot to return obj ...



More information about the Distr-commits mailing list