FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
dense_vector.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
10#include <kernel/lafem/forward.hpp>
12#include <kernel/util/type_traits.hpp>
13#include <kernel/util/math.hpp>
14#include <kernel/util/random.hpp>
15#include <kernel/lafem/container.hpp>
16#include <kernel/lafem/dense_vector_blocked.hpp>
17#include <kernel/lafem/arch/component_invert.hpp>
18#include <kernel/lafem/arch/dot_product.hpp>
19#include <kernel/lafem/arch/norm.hpp>
20#include <kernel/lafem/arch/max_abs_index.hpp>
21#include <kernel/lafem/arch/min_abs_index.hpp>
22#include <kernel/lafem/arch/max_index.hpp>
23#include <kernel/lafem/arch/min_index.hpp>
24#include <kernel/lafem/arch/max_rel_diff.hpp>
25#include <kernel/lafem/arch/scale.hpp>
26#include <kernel/lafem/arch/axpy.hpp>
27#include <kernel/lafem/arch/component_product.hpp>
28#include <kernel/adjacency/permutation.hpp>
29#include <kernel/util/statistics.hpp>
30#include <kernel/util/time_stamp.hpp>
31
32#include <iostream>
33#include <fstream>
34#include <string>
35#include <stdint.h>
36
37namespace FEAT
38{
39 namespace LAFEM
40 {
56 template <typename DT_, typename IT_ = Index>
57 class DenseVector : public Container<DT_, IT_>
58 {
59 public:
66 {
67 public:
69 typedef DT_ DataType;
70 typedef IT_ IndexType;
71
72 private:
73 Index _num_entries;
74 DT_ * _data;
75
76 public:
77 explicit ScatterAxpy(VectorType & vector) :
78 _num_entries(vector.size()),
79 _data(vector.elements())
80 {
81 }
82
83 template <typename LocalVector_, typename Mapping_>
84 void operator()(const LocalVector_ & loc_vec, const Mapping_ & mapping, DT_ alpha = DT_(1))
85 {
86 // loop over all local entries
87 for (int i(0); i < mapping.get_num_local_dofs(); ++i)
88 {
89 // get dof index
90 Index dof_idx = mapping.get_index(i);
91 ASSERT(dof_idx < _num_entries);
92
93 // update vector entry
94 _data[dof_idx] += alpha * loc_vec[i];
95 }
96 }
97 }; // class ScatterAxpy
98
105 {
106 public:
108 typedef DT_ DataType;
109 typedef IT_ IndexType;
110
111 private:
112 Index _num_entries;
113 const DT_ * _data;
114
115 public:
116 explicit GatherAxpy(const VectorType & vector) :
117 _num_entries(vector.size()),
118 _data(vector.elements())
119 {
120 }
121
122 template <typename LocalVector_, typename Mapping_>
123 void operator()(LocalVector_ & loc_vec, const Mapping_ & mapping, DT_ alpha = DT_(1))
124 {
125 // loop over all local entries
126 for (int i(0); i < mapping.get_num_local_dofs(); ++i)
127 {
128 // get dof index
129 Index dof_idx = mapping.get_index(i);
130 ASSERT(dof_idx < _num_entries);
131
132 // update local vector data
133 loc_vec[i] += alpha * _data[dof_idx];
134 }
135 }
136 }; // class GatherAxpy
137
138 public:
140 typedef DT_ DataType;
142 typedef IT_ IndexType;
144 typedef DT_ ValueType;
146 template <typename DT2_ = DT_, typename IT2_ = IT_>
148
150 template <typename DataType2_, typename IndexType2_>
152
158 explicit DenseVector() :
159 Container<DT_, IT_> (0)
160 {
161 }
162
170 explicit DenseVector(Index size_in) :
171 Container<DT_, IT_>(size_in)
172 {
173 if (size_in == Index(0))
174 return;
175
176 this->_elements.push_back(MemoryPool::template allocate_memory<DT_>(size_in));
177
178 this->_elements_size.push_back(size_in);
179 }
180
189 explicit DenseVector(Index size_in, DT_ value) :
190 Container<DT_, IT_>(size_in)
191 {
192 if (size_in == Index(0))
193 return;
194
195 this->_elements.push_back(MemoryPool::template allocate_memory<DT_>(size_in));
196 this->_elements_size.push_back(size_in);
197
198 MemoryPool::set_memory(this->_elements.at(0), value, size_in);
199 }
200
216 explicit DenseVector(Index size_in, DT_ * data) :
217 Container<DT_, IT_>(size_in)
218 {
219 if (size_in == Index(0))
220 return;
221
222 this->_elements.push_back(data);
223 this->_elements_size.push_back(size_in);
224
225 for (Index i(0) ; i < this->_elements.size() ; ++i)
227 for (Index i(0) ; i < this->_indices.size() ; ++i)
229 }
230
242 explicit DenseVector(const DenseVector & dv_in, Index size_in, Index offset_in) :
243 Container<DT_, IT_>(size_in)
244 {
245 XASSERT(size_in > Index(0));
246 XASSERTM(size_in + offset_in <= dv_in.size(), "Ranged vector part exceeds original vector size!");
247
248 this->_foreign_memory = true;
249
250 DT_ * te(const_cast<DT_ *>(dv_in.elements()));
251 this->_elements.push_back(te + offset_in);
252 this->_elements_size.push_back(size_in);
253 }
254
262 template <int BS_>
264 Container<DT_, IT_>(other.template size<Perspective::pod>())
265 {
266 convert(other);
267 }
268
277 explicit DenseVector(FileMode mode, String filename) :
278 Container<DT_, IT_>(0)
279 {
280 read_from(mode, filename);
281 }
282
291 explicit DenseVector(FileMode mode, std::istream& file) :
292 Container<DT_, IT_>(0)
293 {
294 read_from(mode, file);
295 }
296
304 template <typename DT2_ = DT_, typename IT2_ = IT_>
305 explicit DenseVector(std::vector<char> input) :
306 Container<DT_, IT_>(0)
307 {
308 deserialize<DT2_, IT2_>(input);
309 }
310
321 explicit DenseVector(Random & rng, Index size_in, DataType min, DataType max) :
322 Container<DT_, IT_>(size_in)
323 {
324 if (size_in == Index(0))
325 return;
326
327 this->_elements.push_back(MemoryPool::template allocate_memory<DT_>(size_in));
328 this->_elements_size.push_back(size_in);
329
330 this->format(rng, min, max);
331 }
332
341 Container<DT_, IT_>(std::forward<DenseVector>(other))
342 {
343 }
344
348 virtual ~DenseVector()
349 {
350 }
351
360 {
361 this->move(std::forward<DenseVector>(other));
362
363 return *this;
364 }
365
375 {
376 DenseVector t;
377 t.clone(*this, clone_mode);
378 return t;
379 }
380
389 template <typename DT2_, typename IT2_>
390 void clone(const DenseVector<DT2_, IT2_> & other, CloneMode clone_mode = CloneMode::Deep)
391 {
392 Container<DT_, IT_>::clone(other, clone_mode);
393 }
394
402 template <typename DT2_, typename IT2_>
404 {
405 this->assign(other);
406 }
407
415 template <typename DT2_, typename IT2_, int BS2_>
417 {
418 this->clear();
419
420 this->_scalar_index.push_back(other.template size<Perspective::pod>());
421 this->_elements.push_back(other.get_elements().at(0));
422 this->_elements_size.push_back(this->size());
423
424 for (Index i(0) ; i < this->_elements.size() ; ++i)
426 for (Index i(0) ; i < this->_indices.size() ; ++i)
428 }
429
437 template <typename VT_>
438 void convert(const VT_ & a)
439 {
440 DenseVector vec(a.template size<Perspective::pod>());
441 a.set_vec(vec.elements());
442 this->move(std::move(vec));
443 }
444
452 template <typename DT2_ = DT_, typename IT2_ = IT_>
453 void deserialize(std::vector<char> input)
454 {
455 this->template _deserialize<DT2_, IT2_>(FileMode::fm_dv, input);
456 }
457
470 template <typename DT2_ = DT_, typename IT2_ = IT_>
471 std::vector<char> serialize(const LAFEM::SerialConfig& config = LAFEM::SerialConfig()) const
472 {
473 return this->template _serialize<DT2_, IT2_>(FileMode::fm_dv, config);
474 }
475
483 template <int BlockSize_>
485 {
487
488 const auto* p = elements();
489 auto* rp = result.template elements<Perspective::native>();
490 for (Index i(0) ; i < this->size() ; ++i)
491 {
492 rp[i] = typename decltype(result)::ValueType(p[i]);
493 }
494 return result;
495 }
496
502 template <typename VT_>
503 void copy(const VT_ & a)
504 {
505 XASSERTM(this->template size<Perspective::pod>() == a.template size<Perspective::pod>(), "Vectors have not the same size!");
506
507 a.set_vec(this->elements());
508 }
509
515 template <typename VT_>
516 void copy_inv(VT_ & a) const
517 {
518 XASSERTM(this->template size<Perspective::pod>() == a.template size<Perspective::pod>(), "Vectors have not the same size!");
519
520 a.set_vec_inv(this->elements());
521 }
522
530 void read_from(FileMode mode, const String& filename)
531 {
532 std::ios_base::openmode bin = std::ifstream::in | std::ifstream::binary;
533 if (mode == FileMode::fm_mtx)
534 bin = std::ifstream::in;
535 std::ifstream file(filename.c_str(), bin);
536 if (! file.is_open())
537 XABORTM("Unable to open Vector file " + filename);
538 read_from(mode, file);
539 file.close();
540 }
541
548 void read_from(FileMode mode, std::istream & file)
549 {
550 switch (mode)
551 {
552 case FileMode::fm_mtx:
553 {
554 this->clear();
555 this->_scalar_index.push_back(0);
556
557 Index rows;
558 String line;
559 std::getline(file, line);
560 if (line.find("%%MatrixMarket matrix array real general") == String::npos)
561 {
562 XABORTM("Input-file is not a compatible mtx-vector-file");
563 }
564 while (! file.eof())
565 {
566 std::getline(file, line);
567 if (file.eof())
568 XABORTM("Input-file is empty");
569
570 String::size_type begin(line.find_first_not_of(" "));
571 if (line.at(begin) != '%')
572 break;
573 }
574 {
575 String::size_type begin(line.find_first_not_of(" "));
576 line.erase(0, begin);
577 String::size_type end(line.find_first_of(" "));
578 String srows(line, 0, end);
579 rows = (Index)atol(srows.c_str());
580 line.erase(0, end);
581
582 begin = line.find_first_not_of(" ");
583 line.erase(0, begin);
584 end = line.find_first_of(" ");
585 String scols(line, 0, end);
586 Index cols((Index)atol(scols.c_str()));
587 line.erase(0, end);
588 XASSERTM(cols == 1, "Input-file is no dense-vector-file");
589 }
590
591 DenseVector<DT_, IT_> tmp(rows);
592 DT_ * pval(tmp.elements());
593
594 while (! file.eof())
595 {
596 std::getline(file, line);
597 if (file.eof())
598 break;
599
600 String::size_type begin(line.find_first_not_of(" "));
601 line.erase(0, begin);
602 String::size_type end(line.find_first_of(" "));
603 String sval(line, 0, end);
604 DT_ tval((DT_)atof(sval.c_str()));
605
606 *pval = tval;
607 ++pval;
608 }
609 this->move(std::move(tmp));
610 break;
611 }
612 case FileMode::fm_exp:
613 {
614 this->clear();
615 this->_scalar_index.push_back(0);
616
617 std::vector<DT_> data;
618
619 while (! file.eof())
620 {
621 std::string line;
622 std::getline(file, line);
623 if (line.find("#", 0) < line.npos)
624 continue;
625 if (file.eof())
626 break;
627
628 std::string n_z_s;
629
630 std::string::size_type first_digit(line.find_first_not_of(" "));
631 line.erase(0, first_digit);
632 std::string::size_type eol(line.length());
633 for (std::string::size_type i(0); i < eol; ++i)
634 {
635 n_z_s.append(1, line[i]);
636 }
637
638 DT_ n_z((DT_)atof(n_z_s.c_str()));
639
640 data.push_back(n_z);
641 }
642
643 this->_scalar_index.at(0) = Index(data.size());
644 this->_elements.push_back(MemoryPool::template allocate_memory<DT_>(Index(data.size())));
645 this->_elements_size.push_back(Index(data.size()));
646 MemoryPool::copy(this->_elements.at(0), &data[0], Index(data.size()));
647 break;
648 }
649 case FileMode::fm_dv:
651 this->template _deserialize<double, std::uint64_t>(FileMode::fm_dv, file);
652 break;
653 default:
654 XABORTM("Filemode not supported!");
655 }
656 }
657
664 void write_out(FileMode mode, const String& filename) const
665 {
666 std::ios_base::openmode bin = std::ofstream::out | std::ofstream::binary;
667 if (mode == FileMode::fm_mtx || mode == FileMode::fm_exp)
668 bin = std::ofstream::out;
669 std::ofstream file;
670 char* buff = nullptr;
671 if(mode == FileMode::fm_mtx)
672 {
673 buff = new char[LAFEM::FileOutStreamBufferSize];
674 file.rdbuf()->pubsetbuf(buff, LAFEM::FileOutStreamBufferSize);
675 }
676 file.open(filename.c_str(), bin);
677 if(! file.is_open())
678 XABORTM("Unable to open Matrix file " + filename);
679 write_out(mode, file);
680 file.close();
681 delete[] buff;
682 }
683
690 void write_out(FileMode mode, std::ostream & file) const
691 {
692 switch (mode)
693 {
694 case FileMode::fm_mtx:
695 {
697 temp.convert(*this);
698
699 const Index tsize(temp.size());
700 file << "%%MatrixMarket matrix array real general\n";
701 file << tsize << " " << 1 << "\n";
702
703 const DT_ * pval(temp.elements());
704 for (Index i(0); i < tsize; ++i, ++pval)
705 {
706 file << stringify_fp_sci(*pval) << "\n";
707 }
708 break;
709 }
710 case FileMode::fm_exp:
711 {
712 DT_ * temp = MemoryPool::template allocate_memory<DT_>((this->size()));
713 MemoryPool::copy(temp, this->_elements.at(0), this->size());
714
715 for (Index i(0); i < this->size(); ++i)
716 {
717 file << stringify_fp_sci(temp[i]) << "\n";
718 }
720 break;
721 }
722 case FileMode::fm_dv:
724 this->template _serialize<double, std::uint64_t>(FileMode::fm_dv, file);
725 break;
726 default:
727 XABORTM("Filemode not supported!");
728 }
729 }
730
736 template <Perspective = Perspective::native>
737 DT_ * elements()
738 {
739 if (this->_elements.size() == 0)
740 return nullptr;
741
742 return this->_elements.at(0);
743 }
744
745 template <Perspective = Perspective::native>
746 DT_ const * elements() const
747 {
748 if (this->_elements.size() == 0)
749 return nullptr;
750
751 return this->_elements.at(0);
752 }
753
761 const DT_ operator()(Index index) const
762 {
763 ASSERT(index < this->size());
764
765 MemoryPool::synchronize();
766
767 return elements()[index];
768 }
769
776 void operator()(Index index, DT_ value)
777 {
778 ASSERT(index < this->size());
779 elements()[index] = value;
780 MemoryPool::synchronize();
781 }
782
788 static String name()
789 {
790 return "DenseVector";
791 }
792
799 void copy(const DenseVector & x, bool full = false)
800 {
801 this->_copy_content(x, full);
802 }
803
806
813 void axpy(
814 const DenseVector & x,
815 const DT_ alpha = DT_(1))
816 {
817 XASSERTM(x.size() == this->size(), "Vector size does not match!");
818
819 TimeStamp ts_start;
820
821 Statistics::add_flops(this->size() * 2);
822 Arch::Axpy::value(this->elements(), alpha, x.elements(), this->size());
823
824 TimeStamp ts_stop;
825 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
826 }
827
834 void component_product(const DenseVector & x, const DenseVector & y)
835 {
836 XASSERTM(this->size() == x.size(), "Vector size does not match!");
837 XASSERTM(this->size() == y.size(), "Vector size does not match!");
838
839 TimeStamp ts_start;
840
842 Arch::ComponentProduct::value(this->elements(), x.elements(), y.elements(), this->size());
843
844 TimeStamp ts_stop;
845 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
846 }
847
857 void component_invert(const DenseVector & x, const DT_ alpha = DT_(1))
858 {
859 XASSERTM(this->size() == x.size(), "Vector size does not match!");
860
861 TimeStamp ts_start;
862
864 Arch::ComponentInvert::value(this->elements(), x.elements(), alpha, this->size());
865
866 TimeStamp ts_stop;
867 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
868 }
869
876 void scale(const DenseVector & x, const DT_ alpha)
877 {
878 XASSERTM(x.size() == this->size(), "Vector size does not match!");
879
880 TimeStamp ts_start;
881
883 Arch::Scale::value(this->elements(), x.elements(), alpha, this->size());
884
885 TimeStamp ts_stop;
886 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
887 }
888
898 DataType triple_dot(const DenseVector & x, const DenseVector & y) const
899 {
900 XASSERTM(x.size() == this->size(), "Vector size does not match!");
901 XASSERTM(y.size() == this->size(), "Vector size does not match!");
902
903 TimeStamp ts_start;
904
905 Statistics::add_flops(this->size() * 3);
906 DataType result = Arch::TripleDotProduct::value(this->elements(), x.elements(), y.elements(), this->size());
907
908 TimeStamp ts_stop;
909 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
910
911 return result;
912 }
913
921 DataType dot(const DenseVector & x) const
922 {
923 XASSERTM(x.size() == this->size(), "Vector size does not match!");
924
925 TimeStamp ts_start;
926
927 Statistics::add_flops(this->size() * 2);
928 DataType result = Arch::DotProduct::value(this->elements(), x.elements(), this->size());
929
930 TimeStamp ts_stop;
931 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
932
933 return result;
934 }
935
940 DT_ norm2() const
941 {
942 TimeStamp ts_start;
943 Statistics::add_flops(this->size() * 2);
944
945 DT_ result = Arch::Norm2::value(this->elements(), this->size());
946
947 TimeStamp ts_stop;
948 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
949
950 return result;
951 }
952
959 DT_ norm2sqr() const
960 {
961 // fallback
962 return Math::sqr(this->norm2());
963 }
964
970 DT_ max_abs_element() const
971 {
972 TimeStamp ts_start;
973
974 Index max_abs_index = Arch::MaxAbsIndex::value(this->template elements<Perspective::pod>(), this->template size<Perspective::pod>());
975 ASSERT(max_abs_index < this->template size<Perspective::pod>());
976 DT_ result;
977 MemoryPool::copy(&result, this->template elements<Perspective::pod>() + max_abs_index, 1);
978 result = Math::abs(result);
979
980 TimeStamp ts_stop;
981 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
982
983 return result;
984 }
985
991 DT_ min_abs_element() const
992 {
993 TimeStamp ts_start;
994
995 Index min_abs_index = Arch::MinAbsIndex::value(this->template elements<Perspective::pod>(), this->template size<Perspective::pod>());
996 ASSERT(min_abs_index < this->template size<Perspective::pod>());
997 DT_ result;
998 MemoryPool::copy(&result, this->template elements<Perspective::pod>() + min_abs_index, 1);
999 result = Math::abs(result);
1000
1001 TimeStamp ts_stop;
1002 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
1003
1004 return result;
1005 }
1006
1012 DT_ max_element() const
1013 {
1014 TimeStamp ts_start;
1015
1016 Index max_index = Arch::MaxIndex::value(this->template elements<Perspective::pod>(), this->template size<Perspective::pod>());
1017 ASSERT(max_index < this->template size<Perspective::pod>());
1018 DT_ result;
1019 MemoryPool::copy(&result, this->template elements<Perspective::pod>() + max_index, 1);
1020
1021 TimeStamp ts_stop;
1022 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
1023
1024 return result;
1025 }
1026
1032 DT_ min_element() const
1033 {
1034 TimeStamp ts_start;
1035
1036 Index min_index = Arch::MinIndex::value(this->template elements<Perspective::pod>(), this->template size<Perspective::pod>());
1037 ASSERT(min_index < this->template size<Perspective::pod>());
1038 DT_ result;
1039 MemoryPool::copy(&result, this->template elements<Perspective::pod>() + min_index, 1);
1040
1041 TimeStamp ts_stop;
1042 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
1043
1044 return result;
1045 }
1046
1053 DT_ max_rel_diff(const DenseVector & x) const
1054 {
1055 XASSERTM(x.used_elements() == this->used_elements(), "Nonzero count does not match!");
1056 TimeStamp ts_start;
1057
1058 DataType max_rel_diff = Arch::MaxRelDiff::value(this->template elements<Perspective::pod>(), x.template elements<Perspective::pod>(), this->template size<Perspective::pod>());
1059
1060 TimeStamp ts_stop;
1061 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
1062
1063 return max_rel_diff;
1064 }
1065
1074 bool same_layout(const DenseVector& x) const
1075 {
1076 if (this->size() == 0 && x.size() == 0 && this->get_elements().size() == 0 && x.get_elements().size() == 0)
1077 return true;
1078 if (this->size() != x.size())
1079 return false;
1080 if (this->get_elements().size() != x.get_elements().size())
1081 return false;
1082 if (this->get_indices().size() != x.get_indices().size())
1083 return false;
1084
1085 return true;
1086 }
1087
1089
1092 {
1093 if (perm.size() == 0)
1094 return;
1095
1096 XASSERTM(perm.size() == this->size(), "Container size does not match permutation size");
1097
1098 perm.apply(elements());
1099 }
1100
1103 void set_vec(DT_ * const pval_set) const
1104 {
1105 MemoryPool::copy(pval_set, this->elements(), this->size());
1106 }
1107
1109 void set_vec_inv(const DT_ * const pval_set)
1110 {
1111 MemoryPool::copy(this->elements(), pval_set, this->size());
1112 }
1114
1115
1122 friend std::ostream & operator<<(std::ostream & lhs, const DenseVector & b)
1123 {
1124 lhs << "[";
1125 for (Index i(0); i < b.size(); ++i)
1126 {
1127 lhs << " " << stringify(b(i));
1128 }
1129 lhs << "]";
1130
1131 return lhs;
1132 }
1133 }; // class DenseVector<...>
1134
1135 #ifdef FEAT_EICKT
1136 extern template class DenseVector<float, std::uint32_t>;
1137 extern template class DenseVector<double, std::uint32_t>;
1138 extern template class DenseVector<float, std::uint64_t>;
1139 extern template class DenseVector<double, std::uint64_t>;
1140 #endif
1141
1142 } // namespace LAFEM
1143} // 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 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
void apply(Tx_ *x, bool invert=false) const
Applies In-Situ permutation.
Container base class.
Definition: container.hpp:220
const std::vector< IT_ * > & get_indices() const
Returns a list of all Index arrays.
Definition: container.hpp:1078
bool _foreign_memory
do we use memory that we did not allocate, nor are we allowed to free it - this mostly holds true,...
Definition: container.hpp:238
std::vector< DT_ * > _elements
List of pointers to all datatype dependent arrays.
Definition: container.hpp:226
Index used_elements() const
Returns the number of effective stored elements.
Definition: container.hpp:1155
const std::vector< DT_ * > & get_elements() const
Returns a list of all data arrays.
Definition: container.hpp:1068
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
virtual void clear()
Free all allocated arrays.
Definition: container.hpp:875
void format(DT_ value=DT_(0))
Reset all elements of the container to a given value or zero if missing.
Definition: container.hpp:851
std::vector< Index > _scalar_index
List of scalars with datatype index.
Definition: container.hpp:234
Gather-Axpy operation for DenseVector.
Scatter-Axpy operation for DenseVector.
Blocked Dense data vector class template.
Dense data vector class template.
DenseVector(Index size_in, DT_ *data)
Constructor.
void scale(const DenseVector &x, const DT_ alpha)
Calculate .
DT_ min_element() const
Retrieve the minimum value of this vector.
const DT_ operator()(Index index) const
Retrieve specific vector element.
void write_out(FileMode mode, const String &filename) const
Write out vector to file.
void convert(const DenseVector< DT2_, IT2_ > &other)
Conversion method.
DenseVector(const DenseVectorBlocked< DT_, IT_, BS_ > &other)
Constructor.
void component_product(const DenseVector &x, const DenseVector &y)
Calculate .
void copy(const DenseVector &x, bool full=false)
Performs .
void write_out(FileMode mode, std::ostream &file) const
Write out vector to file.
void deserialize(std::vector< char > input)
Deserialization of complete container entity.
virtual ~DenseVector()
Destructor.
DenseVector & operator=(DenseVector &&other)
Assignment move operator.
DataType dot(const DenseVector &x) const
Calculate .
DataType triple_dot(const DenseVector &x, const DenseVector &y) const
Calculate .
DT_ DataType
Our datatype.
void convert(const VT_ &a)
Conversion method.
void permute(Adjacency::Permutation &perm)
Permutate vector according to the given Permutation.
DT_ * elements()
Get a pointer to the data array.
DT_ ValueType
Our value type.
void convert(const DenseVectorBlocked< DT2_, IT2_, BS2_ > &other)
Conversion method.
bool same_layout(const DenseVector &x) const
Checks if the structural layout of this vector matches that of another vector. This excludes comparis...
IT_ IndexType
Our indextype.
std::vector< char > serialize(const LAFEM::SerialConfig &config=LAFEM::SerialConfig()) const
Serialization of complete container entity.
DenseVector(FileMode mode, std::istream &file)
Constructor.
DT_ norm2sqr() const
Calculates and returns the squared euclid norm of this vector.
DenseVector(DenseVector &&other)
Move Constructor.
DenseVector(Index size_in, DT_ value)
Constructor.
DT_ max_rel_diff(const DenseVector &x) const
Retrieve the maximum relative difference of this vector and another one y.max_rel_diff(x) returns .
DenseVector(Random &rng, Index size_in, DataType min, DataType max)
Constructor.
DenseVector(Index size_in)
Constructor.
void read_from(FileMode mode, const String &filename)
Read in vector from file.
void copy_inv(VT_ &a) const
Performs .
void component_invert(const DenseVector &x, const DT_ alpha=DT_(1))
Performs .
void axpy(const DenseVector &x, const DT_ alpha=DT_(1))
Calculate .
void operator()(Index index, DT_ value)
Set specific vector element.
static String name()
Returns a descriptive string.
DenseVectorBlocked< DT_, IT_, BlockSize_ > inflate_to_blocks()
Expand DenseVector to DenseVectorBlocked.
DT_ min_abs_element() const
Retrieve the absolute minimum value of this vector.
DT_ max_element() const
Retrieve the maximum value of this vector.
void copy(const VT_ &a)
Performs .
DenseVector clone(CloneMode clone_mode=CloneMode::Deep) const
Clone operation.
DenseVector(FileMode mode, String filename)
Constructor.
DenseVector(std::vector< char > input)
Constructor.
DT_ norm2() const
Calculates and returns the euclid norm of this vector.
DT_ max_abs_element() const
Retrieve the absolute maximum value of this vector.
friend std::ostream & operator<<(std::ostream &lhs, const DenseVector &b)
DenseVector streaming operator.
void clone(const DenseVector< DT2_, IT2_ > &other, CloneMode clone_mode=CloneMode::Deep)
Clone operation.
DenseVector(const DenseVector &dv_in, Index size_in, Index offset_in)
Constructor.
void read_from(FileMode mode, std::istream &file)
Read in vector from stream.
Config class for serialize parameter.
Definition: container.hpp:47
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
Pseudo-Random Number Generator.
Definition: random.hpp:54
static void add_flops(Index flops)
Add an amount of flops to the global flop counter.
Definition: statistics.hpp:206
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
constexpr std::size_t FileOutStreamBufferSize
OutStreamBufferSize.
Definition: base.hpp:124
T_ abs(T_ x)
Returns the absolute value.
Definition: math.hpp:275
T_ sqr(T_ x)
Returns the square of a value.
Definition: math.hpp:95
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
@ value
specifies whether the space should supply basis function values
std::uint64_t Index
Index data type.