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_VectorImp.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 
11 
12 template <typename OrdinalType, typename ValueType>
14 Vector(OrdinalType vec_size, OrdinalType deriv_sz,
15  VectorDerivOrientation orient) :
16  deriv_size_(deriv_sz), orient_(orient), stride_(1), vec_(vec_size)
17 {
18  ValueType* x = NULL;
19  ValueType* dx_ = NULL;
20  if (vec_size > 0) {
22  if (deriv_size_ > 0)
24  }
25  if (orient_ == Row) {
26  stride_ = vec_size;
27  for (OrdinalType i=0; i<vec_size; i++)
28  vec_[i].setMemory(deriv_size_, x+i, dx_+i, stride_);
29  }
30  else {
31  stride_ = 1;
32  for (OrdinalType i=0; i<vec_size; i++)
33  vec_[i].setMemory(deriv_size_, x+i, dx_+i*deriv_size_, stride_);
34  }
35 }
36 
37 template <typename OrdinalType, typename ValueType>
39 Vector(const Sacado::Fad::Vector< OrdinalType, Sacado::Fad::DVFad<ValueType> >& fv) :
40  deriv_size_(fv.deriv_size_), orient_(fv.orient_), stride_(fv.stride_),
41  vec_(fv.size())
42 {
43  OrdinalType vec_size = fv.size();
44  ValueType* x = NULL;
45  ValueType* dx_ = NULL;
46  if (vec_size > 0) {
48  if (deriv_size_ > 0)
50  }
51  if (orient_ == Row) {
52  for (OrdinalType i=0; i<vec_size; i++) {
53  vec_[i].setMemory(deriv_size_, x+i, dx_+i, stride_);
54  vec_[i] = fv.vec_[i];
55  }
56  }
57  else {
58  for (OrdinalType i=0; i<vec_size; i++) {
59  vec_[i].setMemory(deriv_size_, x+i, dx_+i*deriv_size_, stride_);
60  vec_[i] = fv.vec_[i];
61  }
62  }
63 }
64 
65 namespace Sacado {
66 namespace Fad {
67 template <typename OrdinalType, typename ValueType>
68 Vector< OrdinalType, DVFad<ValueType> >::
69 ~Vector()
70 {
71  // Here we must destroy the value and derivative arrays
72  if (vec_.size() > 0) {
73  ValueType *v = vals();
75  if (deriv_size_ > 0) {
76  v = dx();
77  ds_array<ValueType>::destroy_and_release(v, vec_.size()*deriv_size_);
78  }
79  }
80 }
81 }
82 }
83 
84 template <typename OrdinalType, typename ValueType>
88 {
89  vec_ = fv.vec_;
90  return *this;
91 }
92 
93 template <typename OrdinalType, typename ValueType>
94 ValueType*
96 vals()
97 {
98  if (vec_.size() == 0)
99  return NULL;
100  return &(vec_[0].val());
101 }
102 
103 template <typename OrdinalType, typename ValueType>
104 const ValueType*
106 vals() const
107 {
108  if (vec_.size() == 0)
109  return NULL;
110  return &(vec_[0].val());
111 }
112 
113 template <typename OrdinalType, typename ValueType>
114 ValueType*
116 dx()
117 {
118  if (vec_.size() == 0 || deriv_size_ == 0)
119  return NULL;
120  return &(vec_[0].fastAccessDx(0));
121 }
122 
123 template <typename OrdinalType, typename ValueType>
124 const ValueType*
126 dx() const
127 {
128  if (vec_.size() == 0 || deriv_size_ == 0)
129  return NULL;
130  return &(vec_[0].fastAccessDx(0));
131 }
expr expr dx(i)
A class for storing a contiguously allocated array of Fad objects. This is a general definition that ...
static SACADO_INLINE_FUNCTION void destroy_and_release(T *m, int sz)
Destroy array elements and release memory.
Forward-mode AD class using dynamic memory allocation and expression templates.
std::vector< FadType > vec_
Vector of Fad&#39;s.
OrdinalType deriv_size_
Size of derivative array.
Base template specification for ValueType.
static SACADO_INLINE_FUNCTION T * get_and_fill(int sz)
Get memory for new array of length sz and fill with zeros.