This is the mail archive of the
gsl-discuss@sources.redhat.com
mailing list for the GSL project.
Re: modifying matrix allocation functions for use with R
- To: Faheem Mitha <faheem at email dot unc dot edu>
- Subject: Re: modifying matrix allocation functions for use with R
- From: Brian Gough <bjg at network-theory dot co dot uk>
- Date: Sat, 6 Oct 2001 12:46:37 +0100 (BST)
- Cc: <gsl-discuss at sources dot redhat dot com>
- References: <Pine.LNX.4.33.0110051535210.7289-100000@Chrestomanci>
Faheem Mitha writes:
> One option I was considering was rewriting gsl_matrix_alloc (leaving out
> the error checking) in terms of R_alloc. However, I can't find the code
> for FUNCTION(gsl_block, alloc) (I assume this means gsl_block_alloc)
> used in the code for gsl_matrix_alloc. gsl_matrix_alloc itself seems to be
> in matrix/init_source.c. Can someone point me to the code for
> gsl_block_alloc, or suggest any other options?
Based on my reading of the R documentation, I would suggest using the
standard gsl_matrix_alloc in this case, and handling any errors that
occur with the R libray function error().
e.g.,
m = gsl_matrix_alloc(...)
if (m == 0) { error ("could not allocate matrix"); } ;
....
gsl_matrix_free(m);
This would only add a few lines to your code, and will work with the
standard GSL library so your extension will be more portable.
If you want to return an R object containing a gsl_matrix which can be
garbage collected then you could use a C++ wrapper, as the C++
interface in R allows the use of separate constructors and
destructors.
regards
Brian Gough