FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
sparse_vector_blocked.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
11#include <kernel/util/type_traits.hpp>
12#include <kernel/lafem/container.hpp>
13#include <kernel/lafem/dense_vector.hpp>
14#include <kernel/util/tiny_algebra.hpp>
15#include <kernel/util/math.hpp>
16#include <kernel/lafem/arch/max_abs_index.hpp>
17#include <kernel/lafem/arch/min_abs_index.hpp>
18#include <kernel/lafem/arch/max_index.hpp>
19#include <kernel/lafem/arch/min_index.hpp>
20#include <kernel/lafem/arch/max_rel_diff.hpp>
21#include <kernel/adjacency/permutation.hpp>
22#include <array>
23
24namespace FEAT
25{
26 namespace LAFEM
27 {
29 namespace Intern
30 {
31 template<typename DT_, int BlockSize_, Perspective perspective_>
32 struct SparseVectorBlockedPerspectiveHelper
33 {
34 typedef Tiny::Vector<DT_, BlockSize_> Type;
35 };
36
37 template<typename DT_, int BlockSize_>
38 struct SparseVectorBlockedPerspectiveHelper<DT_, BlockSize_, Perspective::pod>
39 {
40 typedef DT_ Type;
41 };
42 } // namespace Intern
44
67 template <typename DT_, typename IT_, int BlockSize_>
68 class SparseVectorBlocked : public Container<DT_, IT_>
69 {
70 private:
71 template <typename T1_, typename T2_>
72 static void _insertion_sort(T1_ * key, T2_ * val1, Index size)
73 {
74 T1_ swap_key;
75 T2_ swap1;
76 for (Index i(1), j ; i < size ; ++i)
77 {
78 swap_key = key[i];
79 swap1 = val1[i];
80 j = i;
81 while (j > 0 && key[j-1] > swap_key)
82 {
83 key[j] = key[j-1];
84 val1[j] = val1[j-1];
85 --j;
86 }
87 key[j] = swap_key;
88 val1[j] = swap1;
89 }
90 }
91
92 Index & _used_elements()
93 {
94 return this->_scalar_index.at(1);
95 }
96
97 Index & _allocated_elements()
98 {
99 return this->_scalar_index.at(2);
100 }
101
102 Index & _sorted()
103 {
104 return this->_scalar_index.at(4);
105 }
106
107 bool _remove_element(IT_ ind)
108 {
109 IT_* pindices = this->_indices.at(0);
110 IT_* ptr = std::find(pindices, pindices + _used_elements(), ind);
111 if(ptr == pindices + _used_elements())
112 {
113 return false;
114 }
115 _sorted() = 0;
116 *ptr = std::numeric_limits<IT_>::max();
117 sort();
118 return true;
119 }
120
121 public:
123 typedef DT_ DataType;
125 typedef IT_ IndexType;
127 static constexpr int BlockSize = BlockSize_;
130
137 Container<DT_, IT_> (0)
138 {
139 this->_scalar_index.push_back(0);
140 this->_scalar_index.push_back(0);
141 this->_scalar_index.push_back(Math::min<Index>(0, 1000));
142 this->_scalar_index.push_back(1);
143 }
144
151 template <typename DT2_ = DT_, typename IT2_ = IT_>
152 explicit SparseVectorBlocked(std::vector<char> input) :
153 Container<DT_, IT_>(0)
154 {
155 deserialize<DT2_,IT2_>(input);
156 }
157
166 explicit SparseVectorBlocked(FileMode mode, const String& filename) :
167 Container<DT_, IT_>(0)
168 {
169 read_from(mode, filename);
170 }
171
180 explicit SparseVectorBlocked(FileMode mode, std::istream& file) :
181 Container<DT_, IT_>(0)
182 {
183 read_from(mode, file);
184 }
185
186
194 explicit SparseVectorBlocked(Index size_in) :
195 Container<DT_, IT_>(size_in)
196 {
197 this->_scalar_index.push_back(0);
198 this->_scalar_index.push_back(0);
199 this->_scalar_index.push_back(Math::min<Index>(size_in, 1000));
200 this->_scalar_index.push_back(1);
201 }
202
214 DenseVector<IT_, IT_> & indices_in, bool is_sorted = true) :
215 Container<DT_, IT_>(size_in)
216 {
217 XASSERT(size_in != Index(0));
218 XASSERTM(indices_in.size() == elements_in.size(), "Vector size mismatch!");
219
220 this->_scalar_index.push_back(elements_in.size());
221 this->_scalar_index.push_back(elements_in.size());
222 this->_scalar_index.push_back(Math::min<Index>(size_in, 1000));
223 this->_scalar_index.push_back(Index(is_sorted));
224
225 this->_elements.push_back(elements_in.template elements<Perspective::pod>());
226 this->_elements_size.push_back(elements_in.template size<Perspective::pod>());
227 this->_indices.push_back(indices_in.elements());
228 this->_indices_size.push_back(indices_in.size());
229
230 for (Index i(0) ; i < this->_elements.size() ; ++i)
232 for (Index i(0) ; i < this->_indices.size() ; ++i)
234
235 this->sort();
236 }
237
246 Container<DT_, IT_>(std::forward<SparseVectorBlocked>(other))
247 {
248 }
249
258 {
259 this->move(std::forward<SparseVectorBlocked>(other));
260
261 return *this;
262 }
263
273 {
275 t.clone(*this, clone_mode);
276 return t;
277 }
278
287 template<typename DT2_, typename IT2_>
289 {
290 Container<DT_, IT_>::clone(other, clone_mode);
291 }
292
303 template <typename DT2_, typename IT2_>
305 {
306 this->sort();
307 this->clone(other);
308 }
309
318 template <Perspective perspective_ = Perspective::native>
319 auto elements() const -> const typename Intern::SparseVectorBlockedPerspectiveHelper<DT_, BlockSize_, perspective_>::Type *
320 {
321 if (this->empty())
322 return nullptr;
323
324 if (sorted() == 0)
325 const_cast<SparseVectorBlocked *>(this)->sort();
326 return (const typename Intern::SparseVectorBlockedPerspectiveHelper<DT_, BlockSize_, perspective_>::Type *)(this->_elements.at(0));
327 }
328
331 template <Perspective perspective_ = Perspective::native>
332 auto elements() -> typename Intern::SparseVectorBlockedPerspectiveHelper<DT_, BlockSize_, perspective_>::Type *
333 {
334 if (this->empty())
335 return nullptr;
336
337 if (sorted() == 0)
338 const_cast<SparseVectorBlocked *>(this)->sort();
339 return (typename Intern::SparseVectorBlockedPerspectiveHelper<DT_, BlockSize_, perspective_>::Type *)(this->_elements.at(0));
340 }
341
347 IT_ * indices()
348 {
349 if(this->_indices.empty())
350 return nullptr;
351 if (sorted() == 0)
352 const_cast<SparseVectorBlocked *>(this)->sort();
353 return this->_indices.at(0);
354 }
355
358 IT_ const * indices() const
359 {
360 if(this->_indices.empty())
361 return nullptr;
362 if (sorted() == 0)
363 const_cast<SparseVectorBlocked *>(this)->sort();
364 return this->_indices.at(0);
365 }
366
373 template <Perspective perspective_ = Perspective::native>
374 Index size() const
375 {
376 if (perspective_ == Perspective::pod)
377 return static_cast<const Container<DT_, IT_> *>(this)->size() * Index(BlockSize_);
378 else
379 return static_cast<const Container<DT_, IT_> *>(this)->size();
380 }
381
389 const ValueType operator()(Index index) const
390 {
391 ASSERTM(index < this->_scalar_index.at(0), "index exceeds sparse vector size");
392
393 MemoryPool::synchronize();
394
395 if (this->_elements.empty())
396 return ValueType(0.);
397
398 if (sorted() == 0)
399 const_cast<SparseVectorBlocked *>(this)->sort();
400
401 Index i(0);
402 while (i < used_elements())
403 {
404 if (indices()[i] >= index)
405 break;
406 ++i;
407 }
408
409 if (i < used_elements() && indices()[i] == index)
410 {
411 return this->elements()[i];
412 }
413 else
414 return ValueType(0.);
415 }
416
417
424 void operator()(Index index, const ValueType& val)
425 {
426 ASSERTM(index < this->_scalar_index.at(0), "index exceeds sparse vector size");
427
428 // flag container as not sorted anymore
429 // CAUTION: do not use any method triggering resorting until we are finished
430 _sorted() = 0;
431
432 // vector is empty, no arrays allocated
433 if (this->_elements.size() == 0)
434 {
435 this->_elements.push_back(MemoryPool::template allocate_memory<DT_>(alloc_increment() * Index(BlockSize_)));
436 this->_elements_size.push_back(alloc_increment() * Index(BlockSize_));
437 MemoryPool::template set_memory<DT_>(this->_elements.back(), DT_(4711), alloc_increment() * Index(BlockSize_));
438 this->_indices.push_back(MemoryPool::template allocate_memory<IT_>(alloc_increment()));
439 this->_indices_size.push_back(alloc_increment());
440 MemoryPool::template set_memory<IT_>(this->_indices.back(), IT_(4711), alloc_increment());
441 _allocated_elements() = alloc_increment();
442 MemoryPool::copy(this->_elements.at(0), val.v, Index(BlockSize_));
443 MemoryPool::set_memory(this->_indices.at(0), IT_(index));
444 _used_elements() = 1;
445 }
446
447 // append element in already allocated arrays
448 else if(_used_elements() < allocated_elements())
449 {
450 MemoryPool::copy(this->_elements.at(0) + _used_elements() * Index(BlockSize_), val.v,
451 Index(BlockSize_));
452 MemoryPool::set_memory(this->_indices.at(0) + _used_elements(), IT_(index));
453 ++_used_elements();
454 }
455
456 // reallocate arrays, append element
457 else
458 {
459 _allocated_elements() += alloc_increment();
460
461 DT_ * elements_new(MemoryPool::template allocate_memory<DT_>(
462 allocated_elements() * Index(BlockSize_)));
463 MemoryPool::template set_memory<DT_>(elements_new, DT_(4711),
464 allocated_elements() * Index(BlockSize_));
465 IT_ * indices_new(MemoryPool::template allocate_memory<IT_>(allocated_elements()));
466 MemoryPool::template set_memory<IT_>(indices_new, IT_(4711), allocated_elements());
467
468 MemoryPool::copy(elements_new, this->_elements.at(0), _used_elements() * Index(BlockSize_));
469 MemoryPool::copy(indices_new, this->_indices.at(0), _used_elements());
470
473
474 this->_elements.at(0) = elements_new;
475 this->_indices.at(0) = indices_new;
476
477 MemoryPool::copy(this->_elements.at(0) + used_elements() * Index(BlockSize_), val.v,
478 Index(BlockSize_));
479 MemoryPool::set_memory(this->_indices.at(0) + _used_elements(), IT_(index));
480
481 ++_used_elements();
482 this->_elements_size.at(0) = allocated_elements() * Index(BlockSize_);
483 this->_indices_size.at(0) = allocated_elements();
484 }
485 }
486
488 void sort()
489 {
490 if (sorted() == 0)
491 {
492 //first of all, mark vector as sorted, because otherwise we would call ourselves inifite times
493 // CAUTION: do not use any method triggering resorting until we are finished
494 _sorted() = 1;
495
496 // check if there is anything to be sorted
497 if(_used_elements() == Index(0))
498 return;
499
500 IT_ * pindices;
501 ValueType * pelements;
502 pindices = this->_indices.at(0);
503 pelements = this->elements();
504
505 _insertion_sort(pindices, pelements, _used_elements());
506
507 // find and mark duplicate entries
508 for (Index i(1) ; i < _used_elements() ; ++i)
509 {
510 if (pindices[i-1] == pindices[i])
511 {
512 pindices[i-1] = std::numeric_limits<IT_>::max();
513 }
514 }
515
516 // sort out marked duplicated elements
517 _insertion_sort(pindices, pelements, _used_elements());
518 Index junk(0);
519 while (pindices[_used_elements() - 1 - junk] == std::numeric_limits<IT_>::max() && junk < _used_elements())
520 ++junk;
521 _used_elements() -= junk;
522 }
523 }
524
532 template <typename DT2_ = DT_, typename IT2_ = IT_>
533 void deserialize(std::vector<char> input)
534 {
535 this->template _deserialize<DT2_, IT2_>(FileMode::fm_svb, input);
536 }
537
538
539 template<typename IndexContainer>
540 bool remove_elements(const IndexContainer& inds)
541 {
542 bool success = true;
543 for(auto i : inds)
544 {
545 success &= _remove_element(IndexType(i));
546 }
547 return success;
548 }
549
550 bool remove_element(IndexType ind)
551 {
552 return _remove_element(ind);
553 }
554
555 bool element_exists(IndexType ind) const
556 {
557 const IT_* pindices = this->_indices.at(0);
558 return std::find(pindices, pindices + this->_scalar_index.at(1), ind) != pindices + this->_scalar_index.at(1);
559 }
560
571 template <typename DT2_ = DT_, typename IT2_ = IT_>
572 std::vector<char> serialize(const LAFEM::SerialConfig& config = SerialConfig()) const
573 {
574 return this->template _serialize<DT2_, IT2_>(FileMode::fm_svb, config);
575 }
576
583 void read_from(FileMode mode, const String& filename)
584 {
585 std::ifstream file(filename.c_str(), std::ifstream::in | std::ifstream::binary);
586 if (! file.is_open())
587 XABORTM("Unable to open Vector file " + filename);
588 read_from(mode, file);
589 file.close();
590 }
591
598 void read_from(FileMode mode, std::istream& file)
599 {
600 switch(mode)
601 {
603 case FileMode::fm_svb:
604 this->template _deserialize<double, std::uint64_t>(FileMode::fm_svb, file);
605 break;
606 default:
607 XABORTM("Filemode not supported!");
608 }
609 }
610
617 void write_out(FileMode mode, const String& filename) const
618 {
619 std::ios_base::openmode bin = std::ofstream::out | std::ofstream::binary;
620 if(mode == FileMode::fm_mtx)
621 bin = std::ofstream::out;
622 std::ofstream file;
623 char* buff = nullptr;
624 if(mode == FileMode::fm_mtx)
625 {
626 buff = new char[LAFEM::FileOutStreamBufferSize];
627 file.rdbuf()->pubsetbuf(buff, LAFEM::FileOutStreamBufferSize);
628 }
629 file.open(filename.c_str(), bin);
630 if(! file.is_open())
631 XABORTM("Unable to open Matrix file " + filename);
632 write_out(mode, file);
633 file.close();
634 delete[] buff;
635 }
636
643 void write_out(FileMode mode, std::ostream& file) const
644 {
645 switch(mode)
646 {
647 case FileMode::fm_mtx:
648 {
649
650 file << "%%MatrixMarket matrix coordinate real general\n";
651 file << this->size()*BlockSize << " " << 1 << " " << this->used_elements()*BlockSize << "\n";
652
653 const Index u_elem(this->used_elements());
654 const IT_ * pind(this->indices());
655 const DT_ * pval(this->elements<Perspective::pod>());
656 for (Index i(0) ; i < u_elem ; ++i, ++pind, pval+=BlockSize)
657 {
658 for(Index k(0); k < BlockSize; ++k)
659 file << (*pind)*BlockSize+k+1 << " " << 1 << " " << stringify_fp_sci(*(pval+k)) << "\n";
660 }
661 break;
662 }
663
665 case FileMode::fm_svb:
666 this->template _serialize<double, std::uint64_t>(FileMode::fm_svb, file);
667 break;
668 default:
669 XABORTM("Filemode not supported!");
670 }
671 }
672
675
681 DT_ max_abs_element() const
682 {
683 TimeStamp ts_start;
684
685 Index max_abs_index = Arch::MaxAbsIndex::value(this->template elements<Perspective::pod>(), this->template used_elements<Perspective::pod>());
686 ASSERT(max_abs_index < this->template used_elements<Perspective::pod>());
687 DT_ result(this->template elements<Perspective::pod>()[max_abs_index]);
688 result = Math::abs(result);
689
690 TimeStamp ts_stop;
691 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
692
693 return result;
694 }
695
701 DT_ min_abs_element() const
702 {
703 TimeStamp ts_start;
704
705 Index min_abs_index = Arch::MinAbsIndex::value(this->template elements<Perspective::pod>(), this->template used_elements<Perspective::pod>());
706 ASSERT(min_abs_index < this->template used_elements<Perspective::pod>());
707 DT_ result(this->template elements<Perspective::pod>()[min_abs_index]);
708 result = Math::abs(result);
709
710 TimeStamp ts_stop;
711 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
712
713 return result;
714 }
715
721 DT_ max_element() const
722 {
723 TimeStamp ts_start;
724
725 Index max_index = Arch::MaxIndex::value(this->template elements<Perspective::pod>(), this->template used_elements<Perspective::pod>());
726 ASSERT(max_index < this->template used_elements<Perspective::pod>());
727 DT_ result(this->template elements<Perspective::pod>()[max_index]);
728
729 TimeStamp ts_stop;
730 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
731
732 return result;
733 }
734
740 DT_ min_element() const
741 {
742 TimeStamp ts_start;
743
744 Index min_index = Arch::MinIndex::value(this->template elements<Perspective::pod>(), this->template used_elements<Perspective::pod>());
745 ASSERT(min_index < this->template used_elements<Perspective::pod>());
746 DT_ result(this->template elements<Perspective::pod>()[min_index]);
747
748 TimeStamp ts_stop;
749 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
750
751 return result;
752 }
753
761 {
762 XASSERTM(x.used_elements() == this->used_elements(), "Nonzero count does not match!");
763 TimeStamp ts_start;
764
765 DataType max_rel_diff = Arch::MaxRelDiff::value(this->template elements<Perspective::pod>(),
766 x.template elements<Perspective::pod>(), this->template used_elements<Perspective::pod>());
767
768 TimeStamp ts_stop;
769 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
770
771 return max_rel_diff;
772 }
773
775
778 {
779 if (perm.size() == 0)
780 return;
781
782 XASSERTM(perm.size() == this->size(), "Container size does not match permutation size");
783
785
786 auto inv = perm.inverse();
787 const Index * const inv_pos(inv.get_perm_pos());
788 for (Index i(0) ; i < this->used_elements() ; ++i)
789 {
790 const Index col = this->indices()[i];
791 target(inv_pos[col], (*this)(col));
792 }
793
794 target.sort();
795 this->assign(target);
796 }
797
803 template <Perspective perspective_ = Perspective::native>
805 {
806 if (sorted() == 0)
807 const_cast<SparseVectorBlocked *>(this)->sort();
808 if (perspective_ == Perspective::pod)
809 return this->_scalar_index.at(1) * Index(BlockSize_);
810 else
811 return this->_scalar_index.at(1);
812 }
813
820 {
821 if(this->_scalar_index.empty())
822 return Index(0);
823 return this->_scalar_index.at(2);
824 }
825
832 {
833 if(this->_scalar_index.empty())
834 return Index(0);
835 return this->_scalar_index.at(3);
836 }
837
843 Index sorted() const
844 {
845 if(this->_scalar_index.empty())
846 return Index(0);
847 return this->_scalar_index.at(4);
848 }
849
855 static String name()
856 {
857 return "SparseVectorBlocked";
858 }
859
869 bool same_layout(const SparseVectorBlocked& other) const
870 {
871 if(this->size() != other.size())
872 return false;
873 if(this->used_elements() != other.used_elements())
874 return false;
875
876 Index n = this->used_elements();
877 if(n == Index(0))
878 return true; // both vectors are empty
879
880 const IT_* a = this->indices();
881 const IT_* b = other.indices();
882
883 // shallow copy? (aka same array)
884 if(a == b)
885 return true;
886
887 // check all array entries
888 for(Index i(0); i < n; ++i)
889 {
890 if(a[i] != b[i])
891 return false;
892 }
893
894 // okay, arrays are identical
895 return true;
896 }
897
904 friend std::ostream & operator<< (std::ostream & lhs, const SparseVectorBlocked & b)
905 {
906 lhs << "[";
907 for (Index i(0) ; i < b.size() ; ++i)
908 {
909 ValueType t = b(i);
910 for (int j(0) ; j < BlockSize_ ; ++j)
911 lhs << " " << stringify(t[j]);
912 }
913 lhs << "]";
914
915 return lhs;
916 }
917 }; // class SparseVectorBlocked<...>
918 } // namespace LAFEM
919} // namespace FEAT
#define ASSERT(expr)
Debug-Assertion macro definition.
Definition: assertion.hpp:229
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
Definition: assertion.hpp:230
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
FEAT Kernel base header.
Index size() const
returns the size of the permutation
Permutation inverse() const
Computes the inverse permutation.
Container base class.
Definition: container.hpp:220
std::vector< DT_ * > _elements
List of pointers to all datatype dependent arrays.
Definition: container.hpp:226
bool empty() const
Checks whether the container is empty.
Definition: container.hpp:1165
std::vector< Index > _elements_size
List of corresponding datatype array sizes.
Definition: container.hpp:230
Index size() const
Returns the containers size.
Definition: container.hpp:1136
void assign(const Container< DT2_, IT2_ > &other)
Assignment operation.
Definition: container.hpp:280
std::vector< IT_ * > _indices
List of pointers to all IT_ dependent arrays.
Definition: container.hpp:228
void clone(const Container &other, CloneMode clone_mode=CloneMode::Weak)
Clone operation.
Definition: container.hpp:902
void move(Container &&other)
Assignment move operation.
Definition: container.hpp:989
std::vector< Index > _indices_size
List of corresponding IT_ array sizes.
Definition: container.hpp:232
std::vector< Index > _scalar_index
List of scalars with datatype index.
Definition: container.hpp:234
Blocked Dense data vector class template.
Index size() const
The number of elements.
Dense data vector class template.
DT_ * elements()
Get a pointer to the data array.
Config class for serialize parameter.
Definition: container.hpp:47
Sparse vector class template.
void read_from(FileMode mode, const String &filename)
Read in vector from file.
Tiny::Vector< DT_, BlockSize_ > ValueType
Our value type.
SparseVectorBlocked(Index size_in, DenseVectorBlocked< DT_, IT_, BlockSize_ > &elements_in, DenseVector< IT_, IT_ > &indices_in, bool is_sorted=true)
Constructor.
static String name()
Returns a descriptive string.
DT_ min_element() const
Retrieve the minimum value of this vector.
Index sorted() const
Retrieve status of element sorting.
Index size() const
The number of elements.
void deserialize(std::vector< char > input)
Deserialization of complete container entity.
SparseVectorBlocked(Index size_in)
Constructor.
void clone(const SparseVectorBlocked< DT2_, IT2_, BlockSize_ > &other, CloneMode clone_mode=CloneMode::Deep)
Clone operation.
static constexpr int BlockSize
Our size of a single block.
Index used_elements() const
Retrieve non zero element count.
friend std::ostream & operator<<(std::ostream &lhs, const SparseVectorBlocked &b)
SparseVectorBlocked streaming operator.
IT_ const * indices() const
Get a pointer to the non zero indices array.
void operator()(Index index, const ValueType &val)
Set specific vector element.
void write_out(FileMode mode, const String &filename) const
Write out vector to file.
DT_ max_rel_diff(const SparseVectorBlocked &x) const
Retrieve the maximum relative difference of this vector and another one y.max_rel_diff(x) returns .
SparseVectorBlocked(std::vector< char > input)
Constructor.
SparseVectorBlocked(FileMode mode, const String &filename)
Constructor.
SparseVectorBlocked(FileMode mode, std::istream &file)
Constructor.
void permute(Adjacency::Permutation &perm)
Permutate vector according to the given Permutation.
SparseVectorBlocked & operator=(SparseVectorBlocked &&other)
Assignment move operator.
SparseVectorBlocked clone(CloneMode clone_mode=CloneMode::Deep) const
Clone operation.
DT_ min_abs_element() const
Retrieve the absolute minimum value of this vector.
void convert(const SparseVectorBlocked< DT2_, IT2_, BlockSize_ > &other)
Conversion method.
Index allocated_elements() const
Retrieve amount of allocated elements.
std::vector< char > serialize(const LAFEM::SerialConfig &config=SerialConfig()) const
Serialization of complete container entity.
bool same_layout(const SparseVectorBlocked &other) const
Checks whether the layout of this vector is identical to another sparse vector.
const ValueType operator()(Index index) const
Retrieve specific vector element.
IT_ * indices()
Get a pointer to the non zero indices array.
DT_ max_element() const
Retrieve the maximum value of this vector.
auto elements() const -> const typename Intern::SparseVectorBlockedPerspectiveHelper< DT_, BlockSize_, perspective_ >::Type *
Retrieve a pointer to the data array.
void read_from(FileMode mode, std::istream &file)
Read in vector from stream.
SparseVectorBlocked(SparseVectorBlocked &&other)
Move Constructor.
DT_ max_abs_element() const
Retrieve the absolute maximum value of this vector.
auto elements() -> typename Intern::SparseVectorBlockedPerspectiveHelper< DT_, BlockSize_, perspective_ >::Type *
void write_out(FileMode mode, std::ostream &file) const
Write out vector to file.
Index alloc_increment() const
Retrieve allocation incrementation value.
static void copy(DT_ *dest, const DT_ *src, const Index count)
Copy memory area from src to dest.
static void set_memory(DT_ *address, const DT_ val, const Index count=1)
set memory to specific value
static void release_memory(void *address)
release memory or decrease reference counter
static void increase_memory(void *address)
increase memory counter
String class implementation.
Definition: string.hpp:46
Time stamp class.
Definition: time_stamp.hpp:54
double elapsed(const TimeStamp &before) const
Calculates the time elapsed between two time stamps.
Definition: time_stamp.hpp:100
Tiny Vector class template.
T_ v[s_]
actual vector data
constexpr std::size_t FileOutStreamBufferSize
OutStreamBufferSize.
Definition: base.hpp:124
T_ abs(T_ x)
Returns the absolute value.
Definition: math.hpp:275
Type
bitmask for zfp header
Definition: pack.hpp:81
FEAT namespace.
Definition: adjactor.hpp:12
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:944
String stringify_fp_sci(DataType_ value, int precision=0, int width=0, bool sign=false)
Prints a floating point value to a string in scientific notation.
Definition: string.hpp:1088
std::uint64_t Index
Index data type.