This file is indexed.

/usr/include/trilinos/Thyra_DetachedVectorView.hpp is in libtrilinos-thyra-dev 12.4.2-2.

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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
// @HEADER
// ***********************************************************************
// 
//    Thyra: Interfaces and Support for Abstract Numerical Algorithms
//                 Copyright (2004) 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 Roscoe A. Bartlett (bartlettra@ornl.gov) 
// 
// ***********************************************************************
// @HEADER

#include "Thyra_VectorBase.hpp"

#ifndef THYRA_EXPLICIT_VECTOR_VIEW_HPP
#define THYRA_EXPLICIT_VECTOR_VIEW_HPP


namespace Thyra {


/** \brief Create an explicit non-mutable (const) view of a <tt>VectorBase</tt> object.
 *
 * This utility class makes it easy to explicitly access a contiguous subset
 * of elements in any <tt>const VectorBase</tt> object.
 *
 * <b>Warning!</b> Creating an explicit view of an arbitrary
 * <tt>%VectorBase</tt> object may be a very expensive operation (such as with
 * distributed-memory vectors) and should only be done in special cases (such
 * as when the vector is an in-core vector).  There several specialized use
 * cases where creating these types of explicit views are necessary but in
 * most cases this should not be done.
 *
 * If one wants to modify the elements in a <tt>VectorBase</tt> object then
 * one should use the utility class <tt>DetachedVectorView</tt>.
 *
 * The default constructor, copy constructor and assignment operators are not
 * allowed.
 *
 * \ingroup Thyra_Op_Vec_ANA_Development_grp
 */
template<class Scalar>
class ConstDetachedVectorView {
public:

  /** \brief Construct an explicit non-mutable (const) view of a subset of elements.
   *
   * @param v [in] The vector that a view will be taken.  This object must be
   * maintained until <tt>*this</tt> is destroyed.
   *
   * @param rng [in] the range of element indices that the explicit view will
   * be taken.
   *
   * @param forceUnitStride [in] If <tt>true</tt> then the view will have unit
   * stride.
   *
   * Preconditions:<ul>
   *
   * <li>[<tt>rng.full_range()==false</tt>] <tt>rng.ubound() <
   * v.space()->dim()</tt>
   *
   * </ul>
   *
   * Postconditions:<ul>
   *
   * <li><tt>this->sv()</tt> returns the created view
   *
   * <li><tt>this->globalOffset()==rng.lbound()</tt>
   *
   * <li><tt>this->subDim()==rng.size()</tt>
   *
   * <li><tt>this->values()</tt> returns a pointer to a <tt>Scalar</tt> array
   *
   * <li><tt>this->stride()</tt> returns the stride between the elements
   * pointed it in <tt>this->values()</tt>
   *
   * <li>[<tt>forceUnitStride==true</tt>] <tt>this->stride()==1</tt>
   *
   * </ul>
   */
  ConstDetachedVectorView(
    const Teuchos::RCP<const VectorBase<Scalar> > &v
    ,const Range1D &rng = Range1D(), const bool forceUnitStride = false
    )
    {
      this->initialize(v,rng,forceUnitStride);
    }

  /** \brief Construct an explicit non-mutable (const) view of a subset of elements.
   *
   * @param v [in] The vector that a view will be taken.  This object must be
   * maintained until <tt>*this</tt> is destroyed.
   *
   * @param rng [in] the range of element indices that the explicit view will
   * be taken.
   *
   * @param forceUnitStride [in] If <tt>true</tt> then the view will have unit
   * stride.
   *
   * Preconditions:<ul>
   *
   * <li>[<tt>rng.full_range()==false</tt>] <tt>rng.ubound() <
   * v.space()->dim()</tt>
   *
   * </ul>
   *
   * Postconditions:<ul>
   *
   * <li><tt>this->sv()</tt> returns the created view
   *
   * <li><tt>this->globalOffset()==rng.lbound()</tt>
   *
   * <li><tt>this->subDim()==rng.size()</tt>
   *
   * <li><tt>this->values()</tt> returns a pointer to a <tt>Scalar</tt> array
   *
   * <li><tt>this->stride()</tt> returns the stride between the elements
   * pointed it in <tt>this->values()</tt>
   *
   * <li>[<tt>forceUnitStride==true</tt>] <tt>this->stride()==1</tt>
   *
   * </ul>
   */
  ConstDetachedVectorView( const VectorBase<Scalar>& v,
    const Range1D &rng = Range1D(), const bool forceUnitStride = false )
    {
      this->initialize(Teuchos::rcp(&v,false),rng,forceUnitStride);
    }

  /** \brief Free the explicit view on the <tt>VectorBase</tt> object
   * <tt>v</tt> passed to <tt>ConstDetachedVectorView()</tt>.
   */
  ~ConstDetachedVectorView()
    {
      if( sv_s_.stride() != sv_.stride() )
        delete [] const_cast<Scalar*>(sv_.values().get());
      v_->releaseDetachedView(&sv_s_);
    }

  /** \brief Returns the explicit view as an
   * <tt>RTOpPack::ConstSubVectorView<Scalar></tt> object.
   */
  const RTOpPack::ConstSubVectorView<Scalar>& sv() const { return sv_; }

  /** \brief Returns the global offset for the explicit view. */
  Teuchos_Ordinal globalOffset() const { return sv_.globalOffset(); }

  /** \brief Returns the dimension of the explicit view. */
  Teuchos_Ordinal subDim() const { return sv_.subDim(); }

  /** \brief Return a pointer to a <tt>Scalar</tt> array containing the
   * explicit view.
   */
  const Scalar* values() const { return sv_.values().get(); }

  /** \brief Return the stride between elements in the array returned from
   * <tt>this->values()</tt>.
   */
  ptrdiff_t stride() const { return sv_.stride(); }

  /** \brief Zero-based indexing: Preconditions: <tt>values()!=NULL && (0 <= i
   * < subDim()-1)</tt>.
   */
  const Scalar& operator[](Teuchos_Ordinal i) const { return sv_[i]; }

  /** \brief Zero-based indexing: Preconditions: <tt>values()!=NULL && (0 <= i
   * < subDim()-1)</tt>.
   */
  const Scalar& operator()(Teuchos_Ordinal i) const { return sv_(i); }

private:

  Teuchos::RCP<const VectorBase<Scalar> > v_;
  RTOpPack::ConstSubVectorView<Scalar>  sv_s_;
  RTOpPack::ConstSubVectorView<Scalar>  sv_;

  void initialize(
    const Teuchos::RCP<const VectorBase<Scalar> > &v,
    const Range1D &rng, const bool forceUnitStride
    )
    {
      v_ = v;
      v_->acquireDetachedView(rng,&sv_s_);
      if( forceUnitStride && sv_s_.stride() != 1 ) {
        TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "I don't think non-unit stride has ever been tested!");
        //const ArrayRCP<Scalar> values = Teuchos::arcp(sv_s_.subDim());
        //Teuchos_Ordinal i; const Scalar *sv_v;
        //for( sv_v = sv_s_.values().get(), i=0; i < sv_s_.subDim(); ++i, sv_v += sv_s_.stride() )
        //  values[i] = *sv_v;
        //sv_.initialize(sv_s_.globalOffset(),sv_s_.subDim(),values,1);
      }
      else {
        sv_ = sv_s_;
      }
    }
  // Not defined and not to be called
  ConstDetachedVectorView();
  ConstDetachedVectorView(const ConstDetachedVectorView<Scalar>&);
  ConstDetachedVectorView<Scalar>& operator==(const ConstDetachedVectorView<Scalar>&);
};

 
/** \brief Create an explicit mutable (non-const) view of a <tt>VectorBase</tt> object.
 *
 * This utility class makes it easy to explicitly access a contiguous subset
 * of elements in any <tt>VectorBase</tt> object and change the <tt>VectorBase
 * object</tt>.
 *
 * <b>Warning!</b> Creating an explicit view of an arbitrary
 * <tt>%VectorBase</tt> object may be a very expensive operation (such as with
 * distributed-memory vectors) and should only be done in special cases (such
 * as when the vector is an in-core vector).  There several specialized use
 * cases where creating these types of explicit views are necessary but in
 * most cases this should not be done.
 *
 * If one wants to only read the elements in a <tt>VectorBase</tt> object then
 * one should use the utility class <tt>ConstDetachedVectorView</tt>.
 *
 * The default constructor, copy constructor and assignment operators are not
 * allowed.
 *
 * \ingroup Thyra_Op_Vec_ANA_Development_grp
 */
template<class Scalar>
class DetachedVectorView {
public:

  /** \brief Construct an explicit mutable (non-const) view of a subset of elements.
   *
   * @param v [in] The vector that a view will be taken.  This object must be
   * maintained until <tt>*this</tt> is destroyed.  The elements in <tt>v</tt>
   * are not guaranteed to be updated until <tt>*this</tt> is destroyed.
   *
   * @param rng [in] the range of element indices that the explicit view will
   * be taken.
   *
   * @param forceUnitStride [in] If <tt>true</tt> then the view will have unit
   * stride.
   *
   * Preconditions:<ul>
   *
   * <li>[<tt>rng.full_range()==false</tt>] <tt>rng.ubound() <
   * v.space()->dim()</tt>
   *
   * </ul>
   *
   * Postconditions:<ul>
   *
   * <li><tt>this->sv()</tt> returns the created view
   *
   * <li><tt>this->globalOffset()==rng.lbound()</tt>
   *
   * <li><tt>this->subDim()==rng.size()</tt>
   *
   * <li><tt>this->values()</tt> returns a pointer to a <tt>Scalar</tt> array
   *
   * <li><tt>this->stride()</tt> returns the stride between the elements
   * pointed it in <tt>this->values()</tt>
   *
   * <li>[<tt>forceUnitStride==true</tt>] <tt>this->stride()==1</tt>
   *
   * </ul>
   */
  DetachedVectorView(
    const Teuchos::RCP<VectorBase<Scalar> > &v
    ,const Range1D &rng = Range1D(), const bool forceUnitStride = false
    )
    {
      this->initialize(v,rng,forceUnitStride);
    }

  /** \brief Construct an explicit mutable (non-const) view of a subset of elements.
   *
   * @param v [in] The vector that a view will be taken.  This object must be
   * maintained until <tt>*this</tt> is destroyed.  The elements in <tt>v</tt>
   * are not guaranteed to be updated until <tt>*this</tt> is destroyed.
   *
   * @param rng [in] the range of element indices that the explicit view will
   * be taken.
   *
   * @param forceUnitStride [in] If <tt>true</tt> then the view will have unit
   * stride.
   *
   * Preconditions:<ul>
   * <li>[<tt>rng.full_range()==false</tt>] <tt>rng.ubound() < v.space()->dim()</tt>
   * </ul>
   *
   * Postconditions:<ul>
   *
   * <li><tt>this->sv()</tt> returns the created view
   *
   * <li><tt>this->globalOffset()==rng.lbound()</tt>
   *
   * <li><tt>this->subDim()==rng.size()</tt>
   *
   * <li><tt>this->values()</tt> returns a pointer to a <tt>Scalar</tt> array
   *
   * <li><tt>this->stride()</tt> returns the stride between the elements
   * pointed it in <tt>this->values()</tt>
   *
   * <li>[<tt>forceUnitStride==true</tt>] <tt>this->stride()==1</tt>
   *
   * </ul>
   */
  DetachedVectorView( VectorBase<Scalar>& v, const Range1D &rng = Range1D(), const bool forceUnitStride = false )
    {
      this->initialize(Teuchos::rcp(&v,false),rng,forceUnitStride);
    }

  /** \brief Commits back the the explicit view on the <tt>VectorBase</tt>
   * object <tt>v</tt> passed to <tt>DetachedVectorView()</tt>.
   */
  ~DetachedVectorView()
    {
      if( sv_s_.stride() != sv_.stride() ) {
        TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "I don't think non-unit stride has ever been tested!");
        //Teuchos_Ordinal i; Scalar *sv_v; const Scalar *values;
        //for (
        //  sv_v = sv_s_.values().get(), values = sv_.values().get(), i=0;
        //  i < sv_s_.subDim();
        //  ++i, sv_v += sv_s_.stride()
        //  )
        //{
        //  *sv_v = *values++;
        //}
        //delete [] sv_.values().get();
      }
      v_->commitDetachedView(&sv_s_);
    }

  /** \brief Returns the explicit view as an
   * <tt>RTOpPack::ConstSubVectorView<Scalar></tt> object.
   */
  const RTOpPack::SubVectorView<Scalar>& sv() const { return sv_; }

  /** \brief Returns the global offset for the explicit view. */
  Teuchos_Ordinal globalOffset() const { return sv_.globalOffset(); }

  /** \brief Returns the dimension of the explicit view. */
  Teuchos_Ordinal subDim() const { return sv_.subDim(); }

  /** \brief Return a pointer to a <tt>Scalar</tt> array containing the
   * explicit view.
   */
  Scalar* values() const { return sv_.values().get(); }

  /** \brief Return the stride between elements in the array returned from
   * <tt>this->values()</tt>.
   */
  ptrdiff_t stride() const { return sv_.stride(); }

  /** \brief Zero-based indexing: Preconditions: <tt>values()!=NULL && (0 <= i
   * < subDim()-1)</tt>.
   */
  Scalar& operator[](Teuchos_Ordinal i) const { return sv_[i]; }

  /** \brief Zero-based indexing: Preconditions: <tt>values()!=NULL && (0 <= i
   * < subDim()-1)</tt>. */
  Scalar& operator()(Teuchos_Ordinal i) const { return sv_(i); }

private:

  Teuchos::RCP<VectorBase<Scalar> > v_;
  RTOpPack::SubVectorView<Scalar>  sv_s_;
  RTOpPack::SubVectorView<Scalar>  sv_;

  void initialize(
    const Teuchos::RCP<VectorBase<Scalar> > &v
    ,const Range1D &rng, const bool forceUnitStride
    )
    {
      v_ = v;
      v_->acquireDetachedView(rng,&sv_s_);
      if( forceUnitStride && sv_s_.stride() != 1 ) {
        TEUCHOS_TEST_FOR_EXCEPT_MSG(true, "I don't think non-unit stride has ever been tested!");
        //Scalar *values = new Scalar[sv_s_.subDim()];
        //Teuchos_Ordinal i; const Scalar *sv_v;
        //for( sv_v = sv_s_.values().get(), i=0; i < sv_s_.subDim(); ++i, sv_v += sv_s_.stride() )
        //  values[i] = *sv_v;
        //sv_.initialize(sv_s_.globalOffset(),sv_s_.subDim(),values,1);
      }
      else {
        sv_ = sv_s_;
      }
    }

  // Not defined and not to be called
  DetachedVectorView();
  DetachedVectorView(const DetachedVectorView<Scalar>&);
  DetachedVectorView<Scalar>& operator==(const DetachedVectorView<Scalar>&);

};


} // namespace Thyra


#endif // THYRA_EXPLICIT_VECTOR_VIEW_HPP