Re: [Rd] LAPACK Headers

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri, 15 Jun 2007 16:29:01 +0100 (BST)

On Fri, 15 Jun 2007, statmobile_at_gmail.com wrote:

> Prof. Ripley,
>
> I had a feeling I was going a little too deep into the R source code
> in order to pull out these functions. I particularly like these La_*
> functions calling the LAPACK routines, because they have so much of
> the error checking already built-in. I can just copy the code over,
> and hopefully it will pick up everything in my package, but I do have
> two questions.
>
> 1. I seem to vaguely recall that the R-ext documentation mentions
> that routines such as this could possibly change. So if someone
> wants to use any of the LAPACK or BLAS routines in their source
> code, they should really only refer to the programs in
> R_ext/Lapack.h?

Yes.

> 2. I think the LAPACK utilities are key in R, and help new
> researchers avoid having to use proprietary code such as Numerical
> Recipes when doing their research. Is there a reason why code
> such as the La_* wrapper functions are not ``public''? I really
> think they're quite useful.

They are private, and the R developers must be free to change R internals as they need to. If we made public everything that anyone wanted to use, we would never be able to improve R (and we would spend all our time answering questions about private structures).

Also, having a large set of entry points that are accessible is a performance hit for every R session. We've have about half hidden on platforms which support this, and we are likely to hide more (including these).

>
> Thanks,
> Brian
>
>
> On Fri, Jun 15, 2007 at 06:45:09AM +0100, Prof Brian Ripley wrote:
>> He wants "La_dgesv", which is not an LAPACK entry point at all, but a
>> private part of R. The header it is in is private and not installed.
>>
>> There is no guarantee that it will remain visible to an R package, and the
>> only safe thing to do is to copy the code.
>>
>> On Thu, 14 Jun 2007, statmobile_at_gmail.com wrote:
>>
>>> On Thu, Jun 14, 2007 at 11:27:44PM +0100, Hin-Tak Leung wrote:
>>>> Try this? (this is on 2.5.0, I don't use 2.4.x anymore)
>>>>
>>>> #include <R_ext/Lapack.h>
>>>>
>>>
>>> I tried this, but I still get the warning of implicit declaration of
>>> function. It does compile though.
>>>
>>>> Have you actually tried grep dgesv $R_HOME/include/* $R_HOME/include/*/*
>>>> to see which file to include for dgesv ??
>>>
>>> Well, when I grep the R source files, I get:
>>>
>>> $ find . -name "*" -print | xargs grep -i 'La_dgesv'
>>> ./src/main/basedecl.h:SEXP La_dgesv(SEXP, SEXP, SEXP);
>>> ./src/main/lapack.c:SEXP La_dgesv(SEXP A, SEXP B, SEXP tol)
>>> ./src/main/lapack.c:SEXP La_dgesv(SEXP A, SEXP B, SEXP tol)
>>> ./src/main/registration.c: CALLDEF(La_dgesv, 3),
>>> ./src/library/base/R/solve.R: .Call("La_dgesv", a, b, tol, PACKAGE
>>> = "base")
>>> ./src/library/base/R/solve.R: drop(.Call("La_dgesv", a,
>>> as.matrix(b), tol, PACKAGE = "base")))
>>> ./src/modules/lapack/Lapack.c:static SEXP modLa_dgesv(SEXP A, SEXP
>>> Bin, SEXP tolin)
>>> ./src/modules/lapack/Lapack.c: tmp->dgesv = modLa_dgesv;
>>> ./src/include/Rmodules/Rlapack.h:typedef SEXP (*Rf_La_dgesv)(SEXP A,
>>> SEXP B, SEXP tol);
>>> ./src/include/Rmodules/Rlapack.h: Rf_La_dgesv dgesv;
>>>
>>> So it looks like La_dgesv is declared in basedecl.h, but I don't see
>>> this file anywhere else on my machine. Maybe I shouldn't be using
>>> this function in my package?
>>>
>>>
>>>
>>>>
>>>> HTL
>>>>
>>>> statmobile_at_gmail.com wrote:
>>>>> Hey Everyone,
>>>>>
>>>>> I'm running R 2.4.0 on Debian etch 4.0, and I'm trying to call some
>>>>> LAPACK functions from the C code in my package. Actually, to be
>>>>> honest I'm not really having trouble using commands such as La_dgesv
>>>>> from within my C code, but I do get warning when compiling the package
>>>>> saying:
>>>>>
>>>>> ***.c: In function '***':
>>>>> ***.c:37: warning: implicit declaration of function 'La_dgesv'
>>>>> ***.c:37: warning: assignment makes pointer from integer without
>>>>> a cast
>>>>>
>>>>> I tried using:
>>>>>
>>>>> #include <Rmodules/Rlapack.h>
>>>>>
>>>>> but it won't compile the package at all with that included,
>>>>> complaining that
>>>>>
>>>>> ***.h:5:30: error: Rmodules/Rlapack.h: No such file or directory
>>>>>
>>>>> Can someone explain to me how I should include the headers to this
>>>>> AWESOME wrapper code to the LAPACK libraries? Am I not following the
>>>>> proper protocol by using these La_* commands in my package source
>>>>> code?
>>>>>
>>>>> Note, I also have the following in Makevars
>>>>>
>>>>> PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
>>>>>
>>>>> TIA!
>>>>>
>>>>> I initially posted this question on the general list, but I didn't get
>>>>> any responses.
>>>>>
>>>>> ______________________________________________
>>>>> R-devel_at_r-project.org mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>>
>>>
>>>
>>
>> --
>> Brian D. Ripley, ripley_at_stats.ox.ac.uk
>> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
>> University of Oxford, Tel: +44 1865 272861 (self)
>> 1 South Parks Road, +44 1865 272866 (PA)
>> Oxford OX1 3TG, UK Fax: +44 1865 272595
>
>

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Fri 15 Jun 2007 - 16:06:17 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 15 Jun 2007 - 18:34:53 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.