43 template <
int Num,
class T =
float>
class TinyFad {
56 TinyFad(
const T& ind,
const int ini);
67 void diff(
const int ith,
const int n);
70 int N()
const {
return n-1;}
72 const T&
val()
const {
return val_;}
73 T&
val() {
return val_;}
76 const T&
d(
int i)
const {
return df_[i];}
78 const T&
dx(
int i)
const;
104 template <
int Num,
class T>
inline 107 #ifdef PZDEBUG_TINYFAD 108 std::cout <<
"TinyFad::TinyFad(const T& ind, const int ini), ind = " << ind <<
", ini = " << ini << std::endl;
110 if ( ini >= 2 )
error(
"control number ini, out of bound ");
112 for (
int i=0; i<Num; ++i)
118 template <
int Num,
class T>
inline 121 #ifdef PZDEBUG_TINYFAD 122 std::cout <<
"TinyFad::TinyFad()" << std::endl;
124 for (
int i=0; i<Num; ++i)
128 template <
int Num,
class T>
inline 131 #ifdef PZDEBUG_TINYFAD 132 std::cout <<
"TinyFad::TinyFad(const T& in)" << std::endl;
134 for (
int i=0; i<Num; ++i)
138 template <
int Num,
class T>
inline 141 #ifdef PZDEBUG_TINYFAD 142 std::cout <<
"TinyFad::TinyFad(const TinyFad& in)" << std::endl;
145 for (
int i=0; i<Num; ++i)
149 template <
int Num,
class T>
inline 152 #ifdef PZDEBUG_TINYFAD 153 std::cout <<
"TinyFad::~TinyFad()" << std::endl;
157 template <
int Num,
class T>
inline 166 template <
int Num,
class T>
168 if ( (i<0) || (i>=Num ) ) {
169 std::cerr <<
"i = " << i << std::endl;
170 error(
"df_, partial derivative undefined");
176 template <
int Num,
class T>
178 if ( (i<0) || (i>=Num ) ) {
179 std::cerr <<
"i = " << i << std::endl;
180 error(
"df_, partial derivative undefined");
188 template <
int Num,
class T>
inline 192 if (n)
error(
"TinyFad & TinyFad::operator = (const TinyFad & in), you do not change the value of control");
197 for (
int i=0; i<Num; ++i)
208 if (n)
error(
"TinyFad & TinyFad::operator = (const T & in), you do not change the value of control");
212 for (
int i=0; i<Num; i++)
222 if (n)
error(
"TinyFad & TinyFad::operator += (const TinyFad & in), you do not change the value of control");
225 for (
int i=0; i< Num; i++)
226 df_[i] += in.
df_[i] ;
236 if (n)
error(
"TinyFad & TinyFad::operator -= (const TinyFad & in), you do not change the value of control");
239 for (
int i=0; i< Num; i++)
240 df_[i] -= in.
df_[i] ;
250 if (n)
error(
"TinyFad & TinyFad::operator *= (const TinyFad & in), you do not change the value of control");
253 for (
int i=0; i< Num; i++)
254 df_[i] = df_[i] * in.
val_ + val_ * in.
df_[i];
264 if (n)
error(
"TinyFad & TinyFad::operator /= (const TinyFad & in), you do not change the value of control");
267 if (in.
val_ == 0.)
error(
"TinyFad & TinyFad::operator /= (const TinyFad & in), dividing by 0");
269 for (
int i=0; i< Num; i++)
280 if (n)
error(
"TinyFad<Num,T> & TinyFad<Num,T>::operator += (const T & in), you do not change the value of control");
291 if (n)
error(
"TinyFad & TinyFad::operator -= (const T & in), you do not change the value of control");
302 if (n)
error(
"TinyFad & TinyFad::operator *= (const T & in), you do not change the value of control");
307 for (
int i=0; i< Num; i++)
316 if (n)
error(
"TinyFad & TinyFad::operator /= (const T & in), you do not change the value of control");
319 if (in == 0.)
error(
"TinyFad & TinyFad::operator /= (const T & in), dividing by 0");
323 for (
int i=0; i< Num; i++)
331 template <
int Num,
class T>
inline 339 template <
int Num,
class T>
inline 347 template <
int Num,
class T>
inline 354 template <
int Num,
class T>
inline 378 template <
int Num,
class T> std::ostream& operator << (std::ostream& os, const TinyFad<Num,T>& a)
380 os.setf(std::ios::fixed,std::ios::floatfield);
382 os << a.val() <<
" [";
384 for (
int i=0; i< Num; i++) {
TinyFad< Num, T > operator+(const TinyFad< Num, T > &in)
TinyFad< Num, T > & operator-=(const TinyFad< Num, T > &in)
TinyFad(const No_Initialization &)
TPZVec< T > & operator-=(TPZVec< T > &a, const TPZVec< T > &b)
substracts two vectors
AutoPointerMutexArrayInit tmp
const T & dx(int i) const
void diff(const int ith, const int n)
expr_ dx(i) *cos(expr_.val())
TinyFad< Num, T > operator-(const TinyFad< Num, T > &in)
TinyFad< Num, T > & operator=(const TinyFad< Num, T > &in)
TinyFad< Num, T > & operator+=(const TinyFad< Num, T > &in)
TinyFad< Num, T > & operator--()
TinyFad< Num, T > & operator*=(const TinyFad< Num, T > &in)
TinyFad< Num, T > & operator++()
TinyFad< Num, T > & operator/=(const TinyFad< Num, T > &in)