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

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

Change export binding of functions for Visual Studio

without these there is a compilation error in windows
and undeclared function errors.

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

File size: 5.7 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 pdouble;
25
26ADOLC_DLL_EXPORT pdouble mkparam(double pval);
27ADOLC_DLL_EXPORT pdouble getparam(locint index);
28ADOLC_DLL_EXPORT locint mkparam_idx(double pval);
29
30class ADOLC_DLL_EXPORT pdouble {
31    friend ADOLC_DLL_EXPORT class badouble;
32    friend ADOLC_DLL_EXPORT class adub;
33    friend ADOLC_DLL_EXPORT class adouble;
34    friend ADOLC_DLL_EXPORT class adubref;
35protected:
36    double _val;
37    locint _idx;
38    pdouble(const pdouble&) {
39        fprintf(DIAG_OUT,"ADOL-C error: illegal copy construction of pdouble"
40                " variable\n          ... pdouble objects must never be copied\n");
41        throw logic_error("illegal constructor call, errorcode=-2");
42    }
43    pdouble(void) {
44        fprintf(DIAG_OUT,"ADOL-C error: illegal default construction of pdouble"
45                " variable\n");
46        throw logic_error("illegal constructor call, errorcode=-2");
47    }
48    pdouble(double pval);
49    pdouble(locint index);
50public:
51    friend pdouble mkparam(double pval);
52    friend pdouble getparam(locint index);
53    friend locint mkparam_idx(double pval);
54    operator adub() const;
55
56#define _IN_CLASS_ 1
57#define _IN_PDOUBLE_ 1
58#include <adolc/internal/paramfunc.h>
59#undef _IN_PDOUBLE_
60#undef _IN_CLASS_
61
62    ~pdouble() {}
63};
64
65#ifdef ADOLC_ADVANCED_BRANCHING
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); }
76inline adub operator >= ( const pdouble& a, const badouble& b)
77{ return (b <= a); }
78inline adub operator >  ( const pdouble& a, const badouble& b)
79{ return (b < a); }
80inline adub operator <  ( const pdouble& a, const badouble& b)
81{ return (b > a); }
82#else
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 badouble& a, const pdouble& b)
90{ return ((a - b) >= 0); }
91inline int operator >  ( const badouble& a, const pdouble& b)
92{ return ((a - b) > 0); }
93inline int operator <  ( const badouble& a, const pdouble& b)
94{ return ((a - b) < 0); }
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); }
101inline int operator >= ( const pdouble& a, const badouble& b)
102{ return (b <= a); }
103inline int operator >  ( const pdouble& a, const badouble& b)
104{ return (b < a); }
105inline int operator <  ( const pdouble& a, const badouble& b)
106{ return (b > a); }
107#endif
108
109inline adub operator + ( const pdouble& a, const badouble& b)
110{ return (b + a); }
111
112inline adub operator + ( const pdouble& a, double b)
113{ return (b + adub(a)); }
114
115inline adub operator + ( double a, const pdouble& b)
116{ return (a + adub(b)); }
117
118inline adub operator - ( const pdouble& a, const badouble& b)
119{ return ((-b) + a); }
120
121inline adub operator - ( const pdouble& a, double b)
122{ return (adub(a) - b); }
123
124inline adub operator - ( double a, const pdouble& b)
125{ return (a + (-b)); }
126
127inline adub operator * ( const pdouble& a, const badouble& b)
128{ return (b*a); }
129
130inline adub operator * ( const pdouble& a, double b)
131{ return (b * adub(a)); }
132
133inline adub operator * ( double a, const pdouble& b)
134{ return (a * adub(b)); }
135
136inline adub operator / ( const badouble& a, const pdouble& b)
137{ return (a*recipr(b)); }
138
139inline adub operator / ( double a, const pdouble& b)
140{ return (a*recipr(b)); }
141
142inline adub operator / ( const pdouble& a, double b)
143{ return (adub(a)/b); }
144
145inline adub fmax ( const badouble& y, const pdouble& d ) {
146    return (-fmin(-d,-y));
147}
148
149inline adub fmax ( const pdouble& a, const badouble& b)
150{ return fmax(b,a); }
151
152inline adub fmin ( const pdouble& a, const badouble& b)
153{ return fmin(b,a); }
154
155inline adub fmin( const badouble& a, const pdouble& b)
156{ return fmin(a,adub(b)); }
157
158#endif
159
160BEGIN_C_DECLS
161
162/****************************************************************************/
163/* Returns the number of parameters recorded on tape                        */
164/****************************************************************************/
165ADOLC_DLL_EXPORT size_t get_num_param(short tag);
166
167/****************************************************************************/
168/* Overrides the parameters for the next evaluations. This will invalidate  */
169/* the taylor stack, so next reverse call will fail, if not preceeded by a  */
170/* forward call after setting the parameters.                               */
171/****************************************************************************/
172ADOLC_DLL_EXPORT void set_param_vec(short tag, size_t numparam, revreal* paramvec);
173
174END_C_DECLS
175#endif
Note: See TracBrowser for help on using the repository browser.