[Rd] qr.qy and qr.qty give an error message when y is integer and LAPACK=TRUE
With this example set.seed(123) A <- matrix(runif(40), nrow = 8) y <- 1:nrow(A) A.laqr <- qr(A, LAPACK=TRUE) both qr.qy(A.laqr,y) and qr.qty(A.laqr,y) give the respective error messages Error in qr.qy(A.laqr, y) : 'b' must be a numeric matrix Error in qr.qty(A.laqr, y) : 'b' must be a numeric matrix However when Lapack is not used as in A.liqr <- qr(A, LAPACK=FALSE) qr.qy(A.liqr,y) and qr.qty(A.liqr,y) don't issue error messages. Looking at the source of qr.qy and qr.qty in https://svn.r-project.org/R/trunk/src/library/base/R/qr.R I see that in the case of Lapack the storage.mode of y is not set to "double" (in contrast to when Linpack QR has been used). I assume that the error issued when LAPACK=TRUE is not intended. Berend Suggested code change in qr.qy Replace if(!is.null(a) && is.logical(a) && a) return(.Call("qr_qy_real", qr, as.matrix(y), 0, PACKAGE = "base")) with if(!is.null(a) && is.logical(a) && a) { storage.mode(y) <- "double" return(.Call("qr_qy_real", qr, as.matrix(y), 0, PACKAGE = "base")) } and a similar change in qr.qty __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] qr.qy and qr.qty give an error message when y is integer and LAPACK=TRUE
> Berend Hasselman > on Mon, 3 Dec 2012 15:25:21 +0100 writes: > With this example > set.seed(123) A <- matrix(runif(40), nrow = 8) y <- > 1:nrow(A) > A.laqr <- qr(A, LAPACK=TRUE) > both qr.qy(A.laqr,y) and qr.qty(A.laqr,y) give the > respective error messages > Error in qr.qy(A.laqr, y) : 'b' must be a numeric matrix > Error in qr.qty(A.laqr, y) : 'b' must be a numeric matrix > However when Lapack is not used as in > A.liqr <- qr(A, LAPACK=FALSE) > qr.qy(A.liqr,y) and qr.qty(A.liqr,y) don't issue error > messages. You are right... if you look at R 2.15.2 (or even it's patched version). > Looking at the source of qr.qy and qr.qty in > https://svn.r-project.org/R/trunk/src/library/base/R/qr.R Hmm, no: If you really looked at that code (during the last several weeks), you would have noted that the code has *changed* from what you give below... and the current R development version uses .Internal(.) instead of .Call() and the C code behind the .Internal() nicely deals with integer 'y' as well. In short, this is already fixed in R, since ~ September, but it won't probably be fixed in "R 2.15.2 patched" ... Thank you for the report, anyway! Martin > I see that in the case of Lapack the storage.mode of y is > not set to "double" (in contrast to when Linpack QR has > been used). > I assume that the error issued when LAPACK=TRUE is not > intended. > Berend > Suggested code change in qr.qy Replace > if(!is.null(a) && is.logical(a) && a) > return(.Call("qr_qy_real", qr, as.matrix(y), 0, PACKAGE = > "base")) > with > if(!is.null(a) && is.logical(a) && a) { > storage.mode(y) <- "double" return(.Call("qr_qy_real", qr, > as.matrix(y), 0, PACKAGE = "base")) } > and a similar change in qr.qty > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] qr.qy and qr.qty give an error message when y is integer and LAPACK=TRUE
On 03-12-2012, at 16:17, Martin Maechler wrote: >> Berend Hasselman >>on Mon, 3 Dec 2012 15:25:21 +0100 writes: > >> With this example > >> set.seed(123) A <- matrix(runif(40), nrow = 8) y <- >> 1:nrow(A) > >> A.laqr <- qr(A, LAPACK=TRUE) > >> both qr.qy(A.laqr,y) and qr.qty(A.laqr,y) give the >> respective error messages > >> Error in qr.qy(A.laqr, y) : 'b' must be a numeric matrix >> Error in qr.qty(A.laqr, y) : 'b' must be a numeric matrix > >> However when Lapack is not used as in > >> A.liqr <- qr(A, LAPACK=FALSE) > >> qr.qy(A.liqr,y) and qr.qty(A.liqr,y) don't issue error >> messages. > > You are right... if you look at R 2.15.2 (or even it's patched > version). > Which I did. And copied from R 2.15.2. >> Looking at the source of qr.qy and qr.qty in >> https://svn.r-project.org/R/trunk/src/library/base/R/qr.R > > Hmm, no: If you really looked at that code (during the last several weeks), > you would have noted that the code has *changed* from what you > give below... > > and the current R development version uses > .Internal(.) instead of .Call() and the C code behind the > .Internal() nicely deals with integer 'y' as well. > I did look at that code but did not drill down. Stupid. > In short, this is already fixed in R, since ~ September, > but it won't probably be fixed in "R 2.15.2 patched" ... > Apologies for the noise. Berend __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Compilation failure on Solaris: any advice?
Dear all, The current version of my RNiftyReg package is failing to compile on CRAN's Solaris testbed, but I don't have access to a Solaris system to debug on, and Googling the error hasn't been very helpful. The error is CC -library=stlport4 -I/home/ripley/R/cc/include -DNDEBUG -DNDEBUG -DRNIFTYREG -I/usr/local/include-KPIC -O -xlibmil -xtarget=native -nofstore -c niftyreg.cpp -o niftyreg.o "_reg_f3d_sym.cpp", line 25: Error: reg_f3d may not have a type qualifier. "niftyreg.cpp", line 527: Where: While instantiating "reg_f3d_sym::reg_f3d_sym(int, int)". "niftyreg.cpp", line 527: Where: Instantiated from non-template code. "_reg_f3d_sym.cpp", line 26: Error: reg_f3d cannot be initialized in a constructor. "niftyreg.cpp", line 527: Where: While instantiating "reg_f3d_sym::reg_f3d_sym(int, int)". "niftyreg.cpp", line 527: Where: Instantiated from non-template code. "_reg_f3d_sym.cpp", line 26: Error: Could not find reg_f3d::reg_f3d() to initialize base class. "niftyreg.cpp", line 527: Where: While instantiating "reg_f3d_sym::reg_f3d_sym(int, int)". "niftyreg.cpp", line 527: Where: Instantiated from non-template code. 3 Error(s) detected. *** Error code 2 make: Fatal error: Command failed for target `niftyreg.o' (Full log at [1].) The relevant part of the source is a C++ class constructor, part of the library that my package interfaces to: template reg_f3d_sym::reg_f3d_sym(int refTimePoint,int floTimePoint) :reg_f3d::reg_f3d(refTimePoint,floTimePoint) { this->executableName=(char *)"NiftyReg F3D SYM"; this->backwardControlPointGrid=NULL; this->backwardWarped=NULL; this->backwardWarpedGradientImage=NULL; this->backwardDeformationFieldImage=NULL; this->backwardVoxelBasedMeasureGradientImage=NULL; this->backwardNodeBasedGradientImage=NULL; this->backwardBestControlPointPosition=NULL; this->backwardConjugateG=NULL; this->backwardConjugateH=NULL; this->backwardProbaJointHistogram=NULL; this->backwardLogJointHistogram=NULL; this->floatingMaskImage=NULL; this->currentFloatingMask=NULL; this->floatingMaskPyramid=NULL; this->backwardActiveVoxelNumber=NULL; this->inverseConsistencyWeight=0.1; #ifndef NDEBUG printf("[NiftyReg DEBUG] reg_f3d_sym constructor called\n"); #endif } The error does not occur on any Windows, Linux or OS X system which I have access to, so this would seem to be an issue relating to the Solaris compiler toolchain in particular. Can anyone shed any light on it, please? Thanks in advance, Jon -- [1] http://www.r-project.org/nosvn/R.check/r-patched-solaris-x86/RNiftyReg-00install.html [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Documentation on making R code faster?
Hello: Is there a standard reference on how to improve the speed of R code? A recent R-help post asked about "using multicores in R" (see my reply below). It seems to me that there should be a comprehensive answer somewhere, but I couldn't find one. It looks like there might be an opportunity for something on this order to be published, e.g., in The R Journal and / or in some other standard R documentation. I hesitate to mention this, because I don't feel qualified to write such myself. However, I think something like this appropriately placed could attract a reasonable audience. Thanks, Spencer Original Message Subject:Re: [R] Using multicores in R Date: Mon, 03 Dec 2012 11:02:56 -0800 From: Spencer Graves CC: r-h...@r-project.org 1. Have you looked at CRAN Task View: High-Performance and Parallel Computing with R (http://cran.r-project.org/web/views/HighPerformanceComputing.html)? 2. Have you tried the "compiler" package? If I understand correctly, R is a two-stage interpreter, first translating what we know as R into byte code, which is then interpreted by a byte code interpreter. If my memory is correct, this approach can cut the compute time by a factor of 100. 3. Have you reviewed the section on "Profiling R code for speed" in the "Writing R Extensions" manual that becomes available after help.start()? The profiling tools discussed there help identify the portion of more complex code that takes the most time. The standard advice then is to experiment with writing the most time consuming portion several different ways. I've seen many examples where writing what appears to be the same thing in R several different ways identifies one that is easily 10 and maybe 100 or 1000 times faster than the slowest alternative tried. 4. Have you tried using the "sos" package to search for other functions and packages in R that may already have good code doing some of the things you want to do? The "findFn" function in "sos" searches the "functions" subset of the "RSiteSearch" database and returns the result sorted by package. There are also a "union" and "writeFindFn2xls" functions to make it easy to manipulate and evaluate the results, described in a vignette. It's the best literature search I know for anything statistical: If I don't find it there, it's OK to look someplace else. [Caveat: I'm the lead author of "sos", so I'm biased.] Best Wishes, Spencer On 12/3/2012 6:24 AM, Steve Lianoglou wrote: > And also: > > On Monday, December 3, 2012, Uwe Ligges wrote: > >> >> On 03.12.2012 11:14, moriah wrote: >> >>> Hi, >>> >>> I have an R script which is time consuming because it has two nested loops >>> in it of at least 5000 iterations each, I have tried to use the multicore >>> package but id doesn't seem to improve the elapsed time of the script(a >>> shorter script for example) and I can't use the mcapply because of >>> technical >>> reasons. >>> >> Errr, but otherwise multicore does not have an effect ... >> >> See package "parallel" that offers various functions for parallel >> computations. We cannot help much more if you do not tell us what the >> technical reasons are why mcapply() does not work. > > If the work you are doing within each iteration of the loop is trivial, you > will likely even see a decrease in performance if you try to parallelize it. > > Without more info from you regarding your problem, there's little we can do > to help, tho. > > -Steve > > > -- Spencer Graves, PE, PhD President and Chief Technology Officer Structure Inspection and Monitoring, Inc. 751 Emerson Ct. San José, CA 95126 ph: 408-655-4567 web: www.structuremonitoring.com -- Spencer Graves, PE, PhD President and Chief Technology Officer Structure Inspection and Monitoring, Inc. 751 Emerson Ct. San José, CA 95126 ph: 408-655-4567 web: www.structuremonitoring.com __ r-h...@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel