RTOpPack::SparseSubVectorT< Scalar > Class Template Reference

Class for a (sparse or dense) sub-vector. More...

#include <RTOpPack_Types.hpp>

List of all members.

Public Member Functions

 SparseSubVectorT ()
 
 SparseSubVectorT (RTOp_index_type globalOffset, RTOp_index_type subDim, RTOp_index_type subNz, const Scalar values[], ptrdiff_t valuesStride, const RTOp_index_type indices[], ptrdiff_t indicesStride, ptrdiff_t localOffset, int isSorted)
 
 SparseSubVectorT (RTOp_index_type globalOffset, RTOp_index_type subDim, const Scalar values[], ptrdiff_t valuesStride)
 
 SparseSubVectorT (const SubVectorT< Scalar > &sv)
 
void initialize (RTOp_index_type globalOffset, RTOp_index_type subDim, RTOp_index_type subNz, const Scalar values[], ptrdiff_t valuesStride, const RTOp_index_type indices[], ptrdiff_t indicesStride, ptrdiff_t localOffset, int isSorted)
 
void initialize (RTOp_index_type globalOffset, RTOp_index_type subDim, const Scalar values[], ptrdiff_t valuesStride)
 
void set_uninitialized ()
 
void setGlobalOffset (RTOp_index_type globalOffset)
 
RTOp_index_type globalOffset () const
 Offset for the sub-vector into the global vector.
RTOp_index_type subDim () const
 Dimension of the sub-vector.
RTOp_index_type subNz () const
 Number of nonzero elements (subNz == subDim for dense vectors).
const Scalar * values () const
 Array (size min{|valueStride*subNz|,1}) for the values in the vector.
ptrdiff_t valuesStride () const
 Stride between elements in values[].
const RTOp_index_type * indices () const
 Array (size min{|indicesStride*subNz|,1} if not NULL) for the indices of the nonzero elements in the vector (sparse vectors only).
ptrdiff_t indicesStride () const
 Stride between indices in indices[] (sparse vectors only).
ptrdiff_t localOffset () const
 Offset of indices[] into local sub-vector (sparse vectors only).
int isSorted () const
 If isSorted == 0 then the vector is not sorted, otherwise it is sorted (sparse vectors only).


Detailed Description

template<class Scalar>
class RTOpPack::SparseSubVectorT< Scalar >

Class for a (sparse or dense) sub-vector.

Sparse and dense local vectors are supported as follows:

A dense vector vec is identified by vec.subDim() == vec.sub_nz and vec.indices() == NULL in which case vec.indicesStride(), vec.localOffset() and vec.isSorted() are ignored. For a dense sub-vector vec, the corresponding entries in the global vector x(j) (one based) are as follows:


  x( vec.globalOffset() + k )
    = vec.values()[ vec.valueStride() * (k-1) ]

  for k = 1,...,vec.subDim()
 
The stride member vec.valueStride()() may be positive (>0), negative (<0) or even zero (0). A negative stride vec.valueStride() < 0 allows a reverse traversal of the elements in vec.values()[]. A zero stride vec.valueStride()() == 0 allows a vector with all the elements the same.

A sparse vector is identified by vec.subDim() > vec.sub_nz() or vec.indices() != NULL in which case all the fields in the structure are meaningful. The corresponding elements in the global vector x(j) defined as:


  x( vec.globalOffset() + vec.localOffset() + vec.indices()[vec.indicesStride()*(k-1)] )
    = vec.values[vec.valueStride()*(k-1)]

  for k = 1,...,vec.sub_nz
 
If vec.sub_nz == 0 then it is allowed for vec.indices() == NULL. If vec.subDim() > vec.sub_nz > 0 then vec.indices() != NULL must be true.

A sparse sub-vector may be sorted (vec.isSorted()!=0) or unsorted (vec.isSorted()==0) but the indices vec.indices()[k] must be unique. A sorted vector (vec.isSorted()!=0) means that the indices are in ascending order:


  vec.indices()[vec.indicesStride()*(k-1)] < vec.indices()[vec.indicesStride()*(k)]

  for k = 1,...,vec.sub_nz-1
 
The member vec.localOffset() is used to shift the values in vec.indices()[] to be in range of the local sub-vector. In other words:
  
  1 <= vec.localOffset() + vec.indices()[vec.indicesStride()*(k-1)] <= vec.sub_nz

  for k = 1...vec.sub_nz
 
The member vec.valueStride() may be positive (>0), negative (<0) or zero (0). However, the member vec.indicesStride() may be may be positive (>0) or negative (<0) but not zero (0). Allowing vec.indicesStride() == 0 would mean that a vector would have vec.sub_nz nonzero elements with all the same value and all the same indexes and non-unique indices are not allowed. Allowing non-unique indexes would make some operations (e.g. dot product) very difficult to implement and therefore can not be allowed. A sparse vector where vec.valueStride() == 0 is one where all of the non-zeros have the value vec.values[0]. If vec.sub_nz == 0 for a sparse vector then it is allowed for vec.values == NULL and vec.indices() == NULL.

This specification allows a lot of flexibility in determining how the vectors are laid out in memory. However, allowing vectors to be sparse and unsorted may make many user defined operations considerably harder and expensive to implement.

To avoid making mistakes in setting the members of this struct use one of the helper functions RTOp_sparse_sub_vector_from_dense(), RTOp_sparse_sub_vector() or RTOp_sub_vector_null().

Definition at line 249 of file RTOpPack_Types.hpp.


Constructor & Destructor Documentation

template<class Scalar>
RTOpPack::SparseSubVectorT< Scalar >::SparseSubVectorT  )  [inline]
 

Definition at line 252 of file RTOpPack_Types.hpp.

template<class Scalar>
RTOpPack::SparseSubVectorT< Scalar >::SparseSubVectorT RTOp_index_type  globalOffset,
RTOp_index_type  subDim,
RTOp_index_type  subNz,
const Scalar  values[],
ptrdiff_t  valuesStride,
const RTOp_index_type  indices[],
ptrdiff_t  indicesStride,
ptrdiff_t  localOffset,
int  isSorted
[inline]
 

Definition at line 258 of file RTOpPack_Types.hpp.

template<class Scalar>
RTOpPack::SparseSubVectorT< Scalar >::SparseSubVectorT RTOp_index_type  globalOffset,
RTOp_index_type  subDim,
const Scalar  values[],
ptrdiff_t  valuesStride
[inline]
 

Definition at line 269 of file RTOpPack_Types.hpp.

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

Definition at line 278 of file RTOpPack_Types.hpp.


Member Function Documentation

template<class Scalar>
void RTOpPack::SparseSubVectorT< Scalar >::initialize RTOp_index_type  globalOffset,
RTOp_index_type  subDim,
RTOp_index_type  subNz,
const Scalar  values[],
ptrdiff_t  valuesStride,
const RTOp_index_type  indices[],
ptrdiff_t  indicesStride,
ptrdiff_t  localOffset,
int  isSorted
[inline]
 

Definition at line 283 of file RTOpPack_Types.hpp.

template<class Scalar>
void RTOpPack::SparseSubVectorT< Scalar >::initialize RTOp_index_type  globalOffset,
RTOp_index_type  subDim,
const Scalar  values[],
ptrdiff_t  valuesStride
[inline]
 

Definition at line 295 of file RTOpPack_Types.hpp.

template<class Scalar>
void RTOpPack::SparseSubVectorT< Scalar >::set_uninitialized  )  [inline]
 

Definition at line 305 of file RTOpPack_Types.hpp.

template<class Scalar>
void RTOpPack::SparseSubVectorT< Scalar >::setGlobalOffset RTOp_index_type  globalOffset  )  [inline]
 

Definition at line 312 of file RTOpPack_Types.hpp.

template<class Scalar>
RTOp_index_type RTOpPack::SparseSubVectorT< Scalar >::globalOffset  )  const [inline]
 

Offset for the sub-vector into the global vector.

Definition at line 314 of file RTOpPack_Types.hpp.

template<class Scalar>
RTOp_index_type RTOpPack::SparseSubVectorT< Scalar >::subDim  )  const [inline]
 

Dimension of the sub-vector.

Definition at line 316 of file RTOpPack_Types.hpp.

template<class Scalar>
RTOp_index_type RTOpPack::SparseSubVectorT< Scalar >::subNz  )  const [inline]
 

Number of nonzero elements (subNz == subDim for dense vectors).

Definition at line 318 of file RTOpPack_Types.hpp.

template<class Scalar>
const Scalar* RTOpPack::SparseSubVectorT< Scalar >::values  )  const [inline]
 

Array (size min{|valueStride*subNz|,1}) for the values in the vector.

Definition at line 320 of file RTOpPack_Types.hpp.

template<class Scalar>
ptrdiff_t RTOpPack::SparseSubVectorT< Scalar >::valuesStride  )  const [inline]
 

Stride between elements in values[].

Definition at line 322 of file RTOpPack_Types.hpp.

template<class Scalar>
const RTOp_index_type* RTOpPack::SparseSubVectorT< Scalar >::indices  )  const [inline]
 

Array (size min{|indicesStride*subNz|,1} if not NULL) for the indices of the nonzero elements in the vector (sparse vectors only).

Definition at line 326 of file RTOpPack_Types.hpp.

template<class Scalar>
ptrdiff_t RTOpPack::SparseSubVectorT< Scalar >::indicesStride  )  const [inline]
 

Stride between indices in indices[] (sparse vectors only).

Definition at line 328 of file RTOpPack_Types.hpp.

template<class Scalar>
ptrdiff_t RTOpPack::SparseSubVectorT< Scalar >::localOffset  )  const [inline]
 

Offset of indices[] into local sub-vector (sparse vectors only).

Definition at line 330 of file RTOpPack_Types.hpp.

template<class Scalar>
int RTOpPack::SparseSubVectorT< Scalar >::isSorted  )  const [inline]
 

If isSorted == 0 then the vector is not sorted, otherwise it is sorted (sparse vectors only).

Definition at line 332 of file RTOpPack_Types.hpp.


The documentation for this class was generated from the following file:
Generated on Thu Sep 18 12:39:44 2008 for RTOp : Vector Reduction/Transformation Operators by doxygen 1.3.9.1