[Rcpp-devel] Compile Error with Rcpp sugar all

Dirk Eddelbuettel edd at debian.org
Wed May 15 12:55:26 CEST 2013


On 15 May 2013 at 08:19, Benjamin Ward (ENV) wrote:
| Hi all,
| 
| I'm having problem with some code I hope you can help illuminate:
| 
| I've written some code originally to speed up and R function, but now really
| for my own education:
| 
| It's supposed to remove all columns of a matrix containing identical values ( a
| big one!):
| 
| #include <Rcpp.h>
| #include <vector>
| 
| using namespace Rcpp;
| 
| // [[Rcpp::export]]
| CharacterMatrix reduce_sequences(CharacterMatrix completeDNA)
| {
|   std::vector<int> informativeSites;          // Start vector to record
| informative sites I.e columns which are not all identical…
|   for(int i = 0; i < completeDNA.ncol(); i++)      // For each column of the
| matrix…
|   {
|     CharacterVector bpsite(completeDNA.nrow());     //Make a vector to contain
| the column.
|     for(int n = 0; n < completeDNA.nrow(); n++)
|     {
|       bpsite[n] = completeDNA(n,i);  // Fill in the vector with the matrix
| column.
|     }
|     if(any(bpsite != bpsite[0])) informativeSites.push_back(i);     //If values
| are not all identical, push the column index onto the vector.
|   }
|   
|   CharacterMatrix cutDNA(3, informativeSites.size());     //Make new matrix to
| contain only all the columns which are not identical.
|   for(int i = 0; i < informativeSites.size(); i++)
|   {
|     for(int n = 0; n < cutDNA.nrow(); n++)
|     {
|       cutDNA(n,i) = completeDNA(n,informativeSites[i]);    // Use loops to fill
| in the new matrix. 
|     }
|   }
|   return cutDNA;     //Return the new matrix
| }
| 
| 
| However I seem to be having issues with the line:
| if(any(bpsite != bpsite[0])) informativeSites.push_back(i);
| 
| I think it is to do with the any() function, the errors are reported from the
| header file "SingleLogicalResult.h" and involve contorting bool. At least
| that's as far as I can dechiper the errors.

Could be: any() is an Rcpp function, which has to follow the R standard of
having _three_ logical values TRUE, FALSE, and NA.  

That does not map to C++'s 'bool', so you need to wrap the any() inside of an
is_true() to get 'bool' of either TRUE or FALSE.  I think we talk about this
in the sugar vignette.

I saw your post on SO, and the decent vectorised non-Rcpp solution you get
thanks to user flodel.  Let's now see where we get with Rcpp -- it may not be
much faster, but it is a useful learning example for you.

Dirk
 
| The console output below for full details. Is there a way for me to fix this?
| 
| Thanks,
| Ben W.
| 
| > Rcpp::sourceCpp('reduceseq.cpp')
| /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/
| Rcpp/sugar/logical/SingleLogicalResult.h: In instantiation of
| ‘Rcpp::sugar::conversion_to_bool_is_forbidden<false>’:
| /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/
| Rcpp/sugar/logical/SingleLogicalResult.h:74:   instantiated from
| ‘Rcpp::sugar::SingleLogicalResult<NA, T>::operator bool() [with bool NA =
| true, T = Rcpp::sugar::Any<true, Rcpp::sugar::Comparator_With_One_Value<16,
| Rcpp::sugar::not_equal<16>, true, Rcpp::Vector<16> > >]’
| reduceseq.cpp:17:   instantiated from here
| /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/
| Rcpp/sugar/logical/SingleLogicalResult.h:36: error: invalid use of incomplete
| type ‘struct Rcpp::sugar::forbidden_conversion<false>’
| /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/
| Rcpp/sugar/logical/SingleLogicalResult.h:29: error: declaration of ‘struct
| Rcpp::sugar::forbidden_conversion<false>’
| /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/
| Rcpp/sugar/operators/Comparator_With_One_Value.h: In member function ‘int
| Rcpp::sugar::Comparator_With_One_Value<RTYPE, Operator, NA, T>::rhs_is_not_na
| (int) const [with int RTYPE = 16, Operator = Rcpp::sugar::not_equal<16>, bool
| NA = true, T = Rcpp::Vector<16>]’:
| /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/
| Rcpp/sugar/operators/Comparator_With_One_Value.h:38:   instantiated from
| ‘Rcpp::sugar::Comparator_With_One_Value<RTYPE, Operator, NA,
| T>::Comparator_With_One_Value(const Rcpp::VectorBase<RTYPE, LHS_NA, LHS_T>&,
| typename Rcpp::traits::storage_type<RTYPE>::type) [with int RTYPE = 16,
| Operator = Rcpp::sugar::not_equal<16>, bool NA = true, T = Rcpp::Vector<16>]’
| /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/
| Rcpp/sugar/operators/logical_operators__Vector__primitive.h:266:   instantiated
| from ‘Rcpp::sugar::Comparator_With_One_Value<RTYPE, Rcpp::sugar::not_equal
| <RTYPE>, NA, T> operator!=(const Rcpp::VectorBase<RTYPE, NA, VECTOR>&, typename
| Rcpp::traits::storage_type<RTYPE>::type) [with int RTYPE = 16, bool NA = true,
| T = Rcpp::Vector<16>]’
| reduceseq.cpp:17:   instantiated from here
| /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/
| Rcpp/sugar/operators/Comparator_With_One_Value.h:59: error: operands to ?: have
| different types ‘SEXPREC*’ and ‘int’
| /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/
| Rcpp/sugar/operators/Comparator_With_One_Value.h: In member function ‘int
| Rcpp::sugar::Comparator_With_One_Value<RTYPE, Operator, NA, T>::rhs_is_na(int)
| const [with int RTYPE = 16, Operator = Rcpp::sugar::not_equal<16>, bool NA =
| true, T = Rcpp::Vector<16>]’:
| /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/
| Rcpp/sugar/operators/Comparator_With_One_Value.h:38:   instantiated from
| ‘Rcpp::sugar::Comparator_With_One_Value<RTYPE, Operator, NA,
| T>::Comparator_With_One_Value(const Rcpp::VectorBase<RTYPE, LHS_NA, LHS_T>&,
| typename Rcpp::traits::storage_type<RTYPE>::type) [with int RTYPE = 16,
| Operator = Rcpp::sugar::not_equal<16>, bool NA = true, T = Rcpp::Vector<16>]’
| /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/
| Rcpp/sugar/operators/logical_operators__Vector__primitive.h:266:   instantiated
| from ‘Rcpp::sugar::Comparator_With_One_Value<RTYPE, Rcpp::sugar::not_equal
| <RTYPE>, NA, T> operator!=(const Rcpp::VectorBase<RTYPE, NA, VECTOR>&, typename
| Rcpp::traits::storage_type<RTYPE>::type) [with int RTYPE = 16, bool NA = true,
| T = Rcpp::Vector<16>]’
| reduceseq.cpp:17:   instantiated from here
| /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/
| Rcpp/sugar/operators/Comparator_With_One_Value.h:56: error: invalid conversion
| from ‘SEXPREC* const’ to ‘int’
| make: *** [reduceseq.o] Error 1
| g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library
| /Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG  -I/usr/local/include
|  -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/
| include"    -fPIC  -g -O2  -c reduceseq.cpp -o reduceseq.o 
| 
| ----------------------------------------------------------------------
| _______________________________________________
| 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