Thyra::ExplicitVectorView< Scalar > Class Template Reference
[Thyra Operator/Vector Interfaces as an API for the Development of Abstract Numerical Algorithms (ANAs)]

Create an explicit non-mutable (const) view of a VectorBase object. More...

#include <Thyra_ExplicitVectorView.hpp>

List of all members.

Public Member Functions

 ExplicitVectorView (const VectorBase< Scalar > &v, const Range1D &rng=Range1D(), const bool forceUnitStride=false)
 Construct an explicit non-mutable (const) view of a subset of elements.
 ~ExplicitVectorView ()
 Free the explicit view on the VectorBase object v passed to ExplicitVectorView().
const RTOpPack::SubVectorT<
Scalar > & 
sv () const
 Returns the explicit view as an RTOpPack::SubVectorT<Scalar> object.
RTOp_index_type globalOffset () const
 Returns the global offset for the explicit view.
RTOp_index_type subDim () const
 Returns the dimension of the explicit view.
const Scalar * values () const
 Return a pointer to a Scalar array containing the explicit view.
ptrdiff_t stride () const
 Return the stride between elements in the array returned from this->values().
const Scalar & operator[] (RTOp_index_type i) const
 Zero-based indexing: Preconditions: values()!=NULL && (0 <= i <= subDim()-1).
const Scalar & operator() (RTOp_index_type i) const
 One-based indexing: Preconditions: values()!=NULL && (1 <= i <= subDim()).


Detailed Description

template<class Scalar>
class Thyra::ExplicitVectorView< Scalar >

Create an explicit non-mutable (const) view of a VectorBase object.

This utility class makes it easy to explicitly access a contiguous subset of elements in any const VectorBase object.

Warning! Creating an explicit view of an arbitrary VectorBase 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.

The following functions show four different ways to extract a range of elements from in any const VectorBase object and copy then into a raw C++ array:

 //
 // Copy using unit-strided pointer access
 //
 template<class Scalar>
 void copyToArrayPointerUnit(
   const Thyra::VectorBase<Scalar>   &v
   ,const Thyra::Range1D             &rng
   ,Scalar                           x[]   // Size == rng.size()
   )
 {
    Thyra::ExplicitVectorView<Scalar> v_ev(v,rng,true);  // Force unit stride
    const Scalar *v_ptr = v_ev.values();                 // Get pointer to unit-stride data
    for( int k = 0; k < n; ++k )                         // For each element in view:
      x[k] = v_ptr[k];                                   //   Copy elements
    // When this function returns then v_ev will be destroyed and the view will be freed
 }

 //
 // Copy using non-unit-strided pointer access
 //
 template<class Scalar>
 void copyToArrayPointerNonunit(
   const Thyra::VectorBase<Scalar>   &v
   ,const Thyra::Range1D             &rng
   ,Scalar                           x[]   // Size == rng.size()
   )
 {
    Thyra::ExplicitVectorView<Scalar> v_ev(v,rng);           // Allow non-unit stride
    const Scalar        *v_ptr    = v_ev.values();           // Get pointer to non-unit-stride data
    const Thyra::Index  *v_stride = v_ev.stride();           // Get stride between vector data
    for( int k = 0; k < rng.size(); ++k, v_ptr += v_stride ) // For each element in view:
      x[k] = *v_ptr;                                         //   Copy elements
    // When this function returns then v_ev will be destroyed and the view will be freed
 }

 //
 // Copy using possibly non-unit stride with zero-based overloaded function operator[]()
 //
 template<class Scalar>
 void copyToArrayZeroBasedOperator(
   const Thyra::VectorBase<Scalar>   &v
   ,const Thyra::Range1D             &rng
   ,Scalar                           x[]   // Size == rng.size()
   )
 {
    Thyra::ExplicitVectorView<Scalar> v_ev(v,rng);       // Allow non-unit stride 
    for( int k = 0; k < rng.size(); ++k )                // For each element in view:
      x[k] = v_ev[k];                                    //   Copy elements using operator[]()
    // When this function returns then v_ev will be destroyed and the view will be freed
 }

 //
 // Copy using possibly non-unit stride with one-based overloaded function operator()()
 //
 template<class Scalar>
 void copyToArrayOneBasedOperator(
   const Thyra::VectorBase<Scalar>   &v
   ,const Thyra::Range1D             &rng
   ,Scalar                           x[]   // Size == rng.size()
   )
 {
    Thyra::ExplicitVectorView<Scalar> v_ev(v,rng);       // Allow non-unit stride 
    for( int k = 0; k < rng.size(); ++k )                // For each element in view:
      x[k] = v_ev(k+1);                                  //   Copy elements using operator()()
    // When this function returns then v_ev will be destroyed and the view will be freed
 }

If one wants to modify the elements in a VectorBase object then one should use the utility class ExplicitMutableVectorView.

The default constructor, copy constructor and assignment operators are not allowed.

Examples:

ComplexFFTLinearOp.hpp.

Definition at line 134 of file Thyra_ExplicitVectorView.hpp.


Constructor & Destructor Documentation

template<class Scalar>
Thyra::ExplicitVectorView< Scalar >::ExplicitVectorView const VectorBase< Scalar > &  v,
const Range1D rng = Range1D(),
const bool  forceUnitStride = false
[inline]
 

Construct an explicit non-mutable (const) view of a subset of elements.

Parameters:
v [in] The vector that a view will be taken. This object must be maintained until *this is destroyed.
rng [in] the range of element indices that the explicit view will be taken.
forceUnitStride [in] If true then the view will have unit stride.
Preconditions:

Postconditions:

Definition at line 157 of file Thyra_ExplicitVectorView.hpp.

template<class Scalar>
Thyra::ExplicitVectorView< Scalar >::~ExplicitVectorView  )  [inline]
 

Free the explicit view on the VectorBase object v passed to ExplicitVectorView().

Definition at line 173 of file Thyra_ExplicitVectorView.hpp.


Member Function Documentation

template<class Scalar>
const RTOpPack::SubVectorT<Scalar>& Thyra::ExplicitVectorView< Scalar >::sv  )  const [inline]
 

Returns the explicit view as an RTOpPack::SubVectorT<Scalar> object.

Definition at line 180 of file Thyra_ExplicitVectorView.hpp.

template<class Scalar>
RTOp_index_type Thyra::ExplicitVectorView< Scalar >::globalOffset  )  const [inline]
 

Returns the global offset for the explicit view.

Definition at line 182 of file Thyra_ExplicitVectorView.hpp.

template<class Scalar>
RTOp_index_type Thyra::ExplicitVectorView< Scalar >::subDim  )  const [inline]
 

Returns the dimension of the explicit view.

Definition at line 184 of file Thyra_ExplicitVectorView.hpp.

template<class Scalar>
const Scalar* Thyra::ExplicitVectorView< Scalar >::values  )  const [inline]
 

Return a pointer to a Scalar array containing the explicit view.

Definition at line 186 of file Thyra_ExplicitVectorView.hpp.

template<class Scalar>
ptrdiff_t Thyra::ExplicitVectorView< Scalar >::stride  )  const [inline]
 

Return the stride between elements in the array returned from this->values().

Definition at line 188 of file Thyra_ExplicitVectorView.hpp.

template<class Scalar>
const Scalar& Thyra::ExplicitVectorView< Scalar >::operator[] RTOp_index_type  i  )  const [inline]
 

Zero-based indexing: Preconditions: values()!=NULL && (0 <= i <= subDim()-1).

Definition at line 190 of file Thyra_ExplicitVectorView.hpp.

template<class Scalar>
const Scalar& Thyra::ExplicitVectorView< Scalar >::operator() RTOp_index_type  i  )  const [inline]
 

One-based indexing: Preconditions: values()!=NULL && (1 <= i <= subDim()).

Definition at line 192 of file Thyra_ExplicitVectorView.hpp.


The documentation for this class was generated from the following file:
Generated on Thu Sep 18 12:39:54 2008 for Thyra ANA Operator/VectorBase Interfaces and Related Software by doxygen 1.3.9.1