I want to use the R stats::optimize function in Rcpp because I haven't been able to find an Rcpp equivalent. The code below is my attempt at a simple example based on the Example in the optimize help, but fails.
Here's the R function and results
f <- function (x) (x - .33)^2
xmin <- optimize(f, c(0, 1), tol = 0.0001)
xmin
This returns
$minimum
[1] 0.333
$objective
[1] 0
Here's the Rcpp code that fails when sourcing it.
#include <Rcpp.h>
const double tolerance = 1e-0;
// [[Rcpp::export]]
Rcpp::NumericVector f(Rcpp::NumericVector x) {
return pow(x-0.33, 2);
}
Rcpp::List fTg_opt(const double optmin, const double optmax) {
Rcpp::Environment base("package:stats");
Rcpp::Function optimize_r = base["optimize"];
Rcpp::NumericVector interval = {optmin,optmax};
return optimize_r(f, interval, tolerance);
}
The Rstudio console has the following error messages.
> Rcpp::sourceCpp("R/cpp/testopt.cpp")
In file included from testopt.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp.h:27:
In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/RcppCommon.h:157:
In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/traits/traits.h:45:
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/traits/is_convertible.h:35:10: error: function cannot return function type 'Rcpp::Vector<14> (Rcpp::Vector<14>)'
static T MakeT() ;
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/internal/wrap.h:770:75: note: in instantiation of template class 'Rcpp::traits::is_convertible<Rcpp::Vector<14> (Rcpp::Vector<14>), SEXPREC *>' requested here
return wrap_dispatch_unknown(object, typename ::Rcpp::traits::is_convertible<T,SEXP>::type());
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/internal/wrap.h:787:20: note: in instantiation of function template specialization 'Rcpp::internal::wrap_dispatch_eigen<Rcpp::Vector<14> (Rcpp::Vector<14>)>' requested here
return wrap_dispatch_eigen(object, typename traits::is_eigen_base<T>::type());
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/internal/wrap.h:807:20: note: in instantiation of function template specialization 'Rcpp::internal::wrap_dispatch_unknown_importable<Rcpp::Vector<14> (Rcpp::Vector<14>)>' requested here
return wrap_dispatch_unknown_importable(object, typename ::Rcpp::traits::is_importer<T>::type());
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/internal/wrap_end.h:30:25: note: in instantiation of function template specialization 'Rcpp::internal::wrap_dispatch<Rcpp::Vector<14> (Rcpp::Vector<14>)>' requested here
return internal::wrap_dispatch( object, typename ::Rcpp::traits::wrap_type_traits<T>::wrap_category() ) ;
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/grow.h:44:26: note: in instantiation of function template specialization 'Rcpp::wrap<Rcpp::Vector<14> (Rcpp::Vector<14>)>' requested here
return grow( wrap(head), tail ) ;
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/grow.h:65:26: note: in instantiation of function template specialization 'Rcpp::internal::grow__dispatch<Rcpp::Vector<14> (Rcpp::Vector<14>)>' requested here
return internal::grow__dispatch(typename traits::is_named<T>::type(), head, y);
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/generated/grow__pairlist.h:45:9: note: in instantiation of function template specialization 'Rcpp::grow<Rcpp::Vector<14> (Rcpp::Vector<14>)>' requested here
return grow( t1, grow( t2, grow( t3, R_NilValue ) ) ) ;
^
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/generated/Function__operator.h:45:20: note: in instantiation of function template specialization 'Rcpp::pairlist<Rcpp::Vector<14> (Rcpp::Vector<14>), Rcpp::Vector<14>, double>' requested here
return invoke(pairlist(t1, t2, t3), R_GlobalEnv);
^
testopt.cpp:13:20: note: in instantiation of function template specialization 'Rcpp::Function_Impl<PreserveStorage>::operator()<Rcpp::Vector<14> (Rcpp::Vector<14>), Rcpp::Vector<14>, double>' requested here
return optimize_r(f, interval, tolerance);
^
1 error generated.
make: *** [testopt.o] Error 1
clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include" -I"/Users/gcn/Documents/workspace/ISIMIPData/R/cpp" -I/usr/local/include -fPIC -Wall -g -O2 -c testopt.cpp -o testopt.o
Error in Rcpp::sourceCpp("R/cpp/testopt.cpp") :
Error 1 occurred building shared library.
One of your problems here is that you assume that becomes a function you submit to compilation under Rcpp::sourceCpp() is callable under its exported name.
It is not. Try Rcpp::sourceCpp(..., verbose=TRUE), i.e. add that arguments, to see what is really called. Those you could pass around (using SEXP argunments and results, but they are unwieldy).
To prove, here is a 'working but useless' version of your code. If we pass f() from R too, everything is callable.
Morale: The interface still is SEXP .Call("name", SEXP a, SEXP b, ...) even if Rcpp hides that. No Free Lunch (TM). But as my comment hinted, there are optimization packages you can use with Rcpp.
Code
#include <Rcpp.h>
// [[Rcpp::export]]
Rcpp::List fTg_opt(Rcpp::Function f, const double optmin, const double optmax) {
Rcpp::Environment base("package:stats");
Rcpp::Function optimize_r = base["optimize"];
Rcpp::NumericVector interval = {optmin,optmax};
Rcpp::List res = optimize_r(f, interval);
return res;
}
/*** R
f <- function (x) (x - .33)^2
xmin <- optimize(f, c(0, 1), tol = 0.0001)
xmin
fTg_opt(f, 0, 1)
*/
Output
> Rcpp::sourceCpp("~/git/stackoverflow/68674076/question.cpp")
> f <- function (x) (x - .33)^2
> xmin <- optimize(f, c(0, 1), tol = 0.0001)
> xmin
$minimum
[1] 0.33
$objective
[1] 0
> fTg_opt(f, 0, 1)
$minimum
[1] 0.33
$objective
[1] 0
This is how I set up AllJoyn:
cd /opt
sudo mkdir alljoyn
sudo chown -R danny:danny alljoyn
cd alljoyn
repo init -u https://git.allseenalliance.org/gerrit/devtools/manifest.git
repo sync
repo start master --all
Now, I would like to build AllJoyn js bindings, but getting Exceptions (c, cpp and java worked out of the box):
/opt/alljoyn/core/alljoyn$ scons BINDINGS=js GECKO_BASE=/opt/xulrunner-sdk
scons: Reading SConscript files ...
Checking c++ compiler support for -std=c++11 flag... (cached) yes
Using OpenSSL crypto
Building bindings: js
Building services:
GTEST_DIR not specified skipping common unit test build
GTEST_DIR not specified skipping About Service unit test build
GTEST_DIR not specified skipping alljoyn_core unit test build
SQLITE_DIR not specified: skipping Security Manager sample program build
scons: done reading SConscript files.
scons: Building targets ...
[CXX-SH] alljoyn_js/jni/ProxyBusObjectHost.cc
alljoyn_js/jni/ProxyBusObjectHost.cc: In constructor 'ReplyReceiver::ReplyReceiver(Plugin&, BusAttachment&, ProxyBusObject&, qcc::String&, qcc::String&, CallbackNative*, const NPVariant*, uint32_t)':
alljoyn_js/jni/ProxyBusObjectHost.cc:122:119: error: no matching function for call to 'qcc::ManagedObj<ReplyReceiver::_Env>::ManagedObj(ReplyReceiver*, Plugin&, BusAttachment&, ProxyBusObject&, qcc::String&, qcc::String&, CallbackNative*&, const NPVariant*&, uint32_t&)'
env(this, plugin, busAttachment, proxyBusObject, interfaceName, methodName, callbackNative, npargs, npargCount) { }
^
In file included from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/Message.h:30:0,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/AuthListener.h:32,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/BusAttachment.h:34,
from alljoyn_js/jni/BusAttachment.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.cc:16:
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:488:5: note: candidate: qcc::ManagedObj<T>::ManagedObj(qcc::ManagedObj<T>::ManagedCtx*, T*) [with T = ReplyReceiver::_Env]
ManagedObj<T>(ManagedCtx* context, T* object) : context(context), object(object)
^
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:488:5: note: candidate expects 2 arguments, 9 provided
In file included from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/Message.h:30:0,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/AuthListener.h:32,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/BusAttachment.h:34,
from alljoyn_js/jni/BusAttachment.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.cc:16:
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:348:146: note: candidate: template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10> qcc::ManagedObj<T>::ManagedObj(A1&, A2&, A3&, A4&, A5&, A6&, A7&, A8&, A9&, A10&)
template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10> ManagedObj<T>(A1 & arg1, A2 & arg2, A3 & arg3, A4 & arg4, A5 & arg5, A6 & arg6, A7 & arg7, A8 & arg8, A9 & arg9, A10 & arg10)
^
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:348:146: note: template argument deduction/substitution failed:
alljoyn_js/jni/ProxyBusObjectHost.cc:122:119: note: candidate expects 10 arguments, 9 provided
env(this, plugin, busAttachment, proxyBusObject, interfaceName, methodName, callbackNative, npargs, npargCount) { }
^
In file included from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/Message.h:30:0,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/AuthListener.h:32,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/BusAttachment.h:34,
from alljoyn_js/jni/BusAttachment.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.cc:16:
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:324:132: note: candidate: qcc::ManagedObj<T>::ManagedObj(A1&, A2&, A3&, A4&, A5&, A6&, A7&, A8&, A9&) [with A1 = ReplyReceiver*; A2 = qcc::ManagedObj<_Plugin>; A3 = qcc::ManagedObj<ajn::BusAttachment>; A4 = qcc::ManagedObj<ajn::ProxyBusObject>; A5 = qcc::String; A6 = qcc::String; A7 = CallbackNative*; A8 = const _NPVariant*; A9 = unsigned int; T = ReplyReceiver::_Env] <near match>
template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> ManagedObj<T>(A1 & arg1, A2 & arg2, A3 & arg3, A4 & arg4, A5 & arg5, A6 & arg6, A7 & arg7, A8 & arg8, A9 & arg9)
^
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:324:132: note: conversion of argument 1 would be ill-formed:
alljoyn_js/jni/ProxyBusObjectHost.cc:122:119: error: invalid initialization of non-const reference of type 'ReplyReceiver*&' from an rvalue of type 'ReplyReceiver*'
env(this, plugin, busAttachment, proxyBusObject, interfaceName, methodName, callbackNative, npargs, npargCount) { }
^
In file included from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/Message.h:30:0,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/AuthListener.h:32,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/BusAttachment.h:34,
from alljoyn_js/jni/BusAttachment.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.cc:16:
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:301:119: note: candidate: template<class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8> qcc::ManagedObj<T>::ManagedObj(A1&, A2&, A3&, A4&, A5&, A6&, A7&, A8&)
template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> ManagedObj<T>(A1 & arg1, A2 & arg2, A3 & arg3, A4 & arg4, A5 & arg5, A6 & arg6, A7 & arg7, A8 & arg8)
^
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:301:119: note: template argument deduction/substitution failed:
alljoyn_js/jni/ProxyBusObjectHost.cc:122:119: note: candidate expects 8 arguments, 9 provided
env(this, plugin, busAttachment, proxyBusObject, interfaceName, methodName, callbackNative, npargs, npargCount) { }
^
In file included from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/Message.h:30:0,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/AuthListener.h:32,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/BusAttachment.h:34,
from alljoyn_js/jni/BusAttachment.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.cc:16:
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:279:106: note: candidate: template<class A1, class A2, class A3, class A4, class A5, class A6, class A7> qcc::ManagedObj<T>::ManagedObj(A1&, A2&, A3&, A4&, A5&, A6&, A7&)
template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> ManagedObj<T>(A1 & arg1, A2 & arg2, A3 & arg3, A4 & arg4, A5 & arg5, A6 & arg6, A7 & arg7)
^
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:279:106: note: template argument deduction/substitution failed:
alljoyn_js/jni/ProxyBusObjectHost.cc:122:119: note: candidate expects 7 arguments, 9 provided
env(this, plugin, busAttachment, proxyBusObject, interfaceName, methodName, callbackNative, npargs, npargCount) { }
^
In file included from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/Message.h:30:0,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/AuthListener.h:32,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/BusAttachment.h:34,
from alljoyn_js/jni/BusAttachment.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.cc:16:
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:258:93: note: candidate: template<class A1, class A2, class A3, class A4, class A5, class A6> qcc::ManagedObj<T>::ManagedObj(A1&, A2&, A3&, A4&, A5&, A6&)
template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> ManagedObj<T>(A1 & arg1, A2 & arg2, A3 & arg3, A4 & arg4, A5 & arg5, A6 & arg6)
^
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:258:93: note: template argument deduction/substitution failed:
alljoyn_js/jni/ProxyBusObjectHost.cc:122:119: note: candidate expects 6 arguments, 9 provided
env(this, plugin, busAttachment, proxyBusObject, interfaceName, methodName, callbackNative, npargs, npargCount) { }
^
In file included from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/Message.h:30:0,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/AuthListener.h:32,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/BusAttachment.h:34,
from alljoyn_js/jni/BusAttachment.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.cc:16:
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:238:80: note: candidate: template<class A1, class A2, class A3, class A4, class A5> qcc::ManagedObj<T>::ManagedObj(A1&, A2&, A3&, A4&, A5&)
template <typename A1, typename A2, typename A3, typename A4, typename A5> ManagedObj<T>(A1 & arg1, A2 & arg2, A3 & arg3, A4 & arg4, A5 & arg5)
^
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:238:80: note: template argument deduction/substitution failed:
alljoyn_js/jni/ProxyBusObjectHost.cc:122:119: note: candidate expects 5 arguments, 9 provided
env(this, plugin, busAttachment, proxyBusObject, interfaceName, methodName, callbackNative, npargs, npargCount) { }
^
In file included from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/Message.h:30:0,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/AuthListener.h:32,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/BusAttachment.h:34,
from alljoyn_js/jni/BusAttachment.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.cc:16:
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:222:67: note: candidate: template<class A1, class A2, class A3, class A4> qcc::ManagedObj<T>::ManagedObj(A1&, A2&, A3&, A4&)
template <typename A1, typename A2, typename A3, typename A4> ManagedObj<T>(A1 & arg1, A2 & arg2, A3 & arg3, A4 & arg4)
^
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:222:67: note: template argument deduction/substitution failed:
alljoyn_js/jni/ProxyBusObjectHost.cc:122:119: note: candidate expects 4 arguments, 9 provided
env(this, plugin, busAttachment, proxyBusObject, interfaceName, methodName, callbackNative, npargs, npargCount) { }
^
In file included from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/Message.h:30:0,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/AuthListener.h:32,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/BusAttachment.h:34,
from alljoyn_js/jni/BusAttachment.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.cc:16:
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:204:54: note: candidate: template<class A1, class A2, class A3> qcc::ManagedObj<T>::ManagedObj(A1&, A2&, A3&)
template <typename A1, typename A2, typename A3> ManagedObj<T>(A1 & arg1, A2 & arg2, A3 & arg3)
^
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:204:54: note: template argument deduction/substitution failed:
alljoyn_js/jni/ProxyBusObjectHost.cc:122:119: note: candidate expects 3 arguments, 9 provided
env(this, plugin, busAttachment, proxyBusObject, interfaceName, methodName, callbackNative, npargs, npargCount) { }
^
In file included from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/Message.h:30:0,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/AuthListener.h:32,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/BusAttachment.h:34,
from alljoyn_js/jni/BusAttachment.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.cc:16:
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:190:41: note: candidate: template<class A1, class A2> qcc::ManagedObj<T>::ManagedObj(A1&, A2&)
template <typename A1, typename A2> ManagedObj<T>(A1 & arg1, A2 & arg2)
^
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:190:41: note: template argument deduction/substitution failed:
alljoyn_js/jni/ProxyBusObjectHost.cc:122:119: note: candidate expects 2 arguments, 9 provided
env(this, plugin, busAttachment, proxyBusObject, interfaceName, methodName, callbackNative, npargs, npargCount) { }
^
In file included from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/Message.h:30:0,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/AuthListener.h:32,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/BusAttachment.h:34,
from alljoyn_js/jni/BusAttachment.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.cc:16:
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:174:28: note: candidate: template<class A1> qcc::ManagedObj<T>::ManagedObj(A1&)
template <typename A1> ManagedObj<T>(A1 & arg1)
^
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:174:28: note: template argument deduction/substitution failed:
alljoyn_js/jni/ProxyBusObjectHost.cc:122:119: note: candidate expects 1 argument, 9 provided
env(this, plugin, busAttachment, proxyBusObject, interfaceName, methodName, callbackNative, npargs, npargCount) { }
^
In file included from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/Message.h:30:0,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/AuthListener.h:32,
from build/linux/x86_64/debug/dist/cpp/inc/alljoyn/BusAttachment.h:34,
from alljoyn_js/jni/BusAttachment.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.h:19,
from alljoyn_js/jni/ProxyBusObjectHost.cc:16:
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:133:5: note: candidate: qcc::ManagedObj<T>::ManagedObj() [with T = ReplyReceiver::_Env]
ManagedObj<T>()
^
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:133:5: note: candidate expects 0 arguments, 9 provided
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:113:5: note: candidate: qcc::ManagedObj<T>::ManagedObj(const qcc::ManagedObj<T>&, bool) [with T = ReplyReceiver::_Env]
ManagedObj<T>(const ManagedObj<T>&other, bool isDeep)
^
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:113:5: note: candidate expects 2 arguments, 9 provided
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:91:5: note: candidate: qcc::ManagedObj<T>::ManagedObj(qcc::ManagedObj<T>&) [with T = ReplyReceiver::_Env]
ManagedObj<T>(ManagedObj<T>©Me)
^
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:91:5: note: candidate expects 1 argument, 9 provided
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:83:5: note: candidate: qcc::ManagedObj<T>::ManagedObj(const qcc::ManagedObj<T>&) [with T = ReplyReceiver::_Env]
ManagedObj<T>(const ManagedObj<T>©Me)
^
build/linux/x86_64/debug/dist/cpp/inc/qcc/ManagedObj.h:83:5: note: candidate expects 1 argument, 9 provided
scons: *** [build/linux/x86_64/debug/obj/alljoyn_js/jni/ProxyBusObjectHost.os] Error 1
scons: building terminated because of errors.
And when trying to build AllJoyn on Linux for my Android device it complains the compiler is too old:
/opt/alljoyn/core/alljoyn$ scons OS=android CRYPTO=builtin ANDROID_NDK=/opt/android-ndk-r13
scons: Reading SConscript files ...
Checking c++ compiler support for -std=c++11 flag... no
Checking c++ compiler support for -std=c++0x flag... no
*** Compiler too old to build AllJoyn. Aborting.
I'm using the following compiler versions:
$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I'm really confused as from above the c++ compiler should have support for -std=c++11 flag.
Notice: I've downloaded NDK r13 and had to create /opt/android-ndk-r13/RELEASE.TXT which contains r13a in order to pass the version check.
List of /opt:
$ ls /opt
alljoyn android-ndk-r13 android-sdk-linux android-studio xulrunner-sdk
And btw: Setting up and building AllJoyn is a mess. Docs are outdated and contradictory.
--Answer not related to the main topic-- I agree the documents are sometimes very confusing, and now since the merger is on the way there will be more cases of Documents being even more less updated.
I'm working on a arduino(uno) talking clock project. I'm using the code on this site : https://learn.adafruit.com/wave-shield-talking-clock/overview
add the WaveHC library when I get the following error :
Arduino:1.6.6 (Windows 10), Card:"Arduino/Genuino Uno"
TalkingClock:44: error: no matching function for call to 'WaveHC::WaveHC()'
WaveHC wave;
^
\Arduino\TalkingClock\TalkingClock.ino:44:12: note: candidates are:
In file included from \Arduino\TalkingClock\TalkingClock.ino:26:0:
\Arduino\libraries\WaveHC/WaveHC.h:113:3: note: WaveHC::WaveHC(HardwareSerial&)
WaveHC(HardwareSerial& serial);
^
\Arduino\libraries\WaveHC/WaveHC.h:113:3: note: candidate expects 1 argument, 0 provided
\Arduino\libraries\WaveHC/WaveHC.h:77:7: note: constexpr WaveHC::WaveHC(const WaveHC&)
class WaveHC
^
\Arduino\libraries\WaveHC/WaveHC.h:77:7: note: candidate expects 1 argument, 0 provided
\Arduino\libraries\WaveHC/WaveHC.h:77:7: note: constexpr WaveHC::WaveHC(WaveHC&&)
\Arduino\libraries\WaveHC/WaveHC.h:77:7: note: candidate expects 1 argument, 0 provided
TalkingClock:64: error: variable 'hours' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
*hours[] = { h12, h01, h02, h03, h04, h05, h06, h07, h08, h09, h10, h11 },
^
TalkingClock:65: error: variable 'mTens' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
*mTens[] = { m00, m10, m20, m30, m40, m50 },
^
TalkingClock:66: error: variable 'mTeens' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
*mTeens[] = { m11, m12, m13, m14, m15, m16, m17, m18, m19 },
^
TalkingClock:67: error: variable 'mTenX' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
*mTenX[] = { m0x, NULL, m2x, m3x, m4x, m5x },
^
TalkingClock:68: error: variable 'mins' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
*mins[] = { m1, m2, m3, m4, m5, m6, m7, m8, m9 },
^
TalkingClock:69: error: variable 'ampm' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
*ampm[] = { am, pm };
^
exit status 1
no matching function for call to 'WaveHC::WaveHC()'
I am converting some R code to Rcpp code and need to calculate the likelihood for a vector of observations given a vector of means and vector of standard deviations. If I assume the means are 0 and the standard deviations 1, I can write this function (running this requires the 'inline' and 'Rcpp' packages to be loaded),
dtest1 = cxxfunction(signature( x = "numeric"),
'Rcpp::NumericVector xx(x);
return::wrap(dnorm(xx, 0.0, 1.0));',
plugin='Rcpp')
and the result is as expected.
> dtest1(1:3)
[1] 0.241970725 0.053990967 0.004431848
However, if I try to make a function
dtest2 = cxxfunction(signature( x = "numeric", y="numeric", z="numeric" ),
'Rcpp::NumericVector xx(x);
Rcpp::NumericVector yy(y);
Rcpp::NumericVector zz(z);
return::wrap(dnorm(xx, yy, zz));',
plugin='Rcpp')
which would allow me to pass in different means and standard deviations results in an error, shown below. Is there a way to make the function I am trying to make, or I do need to program the normal density manually?
Error
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file31c82bff9d7c.cpp: In function ‘SEXPREC* file31c82bff9d7c(SEXP, SEXP, SEXP)’:
file31c82bff9d7c.cpp:33:53: error: no matching function for call to
‘dnorm4(Rcpp::NumericVector&, Rcpp::NumericVector&, Rcpp::NumericVector&)’
file31c82bff9d7c.cpp:33:53: note: candidates are:
/home/chris/R/x86_64-pc-linux-gnu-library/3.0/Rcpp/include/Rcpp/stats/norm.h:106:1:
note: template<int RTYPE, bool NA, class T> Rcpp::stats::D0<RTYPE, NA, T> Rcpp::dnorm4(const Rcpp::VectorBase<RTYPE, NA, VECTOR>&, bool)
/home/chris/R/x86_64-pc-linux-gnu-library/3.0/Rcpp/include/Rcpp/stats/norm.h:107:1:
note: template<int RTYPE, bool NA, class T> Rcpp::stats::D1<RTYPE, NA, T> Rcpp::dnorm4(const Rcpp::VectorBase<RTYPE, NA, VECTOR>&, double, bool)
/home/chris/R/x86_64-pc-linux-gnu-library/3.0/Rcpp/include/Rcpp/stats/norm.h:108:1:
note: template<int RTYPE, bool NA, class T> Rcpp::stats::D2<RTYPE, NA, T> Rcpp::dnorm4(const Rcpp::VectorBase<RTYPE, NA,
In addition: Warning message:
running command '/usr/lib/R/bin/R CMD SHLIB file31c82bff9d7c.cpp 2> file31c82bff9d7c.cpp.err.txt' had status 1
The sugar dnorm is only vectorized in terms of the first argument.
To simplify (it is slightly more involved, but we don't need to concern ourselves with this yet here), the call
dnorm(xx, 0.0, 1.0)
uses the overload
NumericVector dnorm( NumericVector, double, double )
And the second call tries to use something like
NumericVector dnorm( NumericVector, NumericVector, NumericVector )
which is not implemented. We could implement it, it would have to go high enough in our priority list.
In the meantime, it is easy enough to write a small wrapper, like (this does not handle argument lengths, etc ...) :
NumericVector my_dnorm( NumericVector x, NumericVector means, NumericVector sds){
int n = x.size() ;
NumericVector res(n) ;
for( int i=0; i<n; i++) res[i] = R::dnorm( x[i], means[i], sds[i] ) ;
return res ;
}