RTOpPack: Extra C/C++ Code for Vector Reduction/Transformation Operators  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Attributes | List of all members
RTOp_SparseSubVector Struct Reference

#include <RTOp_SparseSubVector.h>

Public Attributes

const RTOp_index_type * indices
 

Detailed Description

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

Sparse and dense local vectors are supported as follows:

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

 x( vec.global_offset + k )
  = vec.values[ vec.value_stride * (k-1) ]

 for k = 1,...,vec.sub_dim

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

A sparse vector is identified by vec.sub_dim > 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.global_offset + vec.local_offset + vec.indices[vec.indices_stride*(k-1)] )
  = vec.values[vec.value_stride*(k-1)]

 for k = 1,...,vec.sub_nz

If vec.sub_nz == 0 then it is allowed for vec.indices == NULL. If vec.sub_dim > vec.sub_nz > 0 then vec.indices != NULL must be true.

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

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

 for k = 1,...,vec.sub_nz-1

The member vec.local_offset is used to shift the values in vec.indices[] to be in range of the local sub-vector. In other words:

 1 <= vec.local_offset + vec.indices[vec.indices_stride*(k-1)] <= vec.sub_nz

 for k = 1...vec.sub_nz

The member vec.value_stride may be positive (>0), negative (<0) or zero (0). However, the member vec.indices_stride may be may be positive (>0) or negative (<0) but not zero (0). Allowing vec.indices_stride == 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.value_stride == 0 is one where all of the nonzeros 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 131 of file RTOp_SparseSubVector.h.

Member Data Documentation

const RTOp_index_type* RTOp_SparseSubVector::indices

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

Definition at line 146 of file RTOp_SparseSubVector.h.


The documentation for this struct was generated from the following file: