1 /*----------------------------------------------------------------------------
2  ADOL-C -- Automatic Differentiation by Overloading in C++
3  File:     adouble.cpp
4  Revision: $Id$
5  Contents: adouble_tl.cpp contains that definitions of procedures used to
6            define various tapeless adouble operations.
7            These operations actually have two purposes.
8            The first purpose is to actual compute the function, just as
9            the same code written for double precision (single precision -
10            complex - interval) arithmetic would.  The second purpose is
11            to compute directional derivatives in forward mode of
12 	   automatic differentiation.
13 
14  Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz,
15                Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel,
16                Benjamin Letschert, Benjamin Jurgelucks
17 
18  This file is part of ADOL-C. This software is provided as open source.
19  Any use, reproduction, or distribution of the software constitutes
20  recipient's acceptance of the terms of the accompanying license file.
21 
22 ----------------------------------------------------------------------------*/
23 
24 #include <adolc/adtl_hov.h>
25 #include <cmath>
26 #include <iostream>
27 #include <limits>
28 #include "dvlparms.h"
29 
30 using std::cout;
31 
32 extern "C" void adolc_exit(int errorcode, const char *what, const char* function, const char *file, int line);
33 
34 namespace adtl_hov {
35 
36 
37 size_t adouble::numDir = 1;
38 size_t adouble::degree = 1;
39 
40 #ifdef USE_ADTL_REFCOUNTING
41 size_t refcounter::refcnt = 0;
42 #endif
43 
44 
45 /*
46 #if USE_BOOST_POOL
47 boost::pool<boost::default_user_allocator_new_delete>* adouble::advalpool = new
48 boost::pool<boost::default_user_allocator_new_delete>((adouble::numDir+1) * sizeof(double), 32, 10000);
49 #endif
50 */
51 /*******************  i/o operations  ***************************************/
operator <<(ostream & out,const adouble & a)52 ostream& operator << ( ostream& out, const adouble& a) {
53 	out << "Value: " << a.val;
54 	out << " ADValues (" << adouble::numDir << "): ";
55 	FOR_I_EQ_0_LT_NUMDIR
56 	    out << a.ADVAL_I << " ";
57 	out << "(a)";
58     return out;
59 }
60 
operator >>(istream & in,adouble & a)61 istream& operator >> ( istream& in, adouble& a) {
62 	char c;
63 	do in >> c;
64 	while (c!=':' && !in.eof());
65 	in >> a.val;
66 	unsigned int num;
67 	do in >> c;
68 	while (c!='(' && !in.eof());
69 	in >> num;
70 	if (num>adouble::numDir)
71 	{
72 	    cout << "ADOL-C error: to many directions in input\n";
73 	    adolc_exit(-1,"",__func__,__FILE__,__LINE__);
74 	}
75 	do in >> c;
76 	while (c!=':' && !in.eof());
77 	FOR_I_EQ_0_LT_NUMDIR
78 	    in >> a.ADVAL_I;
79 	do in >> c;
80 	while (c!=')' && !in.eof());
81 	return in;
82 }
83 
84 }
85