9 template <
class T>
class TinyFad<1,T> {
22 void diff(
const size_t ith,
const size_t sz){
27 case 0 : dx0_ = T(1.);
break;
28 default : cout <<
"ith = " << ith <<
" out of definition set" << endl;exit(1);
32 TinyFad(
const T& ind,
const int ini) : n(ini+1), val_(ind) {
36 case 0 : dx0_ = T(1.);
break;
37 default : cout <<
"ini = " << ini <<
" out of definition set" << endl;exit(1);
53 int N()
const {
return n-1;}
58 const T&
d0()
const {
return dx0_;}
59 T&
d0() {
return dx0_;}
64 default : cout <<
"i out of bounds" << endl;exit(1);
67 const T&
dx(
int i)
const {
70 default : cout <<
"i out of bounds" << endl;exit(1);
76 default : cout <<
"i out of bounds" << endl;exit(1);
79 const T&
d(
int i)
const {
82 default : cout <<
"i out of bounds" << endl;exit(1);
116 dx0_ = dx0_ * in.
val_ + val_ * in.
dx0_;
122 if (in.
val_ == 0.)
error(
"TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
145 if ( in == T(0.) )
error(
"TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
184 template <
class L,
class R>
inline 193 tmp.d0() = un.d0() + deux.d0();
200 template <
class L,
class R>
inline 211 tmp.
val() = un.
val() + deux;
216 template <
class L,
class R>
inline 222 template <
class L,
class R>
inline 231 tmp.d0() = un.d0()*deux.
val() + un.
val() * deux.d0();
238 template <
class L,
class R>
inline 247 tmp.d0() = un.d0()*deux;
249 tmp.
val() = un.
val() * deux;
254 template <
class L,
class R>
inline 262 template <
class L,
class R>
inline 271 tmp.d0() = un.d0() - deux.d0();
278 template <
class L,
class R>
inline 287 tmp.d0() -= deux.d0();
289 tmp.
val() = un - deux.
val();
294 template <
class L,
class R>
inline 304 tmp.
val() = un.
val() - deux;
309 template <
class L,
class R>
inline 315 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<1,L> & un, const TinyFad<1,R> & deux), dividing by 0");
319 value_type dval = deux.
val();
321 tmp.d0() = ( un.d0()* deux.
val() - un.
val() * deux.d0() ) / dval / dval ;
323 tmp.
val() = un.
val() / dval;
328 template <
class L,
class R>
inline 334 if (deux.
val() == 0.)
error(
"TinyFad & TinyFad::operator /(const L & un, const TinyFad<1,R> & deux), dividing by 0");
338 value_type dval = deux.
val();
340 tmp.d0() = - un * deux.d0() / dval / dval ;
342 tmp.
val() = un / dval;
347 template <
class L,
class R>
inline 353 if (deux == 0.)
error(
"TinyFad & TinyFad::operator /(const TinyFad<1,L> & un, const R & deux), dividing by 0");
358 tmp.d0() = un.d0() / deux;
360 tmp.
val() = un.
val() / deux;
376 if ( in.
val() <= 0)
error(
"TinyFad log (const TinyFad& in) : zero or negative value");
386 if ( in.
val() < 0. )
error(
"TinyFad<1,T> sqrt (const TinyFad& in) : negative value");
390 if ( in.
val() == T(0.) ){
391 if ( in.
d0() != T(0.) ) test =
false;
394 error(
"TinyFad<1,T> sqrt (const TinyFad& in) : null value");
423 if ( in.
val() == 0)
error(
"TinyFad tan (const TinyFad& in) undiefined in 0.");
426 T cosinus =
cos(in.
val());
427 tmp.
d0() = in.
d0() / cosinus / cosinus;
443 if (un.
val() == 0)
error(
"TinyFad pow (const TinyFad& un, const TinyFad& deux), un = 0. ");
456 tmp.d0() = e*in.
d0()*
pow((
double)in.
val(), (double)e-1);
463 int sign = in.
val() > 0? 1:0;
469 template <
class T> std::ostream& operator << (std::ostream& os, const TinyFad<1,T>& a)
471 os.setf(std::ios::fixed,std::ios::scientific);
473 os << a.
val() <<
" [";
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
TinyFad< 1, typename NumericalTraits< L, R >::promote > operator*(const TinyFad< 1, L > &un, const TinyFad< 1, R > &deux)
TinyFad< 1, T > sin(const TinyFad< 1, T > &in)
void diff(const size_t ith, const size_t sz)
TinyFad< 1, T > sqrt(const TinyFad< 1, T > &in)
AutoPointerMutexArrayInit tmp
TinyFad< 1, T > cos(const TinyFad< 1, T > &in)
TinyFad< 1, typename NumericalTraits< L, R >::promote > operator/(const TinyFad< 1, L > &un, const TinyFad< 1, R > &deux)
TinyFad(const T &ind, const int ini)
TinyFad< 1, T > log(const TinyFad< 1, T > &in)
TinyFad< 1, T > tan(const TinyFad< 1, T > &in)
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
TinyFad< 1, T > exp(const TinyFad< 1, T > &in)
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
const T & dx(int i) const
TinyFad< 1, T > & operator++()
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
TinyFad(const No_Initialization &)
TinyFad< 1, T > abs(const TinyFad< 1, T > &in)
TinyFad(const TinyFad< 1, T > &in)
TinyFad< 1, T > & operator--()
TinyFad< 1, T > operator++(int)
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)
TinyFad< 1, T > operator--(int)
TinyFad< 1, T > operator+(const TinyFad< 1, T > &in)
TinyFad< 1, T > operator-(const TinyFad< 1, T > &in)
TinyFad< 1, T > pow(const TinyFad< 1, T > &in, double e)