44 #ifndef RTOPPACK_SPARSE_SUB_VECTOR_T_HPP
45 #define RTOPPACK_SPARSE_SUB_VECTOR_T_HPP
48 #include "RTOpPack_Types.hpp"
49 #include "Teuchos_Assert.hpp"
134 template<
class Scalar>
139 :globalOffset_(0), subDim_(0), subNz_(0),
140 valuesStride_(0), indicesStride_(0), localOffset_(0),
145 Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in, Teuchos_Ordinal subNz_in,
146 const ArrayRCP<const Scalar> &values_in, ptrdiff_t valuesStride_in,
147 const ArrayRCP<const Teuchos_Ordinal> &indices_in, ptrdiff_t indicesStride_in,
148 ptrdiff_t localOffset_in,
bool isSorted_in
150 :globalOffset_(globalOffset_in), subDim_(subDim_in), subNz_(subNz_in),
151 values_(values_in), valuesStride_(valuesStride_in), indices_(indices_in),
152 indicesStride_(indicesStride_in), localOffset_(localOffset_in), isSorted_(isSorted_in)
156 initialize(globalOffset_in, subDim_in, subNz_in, values_in, valuesStride_in,
157 indices_in, indicesStride_in, localOffset_in, isSorted_in);
162 Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in,
163 const ArrayRCP<const Scalar> &values_in, ptrdiff_t valuesStride_in
165 :globalOffset_(globalOffset_in), subDim_(subDim_in), subNz_(subDim_in),
166 values_(values_in), valuesStride_(valuesStride_in),
167 indicesStride_(0), localOffset_(0), isSorted_(true)
171 initialize(globalOffset_in, subDim_in, values_in, valuesStride_in);
177 values_(sv.
values()), valuesStride_(sv.stride()), indicesStride_(0),
178 localOffset_(0), isSorted_(true)
182 Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in, Teuchos_Ordinal subNz_in,
183 const ArrayRCP<const Scalar> &values_in, ptrdiff_t valuesStride_in,
184 const ArrayRCP<const Teuchos_Ordinal> &indices_in, ptrdiff_t indicesStride_in,
185 ptrdiff_t localOffset_in,
bool isSorted_in
196 subNz_in*as<Teuchos_Ordinal>(std::abs(as<int>(valuesStride_in))));
200 subNz_in*as<Teuchos_Ordinal>(std::abs(as<int>(indicesStride_in))));
203 for (
int k = 0; k < subNz_in-1; ++k) {
204 const Teuchos_Ordinal idx_k = indices_in[k*indicesStride_in];
205 const Teuchos_Ordinal idx_kp1 = indices_in[(k+1)*indicesStride_in];
207 "Error indices["<<k<<
"]="<<idx_k<<
" >= indices["<<k+1<<
"]="<<idx_kp1
213 globalOffset_ = globalOffset_in;
217 valuesStride_ = valuesStride_in;
218 indices_ = indices_in;
219 indicesStride_ = indicesStride_in;
220 localOffset_ = localOffset_in;
221 isSorted_ = isSorted_in;
225 Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in,
226 const ArrayRCP<const Scalar> &values_in, ptrdiff_t valuesStride_in
229 initialize(globalOffset_in, subDim_in, subDim_in, values_in, valuesStride_in,
230 Teuchos::null, 0, 0,
true);
235 globalOffset_ = 0; subDim_ = 0; subNz_ = 0;
236 values_ = Teuchos::null; valuesStride_ = 0; indices_ = Teuchos::null;
237 indicesStride_ = 0; localOffset_ = 0; isSorted_ =
false;
240 void setGlobalOffset(Teuchos_Ordinal globalOffset_in) { globalOffset_ = globalOffset_in; }
244 Teuchos_Ordinal
subDim()
const {
return subDim_; }
247 Teuchos_Ordinal
subNz()
const {
return subNz_; }
250 const ArrayRCP<const Scalar>
values()
const {
return values_; }
257 const ArrayRCP<const Teuchos_Ordinal>
indices()
const {
return indices_; }
267 Teuchos_Ordinal globalOffset_;
268 Teuchos_Ordinal subDim_;
269 Teuchos_Ordinal subNz_;
270 ArrayRCP<const Scalar> values_;
271 ptrdiff_t valuesStride_;
272 ArrayRCP<const Teuchos_Ordinal> indices_;
273 ptrdiff_t indicesStride_;
274 ptrdiff_t localOffset_;
283 #endif // RTOPPACK_SPARSE_SUB_VECTOR_T_HPP
bool is_null(const boost::shared_ptr< T > &p)
void initialize(Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in, const ArrayRCP< const Scalar > &values_in, ptrdiff_t valuesStride_in)
SparseSubVectorT(Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in, Teuchos_Ordinal subNz_in, const ArrayRCP< const Scalar > &values_in, ptrdiff_t valuesStride_in, const ArrayRCP< const Teuchos_Ordinal > &indices_in, ptrdiff_t indicesStride_in, ptrdiff_t localOffset_in, bool isSorted_in)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Class for a (sparse or dense) sub-vector.
SparseSubVectorT(const ConstSubVectorView< Scalar > &sv)
#define TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(index, lower_inclusive, upper_exclusive)
bool isSorted() const
If isSorted == false then the vector is not sorted, otherwise it is sorted (sparse vectors only)...
void initialize(Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in, Teuchos_Ordinal subNz_in, const ArrayRCP< const Scalar > &values_in, ptrdiff_t valuesStride_in, const ArrayRCP< const Teuchos_Ordinal > &indices_in, ptrdiff_t indicesStride_in, ptrdiff_t localOffset_in, bool isSorted_in)
ptrdiff_t localOffset() const
Offset of indices[] into local sub-vector (sparse vectors only).
Teuchos_Ordinal subNz() const
Number of nonzero elements (subNz == subDim for dense vectors).
const ArrayRCP< const Scalar > values() const
Array (size min{|valueStride*subNz|,1}) for the values in the vector.
Teuchos_Ordinal subDim() const
Dimension of the sub-vector.
void setGlobalOffset(Teuchos_Ordinal globalOffset_in)
SparseSubVectorT(Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in, const ArrayRCP< const Scalar > &values_in, ptrdiff_t valuesStride_in)
ptrdiff_t indicesStride() const
Stride between indices in indices[] (sparse vectors only).
TypeTo as(const TypeFrom &t)
ptrdiff_t valuesStride() const
Stride between elements in values[].
Teuchos_Ordinal globalOffset() const
Offset for the sub-vector into the global vector.
const ArrayRCP< const Teuchos_Ordinal > indices() const
Array (size indicesStride*subNz) if not Teuchos::null) for the indices of the nonzero elements in the...
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)