[Rcpp-devel] Fwd: How can I avoid calls to coerceToReal
Dirk Eddelbuettel
edd at debian.org
Tue Apr 30 17:43:17 CEST 2013
On 30 April 2013 at 11:19, Pratibha Rana wrote:
|
|
| Hi,
|
| MY application is performing really slow due to unnecessary calls to
| coerceToReal from this line NumericVector ocol = df[j]. Here is a sample
| of what I am doing. Is there a way to avoid the unnecessary overhead?
| Please note that the data in df is float data.
|
|
| void writeDataToPartitionWriter(DataFrame df, Writer
| &res_writer)
| {
|
| NumericVector ocol = df[j];
| if(ocol[i] ==NA_REAL)
| res_writer.setFloat(j, vfloat_null);
| else
| {
| vfloat floatout = static_cast<vfloat>(ocol[i]);
| res_writer.setFloat(j, floatout);
| }
|
| }
Hard to really tell at this point but a few things come to mind:
a) if you know your data is float or double, store it as float or
double.
b) R only has numeric, so if you want to save a few bytes, and save a
conversion, just use std::vector<float> from your data access to you
(internal?) Writer class.
Rcpp does a few things for your convenience, if your profiling reveals them
to be costly just try to do somehthing else...
Year ago, I wrote an (internal at my then-workplace) data accessor to a
(high-performance) column-data store from one of your main competitors. I
just kept everything in STL types til I returned the result home to R as a
Matrix, but I also simplified my case by assuming double for everything...
Dirk
| Thanks
| Pratibha
|
|
|
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list