source: trunk/ADOL-C/include/adolc/advector.h @ 407

Last change on this file since 407 was 394, checked in by kulshres, 7 years ago

DLL-Exporting fixes

std::vector cannot be dll-exported, so we cannot export our advector
as a class. Instead we export all the members other than std::vector

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

File size: 5.0 KB
Line 
1/* ---------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3
4 Revision: $Id$
5 Contents: advector.h contains a vector<adouble> implementation
6           that is able to trace subscripting operations.
7
8 Copyright (c) Kshitij Kulshreshtha
9
10 This file is part of ADOL-C. This software is provided as open source.
11 Any use, reproduction, or distribution of the software constitutes
12 recipient's acceptance of the terms of the accompanying license file.
13
14---------------------------------------------------------------------------*/
15
16#if !defined(ADOLC_ADVECTOR_H)
17#define ADOLC_ADVECTOR_H 1
18
19/****************************************************************************/
20/*                                                         THIS FILE IS C++ */
21#ifdef __cplusplus
22#include <vector>
23
24#include <adolc/adouble.h>
25
26/****************************************************************************/
27/*                                           THIS IS ONLY FOR TAPED VERSION */
28#if !defined(TAPELESS)
29
30class advector;
31class adubref;
32
33class ADOLC_DLL_EXPORT adubref {
34    /* This class is supposed to be used only when an advector subscript
35     * occurs as an lvalue somewhere. What we need to do is read the location
36     * of the referenced adouble out of store[location] and perform
37     * operations with this refloc. This means that the tape needs new
38     * opcodes (ref_assign_* /ref_eq_* / ref_{incr,decr}_a) for each of
39     * these operations, most of the code  will simply be copied from
40     * adouble class, since the operation is really the same except for
41     * the part where the refloc is read from store[location].
42     * Reverse mode is also straightforward the same way.
43     *
44     * Convert to a new adub as soon as used as rvalue, this is why adubref
45     * is not a child of badouble, since it should never occur as rvalue.
46     */
47    friend ADOLC_DLL_EXPORT class adub;
48    friend ADOLC_DLL_EXPORT class advector;
49protected:
50    locint location;
51    locint refloc;
52    explicit adubref( locint lo, locint ref );
53    explicit adubref( void ) {
54        fprintf(DIAG_OUT,"ADOL-C error: illegal default construction of adubref"
55                " variable\n");
56        exit(-2);
57    }
58    explicit adubref( double ) {
59        fprintf(DIAG_OUT,"ADOL-C error: illegal  construction of adubref"
60                " variable from double\n");
61        exit(-2);
62    }
63    explicit adubref( const badouble& ) {
64        fprintf(DIAG_OUT,"ADOL-C error: illegal  construction of adubref"
65                " variable from badouble\n");
66        exit(-2);
67    }
68    explicit adubref( const adub& ) {
69        fprintf(DIAG_OUT,"ADOL-C error: illegal  construction of adubref"
70                " variable from adub\n");
71        exit(-2);
72    }
73public:
74    /* adub prevents postfix operators to occur on the left
75       side of an assignment which would not work  */
76    adub operator++( int );
77    adub operator--( int );
78    adubref& operator++( void );
79    adubref& operator--( void );
80    adubref& operator = ( double );
81    adubref& operator = ( const badouble& );
82    adubref& operator = ( const adubref& );
83    adubref& operator +=  ( double );
84    adubref& operator +=  ( const badouble& );
85    adubref& operator -=  ( double x );
86    adubref& operator -=  ( const badouble& );
87    adubref& operator *=  ( double x );
88    adubref& operator *=  ( const badouble& );
89    adubref& operator /=  ( double x );
90    adubref& operator /=  ( const badouble& );
91    adubref& operator <<= ( double );
92    void declareIndependent();
93    adubref& operator >>= ( double& );
94    void declareDependent();
95    operator adub() const;
96    friend ADOLC_DLL_EXPORT void condassign(adubref, const badouble&, const badouble&, const badouble&);
97    friend ADOLC_DLL_EXPORT void condassign(adubref, const badouble&, const badouble&);
98};
99
100class advector {
101private:
102    struct ADOLC_DLL_EXPORT blocker {
103        adouble *dflt;
104        blocker() {}
105        blocker(size_t n);
106        ~blocker() {}
107    } blk;
108    std::vector<adouble> data;
109    ADOLC_DLL_EXPORT bool nondecreasing() const;
110public:
111    ADOLC_DLL_EXPORT advector() : blk(), data() {}
112    ADOLC_DLL_EXPORT explicit advector(size_t n) : blk(n), data(n, *blk.dflt) { delete blk.dflt; }
113    ADOLC_DLL_EXPORT ~advector() {}
114    ADOLC_DLL_EXPORT advector(const advector& x) : blk(x.data.size()), data(x.data) { delete blk.dflt; }
115    ADOLC_DLL_EXPORT advector(const vector<adouble>& v) : blk(v.size()), data(v) { delete blk.dflt; }
116    ADOLC_DLL_EXPORT size_t size() const { return data.size(); }
117    ADOLC_DLL_EXPORT operator const vector<adouble>&() const { return data; }
118    ADOLC_DLL_EXPORT operator vector<adouble>&() { return data; }
119    ADOLC_DLL_EXPORT adub operator[](const badouble& index) const;
120    ADOLC_DLL_EXPORT adubref operator[](const badouble& index);
121    ADOLC_DLL_EXPORT adouble& operator[](size_t i) { return data[i]; }
122    ADOLC_DLL_EXPORT const adouble& operator[](size_t i) const { return data[i]; }
123    ADOLC_DLL_EXPORT adouble lookupindex(const badouble& x, const badouble& y) const;
124};
125
126#endif /* TAPELESS */
127#endif /* __cplusplus */
128#endif /* ADOLC_ADVECTOR_H */
Note: See TracBrowser for help on using the repository browser.