Invalid scope 'function' to arbb_end_loop: invalid control pairs

Invalid scope 'function' to arbb_end_loop: invalid control pairs

HiI still have another example where i get an error due to the boolean data in the code below :// pay off class to valuate optionclass PayOffSimple2{public : arbb::f64 strike ; arbb::boolean bVendeur; PayOffSimple2() : strike(0.),bVendeur(true){} PayOffSimple2( arbb::f64 strike_, arbb::boolean bVendeur_):strike(strike_),bVendeur(bVendeur_){} arbb::f64 operator()( const arbb::f64 & x) const { _if (bVendeur) { return arbb::max(arbb::exp(x)-strike,0.); } _end_if; return -arbb::max(arbb::exp(x)-strike,0.); }};// arbb wrappervoid caller2( const arbb::usize & N, const arbb::f64 & strike, const arbb::boolean & bVendeur){ // instanciation of a class inside arbb PayOffSimple2 pay(strike, bVendeur); arbb::dense Sol(N); _for (arbb::usize i= 0 , i < N , ++i) { Sol[i] = pay(static_cast(i)); } _end_for;}// main callint main(int argc, char *argv[]){ arbb::usize N_ = 10 ; arbb::f64 strike = 5. ; arbb::boolean bVendeur2 = true ;// OK PayOffSimple2 paySimple(strike, bVendeur2); arbb::dense sol(N_) ; _for (arbb::usize i= 0 , i < N_ , ++i) { sol[i] = paySimple(static_cast(i)); } _end_for; // error dur to boolean test arbb::call(caller2)(N_,strike, bVendeur2); return 0 ;}Can you explain to me the failure.Thank you very muchSincerely yours

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

A return statement cannot be used within an ArBB control flow. This is a known issue. To work around, you need to move the return statement outside the _if/_else branches. For example:

arbb::f64 operator()( const arbb::f64 & x) const {
arbb::f64 ret; _if (bVendeur) { ret = arbb::max(arbb::exp(x)-strike,0.); }
_else
{
ret = -arbb::max(arbb::exp(x)-strike,0.);
} _end_if; return ret; }

Alternatively, you can also use the arbb::select() operator in this case:

arbb::f64 operator()( const arbb::f64 & x) const {
return arbb::select(bVendeur, arbb::max(arbb::exp(x)-strike,0.), -arbb::max(arbb::exp(x)-strike,0.));
}

Let us know if you have questions.

Leave a Comment

Please sign in to add a comment. Not a member? Join today