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
12#include <kernel/util/math.hpp>
13#include <kernel/util/random.hpp>
14#include <kernel/util/statistics.hpp>
15#include <kernel/util/time_stamp.hpp>
16#include <kernel/util/type_traits.hpp>
17#include <kernel/adjacency/permutation.hpp>
18#include <kernel/lafem/forward.hpp>
19#include <kernel/lafem/container.hpp>
20#include <kernel/lafem/arch/axpy_dense.hpp>
21#include <kernel/lafem/arch/component_invert_dense.hpp>
22#include <kernel/lafem/arch/component_product_dense.hpp>
23#include <kernel/lafem/arch/dot_product_dense.hpp>
24#include <kernel/lafem/arch/max_rel_diff_dense.hpp>
25#include <kernel/lafem/arch/min_max_index_dense.hpp>
26#include <kernel/lafem/arch/min_max_value_dense.hpp>
27#include <kernel/lafem/arch/norm2_dense.hpp>
28#include <kernel/lafem/arch/scale_dense.hpp>
29#include <kernel/lafem/arch/triple_dot_product_dense.hpp>
30
31#include <iostream>
32#include <fstream>
33#include <string>
34#include <stdint.h>
35
36namespace FEAT
37{
38 namespace LAFEM
39 {
55 template <typename DT_, typename IT_ = Index>
56 class DenseVector : public Container<DT_, IT_>
57 {
58 public:
60 typedef DT_ DataType;
62 typedef IT_ IndexType;
64 typedef DT_ ValueType;
66 template <typename DT2_ = DT_, typename IT2_ = IT_>
68
70 template <typename DataType2_, typename IndexType2_>
72
73 protected:
74 Index& _size()
75 {
76 return this->_elements_size.at(0);
77 }
78
79 public:
85 DenseVector() = default;
86
94 explicit DenseVector(Index size_in)
95 {
96 if (size_in == Index(0))
97 return;
98
99 this->_elements.push_back(Memory::Arbiter(sizeof(DT_) * size_in));
100 this->_elements_size.push_back(size_in);
101 }
102
111 explicit DenseVector(Index size_in, DT_ value) :
112 DenseVector(size_in)
113 {
114 this->format(value);
115 }
116
132 explicit DenseVector(Index size_in, Memory::Arbiter&& data)
133 {
134 if (size_in == Index(0))
135 return;
136
137 this->_elements.push_back(std::forward<Memory::Arbiter>(data));
138 this->_elements_size.push_back(size_in);
139 }
140
152 explicit DenseVector(const DenseVector & dv_in, Index size_in, Index offset_in)
153 {
154 XASSERT(size_in > Index(0));
155 XASSERTM(size_in + offset_in <= dv_in.size(), "Ranged vector part exceeds original vector size!");
156
157 this->_elements.push_back(dv_in._elements.front().attach(offset_in * sizeof(DT_), size_in * sizeof(DT_)));
158 this->_elements_size.push_back(size_in);
159 }
160
168 template <int block_size_>
170 {
171 this->convert(other);
172 }
173
182 explicit DenseVector(FileMode mode, String filename)
183 {
184 this->read_from(mode, filename);
185 }
186
195 explicit DenseVector(FileMode mode, std::istream& file)
196 {
197 this->read_from(mode, file);
198 }
199
207 template <typename DT2_ = DT_, typename IT2_ = IT_>
208 explicit DenseVector(std::vector<char> input)
209 {
210 this->deserialize<DT2_, IT2_>(input);
211 }
212
223 explicit DenseVector(Random & rng, Index size_in, DataType min, DataType max) :
224 DenseVector(size_in)
225 {
226 this->format(rng, min, max);
227 }
228
237 Container<DT_, IT_>(std::forward<DenseVector>(other))
238 {
239 }
240
244 virtual ~DenseVector() = default;
245
254 {
255 this->move(std::forward<DenseVector>(other));
256 return *this;
257 }
258
268 {
269 DenseVector t;
270 t.clone(*this, clone_mode);
271 return t;
272 }
273
282 template <typename DT2_, typename IT2_>
283 void clone(const DenseVector<DT2_, IT2_> & other, CloneMode clone_mode = CloneMode::Deep)
284 {
285 Container<DT_, IT_>::clone(other, clone_mode);
286 }
287
295 template <typename DT2_, typename IT2_>
297 {
298 this->assign(other);
299 }
300
308 template <typename DT2_, typename IT2_, int BS2_>
310 {
311 this->assign(other);
312 }
313
321 template <typename VT_>
322 void convert(const VT_ & a)
323 {
324 DenseVector vec(a.size_raw());
325 vec.copy(a);
326 this->move(std::move(vec));
327 }
328
334 template <typename VT_>
335 void copy(const VT_ & a)
336 {
337 XASSERTM(this->size_raw() == a.size_raw(), "Vectors have not the same size!");
338 Memory::TypedView<DT_> x(this->elements_view_w());
339 a.get_values(x.get_w());
340 }
341
347 template <typename VT_>
348 void copy_to(VT_ & a) const
349 {
350 XASSERTM(this->size_raw() == a.size_raw(), "Vectors have not the same size!");
351 Memory::TypedView<DT_> x(this->elements_view_r());
352 a.set_values(x.get_r());
353 }
354
362 template <typename DT2_ = DT_, typename IT2_ = IT_>
363 void deserialize(std::vector<char> input)
364 {
365 this->template _deserialize<DT2_, IT2_>(FileMode::fm_dv, input);
366 }
367
380 template <typename DT2_ = DT_, typename IT2_ = IT_>
381 std::vector<char> serialize(const LAFEM::SerialConfig& config = LAFEM::SerialConfig()) const
382 {
383 return this->template _serialize<DT2_, IT2_>(FileMode::fm_dv, config);
384 }
385
393 template <int block_size_>
395 {
396 const Index n = this->size();
398
399 auto vb = result.elements_view_w();
400 const auto vx = this->elements_view_r();
401 for(Index i(0); i < n; ++i)
402 vb[i] = vx(i);
403
404 return result;
405 }
406
414 void read_from(FileMode mode, const String& filename)
415 {
416 std::ios_base::openmode bin = std::ifstream::in | std::ifstream::binary;
417 if (mode == FileMode::fm_mtx)
418 bin = std::ifstream::in;
419 std::ifstream file(filename.c_str(), bin);
420 if (! file.is_open())
421 XABORTM("Unable to open Vector file " + filename);
422 read_from(mode, file);
423 file.close();
424 }
425
432 void read_from(FileMode mode, std::istream & file)
433 {
434 switch (mode)
435 {
436 case FileMode::fm_mtx:
437 {
438 Index rows;
439 String line;
440 std::getline(file, line);
441 if (line.find("%%MatrixMarket matrix array real general") == String::npos)
442 {
443 XABORTM("Input-file is not a compatible mtx-vector-file");
444 }
445 while (! file.eof())
446 {
447 std::getline(file, line);
448 if (file.eof())
449 XABORTM("Input-file is empty");
450
451 String::size_type begin(line.find_first_not_of(" "));
452 if (line.at(begin) != '%')
453 break;
454 }
455 {
456 String::size_type begin(line.find_first_not_of(" "));
457 line.erase(0, begin);
458 String::size_type end(line.find_first_of(" "));
459 String srows(line, 0, end);
460 rows = (Index)atol(srows.c_str());
461 line.erase(0, end);
462
463 begin = line.find_first_not_of(" ");
464 line.erase(0, begin);
465 end = line.find_first_of(" ");
466 String scols(line, 0, end);
467 Index cols((Index)atol(scols.c_str()));
468 line.erase(0, end);
469 XASSERTM(cols == 1, "Input-file is no dense-vector-file");
470 }
471
472 DenseVector<DT_, IT_> tmp(rows);
473 Memory::TypedView<DT_> tmp_view(tmp.elements_view_w());
474 DT_* pval = tmp_view.get_w();
475
476 while (! file.eof())
477 {
478 std::getline(file, line);
479 if (file.eof())
480 break;
481
482 String::size_type begin(line.find_first_not_of(" "));
483 line.erase(0, begin);
484 String::size_type end(line.find_first_of(" "));
485 String sval(line, 0, end);
486 DT_ tval((DT_)atof(sval.c_str()));
487
488 *pval = tval;
489 ++pval;
490 }
491 tmp_view.release();
492 this->move(std::move(tmp));
493 break;
494 }
495 case FileMode::fm_exp:
496 {
497 std::vector<DT_> data;
498
499 while (! file.eof())
500 {
501 std::string line;
502 std::getline(file, line);
503 if (line.find("#", 0) < line.npos)
504 continue;
505 if (file.eof())
506 break;
507
508 std::string n_z_s;
509
510 std::string::size_type first_digit(line.find_first_not_of(" "));
511 line.erase(0, first_digit);
512 std::string::size_type eol(line.length());
513 for (std::string::size_type i(0); i < eol; ++i)
514 {
515 n_z_s.append(1, line[i]);
516 }
517
518 DT_ n_z((DT_)atof(n_z_s.c_str()));
519
520 data.push_back(n_z);
521 }
522
523 DenseVector<DT_, IT_> tmp(data.size());
524 {
525 Memory::TypedView<DT_> tmp_view(tmp.elements_view_w());
526 tmp_view.convert_from(data.data());
527 }
528
529 this->move(std::move(tmp));
530 break;
531 }
532
533 case FileMode::fm_dv:
534 [[fallthrough]];
535
537 this->template _deserialize<double, std::uint64_t>(FileMode::fm_dv, file);
538 break;
539
540 default:
541 XABORTM("Filemode not supported!");
542 }
543 }
544
551 void write_out(FileMode mode, const String& filename) const
552 {
553 std::ios_base::openmode bin = std::ofstream::out | std::ofstream::binary;
554 if (mode == FileMode::fm_mtx || mode == FileMode::fm_exp)
555 bin = std::ofstream::out;
556 std::ofstream file;
557 char* buff = nullptr;
558 if(mode == FileMode::fm_mtx)
559 {
560 buff = new char[LAFEM::file_out_stream_buffer_size];
561 file.rdbuf()->pubsetbuf(buff, LAFEM::file_out_stream_buffer_size);
562 }
563 file.open(filename.c_str(), bin);
564 if(! file.is_open())
565 XABORTM("Unable to open Matrix file " + filename);
566 write_out(mode, file);
567 file.close();
568 delete[] buff;
569 }
570
577 void write_out(FileMode mode, std::ostream & file) const
578 {
579 switch (mode)
580 {
581 case FileMode::fm_mtx:
582 {
583 const Index tsize(this->size_raw());
584 file << "%%MatrixMarket matrix array real general\n";
585 file << tsize << " " << 1 << "\n";
586 file << std::scientific << std::setprecision(Type::Traits<DT_>::format_precision);
587 const Memory::TypedView<DT_> elem_view(this->elements_view_r());
588 for (Index i(0); i < tsize; ++i)
589 {
590 file << elem_view(i) << "\n";
591 }
592 break;
593 }
594
595 case FileMode::fm_exp:
596 {
597 const Index tsize(this->size_raw());
598 file << std::scientific << std::setprecision(Type::Traits<DT_>::format_precision);
599 const Memory::TypedView<DT_> elem_view(this->elements_view_r());
600 for (Index i(0); i < tsize; ++i)
601 {
602 file << elem_view(i) << "\n";
603 }
604 break;
605 }
606
607 case FileMode::fm_dv:
608 [[fallthrough]];
609
611 this->template _serialize<double, std::uint64_t>(FileMode::fm_dv, file);
612 break;
613
614 default:
615 XABORTM("Filemode not supported!");
616 }
617 }
618
620 Index size() const
621 {
622 return this->_elements_size.empty() ? Index(0) : this->_elements_size.at(0);
623 }
624
627 {
628 return this->size();
629 }
630
632 bool empty() const
633 {
634 return this->_elements_size.empty() || (this->_elements_size.at(0) <= Index(0));
635 }
636
639 {
640 return this->_elements.front();
641 }
642
645 {
646 return this->_elements.front();
647 }
648
650 {
651 if(this->_elements.empty())
652 return Memory::TypedView<DT_>();
653 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, Memory::Access::read));
654 }
655
657 {
658 if(this->_elements.empty())
659 return Memory::TypedView<DT_>();
660 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, Memory::Access::write));
661 }
662
663 Memory::TypedView<DT_> elements_view_rw(Memory::Location loc = Memory::Location::main)
664 {
665 if(this->_elements.empty())
666 return Memory::TypedView<DT_>();
667 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, Memory::Access::read_write));
668 }
669
670 Memory::TypedView<DT_> elements_view(Memory::Location loc, Memory::Access acc)
671 {
672 if(this->_elements.empty())
673 return Memory::TypedView<DT_>();
674 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, acc));
675 }
676
677 Memory::TypedView<DT_> elements_view_raw_r(Memory::Location loc = Memory::Location::main) const
678 {
679 if(this->_elements.empty())
680 return Memory::TypedView<DT_>();
681 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, Memory::Access::read));
682 }
683
684 Memory::TypedView<DT_> elements_view_raw_w(Memory::Location loc = Memory::Location::main)
685 {
686 if(this->_elements.empty())
687 return Memory::TypedView<DT_>();
688 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, Memory::Access::write));
689 }
690
691 Memory::TypedView<DT_> elements_view_raw_rw(Memory::Location loc = Memory::Location::main)
692 {
693 if(this->_elements.empty())
694 return Memory::TypedView<DT_>();
695 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, Memory::Access::read_write));
696 }
697
698 Memory::TypedView<DT_> elements_view_raw(Memory::Location loc, Memory::Access acc)
699 {
700 if(this->_elements.empty())
701 return Memory::TypedView<DT_>();
702 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, acc));
703 }
704
710 static String name()
711 {
712 return "DenseVector";
713 }
714
721 void copy(const DenseVector & x, bool full = false)
722 {
723 this->_copy_content(x, full);
724 }
725
728
735 void axpy(
736 const DenseVector & x,
737 const DT_ alpha = DT_(1))
738 {
739 XASSERTM(x.size() == this->size(), "Vector size does not match!");
740
741 if(this->empty())
742 return;
743
744 TimeStamp ts_start;
745 FEAT_KERNEL_MARKER_START("DV_axpy");
746
747 Arch::AxpyDense::template exec<DT_>(this->elements_arbiter(), alpha, x.elements_arbiter(), this->size());
748
749 FEAT_KERNEL_MARKER_STOP("DV_axpy");
750 TimeStamp ts_stop;
751
752 Statistics::add_flops(this->size() * 2);
753 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
754 }
755
762 void component_product(const DenseVector & x, const DenseVector & y)
763 {
764 XASSERTM(this->size() == x.size(), "Vector size does not match!");
765 XASSERTM(this->size() == y.size(), "Vector size does not match!");
766
767 if(this->empty())
768 return;
769
770 TimeStamp ts_start;
771
772 Arch::ComponentProductDense::template exec<DT_>(this->elements_arbiter(), x.elements_arbiter(), y.elements_arbiter(), this->size());
773
774 TimeStamp ts_stop;
775
777 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
778 }
779
789 void component_invert(const DenseVector & x, const DT_ alpha = DT_(1))
790 {
791 XASSERTM(this->size() == x.size(), "Vector size does not match!");
792
793 if(this->empty())
794 return;
795
796 TimeStamp ts_start;
797
798 Arch::ComponentInvertDense::template exec<DT_>(this->elements_arbiter(), x.elements_arbiter(), alpha, this->size());
799
800 TimeStamp ts_stop;
801
803 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
804 }
805
812 void scale(const DenseVector & x, const DT_ alpha)
813 {
814 XASSERTM(x.size() == this->size(), "Vector size does not match!");
815
816 if(this->empty())
817 return;
818
819 TimeStamp ts_start;
820
821 Arch::ScaleDense::template exec<DT_>(this->elements_arbiter(), x.elements_arbiter(), alpha, this->size());
822
823 TimeStamp ts_stop;
824
826 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
827 }
828
838 DataType triple_dot(const DenseVector & x, const DenseVector & y) const
839 {
840 XASSERTM(x.size() == this->size(), "Vector size does not match!");
841 XASSERTM(y.size() == this->size(), "Vector size does not match!");
842 XASSERT(!this->empty());
843
844 TimeStamp ts_start;
845
846 DataType result = Arch::TripleDotProductDense::template exec<DT_>(this->elements_arbiter(), x.elements_arbiter(), y.elements_arbiter(), this->size());
847
848 TimeStamp ts_stop;
849
850 Statistics::add_flops(this->size() * 3);
851 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
852
853 return result;
854 }
855
863 DataType dot(const DenseVector & x) const
864 {
865 XASSERTM(x.size() == this->size(), "Vector size does not match!");
866 XASSERT(!this->empty());
867
868 TimeStamp ts_start;
869
870 DataType result = Arch::DotProductDense::template exec<DT_>(this->elements_arbiter(), x.elements_arbiter(), this->size());
871
872 TimeStamp ts_stop;
873
874 Statistics::add_flops(this->size() * 2);
875 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
876
877 return result;
878 }
879
884 DT_ norm2() const
885 {
886 XASSERT(!this->empty());
887
888 TimeStamp ts_start;
889
890 DataType result = Arch::Norm2Dense::template exec<DT_>(this->elements_arbiter(), this->size());
891
892 TimeStamp ts_stop;
893
894 Statistics::add_flops(this->size() * 2);
895 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
896
897 return result;
898 }
899
906 DT_ norm2sqr() const
907 {
908 // fallback
909 return Math::sqr(this->norm2());
910 }
911
917 DT_ max_abs_element() const
918 {
919 XASSERT(!this->empty());
920
921 TimeStamp ts_start;
922
923 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->elements_arbiter(), this->size(), false, true);
924
925 TimeStamp ts_stop;
926 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
927
928 return result;
929 }
930
936 DT_ min_abs_element() const
937 {
938 XASSERT(!this->empty());
939
940 TimeStamp ts_start;
941
942 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->elements_arbiter(), this->size(), true, true);
943
944 TimeStamp ts_stop;
945 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
946
947 return result;
948 }
949
955 DT_ max_element() const
956 {
957 XASSERT(!this->empty());
958
959 TimeStamp ts_start;
960
961 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->elements_arbiter(), this->size(), false, false);
962
963 TimeStamp ts_stop;
964 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
965
966 return result;
967 }
968
974 DT_ min_element() const
975 {
976 XASSERT(!this->empty());
977
978 TimeStamp ts_start;
979
980 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->elements_arbiter(), this->size(), true, false);
981
982 TimeStamp ts_stop;
983 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
984
985 return result;
986 }
987
994 DT_ max_rel_diff(const DenseVector & x) const
995 {
996 XASSERTM(x.size() == this->size(), "vector size mismatch!");
997 XASSERT(!this->empty());
998
999 TimeStamp ts_start;
1000
1001 DT_ result = Arch::MaxRelDiffDense::template exec<DT_>(this->elements_arbiter(), x.elements_arbiter(), this->size());
1002
1003 TimeStamp ts_stop;
1004 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
1005
1006 return result;
1007 }
1008
1017 bool same_layout(const DenseVector& x) const
1018 {
1019 return this->size() == x.size();
1020 }
1021
1023
1026 {
1027 if(perm.empty())
1028 return;
1029
1030 XASSERTM(perm.size() == this->size(), "Container size does not match permutation size");
1031 XASSERT(!this->empty());
1032
1034
1035 perm.apply(view.get_w());
1036 }
1037
1039
1047 Index get_values(DT_ * const pval_set) const
1048 {
1049 this->_elements.front().copy_to(pval_set, Memory::Location::main);
1050 return this->size_raw();
1051 }
1052
1061 Index set_values(const DT_ * const pval_set)
1062 {
1063 this->_elements.front().copy(pval_set, Memory::Location::main);
1064 return this->size_raw();
1065 }
1067
1074 friend std::ostream & operator<<(std::ostream & lhs, const DenseVector & b)
1075 {
1076 const Memory::TypedView<DT_> view(b.elements_view_r());
1077 const Index n = b.size();
1078 lhs << "[";
1079 for (Index i(0); i < n; ++i)
1080 {
1081 lhs << " " << view[i];
1082 }
1083 lhs << "]";
1084
1085 return lhs;
1086 }
1087
1094 {
1095 public:
1097 typedef DT_ DataType;
1098 typedef IT_ IndexType;
1099
1100 private:
1101 const Index _num_entries;
1102 Memory::TypedView<DT_> _data_view;
1103
1104 public:
1105 explicit ScatterAxpy(VectorType & vector) :
1106 _num_entries(vector.size()),
1108 {
1109 }
1110
1111 template <typename LocalVector_, typename Mapping_>
1112 void operator()(const LocalVector_ & loc_vec, const Mapping_ & mapping, DT_ alpha = DT_(1))
1113 {
1114 // loop over all local entries
1115 for (int i(0); i < mapping.get_num_local_dofs(); ++i)
1116 {
1117 // get dof index
1118 Index dof_idx = mapping.get_index(i);
1119 ASSERT(dof_idx < _num_entries);
1120
1121 // update vector entry
1122 _data_view[dof_idx] += alpha * loc_vec[i];
1123 }
1124 }
1125 }; // class ScatterAxpy
1126
1133 {
1134 public:
1136 typedef DT_ DataType;
1137 typedef IT_ IndexType;
1138
1139 private:
1140 const Index _num_entries;
1141 const Memory::TypedView<DT_> _data_view;
1142
1143 public:
1144 explicit GatherAxpy(const VectorType & vector) :
1145 _num_entries(vector.size()),
1146 _data_view(vector.elements_view_r())
1147 {
1148 }
1149
1150 template <typename LocalVector_, typename Mapping_>
1151 void operator()(LocalVector_ & loc_vec, const Mapping_ & mapping, DT_ alpha = DT_(1))
1152 {
1153 // loop over all local entries
1154 for (int i(0); i < mapping.get_num_local_dofs(); ++i)
1155 {
1156 // get dof index
1157 Index dof_idx = mapping.get_index(i);
1158 ASSERT(dof_idx < _num_entries);
1159
1160 // update local vector data
1161 loc_vec[i] += alpha * _data_view(dof_idx);
1162 }
1163 }
1164 }; // class GatherAxpy
1165 }; // class DenseVector<...>
1166
1167 #ifdef FEAT_EICKT
1168 extern template class DenseVector<float, std::uint32_t>;
1169 extern template class DenseVector<double, std::uint32_t>;
1170 extern template class DenseVector<float, std::uint64_t>;
1171 extern template class DenseVector<double, std::uint64_t>;
1172 #endif
1173
1174 } // namespace LAFEM
1175} // 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
bool empty() const
Checks whether the permutation is empty.
void apply(Tx_ *x, bool invert=false) const
Applies In-Situ permutation.
Container base class.
Definition: container.hpp:224
void format()
Reset all elements of the container to a given value or zero if missing.
Definition: container.hpp:831
void move(Container &&source)
Assignment move operation.
Definition: container.hpp:1007
void clone(const Container &source, CloneMode clone_mode=CloneMode::Weak)
Clone operation.
Definition: container.hpp:904
std::vector< Index > _elements_size
List of corresponding datatype array sizes.
Definition: container.hpp:234
void assign(const Container< DT2_, IT2_ > &other)
Assignment operation.
Definition: container.hpp:285
std::vector< Memory::Arbiter > _elements
List of pointers to all datatype dependent arrays.
Definition: container.hpp:230
Gather-Axpy operation for DenseVector.
Scatter-Axpy operation for DenseVector.
Blocked Dense data vector class template.
Dense data vector class template.
void scale(const DenseVector &x, const DT_ alpha)
Calculate .
DT_ min_element() const
Retrieve the minimum value of this vector.
DenseVector(Index size_in, Memory::Arbiter &&data)
Constructor.
void write_out(FileMode mode, const String &filename) const
Write out vector to file.
const Memory::Arbiter & elements_arbiter() const
Returns a reference to the element array arbiter.
void convert(const DenseVector< DT2_, IT2_ > &other)
Conversion method.
void component_product(const DenseVector &x, const DenseVector &y)
Calculate .
DenseVectorBlocked< DT_, IT_, block_size_ > inflate_to_blocks()
Expand DenseVector to DenseVectorBlocked.
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.
DenseVector & operator=(DenseVector &&other)
Assignment move operator.
DataType dot(const DenseVector &x) const
Calculate .
bool empty() const
Checks whether the vector is empty, i.e. if it has size 0.
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)
Permute vector according to the given Permutation.
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.
void copy_to(VT_ &a) const
Performs .
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.
DenseVector()=default
Constructor.
void component_invert(const DenseVector &x, const DT_ alpha=DT_(1))
Performs .
void axpy(const DenseVector &x, const DT_ alpha=DT_(1))
Calculate .
Memory::Arbiter & elements_arbiter()
Returns a reference to the element array arbiter.
static String name()
Returns a descriptive string.
DT_ min_abs_element() const
Retrieve the absolute minimum value of this vector.
virtual ~DenseVector()=default
Destructor.
DT_ max_element() const
Retrieve the maximum value of this vector.
void copy(const VT_ &a)
Performs .
DenseVector(const DenseVectorBlocked< DT_, IT_, block_size_ > &other)
Constructor.
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.
Index size_raw() const
Returns the size of this vector in scalar data type entries.
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.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Config class for serialize parameter.
Definition: container.hpp:50
Memory arbiter class.
Typed memory view class.
void convert_from(const T_ *ptr_src)
overload of convert_from for the identical type
const T_ * get_r() const
Returns a const typed pointer to the array that grants read access.
T_ * get_w()
Returns a typed pointer to the array that grants write (and read) access.
void release() const
Releases this view.
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:47
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 file_out_stream_buffer_size
OutStreamBufferSize.
Definition: base.hpp:105
T_ sqr(T_ x)
Returns the square of a value.
Definition: math.hpp:95
Access
Memory access enumeration.
@ read_write
read-write access
@ overlap
explicitly allow overlapping writes (see Overlapping Memory Views)
@ read
read-only access
@ write
write-only access (see attention note above)
Location
Memory location enumeration.
FEAT namespace.
Definition: adjactor.hpp:12
@ value
specifies whether the space should supply basis function values
std::uint64_t Index
Index data type.
basic Type Traits struct
Definition: type_traits.hpp:73