/usr/include/adolc/adouble.h is in libadolc-dev 2.5.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | /* ---------------------------------------------------------------------------
ADOL-C -- Automatic Differentiation by Overloading in C++
Revision: $Id: adouble.h 527 2014-07-15 14:09:31Z kulshres $
Contents: adouble.h contains the basis for the class of adouble
included here are all the possible functions defined on
the adouble class. Notice that, as opposed to ealier versions,
both the class adub and the class adouble are derived from a base
class (badouble). See below for further explanation.
Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz,
Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel,
Benjamin Letschert Kshitij Kulshreshtha
This file is part of ADOL-C. This software is provided as open source.
Any use, reproduction, or distribution of the software constitutes
recipient's acceptance of the terms of the accompanying license file.
---------------------------------------------------------------------------*/
#if !defined(ADOLC_ADOUBLE_H)
#define ADOLC_ADOUBLE_H 1
/****************************************************************************/
/* THIS FILE IS C++ */
#ifdef __cplusplus
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <stdexcept>
using std::cout;
using std::cin;
using std::cerr;
using std::ostream;
using std::istream;
using std::logic_error;
#include <adolc/common.h>
/* NOTICE: There are automatic includes at the end of this file! */
/****************************************************************************/
/* FORWARD DECLARATIONS (TAPES) */
/*--------------------------------------------------------------------------*/
class adouble;
class adub;
class badouble;
/*--------------------------------------------------------------------------*/
void ADOLC_DLL_EXPORT condassign( double &res, const double &cond,
const double &arg1, const double &arg2 );
void ADOLC_DLL_EXPORT condassign( double &res, const double &cond,
const double &arg );
/****************************************************************************/
/* CLASS BADOUBLE */
/**
The class badouble contains the basic definitions for
the arithmetic operations, comparisons, etc.
This is a basic class from which the adub and adouble are
derived. Notice that the constructors/destructors for
the class badouble are of the trivial variety. This is the
main difference among badoubles, adubs, and adoubles.
*/
class ADOLC_DLL_EXPORT badouble {
protected:
locint location;
badouble( void ) {};
// must be public when using gcc >= 3.4 ( problems with value() )
// (see GCC 3.4 Release Series - Changes, New Features, and Fixes)
//
// badouble( const badouble& a ) {location = a.location;};
explicit badouble( locint lo ) {
location = lo;
isInit = true;
};
bool isInit; // marker if the badouble is properly initialized
public:
/*--------------------------------------------------------------------------*/
badouble( const badouble& a ) {}; /* ctor */
inline locint loc( void ) const; /* Helpful stuff */
/*------------------------------------------------------------------------*/
badouble& operator >>= ( double& ); /* Assignments */
badouble& operator <<= ( double );
void declareIndependent ();
void declareDependent ();
badouble& operator = ( double );
badouble& operator = ( const badouble& );
badouble& operator = ( const adub& );
double getValue() const;
inline double value() const {
return getValue();
}
void setValue ( const double );
/* badouble& operator = ( const adouble& );
!!! olvo 991210: was the same as badouble-assignment */
/*--------------------------------------------------------------------------*/
friend ADOLC_DLL_EXPORT std::ostream& operator << ( std::ostream&, const badouble& ); /* IO friends */
friend ADOLC_DLL_EXPORT std::istream& operator >> ( std::istream&, const badouble& );
/*------------------------------------------------------------------------*/
badouble& operator += ( double ); /* Operation + Assignment */
badouble& operator += ( const badouble& );
badouble& operator -= ( double y );
badouble& operator -= ( const badouble& );
badouble& operator *= ( double );
badouble& operator *= ( const badouble& );
badouble& operator /= ( double );
badouble& operator /= ( const badouble& );
/* olvo 991122 n2l: new special op_codes */
badouble& operator += ( const adub& );
badouble& operator -= ( const adub& );
/*--------------------------------------------------------------------------*/
/* Comparison (friends) */
#if defined(ADOLC_ADVANCED_BRANCHING)
friend ADOLC_DLL_EXPORT adub operator != ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator == ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator <= ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator >= ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator > ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator < ( const badouble&, const badouble& );
#else
inline friend int operator != ( const badouble&, const badouble& );
inline friend int operator == ( const badouble&, const badouble& );
inline friend int operator <= ( const badouble&, const badouble& );
inline friend int operator >= ( const badouble&, const badouble& );
inline friend int operator > ( const badouble&, const badouble& );
inline friend int operator < ( const badouble&, const badouble& );
#endif
inline friend int operator != ( double, const badouble& );
friend ADOLC_DLL_EXPORT int operator != ( const badouble&, double );
inline friend int operator == ( double, const badouble& );
friend ADOLC_DLL_EXPORT int operator == ( const badouble&, double );
inline friend int operator <= ( double, const badouble& );
friend ADOLC_DLL_EXPORT int operator <= ( const badouble&, double );
inline friend int operator >= ( double, const badouble& );
friend ADOLC_DLL_EXPORT int operator >= ( const badouble&, double );
inline friend int operator > ( double, const badouble& );
friend ADOLC_DLL_EXPORT int operator > ( const badouble&, double );
inline friend int operator < ( double, const badouble& );
friend ADOLC_DLL_EXPORT int operator < ( const badouble&, double );
/*--------------------------------------------------------------------------*/
/* sign operators (friends) */
friend ADOLC_DLL_EXPORT adub operator + ( const badouble& x );
friend ADOLC_DLL_EXPORT adub operator - ( const badouble& x );
/*--------------------------------------------------------------------------*/
/* binary operators (friends) */
friend ADOLC_DLL_EXPORT adub operator + ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator + ( double, const badouble& );
friend ADOLC_DLL_EXPORT adub operator + ( const badouble&, double );
friend ADOLC_DLL_EXPORT adub operator - ( const badouble&, const badouble& );
inline friend adub operator - ( const badouble&, double );
friend ADOLC_DLL_EXPORT adub operator - ( double, const badouble& );
friend ADOLC_DLL_EXPORT adub operator * ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator * ( double, const badouble& );
inline friend adub operator * ( const badouble&, double );
inline friend adub operator / ( const badouble&, double );
friend ADOLC_DLL_EXPORT adub operator / ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator / ( double, const badouble& );
/*--------------------------------------------------------------------------*/
/* unary operators (friends) */
friend ADOLC_DLL_EXPORT adub exp ( const badouble& );
friend ADOLC_DLL_EXPORT adub log ( const badouble& );
friend ADOLC_DLL_EXPORT adub sqrt ( const badouble& );
friend ADOLC_DLL_EXPORT adub sin ( const badouble& );
friend ADOLC_DLL_EXPORT adub cos ( const badouble& );
friend ADOLC_DLL_EXPORT adub tan ( const badouble& );
friend ADOLC_DLL_EXPORT adub asin ( const badouble& );
friend ADOLC_DLL_EXPORT adub acos ( const badouble& );
friend ADOLC_DLL_EXPORT adub atan ( const badouble& );
/*--------------------------------------------------------------------------*/
/* special operators (friends) */
friend ADOLC_DLL_EXPORT adouble atan2 ( const badouble&, const badouble& );
/* no internal use of condassign: */
friend ADOLC_DLL_EXPORT adub pow ( const badouble&, double );
/* uses condassign internally */
friend ADOLC_DLL_EXPORT adouble pow ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adouble pow ( double, const badouble& );
friend ADOLC_DLL_EXPORT adub log10 ( const badouble& );
/* User defined version of logarithm to test extend_quad macro */
friend ADOLC_DLL_EXPORT adouble myquad( const badouble& );
/*--------------------------------------------------------------------------*/
/* Additional ANSI C standard Math functions Added by DWJ on 8/6/90 */
friend ADOLC_DLL_EXPORT adub sinh ( const badouble& );
friend ADOLC_DLL_EXPORT adub cosh ( const badouble& );
friend ADOLC_DLL_EXPORT adub tanh ( const badouble& );
#if defined(ATRIG_ERF)
friend ADOLC_DLL_EXPORT adub asinh ( const badouble& );
friend ADOLC_DLL_EXPORT adub acosh ( const badouble& );
friend ADOLC_DLL_EXPORT adub atanh ( const badouble& );
#endif
friend ADOLC_DLL_EXPORT adub fabs ( const badouble& );
friend ADOLC_DLL_EXPORT adub ceil ( const badouble& );
friend ADOLC_DLL_EXPORT adub floor ( const badouble& );
friend ADOLC_DLL_EXPORT adub fmax ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub fmax ( double, const badouble& );
friend ADOLC_DLL_EXPORT adub fmax ( const badouble&, double );
friend ADOLC_DLL_EXPORT adub fmin ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub fmin ( double, const badouble& );
friend ADOLC_DLL_EXPORT adub fmin ( const badouble&, double );
friend ADOLC_DLL_EXPORT adub ldexp ( const badouble&, int );
friend ADOLC_DLL_EXPORT adub frexp ( const badouble&, int* );
friend ADOLC_DLL_EXPORT adub erf ( const badouble& );
/*--------------------------------------------------------------------------*/
/* Conditionals */
friend ADOLC_DLL_EXPORT void condassign( adouble &res, const badouble &cond,
const badouble &arg1, const badouble &arg2 );
friend ADOLC_DLL_EXPORT void condassign( adouble &res, const badouble &cond,
const badouble &arg );
};
/****************************************************************************/
/* CLASS ADUB */
/*
The class Adub
---- Basically used as a temporary result. The address for an
adub is usually generated within an operation. That address
is "freed" when the adub goes out of scope (at destruction time).
---- operates just like a badouble, but it has a destructor defined for it.
*/
class ADOLC_DLL_EXPORT adub:public badouble {
friend ADOLC_DLL_EXPORT class adouble;
friend ADOLC_DLL_EXPORT class advector;
friend ADOLC_DLL_EXPORT class adubref;
friend ADOLC_DLL_EXPORT adub* adubp_from_adub(const adub&);
adub( adub const &) {
isInit = false;
fprintf(DIAG_OUT,"ADOL-C error: illegal copy construction of adub"
" variable\n ... adub objects must never be copied\n");
throw logic_error("illegal constructor call, errorcode=-2");
}
adub( void ) {
isInit = false;
fprintf(DIAG_OUT,"ADOL-C error: illegal default construction of adub"
" variable\n");
throw logic_error("illegal constructor call, errorcode=-2");
}
explicit adub( double ) {
isInit = false;
fprintf(DIAG_OUT,"ADOL-C error: illegal construction of adub variable"
" from double\n");
throw logic_error("illegal constructor call, errorcode=-2");
}
protected:
/* this is the only logically legal constructor, which can be called by
* friend classes and functions
*/
adub( locint lo ) : badouble(lo) {}
public:
/*--------------------------------------------------------------------------*/
/* Comparison (friends) */
#if defined(ADOLC_ADVANCED_BRANCHING)
friend ADOLC_DLL_EXPORT adub operator != ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator == ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator <= ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator >= ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator < ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator > ( const badouble&, const badouble& );
#endif
/*--------------------------------------------------------------------------*/
/* sign operators (friends) */
friend ADOLC_DLL_EXPORT adub operator + ( const badouble& x );
friend ADOLC_DLL_EXPORT adub operator - ( const badouble& x );
/*--------------------------------------------------------------------------*/
/* binary operators (friends) */
friend ADOLC_DLL_EXPORT adub operator + ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator + ( double, const badouble& );
friend ADOLC_DLL_EXPORT adub operator + ( const badouble&, double );
friend ADOLC_DLL_EXPORT adub operator - ( const badouble&, const badouble& );
inline friend adub operator - ( const badouble&, double );
friend ADOLC_DLL_EXPORT adub operator - ( double, const badouble& );
friend ADOLC_DLL_EXPORT adub operator * ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator * ( double, const badouble& );
inline friend adub operator * ( const badouble&, double );
inline friend adub operator / ( const badouble&, double );
friend ADOLC_DLL_EXPORT adub operator / ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub operator / ( double, const badouble& );
/*--------------------------------------------------------------------------*/
/* unary operators (friends) */
friend ADOLC_DLL_EXPORT adub exp ( const badouble& );
friend ADOLC_DLL_EXPORT adub log ( const badouble& );
friend ADOLC_DLL_EXPORT adub sqrt ( const badouble& );
friend ADOLC_DLL_EXPORT adub sin ( const badouble& );
friend ADOLC_DLL_EXPORT adub cos ( const badouble& );
friend ADOLC_DLL_EXPORT adub tan ( const badouble& );
friend ADOLC_DLL_EXPORT adub asin ( const badouble& );
friend ADOLC_DLL_EXPORT adub acos ( const badouble& );
friend ADOLC_DLL_EXPORT adub atan ( const badouble& );
/*--------------------------------------------------------------------------*/
/* special operators (friends) */
/* no internal use of condassign: */
friend ADOLC_DLL_EXPORT adub pow ( const badouble&, double );
friend ADOLC_DLL_EXPORT adub log10 ( const badouble& );
/*--------------------------------------------------------------------------*/
/* Additional ANSI C standard Math functions Added by DWJ on 8/6/90 */
friend ADOLC_DLL_EXPORT adub sinh ( const badouble& );
friend ADOLC_DLL_EXPORT adub cosh ( const badouble& );
friend ADOLC_DLL_EXPORT adub tanh ( const badouble& );
#if defined(ATRIG_ERF)
friend ADOLC_DLL_EXPORT adub asinh ( const badouble& );
friend ADOLC_DLL_EXPORT adub acosh ( const badouble& );
friend ADOLC_DLL_EXPORT adub atanh ( const badouble& );
#endif
friend ADOLC_DLL_EXPORT adub fabs ( const badouble& );
friend ADOLC_DLL_EXPORT adub ceil ( const badouble& );
friend ADOLC_DLL_EXPORT adub floor ( const badouble& );
friend ADOLC_DLL_EXPORT adub fmax ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub fmax ( double, const badouble& );
friend ADOLC_DLL_EXPORT adub fmax ( const badouble&, double );
friend ADOLC_DLL_EXPORT adub fmin ( const badouble&, const badouble& );
friend ADOLC_DLL_EXPORT adub fmin ( double, const badouble& );
friend ADOLC_DLL_EXPORT adub fmin ( const badouble&, double );
friend ADOLC_DLL_EXPORT adub ldexp ( const badouble&, int );
friend ADOLC_DLL_EXPORT adub frexp ( const badouble&, int* );
friend ADOLC_DLL_EXPORT adub erf ( const badouble& );
~adub();
};
/****************************************************************************/
/* CLASS ADOUBLE */
/*
The class adouble.
---Derived from badouble. Contains the standard constructors/destructors.
---At construction, it is given a new address, and at destruction, that
address is freed.
*/
class ADOLC_DLL_EXPORT adouble:public badouble {
friend ADOLC_DLL_EXPORT class advector;
protected:
void initInternal(void); // Init for late initialization
public:
adouble( const adub& );
adouble( const adouble& );
adouble( void );
adouble( double );
/* adub prevents postfix operators to occur on the left
side of an assignment which would not work */
adub operator++( int );
adub operator--( int );
badouble& operator++( void );
badouble& operator--( void );
/* inline double value(); */
~adouble();
adouble& operator = ( double );
adouble& operator = ( const badouble& );
adouble& operator = ( const adouble& );
adouble& operator = ( const adub& );
inline locint loc(void) const;
};
/****************************************************************************/
/* INLINE DEFINITIONS */
/*--------------------------------------------------------------------------*/
inline locint badouble::loc( void ) const {
return location;
}
inline locint adouble::loc( void ) const {
const_cast<adouble*>(this)->initInternal();
return location;
}
/*--------------------------------------------------------------------------*/
/* Comparison */
#if !defined(ADOLC_ADVANCED_BRANCHING)
inline int operator != ( const badouble& u, const badouble& v ) {
return (u-v != 0);
}
inline int operator == ( const badouble& u, const badouble& v ) {
return (u-v == 0);
}
inline int operator <= ( const badouble& u, const badouble& v ) {
return (u-v <= 0);
}
inline int operator >= ( const badouble& u, const badouble& v ) {
return (u-v >= 0);
}
inline int operator > ( const badouble& u, const badouble& v ) {
return (u-v > 0);
}
inline int operator < ( const badouble& u, const badouble& v ) {
return (u-v < 0);
}
#endif
inline int operator != ( double coval, const badouble& v) {
if (coval)
return (-coval+v != 0);
else
return (v != 0);
}
inline int operator == ( double coval, const badouble& v) {
if (coval)
return (-coval+v == 0);
else
return (v == 0);
}
inline int operator <= ( double coval, const badouble& v ) {
if (coval)
return (-coval+v >= 0);
else
return (v >= 0);
}
inline int operator >= ( double coval, const badouble& v ) {
if (coval)
return (-coval+v <= 0);
else
return (v <= 0);
}
inline int operator > ( double coval, const badouble& v ) {
if (coval)
return (-coval+v < 0);
else
return (v < 0);
}
inline int operator < ( double coval, const badouble& v ) {
if (coval)
return (-coval+v > 0);
else
return (v > 0);
}
/*--------------------------------------------------------------------------*/
/* Subtract a floating point from an adouble */
inline adub operator - ( const badouble& x , double coval ) {
return (-coval) + x;
}
/*--------------------------------------------------------------------------*/
/* Multiply an adouble by a floating point */
inline adub operator * (const badouble& x, double coval) {
return coval * x;
}
/*--------------------------------------------------------------------------*/
/* Divide an adouble by a floating point */
inline adub operator / (const badouble& x, double coval) {
return (1.0/coval) * x;
}
/****************************************************************************/
/* THAT'S ALL*/
#endif /* __cplusplus */
#endif /* ADOLC_ADOUBLE_H */
|