Hi, I am about to write functions for multivariate kernel densitiy estimation with mixed categorical and continuous date (accoring to Jeff Racine and Qi Li), and the leave-one-out window esitmation needs a lot of computation. I am now optimizing the code performance and therefore fhe following questions: As R uses call-by-value for functions, is it computational expensive to pass large matrices in function arguments? (i.e. are they really copied and does this need much computing time?) Is it maybe better to work with locally visible variables and nested functions in the optimized code? I have already used Rprof (and I could speed up the code a lot by the information from Rprof), but it does not tell me about that. Thank you for your hints! Axel ________________________________________ Fraunhofer Institut fuer Arbeitswirtschaft und Organisation (IAO) Dipl. Inf. Axel Benz Nobelstr. 12 D-70569 Stuttgart Germany Tel. +49(0)7119702289 Fax. +49(0)7119702192 mail: mailto:axel.benz@iao.fhg.de www: http://www.vis.iao.fhg.de ________________________________________ [[alternative HTML version deleted]]
Axel - I believe that a function argument is not literally copied until the first time it is modified within the function. See email exchanges on this list from/to Ross Boylan within the month of September for a more authoritative answer to this question. (Do you know about the R-help archives at three sites listed on http://cran.R-project.org/search.html ?) - tom blackwell - u michigan medical school - ann arbor - On Fri, 26 Sep 2003, Axel Benz wrote:> I am about to write functions for multivariate kernel densitiy estimation > with mixed categorical and continuous date (accoring to Jeff Racine and Qi > Li), and the leave-one-out window esitmation needs a lot of computation. > I am now optimizing the code performance and therefore fhe following > questions: > > As R uses call-by-value for functions, is it computational expensive to pass > large matrices in function arguments? > > (i.e. are they really copied and does this need much computing time?) Is it > maybe better to work with locally visible variables and nested functions in > the optimized code? > > I have already used Rprof (and I could speed up the code a lot by the > information from Rprof), but it does not tell me about that. > > Thank you for your hints! > > Axel > ________________________________________ > Fraunhofer Institut fuer > Arbeitswirtschaft und Organisation (IAO) > Dipl. Inf. Axel Benz > Nobelstr. 12 > D-70569 Stuttgart > Germany > Tel. +49(0)7119702289 > Fax. +49(0)7119702192 > mail: mailto:axel.benz at iao.fhg.de > www: http://www.vis.iao.fhg.de > ________________________________________
On Fri, 26 Sep 2003, Axel Benz wrote:> Hi, > I am about to write functions for multivariate kernel densitiy estimation > with mixed categorical and continuous date (accoring to Jeff Racine and Qi > Li), and the leave-one-out window esitmation needs a lot of computation. > I am now optimizing the code performance and therefore fhe following > questions: > > As R uses call-by-value for functions, is it computational expensive to pass > large matrices in function arguments?No, as long as they are not modified. R doesn't make actual copies if it knows they aren't needed, it just creates a reference to the original object.> (i.e. are they really copied and does this need much computing time?) Is it > maybe better to work with locally visible variables and nested functions in > the optimized code?It probably won't make a detectable difference. Looking up a variable is microscopically quicker if it is local (eg passed as a parameter), but you need fairly extreme cases for this to be noticeable. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle