Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_Sparse3Tensor.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef STOKHOS_SPARSE3TENSOR_HPP
11 #define STOKHOS_SPARSE3TENSOR_HPP
12 
13 #include <ostream>
14 #include <map>
15 #include "Stokhos_SparseArray.hpp"
16 
17 namespace Stokhos {
18 
23  template <typename ordinal_type, typename value_type>
24  class Sparse3Tensor {
25 
26  private:
27 
28  typedef std::map<const ordinal_type, value_type> i_map;
29  typedef std::map<const ordinal_type, i_map> ji_map;
30  typedef std::map<const ordinal_type, ji_map> kji_map;
31 
32  typedef std::map<const ordinal_type, value_type> j_map;
33  typedef std::map<const ordinal_type, j_map> kj_map;
34  typedef std::map<const ordinal_type, kj_map> ikj_map;
35 
39 
43 
44  public:
45 
48 
51 
54 
57 
60 
63 
66 
69 
71  Sparse3Tensor();
72 
75 
78  const value_type& c);
79 
82  const value_type& c);
83 
85 
90  void fillComplete();
91 
93  bool fillCompleted() const;
94 
96  void print(std::ostream& os) const;
97 
100 
102  ordinal_type num_entries() const;
103 
106 
108  ordinal_type num_k() const;
109 
111  ordinal_type num_j(const k_iterator& k) const;
112 
114  ordinal_type num_i(const kj_iterator& j) const;
115 
117  k_iterator find_k(ordinal_type k) const;
118 
120  kj_iterator find_j(const k_iterator& k, ordinal_type j) const;
121 
123  kji_iterator find_i(const kj_iterator& j, ordinal_type i) const;
124 
126  k_iterator k_begin() const;
127 
129  k_iterator k_end() const;
130 
133 
135  k_reverse_iterator k_rend() const;
136 
138  kj_iterator j_begin(const k_iterator& k) const;
139 
141  kj_iterator j_end(const k_iterator& k) const;
142 
144  kj_iterator j_begin(const k_reverse_iterator& k) const;
145 
147  kj_iterator j_end(const k_reverse_iterator& k) const;
148 
150  kji_iterator i_begin(const kj_iterator& j) const;
151 
153  kji_iterator i_end(const kj_iterator& j) const;
154 
156 
159 
161  ordinal_type num_i() const;
162 
164  ordinal_type num_k(const i_iterator& i) const;
165 
167  ordinal_type num_j(const ik_iterator& k) const;
168 
170  i_iterator find_i(ordinal_type i) const;
171 
173  ik_iterator find_k(const i_iterator& i, ordinal_type k) const;
174 
176  ikj_iterator find_j(const ik_iterator& k, ordinal_type j) const;
177 
179  i_iterator i_begin() const;
180 
182  i_iterator i_end() const;
183 
186 
188  i_reverse_iterator i_rend() const;
189 
191  ik_iterator k_begin(const i_iterator& i) const;
192 
194  ik_iterator k_end(const i_iterator& i) const;
195 
197  ik_iterator k_begin(const i_reverse_iterator& i) const;
198 
200  ik_iterator k_end(const i_reverse_iterator& i) const;
201 
203  ikj_iterator j_begin(const ik_iterator& k) const;
204 
206  ikj_iterator j_end(const ik_iterator& k) const;
207 
209 
210  private:
211 
212  // Prohibit copying
214 
215  // Prohibit Assignment
217 
218  protected:
219 
222 
225 
228 
231 
233 
236 
239 
242 
244 
245  }; // class Sparse3Tensor
246 
250  template <typename ordinal_type, typename value_type>
251  std::ostream&
252  operator << (std::ostream& os,
254  Cijk.print(os);
255  return os;
256  }
257 
261  template <typename index_iterator, typename value_iterator>
264  return *it;
265  }
266 
270  template <typename index_iterator, typename value_iterator>
273  {
274  return *it;
275  }
276 
281  template <typename index_iterator, typename value_iterator>
284  return it.value();
285  }
286 
287 } // namespace Stokhos
288 
289 // Include template definitions
291 
292 #endif // STOKHOS_SPARSE3TENSOR_HPP
j_sparse_array::const_iterator ikj_iterator
Iterator for looping over j entries given i and k.
bool fill_completed
Indicate whether fillComplete() has been called.
SparseArray< ordinal_type, j_sparse_array > kj_sparse_array
Sparse3Tensor & operator=(const Sparse3Tensor &b)
k_iterator k_begin() const
Iterator pointing to first k entry.
SparseArrayIterator< index_iterator, value_iterator >::value_type index(const SparseArrayIterator< index_iterator, value_iterator > &it)
std::map< const ordinal_type, ji_map > kji_map
ordinal_type num_j(const k_iterator &k) const
Number of j entries in C(i,j,k) for given k.
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
std::iterator_traits< value_iterator_type >::reference value_reference
ji_sparse_array::const_iterator kj_iterator
Iterator for looping over j entries given k.
ikj_sparse_array::const_iterator i_iterator
Iterator for looping over i entries.
ordinal_type num_k() const
Number of k entries in C(i,j,k)
kj_iterator j_begin(const k_iterator &k) const
Iterator pointing to first j entry for given k.
ikj_sparse_array::const_reverse_iterator i_reverse_iterator
Iterator for looping over i entries in reverse.
void fillComplete()
Signal all terms have been added.
std::map< const ordinal_type, kj_map > ikj_map
Container for a &quot;sparse&quot; array.
i_reverse_iterator i_rbegin() const
Reverse iterator pointing to last k entry.
kj_iterator j_end(const k_iterator &k) const
Iterator pointing to last j entry for given k.
Bi-directional iterator for traversing a sparse array.
Bi-directional reverse iterator for traversing a sparse array.
std::map< const ordinal_type, value_type > j_map
kji_sparse_array::const_iterator k_iterator
Iterator for looping over k entries.
ikj_sparse_array ikj_array
kji indices and values in Cijk (data structure for iterating)
SparseArrayReverseIterator< index_iterator, value_iterator >::value_type index(const SparseArrayReverseIterator< index_iterator, value_iterator > &it)
std::map< const ordinal_type, j_map > kj_map
std::ostream & operator<<(std::ostream &os, const ProductContainer< coeff_type > &vec)
SparseArray< ordinal_type, value_type > j_sparse_array
void add_term(ordinal_type i, ordinal_type j, ordinal_type k, const value_type &c)
Add new term for given (i,j,k)
i_reverse_iterator i_rend() const
Reverse iterator pointing to first k entry.
std::map< const ordinal_type, i_map > ji_map
SparseArray< ordinal_type, ji_sparse_array > kji_sparse_array
k_iterator k_end() const
Iterator pointing to last k entry.
k_iterator find_k(ordinal_type k) const
Return k iterator for given index k.
kji_sparse_array kji_array
kji indices and values in Cijk (data structure for iterating)
i_iterator i_begin() const
Iterator pointing to first k entry.
kj_sparse_array::const_iterator ik_iterator
Iterator for looping over k entries given i.
bool fillCompleted() const
Return whether fillComplete() has been called.
j_sparse_array::const_iterator kji_iterator
Iterator for looping over i entries given k and j.
SparseArray< ordinal_type, value_type > i_sparse_array
std::map< const ordinal_type, value_type > i_map
ikj_map ikj_data
ikj indices and values in Cijk (data structure for filling)
SparseArrayIterator< index_iterator, value_iterator >::value_reference value(const SparseArrayIterator< index_iterator, value_iterator > &it)
kji_iterator find_i(const kj_iterator &j, ordinal_type i) const
Return i iterator given j iterator and index i.
ordinal_type num_i() const
Number of i entries in C(i,j,k)
void print(std::ostream &os) const
Print tensor.
void sum_term(ordinal_type i, ordinal_type j, ordinal_type k, const value_type &c)
Add new term for given (i,j,k) and sum in if already there.
k_reverse_iterator k_rbegin() const
Reverse iterator pointing to last k entry.
SparseArray< ordinal_type, i_sparse_array > ji_sparse_array
value_type getValue(ordinal_type i, ordinal_type j, ordinal_type k) const
Get Cijk value for a given i, j, k indices.
value_reference value() const
Return value associated with iterator.
k_reverse_iterator k_rend() const
Reverse iterator pointing to first k entry.
i_iterator i_end() const
Iterator pointing to last k entry.
kj_iterator find_j(const k_iterator &k, ordinal_type j) const
Return j iterator given k iterator and index j.
kji_map kji_data
kji indices and values in Cijk (data structure for filling)
kji_sparse_array::const_reverse_iterator k_reverse_iterator
Iterator for looping over k entries in reverse.
SparseArray< ordinal_type, kj_sparse_array > ikj_sparse_array
ordinal_type num_entries() const
Return number of non-zero entries.