source: trunk/ADOL-C/include/adolc/param.h @ 566

Last change on this file since 566 was 566, checked in by kulshres, 5 years ago

More Windows compilation fixes

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

File size: 5.6 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     param.h
4 Revision: $Id$
5 Contents: class for parameter dependent functions
6 
7 Copyright (c) Kshitij Kulshreshtha
8
9 This file is part of ADOL-C. This software is provided as open source.
10 Any use, reproduction, or distribution of the software constitutes
11 recipient's acceptance of the terms of the accompanying license file.
12
13----------------------------------------------------------------------------*/
14
15#if !defined(ADOLC_PARAM_H)
16#define ADOLC_PARAM_H 1
17#if defined(__cplusplus)
18
19#include <cstdio>
20#include <stdexcept>
21
22using std::logic_error;
23
24class ADOLC_DLL_EXPORT pdouble {
25    friend ADOLC_DLL_EXPORT class badouble;
26    friend ADOLC_DLL_EXPORT class adub;
27    friend ADOLC_DLL_EXPORT class adouble;
28    friend ADOLC_DLL_EXPORT class adubref;
29protected:
30    double _val;
31    locint _idx;
32    pdouble(const pdouble&) {
33        fprintf(DIAG_OUT,"ADOL-C error: illegal copy construction of pdouble"
34                " variable\n          ... pdouble objects must never be copied\n");
35        throw logic_error("illegal constructor call, errorcode=-2");
36    }
37    pdouble(void) {
38        fprintf(DIAG_OUT,"ADOL-C error: illegal default construction of pdouble"
39                " variable\n");
40        throw logic_error("illegal constructor call, errorcode=-2");
41    }
42    pdouble(double pval);
43    pdouble(locint index);
44public:
45    friend ADOLC_DLL_EXPORT pdouble mkparam(double pval);
46    friend ADOLC_DLL_EXPORT pdouble getparam(locint index);
47    friend ADOLC_DLL_EXPORT locint mkparam_idx(double pval);
48    operator adub() const;
49
50#define _IN_CLASS_ 1
51#define _IN_PDOUBLE_ 1
52#include <adolc/internal/paramfunc.h>
53#undef _IN_PDOUBLE_
54#undef _IN_CLASS_
55
56    ~pdouble() {}
57};
58
59#ifdef ADOLC_ADVANCED_BRANCHING
60inline adub operator != ( const pdouble& a, const badouble& b)
61{ return (b != a); }
62inline adub operator == ( const pdouble& a, const badouble& b)
63{ return (b == a); }
64inline adub operator <= ( const pdouble& a, const badouble& b)
65{ return (b >= a); }
66inline adub operator <= ( const pdouble& a, const badouble& b)
67{ return (b >= a); }
68inline adub operator <= ( const pdouble& a, const badouble& b)
69{ return (b >= a); }
70inline adub operator >= ( const pdouble& a, const badouble& b)
71{ return (b <= a); }
72inline adub operator >  ( const pdouble& a, const badouble& b)
73{ return (b < a); }
74inline adub operator <  ( const pdouble& a, const badouble& b)
75{ return (b > a); }
76#else
77inline int operator != ( const badouble& a, const pdouble& b) 
78{ return ((a - b) != 0); }
79inline int operator == ( const badouble& a, const pdouble& b) 
80{ return ((a - b) == 0); }
81inline int operator <= ( const badouble& a, const pdouble& b)
82{ return ((a - b) <= 0); }
83inline int operator >= ( const badouble& a, const pdouble& b)
84{ return ((a - b) >= 0); }
85inline int operator >  ( const badouble& a, const pdouble& b)
86{ return ((a - b) > 0); }
87inline int operator <  ( const badouble& a, const pdouble& b)
88{ return ((a - b) < 0); }
89inline int operator != ( const pdouble& a, const badouble& b)
90{ return (b != a); }
91inline int operator == ( const pdouble& a, const badouble& b)
92{ return (b == a); }
93inline int operator <= ( const pdouble& a, const badouble& b)
94{ return (b >= a); }
95inline int operator >= ( const pdouble& a, const badouble& b)
96{ return (b <= a); }
97inline int operator >  ( const pdouble& a, const badouble& b)
98{ return (b < a); }
99inline int operator <  ( const pdouble& a, const badouble& b)
100{ return (b > a); }
101#endif
102
103inline adub operator + ( const pdouble& a, const badouble& b)
104{ return (b + a); }
105
106inline adub operator + ( const pdouble& a, double b)
107{ return (b + adub(a)); }
108
109inline adub operator + ( double a, const pdouble& b)
110{ return (a + adub(b)); }
111
112inline adub operator - ( const pdouble& a, const badouble& b)
113{ return ((-b) + a); }
114
115inline adub operator - ( const pdouble& a, double b)
116{ return (adub(a) - b); }
117
118inline adub operator - ( double a, const pdouble& b)
119{ return (a + (-b)); }
120
121inline adub operator * ( const pdouble& a, const badouble& b)
122{ return (b*a); }
123
124inline adub operator * ( const pdouble& a, double b)
125{ return (b * adub(a)); }
126
127inline adub operator * ( double a, const pdouble& b)
128{ return (a * adub(b)); }
129
130inline adub operator / ( const badouble& a, const pdouble& b)
131{ return (a*recipr(b)); }
132
133inline adub operator / ( double a, const pdouble& b)
134{ return (a*recipr(b)); }
135
136inline adub operator / ( const pdouble& a, double b)
137{ return (adub(a)/b); }
138
139inline adub fmax ( const badouble& y, const pdouble& d ) {
140    return (-fmin(-d,-y));
141}
142
143inline adub fmax ( const pdouble& a, const badouble& b)
144{ return fmax(b,a); }
145
146inline adub fmin ( const pdouble& a, const badouble& b)
147{ return fmin(b,a); }
148
149inline adub fmin( const badouble& a, const pdouble& b)
150{ return fmin(a,adub(b)); }
151
152#endif
153
154BEGIN_C_DECLS
155
156/****************************************************************************/
157/* Returns the number of parameters recorded on tape                        */
158/****************************************************************************/
159ADOLC_DLL_EXPORT size_t get_num_param(short tag);
160
161/****************************************************************************/
162/* Overrides the parameters for the next evaluations. This will invalidate  */
163/* the taylor stack, so next reverse call will fail, if not preceeded by a  */
164/* forward call after setting the parameters.                               */
165/****************************************************************************/
166ADOLC_DLL_EXPORT void set_param_vec(short tag, size_t numparam, revreal* paramvec);
167
168END_C_DECLS
169#endif
Note: See TracBrowser for help on using the repository browser.