[Rcpp-devel] Rcpp:wrap - any limitations for vector size?
Mathias Bader
mail at mathiasbader.de
Thu Aug 9 14:08:46 CEST 2012
Hello
I am working with Rcpp as part of my master thesis to speed up an MCMC
simulation. I happen to have a wired bug which I am trying to find for
some days now and I think I narrowed it down to the part of the code,
where C++ returns a list back to R.
I can output the list in C++ before returning it, everything looks fine
then. When trying to output the same data after receiving it in R, R
Studio crashes.
I am connecting R and C++ using the following code:
# define the C++ compiled function for the MCMC simulation
require('inline')
settings <- getPlugin("Rcpp")
settings$env$PKG_CXXFLAGS <- paste("-I", getwd(), sep="")
src_dppc <- paste(readLines("dppClustering.cpp"), collapse="\n")
header_includes <- paste(readLines("headerIncludes.h"), collapse="\n")
compiledClustering <- cxxfunction(signature(
R_data="numeric",
R_initial_point_assignment="numeric",
R_alpha="numeric",
R_mcmc_steps="integer",
R_sd_min="numeric",
R_next_cluster_index="integer",
R_cluster_index_mapping="numeric",
R_cluster_ids="numeric",
R_cluster_ids_silhouette_values="numeric",
R_performed_steps_count="integer",
R_likelihood_method="character"
), src_dppc, plugin="Rcpp", settings=settings,
includes=header_includes)
The call in R looks as follows:
# perform clustering
results <- compiledClustering(
R_data = data,
R_initial_point_assignment = d$final.clustering,
R_alpha = dppc.config.alpha,
R_mcmc_steps = steps.to.perform,
R_sd_min = dppc.config.sd.min,
R_next_cluster_index = d$next.cluster.index,
R_cluster_index_mapping = d$cluster.index.mapping,
R_cluster_ids = as.vector(t(d$cluster.ids)),
R_cluster_ids_silhouette_values = d$cluster.ids.silhouette.values,
R_performed_steps_count = d$performed.steps.count,
R_likelihood_method = d$method.to.use
)
If I try to output the returned list after that call using
"cat(results)", it will output the returned list till the third last
element. From that element it outputs only the name of the element, but
not the value and then it crashes before outputting the last two
elements. Always at that point.
In my C++ code I create the return value using the following code:
// create return object
Rcpp::List results = Rcpp::List::create(
Named("clusterAssignment") = wrap(r_cluster_assignment),
Named("debugOutput") = wrap(r_debug_output),
Named("clusterCountIncreases") = wrap(r_cluster_count_increases),
Named("clusterCountDecreases") = wrap(r_cluster_count_decreases),
Named("dataMovementPointIndices") =
wrap(r_data_movement_point_indices),
Named("dataMovementNewClusters") =
wrap(r_data_movement_new_clusters),
Named("clusterIndexMappingRev") =
wrap(r_cluster_index_mapping_rev),
Named("nextClusterIndex") =
wrap(r_next_cluster_index_return),
Named("clusterCounts") = wrap(r_cluster_counts),
Named("McmcClusterIds") = wrap(r_mcmc_cluster_ids),
Named("clusterIds") = wrap(r_cluster_ids),
Named("clusterIdsSilhouetteValues") =
wrap(r_cluster_ids_silhouette_values)
);
My question: Is there any restriction on the size of the vectors which
I hand from C++ to R? Because during the MCMC simulation the vectors
might become really big.
Thank you very much
Mathias
More information about the Rcpp-devel
mailing list