Helle R people, here''s my slightly out of range question: i am in c code (dll call from R - passing a matrix as double * data, int * row and int * col). In C/C++, i''d like to handle this *double as a 2D matrix with (*row-1) rows and (*col - 1) columns. Something like double t [*row -1 ] [*col -1] doesn''t work (of course) but this is the idea - declaration of a 2D array with dimensions passed as arguments. Is the solution pure C/C++ or should i use R.h ... Any advice or solution. Merci d''avance, Cordialement, -- Nicolas Baurin Doctorant Institut de Chimie Organique et Analytique, UPRES-A 6005 Universit? d''Orl?ans, BP 6759 45067 ORLEANS Cedex 2, France Tel: (33+) 2 38 49 45 77 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 16-May-00 nicolas baurin wrote:> Helle R people, > > here''s my slightly out of range question: i am in c code (dll call from > R - passing a matrix as double * data, int * row and int * col). In > C/C++, i''d like to handle this *double as a 2D matrix with (*row-1) rows > and (*col - 1) columns. Something like double t [*row -1 ] [*col -1] > doesn''t work (of course) but this is the idea - declaration of a 2D > array with dimensions passed as arguments.I faced this problem myself writing routines for multivariate time series and came up with a solution which you will find in the C source for the "ts" package in files carray.c, carray.h. I have used a structure called "Array" to represent a multi-dimensional array of doubles using arrays of pointers. (and pointers to pointers...) A matrix would be created with the function Array make_matrix(double vec[], int nrow, int ncol); Then you would use the macro MATRIX(x) to cast the result to an array of pointers which behaves just like a two-dimensional array, e.g. MATRIX(x)[i][j] would access the (i,j)th element. There are some convenience functions for doing element-wise arithmetic, matrix multiplication and so on. I hope this helps. Martyn -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prof Brian Ripley
2000-May-16 13:16 UTC
[R] C code: how to handle *double as a matrix t[] []
> X-Priority: 3 (Normal) > Date: Tue, 16 May 2000 14:45:47 +0200 (CEST) > From: Martyn Plummer <plummer at iarc.fr> > To: nicolas baurin <nicolas.baurin at univ-orleans.fr> > Subject: RE: [R] C code: how to handle *double as a matrix t[] [] > Cc: "r-help at stat.math.ethz.ch" <r-help at stat.math.ethz.ch> > > On 16-May-00 nicolas baurin wrote: > > Helle R people, > > > > here''s my slightly out of range question: i am in c code (dll call from > > R - passing a matrix as double * data, int * row and int * col). In > > C/C++, i''d like to handle this *double as a 2D matrix with (*row-1) rows > > and (*col - 1) columns. Something like double t [*row -1 ] [*col -1] > > doesn''t work (of course) but this is the idea - declaration of a 2D > > array with dimensions passed as arguments. > > I faced this problem myself writing routines for multivariate time > series and came up with a solution which you will find in the C source for > the "ts" package in files carray.c, carray.h. I have used a structure called > "Array" to represent a multi-dimensional array of doubles using arrays > of pointers. (and pointers to pointers...) A matrix would be created with > the function > > Array make_matrix(double vec[], int nrow, int ncol); > > Then you would use the macro MATRIX(x) to cast the result to an > array of pointers which behaves just like a two-dimensional array, > e.g. MATRIX(x)[i][j] would access the (i,j)th element. There are > some convenience functions for doing element-wise arithmetic, > matrix multiplication and so on. >Another similar idea is to use the Numerical Recipes support functions as in e.g. package nnet (part of the VR bundle). -- 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 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
As soon as I sent my previous query on adding tables "below" one another into a larger table, the answer struck me: transpose the individual tables concatenate adjust the dimensions of the resulting table transpose Sorry to have bothered the mailing list. -- Art Salwin salwin at mitretek.org (202) 863-2985 (202) 863-2988 (fax) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Art Salwin <salwin at mitretek.org> writes:> As soon as I sent my previous query on adding tables > "below" one another into a larger table, the answer struck > me: > > transpose the individual tables > concatenate > adjust the dimensions of the resulting table > transpose > > Sorry to have bothered the mailing list.rbind() would be easier, though... -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /''_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._