CppADCodeGen  HEAD
A C++ Algorithmic Differentiation Package with Source Code Generation
linear_index_pattern.hpp
1 #ifndef CPPAD_CG_LINEAR_INDEX_PATTERN_INCLUDED
2 #define CPPAD_CG_LINEAR_INDEX_PATTERN_INCLUDED
3 /* --------------------------------------------------------------------------
4  * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5  * Copyright (C) 2013 Ciengis
6  * Copyright (C) 2018 Joao Leal
7  *
8  * CppADCodeGen is distributed under multiple licenses:
9  *
10  * - Eclipse Public License Version 1.0 (EPL1), and
11  * - GNU General Public License Version 3 (GPL3).
12  *
13  * EPL1 terms and conditions can be found in the file "epl-v10.txt", while
14  * terms and conditions for the GPL3 can be found in the file "gpl3.txt".
15  * ----------------------------------------------------------------------------
16  * Author: Joao Leal
17  */
18 
19 namespace CppAD {
20 namespace cg {
21 
26 protected:
27  long xOffset_;
28  // slope
29  long dy_;
30  long dx_;
31  // constant term
32  long b_;
33 public:
34 
35  inline LinearIndexPattern(long xOffset, long dy, long dx, long b) :
36  xOffset_(xOffset),
37  dy_(dy),
38  dx_(dx),
39  b_(b) {
40  }
41 
42  inline virtual ~LinearIndexPattern() = default;
43 
44  inline long getXOffset()const {
45  return xOffset_;
46  }
47 
48  inline long getLinearSlopeDy() const {
49  return dy_;
50  }
51 
52  inline void setLinearSlopeDy(long dy) {
53  dy_ = dy;
54  }
55 
56  inline long getLinearSlopeDx() const {
57  return dx_;
58  }
59 
60  inline long getLinearConstantTerm() const {
61  return b_;
62  }
63 
64  inline void setLinearConstantTerm(long b) {
65  b_ = b;
66  }
67 
68  inline IndexPatternType getType() const override {
69  return IndexPatternType::Linear;
70  }
71 
72  inline void getSubIndexes(std::set<IndexPattern*>& indexes) const override {
73  // nothing to add
74  }
75 
76  inline long evaluate(long x) const {
77  return ((x - xOffset_) / dx_) * dy_ + b_;
78  }
79 
80 };
81 
82 } // END cg namespace
83 } // END CppAD namespace
84 
85 #endif