45 template <
typename ordinal_type,
typename value_type>
52 template <
typename ordinal_type,
typename value_type>
59 "You can't call add_term() after calling fillComplete()!");
62 kji_data[k][
j][i] = c;
63 ikj_data[i][k][
j] = c;
66 template <
typename ordinal_type,
typename value_type>
73 "You can't call sum_term() after calling fillComplete()!");
76 kji_data[k][
j][i] += c;
77 ikj_data[i][k][
j] += c;
80 template <
typename ordinal_type,
typename value_type>
88 ikj_array.resize(ikj_data.size());
90 for (
typename ikj_map::const_iterator i_it = ikj_data.begin();
91 i_it != ikj_data.end(); ++i_it) {
92 ikj_array.indices[n] = i_it->first;
93 ikj_array.values[n].resize(i_it->second.size());
95 for (
typename kj_map::const_iterator k_it = i_it->second.begin();
96 k_it != i_it->second.end(); ++k_it) {
97 ikj_array.values[n].indices[l] = k_it->first;
98 ikj_array.values[n].values[l].resize(k_it->second.size());
100 for (
typename j_map::const_iterator j_it = k_it->second.begin();
101 j_it != k_it->second.end(); ++j_it) {
102 ikj_array.values[n].values[l].indices[m] = j_it->first;
103 ikj_array.values[n].values[l].values[m] = j_it->second;
111 kji_array.resize(kji_data.size());
113 for (
typename kji_map::const_iterator k_it = kji_data.begin();
114 k_it != kji_data.end(); ++k_it) {
115 kji_array.indices[n] = k_it->first;
116 kji_array.values[n].resize(k_it->second.size());
118 for (
typename ji_map::const_iterator j_it = k_it->second.begin();
119 j_it != k_it->second.end(); ++j_it) {
120 kji_array.values[n].indices[l] = j_it->first;
121 kji_array.values[n].values[l].resize(j_it->second.size());
123 for (
typename i_map::const_iterator i_it = j_it->second.begin();
124 i_it != j_it->second.end(); ++i_it) {
125 kji_array.values[n].values[l].indices[m] = i_it->first;
126 kji_array.values[n].values[l].values[m] = i_it->second;
137 fill_completed =
true;
140 template <
typename ordinal_type,
typename value_type>
145 return fill_completed;
148 template <
typename ordinal_type,
typename value_type>
155 "You must call fillComplete() before calling print()!");
161 os <<
"k = " << index(k)
162 <<
", j = " << index(
j)
163 <<
", i = " << index(i)
164 <<
", Cijk = " << value(i) << std::endl;
167 template <
typename ordinal_type,
typename value_type>
174 "You must call fillComplete() before calling getValue()!");
182 if (j_it == j_end(k_it))
186 if (i_it == i_end(j_it))
192 template <
typename ordinal_type,
typename value_type>
199 "You must call fillComplete() before calling num_entries()!");
203 for (
k_iterator k = k_begin(); k != k_end(); ++k)
211 template <
typename ordinal_type,
typename value_type>
218 "You must call fillComplete() before calling num_k()!");
220 return kji_array.size();
223 template <
typename ordinal_type,
typename value_type>
230 "You must call fillComplete() before calling num_j()!");
233 return k.
value().size();
236 template <
typename ordinal_type,
typename value_type>
243 "You must call fillComplete() before calling num_i()!");
245 return j.
value().size();
248 template <
typename ordinal_type,
typename value_type>
255 "You must call fillComplete() before calling find_k()!");
257 return kji_array.find(k);
260 template <
typename ordinal_type,
typename value_type>
267 "You must call fillComplete() before calling find_j()!");
269 return k.
value().find(j);
272 template <
typename ordinal_type,
typename value_type>
279 "You must call fillComplete() before calling find_i()!");
281 return j.
value().find(i);
284 template <
typename ordinal_type,
typename value_type>
291 "You must call fillComplete() before calling k_begin()!");
293 return kji_array.begin();
296 template <
typename ordinal_type,
typename value_type>
303 "You must call fillComplete() before calling k_end()!");
305 return kji_array.end();
308 template <
typename ordinal_type,
typename value_type>
315 "You must call fillComplete() before calling k_rbegin()!");
317 return kji_array.rbegin();
320 template <
typename ordinal_type,
typename value_type>
327 "You must call fillComplete() before calling k_rend()!");
329 return kji_array.rend();
332 template <
typename ordinal_type,
typename value_type>
339 "You must call fillComplete() before calling j_begin()!");
341 return k.
value().begin();
344 template <
typename ordinal_type,
typename value_type>
351 "You must call fillComplete() before calling j_end()!");
353 return k.
value().end();
356 template <
typename ordinal_type,
typename value_type>
363 "You must call fillComplete() before calling j_begin()!");
365 return k.
value().begin();
368 template <
typename ordinal_type,
typename value_type>
375 "You must call fillComplete() before calling j_end()!");
377 return k.
value().end();
380 template <
typename ordinal_type,
typename value_type>
387 "You must call fillComplete() before calling i_begin()!");
389 return j.
value().begin();
392 template <
typename ordinal_type,
typename value_type>
399 "You must call fillComplete() before calling i_end()!");
401 return j.
value().end();
404 template <
typename ordinal_type,
typename value_type>
411 "You must call fillComplete() before calling num_i()!");
413 return ikj_array.size();
416 template <
typename ordinal_type,
typename value_type>
423 "You must call fillComplete() before calling num_k()!");
425 return i.
value().size();
428 template <
typename ordinal_type,
typename value_type>
431 num_j(
const ik_iterator& k)
const
435 "You must call fillComplete() before calling num_j()!");
437 return k.value().size();
440 template <
typename ordinal_type,
typename value_type>
447 "You must call fillComplete() before calling find_i()!");
449 return ikj_array.find(i);
452 template <
typename ordinal_type,
typename value_type>
459 "You must call fillComplete() before calling find_k()!");
461 return i.
value().find(k);
464 template <
typename ordinal_type,
typename value_type>
471 "You must call fillComplete() before calling find_j()!");
473 return k.value().find(j);
476 template <
typename ordinal_type,
typename value_type>
483 "You must call fillComplete() before calling i_begin()!");
485 return ikj_array.begin();
488 template <
typename ordinal_type,
typename value_type>
495 "You must call fillComplete() before calling i_end()!");
497 return ikj_array.end();
500 template <
typename ordinal_type,
typename value_type>
507 "You must call fillComplete() before calling i_rbegin()!");
509 return ikj_array.rbegin();
512 template <
typename ordinal_type,
typename value_type>
519 "You must call fillComplete() before calling i_rend()!");
521 return ikj_array.rend();
524 template <
typename ordinal_type,
typename value_type>
531 "You must call fillComplete() before calling k_begin()!");
533 return i.
value().begin();
536 template <
typename ordinal_type,
typename value_type>
543 "You must call fillComplete() before calling k_end()!");
545 return i.
value().end();
548 template <
typename ordinal_type,
typename value_type>
555 "You must call fillComplete() before calling k_begin()!");
557 return i.
value().begin();
560 template <
typename ordinal_type,
typename value_type>
567 "You must call fillComplete() before calling k_end()!");
569 return i.
value().end();
572 template <
typename ordinal_type,
typename value_type>
575 j_begin(
const ik_iterator& k)
const
579 "You must call fillComplete() before calling j_begin()!");
581 return k.value().begin();
584 template <
typename ordinal_type,
typename value_type>
587 j_end(
const ik_iterator& k)
const
591 "You must call fillComplete() before calling j_end()!");
593 return k.value().end();
Sparse3Tensor()
Constructor.
k_iterator k_begin() const
Iterator pointing to first k entry.
ordinal_type num_j(const k_iterator &k) const
Number of j entries in C(i,j,k) for given k.
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void fillComplete()
Signal all terms have been added.
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.
void add_term(ordinal_type i, ordinal_type j, ordinal_type k, const value_type &c)
Add new term for given (i,j,k)
value_reference value() const
Return value associated with iterator.
i_reverse_iterator i_rend() const
Reverse iterator pointing to first k entry.
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.
i_iterator i_begin() const
Iterator pointing to first k entry.
bool fillCompleted() const
Return whether fillComplete() has been called.
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.
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.
ordinal_type num_entries() const
Return number of non-zero entries.