This file is indexed.

/usr/include/trilinos/ROL_RiskVector.hpp is in libtrilinos-rol-dev 12.10.1-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// @HEADER
// ************************************************************************
//
//               Rapid Optimization Library (ROL) Package
//                 Copyright (2014) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact lead developers:
//              Drew Kouri   (dpkouri@sandia.gov) and
//              Denis Ridzal (dridzal@sandia.gov)
//
// ************************************************************************
// @HEADER

#ifndef ROL_RISKVECTOR_HPP
#define ROL_RISKVECTOR_HPP

#include "ROL_StdVector.hpp"
#include "ROL_RiskMeasureInfo.hpp"
#include "Teuchos_ParameterList.hpp"

namespace ROL {

template<class Real> 
class RiskVector : public Vector<Real> {
private:
  Teuchos::RCP<std::vector<Real> > stat_;
  Teuchos::RCP<StdVector<Real> >   stat_vec_;
  Teuchos::RCP<Vector<Real> >      vec_;

  bool augmented_;
  int nStat_;

  mutable bool isDualInitialized_;
  mutable Teuchos::RCP<Vector<Real> > dual_vec1_;
  mutable Teuchos::RCP<RiskVector<Real> > dual_vec_;

public:
  RiskVector( Teuchos::ParameterList &parlist,
        const Teuchos::RCP<Vector<Real> > &vec,
        const Real stat = 1 )
    : stat_(Teuchos::null), stat_vec_(Teuchos::null), vec_(vec),
      augmented_(false), nStat_(0), isDualInitialized_(false) {
    // Get risk measure information
    std::string name;
    std::vector<Real> lower, upper;
    bool activated(false);
    int nStat(0);
    RiskMeasureInfo<Real>(parlist,name,nStat,lower,upper,activated);
    augmented_ = (nStat > 0) ? true : false;
    nStat_ = nStat;
    // Initialize statistic vector
    if (augmented_) {
      stat_ = Teuchos::rcp(new std::vector<Real>(nStat_,stat));
      stat_vec_ = Teuchos::rcp(new StdVector<Real>(stat_));
    }
  }

  RiskVector( const Teuchos::RCP<Vector<Real> > &vec,
              const bool augmented = false )
    : stat_(Teuchos::null), stat_vec_(Teuchos::null), vec_(vec),
      augmented_(augmented), nStat_((augmented ? 1 : 0)), isDualInitialized_(false) {
    if (augmented) {
      stat_ = Teuchos::rcp(new std::vector<Real>(nStat_,0));
      stat_vec_ = Teuchos::rcp(new StdVector<Real>(stat_));
    }
  }
 
  RiskVector( const Teuchos::RCP<Vector<Real> > &vec,
              const std::vector<Real> &stat,
              const bool augmented = true )
    : stat_(Teuchos::null), stat_vec_(Teuchos::null), vec_(vec),
      augmented_(augmented), nStat_(stat.size()), isDualInitialized_(false) {
    if (augmented) {
      stat_ = Teuchos::rcp(new std::vector<Real>(stat));
      stat_vec_ = Teuchos::rcp(new StdVector<Real>(stat_));
    }
  }

  void set( const Vector<Real> &x ) {
    const RiskVector<Real> &xs = Teuchos::dyn_cast<const RiskVector<Real> >(x);
    vec_->set(*(xs.getVector()));
    if (augmented_) {
      stat_vec_->set(*(xs.getStatistic()));
    }
  }

  void plus( const Vector<Real> &x ) {
    const RiskVector<Real> &xs = Teuchos::dyn_cast<const RiskVector<Real> >(x);
    vec_->plus(*(xs.getVector()));
    if (augmented_) {
      stat_vec_->plus(*(xs.getStatistic()));
    }
  }

  void scale( const Real alpha ) {
    vec_->scale(alpha);
    if (augmented_) {
      stat_vec_->scale(alpha);
    }
  }

  void axpy( const Real alpha, const Vector<Real> &x ) {
    const RiskVector<Real> &xs = Teuchos::dyn_cast<const RiskVector<Real> >(x);
    vec_->axpy(alpha,*(xs.getVector()));
    if (augmented_) {
      stat_vec_->axpy(alpha,*(xs.getStatistic()));
    }
  }

  Real dot( const Vector<Real> &x ) const {
    const RiskVector<Real> &xs = Teuchos::dyn_cast<const RiskVector<Real> >(x);
    Real val = vec_->dot(*(xs.getVector()));
    if (augmented_) {
      val += stat_vec_->dot(*(xs.getStatistic()));
    }
    return val;
  }

  Real norm(void) const {
    return sqrt( dot(*this) );
  }

  Teuchos::RCP<Vector<Real> > clone(void) const {
    std::vector<Real> stat(nStat_,static_cast<Real>(0));
    return Teuchos::rcp(new RiskVector(vec_->clone(),stat,augmented_));
  }

  const Vector<Real> &dual(void) const {
    // Initialize dual vectors if not already initialized
    if ( !isDualInitialized_ ) {
      dual_vec1_ = vec_->dual().clone();
      std::vector<Real> stat(nStat_,static_cast<Real>(0));
      dual_vec_  = Teuchos::rcp(new RiskVector<Real>(dual_vec1_,stat,augmented_));
      isDualInitialized_ = true;
    }
    // Set vector component 
    dual_vec1_->set(vec_->dual());
    // Set statistic component
    if ( augmented_ ) {
      Teuchos::rcp_dynamic_cast<RiskVector<Real> >(dual_vec_)->setStatistic(*stat_);
    }
    // Return dual vector
    return *dual_vec_;
  }

  Teuchos::RCP<Vector<Real> > basis( const int i )  const {
    Teuchos::RCP<Vector<Real> > e1;
    std::vector<Real> e2(nStat_,static_cast<Real>(0));
    int n1 = vec_->dimension(), n2 = stat_vec_->dimension();
    if ( i < n1 ) {
      e1 = vec_->basis(i);
    }
    else if (i >= n1 && i < n1+n2) {
      e1 = vec_->clone(); e1->zero();
      e2[i-n1] = static_cast<Real>(1);
    }
    else {
      TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
        ">>> ERROR (ROL::RiskVector::Basis): index is out of bounds.");
    }
    return Teuchos::rcp(new RiskVector<Real>(e1,e2,augmented_));
  }

  void applyUnary( const Elementwise::UnaryFunction<Real> &f ) {
    vec_->applyUnary(f);
    if (augmented_) {
      stat_vec_->applyUnary(f);
    }
  }

  void applyBinary( const Elementwise::BinaryFunction<Real> &f, const Vector<Real> &x ) {
    const RiskVector<Real> &xs = Teuchos::dyn_cast<const RiskVector<Real> >(x);
    vec_->applyBinary(f,*xs.getVector());
    if (augmented_) {
      stat_vec_->applyBinary(f,*xs.getStatistic());
    }
  }

  Real reduce( const Elementwise::ReductionOp<Real> &r ) const {
    Real result = r.initialValue();
    r.reduce(vec_->reduce(r),result);
    if (augmented_) {
      r.reduce(stat_vec_->reduce(r),result);
    }
    return result;
  }

  int dimension(void) const {
    int dim = vec_->dimension();
    if (augmented_) {
      dim += stat_vec_->dimension();
    }
    return dim;
  }

  /***************************************************************************/
  /************ ROL VECTOR ACCESSOR FUNCTIONS ********************************/
  /***************************************************************************/
  Teuchos::RCP<const StdVector<Real> > getStatistic(void) const {
    return stat_vec_;
  }

  Teuchos::RCP<StdVector<Real> > getStatistic(void) {
    return stat_vec_;
  }

  Teuchos::RCP<const Vector<Real> > getVector(void) const {
    return vec_;
  }

  Teuchos::RCP<Vector<Real> > getVector(void) {
    return vec_;
  }

  /***************************************************************************/
  /************ COMPONENT ACCESSOR FUNCTIONS *********************************/
  /***************************************************************************/
  const Real getStatistic(const int i) const {
    TEUCHOS_TEST_FOR_EXCEPTION((i < 0 || i > (int)nStat_-1),std::invalid_argument,
      ">>> ERROR (ROL::RiskVector::getStatistic): index out-of-bounds.");
    TEUCHOS_TEST_FOR_EXCEPTION(!augmented_,std::invalid_argument,
      ">>> ERROR (ROL::RiskVector::getStatistic): vector is not augmented.");
    return (*stat_)[i];
  }

  void getStatistic(std::vector<Real> &stat) const {
    stat.clear();
    if ( augmented_ ) {
      stat.assign(stat_->begin(),stat_->end());
    }
  }

  void setStatistic(const Real stat) {
    if ( augmented_ ) {
      stat_->assign(nStat_,stat);
    }
  }
 
  void setStatistic(const std::vector<Real> &stat) {
    if ( augmented_ ) {
      stat_->assign(stat.begin(),stat.end());
    }
  }
 
  void setVector(const Vector<Real>& vec) {
    vec_->set(vec);
  }
};

}

#endif