5 #include <blitz/tinyvec-et.h> 9 #ifdef ARRAY_AD_DIAGNOSTIC 10 #define ARRAY_AD_DIAGNOSTIC_MSG std::cerr << "In " << __LINE__ << "\n" 12 #define ARRAY_AD_DIAGNOSTIC_MSG 53 : val(V.val), jac(V.jac), is_const(V.is_const)
61 val.reference(V.val.copy());
62 jac.reference(V.jac.copy());
63 is_const = V.is_const;
82 ArrayAd(
const blitz::Array<T, D>& Val,
const blitz::Array<T, D+1>& Jac,
83 bool Is_const =
false,
bool Force_copy =
false)
84 : val(Force_copy ? Val.
copy() : Val),
85 jac(Force_copy ? Jac.
copy() : Jac), is_const(Is_const)
88 if(jac.extent(D) == 0) {
90 blitz::TinyVector<int, D + 1> s2;
91 for(
int i = 0; i < D; ++i)
92 s2(i) = val.shape()(i);
98 ArrayAd(
const blitz::Array<T, D>& Val,
bool Force_copy =
false)
99 : val(Force_copy ? Val.
copy() : Val), is_const(true)
102 blitz::TinyVector<int, D + 1> s2;
103 for(
int i = 0; i < D; ++i)
104 s2(i) = val.shape()(i);
109 ArrayAd(
const blitz::Array<T, D>& Val,
int nvar,
bool Force_copy =
false)
110 : val(Force_copy ? Val.
copy() : Val), is_const(nvar == 0)
112 blitz::TinyVector<int, D + 1> s2;
113 for(
int i = 0; i < D; ++i)
114 s2(i) = val.shape()(i);
120 ArrayAd() :val(0), jac(0,1), is_const(false) {}
122 : val(n1), jac(n1,
std::max(nvar, 1)), is_const(nvar == 0)
128 : val(n1, n2), jac(n1, n2,
std::max(nvar, 1)), is_const(nvar == 0)
134 : val(n1, n2, n3), jac(n1, n2, n3,
std::max(nvar, 1)),
140 ArrayAd(
int n1,
int n2,
int n3,
int n4,
int nvar)
141 : val(n1, n2, n3, n4), jac(n1, n2, n3, n4,
std::max(nvar, 1)),
147 ArrayAd(
int n1,
int n2,
int n3,
int n4,
int n5,
int nvar)
148 : val(n1, n2, n3, n4, n5), jac(n1, n2, n3, n4, n5,
std::max(nvar, 1)),
154 ArrayAd(
const blitz::TinyVector<int, D>& Shape,
int nvar)
155 : val(Shape), is_const(nvar == 0)
157 blitz::TinyVector<int, D + 1> s2;
158 for(
int i = 0; i < D; ++i)
160 s2(D) = std::max(nvar, 1);
169 blitz::TinyVector<int, D + 1> s2;
170 for(
int i = 0; i < D; ++i)
171 s2(i) = val.shape()(i);
172 s2(D) = std::max(nvar, 1);
175 is_const = (nvar ==0);
177 void resize(
const blitz::TinyVector<int, D>& Shape,
int nvar)
180 is_const = (nvar ==0);
181 blitz::TinyVector<int, D + 1> s2;
182 for(
int i = 0; i < D; ++i)
184 s2(D) = std::max(nvar, 1);
191 val.resize(n1); jac.resize(n1, std::max(nvar, 1));
192 is_const = (nvar == 0);
198 val.resize(n1, n2); jac.resize(n1, n2, std::max(nvar, 1));
199 is_const = (nvar == 0);
203 void resize(
int n1,
int n2,
int n3,
int nvar)
205 val.resize(n1, n2, n3); jac.resize(n1, n2, n3, std::max(nvar, 1));
206 is_const = (nvar == 0);
210 void resize(
int n1,
int n2,
int n3,
int n4,
int nvar)
212 val.resize(n1, n2, n3, n4);
213 jac.resize(n1, n2, n3, n4, std::max(nvar, 1));
214 is_const = (nvar == 0);
218 void resize(
int n1,
int n2,
int n3,
int n4,
int n5,
int nvar)
220 val.resize(n1, n2, n3, n4, n5);
221 jac.resize(n1, n2, n3, n4, n5, std::max(nvar, 1));
222 is_const = (nvar == 0);
232 jac(i1, blitz::Range::all()));
240 jac(i1, i2, blitz::Range::all()));
248 jac(i1, i2, i3, blitz::Range::all()));
256 jac(i1, i2, i3, i4, blitz::Range::all()));
264 jac(i1, i2, i3, i4, i5, blitz::Range::all()));
272 jac(i1, blitz::Range::all()));
280 jac(i1, i2, blitz::Range::all()));
288 jac(i1, i2, i3, blitz::Range::all()));
296 jac(i1, i2, i3, i4, blitz::Range::all()));
304 jac(i1, i2, i3, i4, i5, blitz::Range::all()));
306 const blitz::Array<T, D>&
value()
const {
return val;}
310 return blitz::Array<T, D+1>();
313 blitz::Array<T, D>&
value() {
return val;}
316 blitz::Array<AutoDerivative<T>, D>
to_array()
const 319 blitz::Array<AutoDerivative<T>, D> res(val.shape());
330 blitz::IndexPlaceholder<D> ig;
337 return ArrayAd<T, 1>(val(r1), jac(r1, blitz::Range::all()), is_const);
339 template<
typename T1,
typename T2>
343 (val(r1, r2), jac(r1, r2, blitz::Range::all()), is_const);
345 template<
typename T1,
typename T2,
typename T3>
350 (val(r1, r2, r3), jac(r1, r2, r3, blitz::Range::all()), is_const);
352 template<
typename T1,
typename T2,
typename T3,
typename T4>
357 (val(r1, r2, r3, r4), jac(r1, r2, r3, r4, blitz::Range::all()),
360 template<
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
365 (val(r1, r2, r3, r4, r5), jac(r1, r2, r3, r4, r5, blitz::Range::all()),
368 int rows()
const {
return val.rows();}
369 int cols()
const {
return val.cols();}
370 int depth()
const {
return val.depth();}
373 { val.reference(V.val); jac.reference(V.jac); is_const = V.is_const;}
375 {
return ArrayAd<T,D>(val.copy(), jac.copy(), is_const); }
381 return jac.extent(D);
383 const blitz::TinyVector<int, D>&
shape()
const {
return val.shape(); }
386 { os << V.val <<
"\n" << V.jac <<
"\n";
return os;}
388 { is >> V.val >> V.jac;
return is; }
394 return blitz::all(A.val == this->val) &&
395 blitz::all(A.jac == this->jac) &&
396 A.val.dimensions() == this->val.dimensions() &&
397 A.jac.dimensions() == this->jac.dimensions() &&
398 blitz::all(A.val.shape() == this->val.shape()) &&
399 blitz::all(A.jac.shape() == this->jac.shape());
403 {
return !(A == *
this); }
406 blitz::Array<T, D> val;
407 blitz::Array<T, D + 1> jac;
#define ARRAY_AD_DIAGNOSTIC_MSG
void resize_number_variable(int nvar)
blitz::Array< T, D+1 > & jacobian()
blitz::Array< T, D > & value()
blitz::Array< AutoDerivative< double >, 1 > auto_derivative(const blitz::Array< double, 1 > &Val, const blitz::Array< double, 2 > &Jac)
Utility routine to take value and Jacobian separately and create a blitz::Array<AutoDerivative<double...
ArrayAd(const blitz::Array< T, D > &Val, bool Force_copy=false)
ArrayAd & operator=(const AutoDerivative< T > &V)
bool operator==(const ArrayAd< T, D > &A) const
We define != in terms of this operator.
ArrayAd & operator=(const T &V)
AutoDerivative< T > operator()(int i1, int i2, int i3, int i4) const
ArrayAd(int n1, int n2, int nvar)
AutoDerivative< T > operator()(int i1) const
ArrayAd(int n1, int n2, int n3, int n4, int n5, int nvar)
void resize(int n1, int n2, int nvar)
ArrayAd< T, blitz::SliceInfo< T, T1, T2, T3, T4 >::rank > operator()(T1 r1, T2 r2, T3 r3, T4 r4) const
ArrayAd< T, blitz::SliceInfo< T, T1, T2 >::rank > operator()(T1 r1, T2 r2) const
AutoDerivativeRef< T > operator()(int i1, int i2, int i3, int i4)
void resize(int n1, int n2, int n3, int nvar)
ArrayAd & operator=(const ArrayAd< T, D > &V)
This is the base of the exception hierarchy for Full Physics code.
AutoDerivative< T > operator()(int i1, int i2, int i3, int i4, int i5) const
ArrayAd< T, blitz::SliceInfo< T, T1, T2, T3 >::rank > operator()(T1 r1, T2 r2, T3 r3) const
friend std::istream & operator>>(std::istream &is, ArrayAd< T, D > &V)
const blitz::Array< T, D+1 > jacobian() const
void resize(int n1, int n2, int n3, int n4, int n5, int nvar)
blitz::Array< AutoDerivative< T >, D > to_array() const
Helper class that gives us a reference that we can assign a AutoDerivative to and write into the corr...
void resize(int n1, int n2, int n3, int n4, int nvar)
const Unit A("A", 1.0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0)
AutoDerivativeRef< T > operator()(int i1)
const blitz::Array< T, D > & value() const
void resize(const blitz::TinyVector< int, D > &Shape, int nvar)
AutoDerivative< T > operator()(int i1, int i2, int i3) const
The AutoDerivative<T> works well, and it works with blitz if you create a blitz::Array<AutoDerivative...
There are a number of tools that can be used to do "Automatic Differentiation" (see for example http:...
ArrayAd(int n1, int nvar)
ArrayAd< T, D > copy() const
ArrayAd(const blitz::Array< AutoDerivative< T >, D > &V)
ArrayAd(const ArrayAd< T, D > &V)
const blitz::Array< T, 1 > & gradient() const
Gradient.
AutoDerivative< T > operator()(int i1, int i2) const
int number_variable() const
void resize(int n1, int nvar)
void reference(const ArrayAd< T, D > &V)
AutoDerivativeRef< T > operator()(int i1, int i2, int i3, int i4, int i5)
ArrayAd(int n1, int n2, int n3, int nvar)
ArrayAd(const blitz::TinyVector< int, D > &Shape, int nvar)
Contains classes to abstract away details in various Spurr Radiative Transfer software.
ArrayAd< T, blitz::SliceInfo< T, T1, T2, T3, T4, T5 >::rank > operator()(T1 r1, T2 r2, T3 r3, T4 r4, T5 r5) const
const T & value() const
Convert to type T.
const blitz::TinyVector< int, D > & shape() const
AutoDerivativeRef< T > operator()(int i1, int i2)
ArrayAd< T, 1 > operator()(const blitz::Range &r1) const
AutoDerivativeRef< T > operator()(int i1, int i2, int i3)
ArrayAd & operator=(const blitz::Array< T, D > &V)
ArrayAd(const blitz::Array< T, D > &Val, const blitz::Array< T, D+1 > &Jac, bool Is_const=false, bool Force_copy=false)
bool operator!=(const ArrayAd< T, D > &A) const
double value(const FullPhysics::AutoDerivative< double > &Ad)
ArrayAd(const blitz::Array< T, D > &Val, int nvar, bool Force_copy=false)
ArrayAd(int n1, int n2, int n3, int n4, int nvar)
friend std::ostream & operator<<(std::ostream &os, const ArrayAd< T, D > &V)