-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Labels
Description
If I try to add the result of pmax to another vector, I get a compilation error. I suspect it has something to do with the type of the output of pmax, but I haven't investigated further. As seen below, passing the result of pmax into sum is fine.
nf <- nimbleFunction(
run = function(x = double(1), z = double(1)) {
returnType(double())
## return(sum(pmax(x, z)) + sum(log1p(exp(-abs(x))))) # succeeds
return(sum(pmax(x,z) + log1p(exp(-abs(x))))) # compilation error
}
)
cnf <- compileNimble(nf, showCompilerOutput = TRUE)
cnf(rnorm(20), rep(0,20))
Compiling
[Note] This may take a minute.
[Note] On some systems there may be some compiler warnings that can be safely ignored.
Error: Failed to create the shared library.
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -DR_NO_REMAP -DEIGEN_MPL2_ONLY=1 -I"/accounts/vis/paciorek/R/x86_64-pc-linux-gnu-library-ubuntu-22.04/4.4/nimble/include" -Wno-misleading-indentation -Wno-ignored-attributes -Wno-deprecated-declarations -fpic -g -O2 -ffile-prefix-map=/build/r-base-H8urij/r-base-4.4.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c P_4_rcFun_R_GlobalEnv6.cpp -o P_4_rcFun_R_GlobalEnv6.o
using C++ compiler: ‘g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
P_4_rcFun_R_GlobalEnv6.cpp: In function ‘double rcFun_R_GlobalEnv6(NimArr<1, double>&, NimArr<1, double>&)’:
P_4_rcFun_R_GlobalEnv6.cpp:29:85: error: no match for ‘operator+’ (operand types are ‘const Eigen::CwiseBinaryOp<Eigen::internal::scalar_max_op<double, double, 0>, const Eigen::ArrayWrapper<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<-1, -1> > >, const Eigen::ArrayWrapper<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<-1, -1> > > >’ and ‘const Eigen::MatrixWrapper<const Eigen::CwiseUnaryOp<std::function<double(double)>, const Eigen::CwiseUnaryOp<Eigen::internal::scalar_exp_op<double>, const Eigen::ArrayWrapper<const Eigen::CwiseUnaryOp<Eigen::internal::scalar_opposite_op<double>, const Eigen::CwiseUnaryOp<Eigen::internal::scalar_abs_op<double>, const Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<-1, -1> > > > > > > >’)
29 | Interm_99 = (((Eig_ARG1_x_Interm_100).array()).max((Eig_ARG2_z_Interm_101).array()) + ((((-((Eig_ARG1_x_Interm_102).cwiseAbs())).array()).exp()).unaryExpr(std::function< double(double) >( static_cast<double (*)(double)>(&log1p)))).matrix()).sum();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | const Eigen::MatrixWrapper<const Eigen::CwiseUnaryOp<std::function<double(double)>, const Eigen::CwiseUnaryOp<Eigen::internal::scalar_exp_op<double>, const Eigen::ArrayWrapper<const Eigen::CwiseUnaryOp<Eigen::internal::scalar_opposite_op<double>, const Eigen::CwiseUnaryOp<Eigen::internal::scalar_abs_op<double>, const Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<-1, -1> > > > > > > >
| const Eigen::CwiseBinaryOp<Eigen::internal::scalar_max_op<double, double, 0>, const Eigen::ArrayWrapper<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<-1, -1> > >, const Eigen::ArrayWrapper<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<-1, -1> > > >
In file included from /accounts/vis/paciorek/R/x86_64-pc-linux-gnu-library-ubuntu-22.04/4.4/nimble/include/Eigen/Core:19,
from /accounts/vis/paciorek/R/x86_64-pc-linux-gnu-library-ubuntu-22.04/4.4/nimble/include/Eigen/Dense:1,
from /accounts/vis/paciorek/R/x86_64-pc-linux-gnu-library-ubuntu-22.04/4.4/nimble/include/nimble/EigenTypedefs.h:24,
from P_4_rcFun_R_GlobalEnv6.cpp:8:
/accounts/vis/paciorek/R/x86_64-pc-linux-gnu-library-ubuntu-22.04/4.4/nimble/include/Eigen/src/Core/../plugins/CommonCwiseBinaryOps.h:27:28: note: candidate: ‘template<class OtherDerived> const Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<typename Eigen::internal::traits<T>::Scalar, typename Eigen::internal::traits<OtherDerived>::Scalar>, const Derived, const OtherDerived> Eigen::ArrayBase<Derived>::operator+(const Eigen::ArrayBase<OtherDerived>&) const [with OtherDerived = OtherDerived; Derived = Eigen::CwiseBinaryOp<Eigen::internal::scalar_max_op<double, double, 0>, const Eigen::ArrayWrapper<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<-1, -1> > >, const Eigen::ArrayWrapper<Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<-1, -1> > > >]’
27 | EIGEN_MAKE_CWISE_BINARY_OP(operator+,sum)
| ^~~~~~~~
/accounts/vis/paciorek/R/x86_64-pc-linux-gnu-library-ubuntu-22.04/4.4/nimble/include/Eigen/src/Core/util/Macros.h:1339:4: note: in definition of macro ‘EIGEN_MAKE_CWISE_BINARY_OP’
1339 | (METHOD)(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \
| ^~~~~~
/accounts/vis/paciorek/R/x86_64-pc-linux-gnu-library-ubuntu-22.04/4.4/nimble/include/Eigen/src/Core/../plugins/CommonCwiseBinaryOps.h:27:28: note: template argument deduction/substitution failed:
27 | EIGEN_MAKE_CWISE_BINARY_OP(operator+,sum)
| ^~~~~~~~
/accounts/vis/paciorek/R/x86_64-pc-linux-gnu-library-ubuntu-22.04/4.4/nimble/include/Eigen/src/Core/util/Macros.h:1339:4: note: in definition of macro ‘EIGEN_MAKE_CWISE_BINARY_OP’
1339 | (METHOD)(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \
| ^~~~~~
P_4_rcFun_R_GlobalEnv6.cpp:29:239: note: ‘const Eigen::MatrixWrapper<const Eigen::CwiseUnaryOp<std::function<double(double)>, const Eigen::CwiseUnaryOp<Eigen::internal::scalar_exp_op<double>, const Eigen::ArrayWrapper<const Eigen::CwiseUnaryOp<Eigen::internal::scalar_opposite_op<double>, const Eigen::CwiseUnaryOp<Eigen::internal::scalar_abs_op<double>, const Eigen::Map<Eigen::Matrix<double, -1, -1>, 0, Eigen::Stride<-1, -1> > > > > > > >’ is not derived from ‘const Eigen::ArrayBase<Derived>’
29 | Interm_99 = (((Eig_ARG1_x_Interm_100).array()).max((Eig_ARG2_z_Interm_101).array()) + ((((-((Eig_ARG1_x_Interm_102).cwiseAbs())).array()).exp()).unaryExpr(std::function< double(double) >( static_cast<double (*)(double)>(&log1p)))).matrix()).sum();
| ^
In file included from /accounts/vis/paciorek/R/x86_64-pc-linux-gnu-library-ubuntu-22.04/4.4/nimble/include/Eigen/Core:19,
from /accounts/vis/paciorek/R/x86_64-pc-linux-gnu-library-ubuntu-22.04/4.4/nimble/include/Eigen/Dense:1,
from /accounts/vis/paciorek/R/x86_64-pc-linux-gnu-library-ubuntu-22.04/4.4/nimble/include/nimble/EigenTypedefs.h:24,
from P_4_rcFun_R_GlobalEnv6.cpp:8:
/accounts/vis/paciorek/R/x86_64-pc-linux-gnu-library-ubuntu-22.04/4.4/nimble/include/Eigen/src/Core/../plugins/ArrayCwiseBinaryOps.h:241:29: note: candidate: ‘template<class T> const Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<typename Eigen::internal::traits<T>::Scalar, typename Eigen::internal::promote_scalar_arg<typename Eigen::internal::traits<T>::Scalar, T, Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<typename Eigen::internal::traits<T>::Scalar, T, Eigen::internal::scalar_sum_op<typename Eigen::internal::traits<T>::Scalar, T> > >::value>::type>, const Derived, const typename Eigen::internal::plain_constant_type<Derived, typename Eigen::internal::promote_scalar_arg<typename Eigen::internal::traits<T>::Scalar, T, Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<typename Eigen::internal::traits<T>::Scalar, T, Eigen::internal::scalar_sum_op<typename Eigen::internal::traits<T>::Scalar, T> > >::value>::type>::type> Eigen::ArrayBase<Derived>::operator+(const T&) const [with T = T; Derived = Eigen::CwiseBinaryOp<Eigen::internal::scalar_max_op<double, double, 0>, const Eigen::ArrayWrapper<Eigen::Map<Eigen::Matrix<d