22 template<
typename X1,
typename X2>
23 static std::string str(
const X1& x1,
const X2& x2)
25 return "atan2(" + x1->str() +
"," + x2->str() +
")";
28 template<
typename X1,
typename X2>
29 static std::pair<Index,Index> output_shape([[maybe_unused]]
const X1& s1, [[maybe_unused]]
const X2& s2)
34 static Interval fwd(
const Interval& x1,
const Interval& x2);
35 static ScalarType fwd_natural(
const ScalarType& x1,
const ScalarType& x2);
36 static ScalarType fwd_centered(
const ScalarType& x1,
const ScalarType& x2);
37 static void bwd(
const Interval& y, Interval& x1, Interval& x2);
44 atan2(
const ScalarExpr& x1,
const ScalarExpr& x2)
46 return { std::make_shared<AnalyticOperationExpr<Atan2Op,ScalarType,ScalarType,ScalarType>>(x1,x2) };
56 inline ScalarType Atan2Op::fwd_natural(
const ScalarType& x1,
const ScalarType& x2)
60 x1.def_domain && x2.def_domain
61 && !(x1.a == 0. && x2.a == 0.)
65 inline ScalarType Atan2Op::fwd_centered(
const ScalarType& x1,
const ScalarType& x2)
67 if(centered_form_not_available_for_args(x1,x2))
68 return fwd_natural(x1,x2);
70 assert(x1.da.rows() == 1);
71 assert(x1.da.rows() == x2.da.rows() && x1.da.cols() == x2.da.cols());
73 IntervalMatrix d(1,x1.da.cols());
74 for(Index i = 0 ; i < d.size() ; i++)
75 d(0,i) = (-x1.a*x2.da(0,i)/(
sqr(x2.a)+
sqr(x1.a)))+(x2.a*x1.da(0,i)/(
sqr(x2.a)+
sqr(x1.a)));
81 x1.def_domain && x2.def_domain
82 && !(x1.a == 0. && x2.a == 0.)
104 if(!y_x2pos.is_empty())
106 Interval xpos = x2 & Interval(0,oo);
109 if(y_x2neg_x1pos.is_empty() || y_x2neg_x1neg.is_empty())
111 Interval z = yall/xpos;
112 AtanOp::bwd(y_x2pos,z);
113 DivOp::bwd(z,yall,xpos);
123 yres |= (x1 & Interval(0,oo));
128 yres |= (x1 & Interval(-oo,0));
132 if(!y_x2neg_x1pos.is_empty())
134 Interval xneg = x2 & Interval(-oo,0);
135 Interval ypos = x1 & Interval(0,oo);
136 Interval z = ypos/xneg;
138 DivOp::bwd(z,ypos,xneg);
143 if(!y_x2neg_x1neg.is_empty())
145 Interval xneg = x2 & Interval(-oo,0);
146 Interval yneg = x1 & Interval(-oo,0);
147 Interval z = yneg/xneg;
149 DivOp::bwd(z,yneg,xneg);
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:62
static Interval pi()
Provides an interval for .
Definition codac2_Interval_impl.h:555
static Interval zero()
Provides an interval for .
Definition codac2_Interval_impl.h:540
double lb() const
Returns the lower bound of this.
Definition codac2_Interval_impl.h:102
static Interval empty()
Provides an empty interval.
Definition codac2_Interval_impl.h:535
static Interval half_pi()
Provides an interval for .
Definition codac2_Interval_impl.h:550
Interval atan2(const Interval &y, const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:140
Interval sqr(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:21