Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_Fad_Vector.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef SACADO_FAD_VECTOR_HPP
11 #define SACADO_FAD_VECTOR_HPP
12 
13 #include <vector>
14 #include "Sacado_Fad_DVFad.hpp"
15 
16 namespace Sacado {
17 
18  namespace Fad {
19 
21  Row,
23  };
24 
32  template <typename OrdinalType, typename FadType >
33  class Vector {
34  public:
35 
38 
40  Vector(OrdinalType vec_size, OrdinalType deriv_sz,
41  VectorDerivOrientation orient = Row) :
42  deriv_size_(deriv_sz), vec_(vec_size) {
43  for (OrdinalType i=0; i<vec_size; i++)
45  }
46 
48  Vector(const Vector& fv) : deriv_size_(fv.deriv_size_), vec_(fv.vec_) {}
49 
51  ~Vector() {}
52 
54  Vector& operator=(const Vector& fv) {
56  vec_ = fv.vec_;
57  return *this;
58  }
59 
61  OrdinalType size() const { return vec_.size(); }
62 
64  OrdinalType deriv_size() const { return deriv_size_; }
65 
67  OrdinalType deriv_stride() const { return 1; }
68 
71 
73  FadType& operator[] (OrdinalType i) { return vec_[i]; }
74 
76  const FadType& operator[](OrdinalType i) const { return vec_[i]; }
77 
78  protected:
79 
81  OrdinalType deriv_size_;
82 
84  std::vector<FadType> vec_;
85 
86  }; // class Vector
87 
94  template <typename OrdinalType, typename ValueType>
95  class Vector< OrdinalType, Sacado::Fad::DVFad<ValueType> > {
96  public:
97 
100 
102  Vector(OrdinalType vec_size, OrdinalType deriv_size,
103  VectorDerivOrientation orient = Row);
104 
106  Vector(const Vector& fv);
107 
109  ~Vector();
110 
112  Vector& operator=(const Vector& fv);
113 
115  OrdinalType size() const { return vec_.size(); }
116 
118  OrdinalType deriv_size() const { return deriv_size_; }
119 
121  OrdinalType deriv_stride() const { return stride_; }
122 
124  VectorDerivOrientation deriv_orientation() const { return orient_; }
125 
127  FadType& operator[] (OrdinalType i) { return vec_[i]; }
128 
130  const FadType& operator[](OrdinalType i) const { return vec_[i]; }
131 
133  ValueType* vals();
134 
136  const ValueType* vals() const;
137 
139  ValueType* dx();
140 
142  const ValueType* dx() const;
143 
144  protected:
145 
147  OrdinalType deriv_size_;
148 
151 
153  OrdinalType stride_;
154 
156  std::vector<FadType> vec_;
157 
158  }; // class Vector
159 
160  } // namespace Fad
161 
162 } // namespace Sacado
163 
164 #include "Sacado_Fad_VectorImp.hpp"
165 
166 #endif // SACADO_FAD_VECTOR_HPP
VectorDerivOrientation orient_
Derivative array orientation.
const FadType & operator[](OrdinalType i) const
Array access.
expr expr dx(i)
FadType & operator[](OrdinalType i)
Array access.
Vector(OrdinalType vec_size, OrdinalType deriv_sz, VectorDerivOrientation orient=Row)
Constructor.
OrdinalType deriv_stride() const
Derivative array stride.
VectorDerivOrientation deriv_orientation() const
Derivative array orientation.
Sacado::Fad::DFad< double > FadType
Vector(const Vector &fv)
Copy constructor.
OrdinalType size() const
Vector size.
A class for storing a contiguously allocated array of Fad objects. This is a general definition that ...
const FadType & operator[](OrdinalType i) const
Array access.
OrdinalType deriv_size() const
Derivative size.
VectorDerivOrientation deriv_orientation() const
Derivative array orientation.
Forward-mode AD class using dynamic memory allocation and expression templates.
std::vector< FadType > vec_
Vector of Fad&#39;s.
Derivatives are stored row-wise (strided)
Vector & operator=(const Vector &fv)
Assignment.
Sacado::Fad::DVFad< ValueType > FadType
Synonym for Fad type.
OrdinalType deriv_size_
Size of derivative array.
Base template specification for ValueType.
Sacado::ValueType< FadType >::type ValueType
Typename of values.