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

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

copy paste typos

Thanks to Mu Wang <wangmu0701@…>

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

File size: 5.5 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); }
78#else
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 badouble& a, const pdouble& b)
90{ return ((a - b) < 0); }
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); }
101inline int operator <  ( const pdouble& a, const badouble& b)
102{ return (b > a); }
103#endif
104
105inline adub operator + ( const pdouble& a, const badouble& b)
106{ return (b + a); }
107
108inline adub operator + ( const pdouble& a, double b)
109{ return (b + adub(a)); }
110
111inline adub operator + ( double a, const pdouble& b)
112{ return (a + adub(b)); }
113
114inline adub operator - ( const pdouble& a, const badouble& b)
115{ return ((-b) + a); }
116
117inline adub operator - ( const pdouble& a, double b)
118{ return (adub(a) - b); }
119
120inline adub operator - ( double a, const pdouble& b)
121{ return (a + (-b)); }
122
123inline adub operator * ( const pdouble& a, const badouble& b)
124{ return (b*a); }
125
126inline adub operator * ( const pdouble& a, double b)
127{ return (b * adub(a)); }
128
129inline adub operator * ( double a, const pdouble& b)
130{ return (a * adub(b)); }
131
132inline adub operator / ( const badouble& a, const pdouble& b)
133{ return (a*recipr(b)); }
134
135inline adub operator / ( double a, const pdouble& b)
136{ return (a*recipr(b)); }
137
138inline adub operator / ( const pdouble& a, double b)
139{ return (adub(a)/b); }
140
141inline adub fmax ( const badouble& y, const pdouble& d ) {
142    return (-fmin(-d,-y));
143}
144
145inline adub fmax ( const pdouble& a, const badouble& b)
146{ return fmax(b,a); }
147
148inline adub fmin ( const pdouble& a, const badouble& b)
149{ return fmin(b,a); }
150
151inline adub fmin( const badouble& a, const pdouble& b)
152{ return fmin(a,adub(b)); }
153
154#endif
155
156BEGIN_C_DECLS
157
158/****************************************************************************/
159/* Returns the number of parameters recorded on tape                        */
160/****************************************************************************/
161ADOLC_DLL_EXPORT size_t get_num_param(short tag);
162
163/****************************************************************************/
164/* Overrides the parameters for the next evaluations. This will invalidate  */
165/* the taylor stack, so next reverse call will fail, if not preceeded by a  */
166/* forward call after setting the parameters.                               */
167/****************************************************************************/
168ADOLC_DLL_EXPORT void set_param_vec(short tag, size_t numparam, revreal* paramvec);
169
170END_C_DECLS
171#endif
Note: See TracBrowser for help on using the repository browser.