Skip to content

type awkwardness with parallel_reduce #136

@paciorek

Description

@paciorek

I'm not sure how this fits into general type questions in nCompiler.

If I use +, this is fine, albeit with the internal accumulator variable being a double. If I use min/max (i.e., pair{min,max}), this fails during C++ compilation:

 nc <- nClass(
    Cpublic = list(
      go = nFunction(
        fun = function(x = 'integerVector') {
          y <- parallel_reduce('pairmin', x, 100)
          return(y)
        },
        returnType = 'integerScalar'
      )
    )
  )
  Cnc <- nCompile(nc)
In file included from nCompiler_units_6.cpp:16:
/tmp/RtmpjUETF2/nCompiler_generatedCode/nClass_10_c_.h: In member function ‘void nClass_10::parallel_reduce_body::operator()(const tbb::blocked_range<int>&)’:
/tmp/RtmpjUETF2/nCompiler_generatedCode/nClass_10_c_.h:29:72: error: no matching function for call to ‘min(Eigen::Tensor<int, 1>::Scalar&, double&)’
   29 | for(i__ = r__.begin(); i__ != r__.end(); ++i__) flex_(val__) = std::min(x[(i__) - 1], val__);
      |                                                                ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/bits/specfun.h:43,
                 from /usr/include/c++/13/cmath:3699,
                 from /system/linux/lib/R-24.04/4.5.0/x86_64/site-library/Rcpp/include/Rcpp/platform/compiler.h:100,
                 from /system/linux/lib/R-24.04/4.5.0/x86_64/site-library/Rcpp/include/Rcpp/r/headers.h:66,
                 from /system/linux/lib/R-24.04/4.5.0/x86_64/site-library/Rcpp/include/RcppCommon.h:30,
                 from /accounts/vis/paciorek/R/x86_64-pc-linux-gnu-library-ubuntu-24.04/4.5/nCompiler/include/nCompiler/nCompiler_omnibus_pre_Rcpp.h:26:
/usr/include/c++/13/bits/stl_algobase.h:233:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)’
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
/tmp/RtmpjUETF2/nCompiler_generatedCode/nClass_10_c_.h:29:72: note:   deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘double’)
   29 | for(i__ = r__.begin(); i__ != r__.end(); ++i__) flex_(val__) = std::min(x[(i__) - 1], val__);
      |                                                                ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:281:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)’
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:281:5: note:   template argument deduction/substitution failed:
/tmp/RtmpjUETF2/nCompiler_generatedCode/nClass_10_c_.h:29:72: note:   deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘double’)
   29 | for(i__ = r__.begin(); i__ != r__.end(); ++i__) flex_(val__) = std::min(x[(i__) - 1], val__);
      |                                                                ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions