FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
dense_matrix.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/math.hpp>
13#include <kernel/lafem/container.hpp>
14#include <kernel/lafem/arch/scale.hpp>
15#include <kernel/lafem/arch/norm.hpp>
16#include <kernel/lafem/arch/axpy.hpp>
17#include <kernel/lafem/arch/apply.hpp>
18#include <kernel/lafem/arch/product_matmat.hpp>
19#include <kernel/lafem/arch/transpose.hpp>
20#include <kernel/lafem/dense_vector.hpp>
21
22
23namespace FEAT
24{
25 namespace LAFEM
26 {
45 template <typename DT_, typename IT_ = Index>
46 class DenseMatrix : public Container<DT_, IT_>
47 {
48 private:
49 Index & _rows()
50 {
51 return this->_scalar_index.at(1);
52 }
53
54 Index & _columns()
55 {
56 return this->_scalar_index.at(2);
57 }
58
59 public:
61 typedef DT_ DataType;
63 typedef IT_ IndexType;
69 template <typename DT2_ = DT_, typename IT2_ = IT_>
71
77 explicit DenseMatrix() :
78 Container< DT_, IT_> (0)
79 {
80 this->_scalar_index.push_back(0);
81 this->_scalar_index.push_back(0);
82 }
83
92 explicit DenseMatrix(Index rows_in, Index columns_in) :
93 Container<DT_, IT_>(rows_in * columns_in)
94 {
95 XASSERT(rows_in != Index(0) && columns_in != Index(0));
96 this->_scalar_index.at(0) = rows_in * columns_in;
97 this->_scalar_index.push_back(rows_in);
98 this->_scalar_index.push_back(columns_in);
99
100 this->_elements.push_back(MemoryPool::template allocate_memory<DT_>(this->_scalar_index.at(0)));
101 this->_elements_size.push_back(this->_scalar_index.at(0));
102 }
103
113 explicit DenseMatrix(Index rows_in, Index columns_in, DT_ value) :
114 Container<DT_, IT_>(rows_in * columns_in)
115 {
116 XASSERT(rows_in != Index(0) && columns_in != Index(0));
117 this->_scalar_index.at(0) = rows_in * columns_in;
118 this->_scalar_index.push_back(rows_in);
119 this->_scalar_index.push_back(columns_in);
120 this->_elements.push_back(MemoryPool::template allocate_memory<DT_>(this->_scalar_index.at(0)));
121 this->_elements_size.push_back(this->_scalar_index.at(0));
122 MemoryPool::set_memory(this->_elements.at(0), value, this->_scalar_index.at(0));
123 }
124
132 template <typename DT2_ = DT_, typename IT2_ = IT_>
133 explicit DenseMatrix(std::vector<char> input) :
134 Container<DT_, IT_>(0)
135 {
136 deserialize<DT2_, IT2_>(input);
137 }
138
139 //Just a test:
146 explicit DenseMatrix(FileMode mode, String filename) :
147 Container<DT_, IT_>(0)
148 {
149 read_from(mode, filename);
150 }
151
158 explicit DenseMatrix(FileMode mode, std::istream& file) :
159 Container<DT_, IT_>(0)
160 {
161 read_from(mode, file);
162 }
163 //end of test
172 Container<DT_, IT_>(std::forward<DenseMatrix>(other))
173 {
174 }
175
184 {
185 this->move(std::forward<DenseMatrix>(other));
186
187 return *this;
188 }
189
199 {
200 DenseMatrix t;
201 t.clone(*this, clone_mode);
202 return t;
203 }
204
213 template<typename DT2_, typename IT2_>
214 void clone(const DenseMatrix<DT2_, IT2_> & other, CloneMode clone_mode = CloneMode::Deep)
215 {
216 Container<DT_, IT_>::clone(other, clone_mode);
217 }
218
226 template <typename DT2_, typename IT2_>
228 {
229 this->assign(other);
230 }
231
237 DT_ * elements()
238 {
239 return this->_elements.at(0);
240 }
241
242 DT_ const * elements() const
243 {
244 return this->_elements.at(0);
245 }
246
255 const DT_ operator()(Index row, Index col) const
256 {
257 ASSERT(row < this->rows());
258 ASSERT(col < this->columns());
259 MemoryPool::synchronize();
260 return this->elements()[row * this->columns() + col];
261 }
262
270 void operator()(Index row, Index col, DT_ value)
271 {
272 ASSERT(row < this->rows());
273 ASSERT(col < this->columns());
274 MemoryPool::set_memory(this->_elements.at(0) + row * this->columns() + col, value);
275 MemoryPool::synchronize();
276 }
277
285 template <typename DT2_ = DT_, typename IT2_ = IT_>
286 void deserialize(std::vector<char> input)
287 {
288 this->template _deserialize<DT2_, IT2_>(FileMode::fm_dm, input);
289 }
290
304 template <typename DT2_ = DT_, typename IT2_ = IT_>
305 std::vector<char> serialize(const LAFEM::SerialConfig& config = LAFEM::SerialConfig()) const
306 {
307 return this->template _serialize<DT2_, IT2_>(FileMode::fm_dm, config);
308 }
309
316 //begin of test
317 void read_from(FileMode mode, const String& filename)
318 {
319 std::ios_base::openmode bin = std::ifstream::in | std::ifstream::binary;
320 if(mode == FileMode::fm_mtx)
321 bin = std::ifstream::in;
322 std::ifstream file(filename.c_str(), bin);
323 if(! file.is_open())
324 XABORTM("Unable to open Matrix file " + filename);
325 read_from(mode, file);
326 file.close();
327 }
328
335 void read_from(FileMode mode, std::istream& file)
336 {
337 this->clear();
338
339 switch(mode)
340 {
341 case FileMode::fm_mtx:
342 {
343
344 Index trows, tcols;
345 String line;
346 std::getline(file, line); // !!? Test on overflow error... could be an enormous matrix... !??
347 //for now, just array real general (aka dense) matrices
348 const bool array_format((line.find("%%MatrixMarket matrix array real general") != String::npos) ? true : false);
349 if (array_format == false)
350 {
351 XABORTM("Input-file is not a compatible array real mtx-file");
352 }
353
354 while(!file.eof())
355 {
356 std::getline(file,line);
357 if (file.eof())
358 XABORTM("Input-file is empty");
359
360 String::size_type begin(line.find_first_not_of(" "));
361 if (line.at(begin) != '%')
362 break;
363 }
364 //Read in number of rows and columns
365 {
366 String::size_type begin(line.find_first_not_of(" "));
367 line.erase(0, begin);
368 String::size_type end(line.find_first_of(" "));
369 String srow(line, 0, end);
370 trows = Index(atol(srow.c_str()));
371 line.erase(0, end);
372
373 begin = line.find_first_not_of(" ");
374 line.erase(0, begin);
375 end = line.find_first_of(" ");
376 String scol(line, 0, end);
377 tcols = Index(atol(scol.c_str()));
378 line.erase(0, end);
379 }
380
381 DenseMatrix<DT_, IT_> result(Index(trows), tcols);
382 Index i(0);
383
384 //Read in value of lines:
385 while(!file.eof())
386 {
387 std::getline(file, line);
388 if(file.eof())
389 break;
390
391 String::size_type begin = line.find_first_not_of(" ");
392 line.erase(0, begin);
393 String::size_type end = line.find_first_of(" ");
394 String sval(line, 0, end);
395 DT_ tval((DT_)atof(sval.c_str()));
396
397 Index row(i / tcols);
398 Index col(i % tcols);
399 result(row, col, tval);
400
401 ++i;
402 }
403 XASSERTM(i == trows * tcols, "Dense MTX file did not contain enough entries!");
404
405 this->move(std::move(result));
406 break;
407
408 }
409 case FileMode::fm_dm:
411 this->template _deserialize<double, std::uint64_t>(FileMode::fm_dm, file);
412 break;
413 default:
414 XABORTM("Filemode not supported!");
415 }
416 }
417
424 void write_out(FileMode mode, const String& filename) const
425 {
426 std::ios_base::openmode bin = std::ofstream::out | std::ofstream::binary;
427 if(mode == FileMode::fm_mtx)
428 bin = std::ofstream::out;
429 std::ofstream file;
430 char* buff = nullptr;
431 if(mode == FileMode::fm_mtx)
432 {
433 buff = new char[LAFEM::FileOutStreamBufferSize];
434 file.rdbuf()->pubsetbuf(buff, LAFEM::FileOutStreamBufferSize);
435 }
436 file.open(filename.c_str(), bin);
437 if(! file.is_open())
438 XABORTM("Unable to open Matrix file " + filename);
439 write_out(mode, file);
440 file.close();
441 delete[] buff;
442 }
443
450 void write_out(FileMode mode, std::ostream& file) const
451 {
452 switch(mode)
453 {
454 case FileMode::fm_mtx:
455 {
456 file << "%%MatrixMarket matrix array real general\n";
457 file << this->rows() << " " << this->columns() << " " << this->used_elements() << "\n";
458
459 for(IT_ row(0) ; row < rows(); ++row)
460 {
461 for(IT_ col(0) ; col < columns() ; ++col)
462 {
463 file << stringify_fp_sci((*this)(row, col)) << "\n";
464 }
465 }
466 break;
467 }
468 case FileMode::fm_dm:
470 this->template _serialize<double, std::uint64_t>(FileMode::fm_dm, file);
471 break;
472 default:
473 XABORTM("Filemode not supported!");
474 }
475 }
476 //end of test
477
483 Index rows() const
484 {
485 return this->_scalar_index.at(1);
486 }
487
494 {
495 return this->_scalar_index.at(2);
496 }
497
503 static String name()
504 {
505 return "DenseMatrix";
506 }
507
514 void copy(const DenseMatrix & x, bool full = false)
515 {
516 this->_copy_content(x, full);
517 }
518
521 {
522 return VectorTypeL(this->rows());
523 }
524
526 VectorTypeR create_vector_r() const
527 {
528 return VectorTypeR(this->columns());
529 }
530
532 Index get_length_of_line(const Index /*row*/) const
533 {
534 return this->columns();
535 }
536
539
545 void scale(const DenseMatrix & x, const DT_ alpha)
546 {
547 XASSERTM(x.rows() == this->rows(), "Row count does not match!");
548 XASSERTM(x.columns() == this->columns(), "Column count does not match!");
549 XASSERTM(x.used_elements() == this->used_elements(), "Nonzero count does not match!");
550
551 TimeStamp ts_start;
552
554 Arch::Scale::value(this->elements(), x.elements(), alpha, this->used_elements());
555
556 TimeStamp ts_stop;
557 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
558 }
559
565 DT_ norm_frobenius() const
566 {
567 TimeStamp ts_start;
568
570 DT_ result = Arch::Norm2::value(this->elements(), this->used_elements());
571
572 TimeStamp ts_stop;
573 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
574
575 return result;
576 }
577
585 void axpy(
586 const DenseMatrix & x,
587 const DT_ alpha = DT_(1))
588 {
589 XASSERTM(x.size() == this->size(), "Vector size does not match!");
590
591 TimeStamp ts_start;
592
593 Statistics::add_flops(this->size() * 2);
594 Arch::Axpy::value(this->elements(), alpha, x.elements(), this->size());
595
596 TimeStamp ts_stop;
597 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
598 }
599
607 {
608 XASSERTM(r.size() == this->rows(), "Vector size of r does not match!");
609 XASSERTM(x.size() == this->columns(), "Vector size of x does not match!");
610
611 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(), "Vector x and r must not share the same memory!");
612
613 TimeStamp ts_start;
614
616 Arch::Apply::dense(r.elements(), DT_(1), DT_(0), r.elements(), this->elements(),
617 x.elements(), this->rows(), this->columns());
618
619 TimeStamp ts_stop;
620 Statistics::add_time_blas2(ts_stop.elapsed(ts_start));
621 }
622
630 {
631 XASSERTM(r.size() == this->columns(), "Vector size of r does not match!");
632 XASSERTM(x.size() == this->rows(), "Vector size of x does not match!");
633
634 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(), "Vector x and r must not share the same memory!");
635
636 TimeStamp ts_start;
637
639 Arch::Apply::dense_transposed(r.elements(), DT_(1), DT_(0), r.elements(), this->elements(),
640 x.elements(), this->rows(), this->columns());
641
642 TimeStamp ts_stop;
643 Statistics::add_time_blas2(ts_stop.elapsed(ts_start));
644 }
645
654 void apply(
656 const DenseVector<DT_, IT_> & x,
657 const DenseVector<DT_, IT_> & y,
658 const DT_ alpha = DT_(1)) const
659 {
660 XASSERTM(r.size() == this->rows(), "Vector size of r does not match!");
661 XASSERTM(x.size() == this->columns(), "Vector size of x does not match!");
662 XASSERTM(y.size() == this->rows(), "Vector size of y does not match!");
663
664 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(), "Vector x and r must not share the same memory!");
665
666 TimeStamp ts_start;
667
668 if(Math::abs(alpha) < Math::eps<DT_>())
669 {
670 r.copy(y);
671 return;
672 }
673
674 Statistics::add_flops( (this->used_elements() + this->rows()) * 2 );
675 Arch::Apply::dense(r.elements(), alpha, DT_(1), y.elements(), this->elements(),
676 x.elements(), this->rows(), this->columns());
677
678 TimeStamp ts_stop;
679 Statistics::add_time_blas2(ts_stop.elapsed(ts_start));
680 }
681
692 const DenseVector<DT_, IT_> & x,
693 const DenseVector<DT_, IT_> & y,
694 const DT_ alpha = DT_(1)) const
695 {
696 XASSERTM(r.size() == this->columns(), "Vector size of r does not match!");
697 XASSERTM(x.size() == this->rows(), "Vector size of x does not match!");
698 XASSERTM(y.size() == this->columns(), "Vector size of y does not match!");
699
700 XASSERTM(r.template elements<Perspective::pod>() != x.template elements<Perspective::pod>(), "Vector x and r must not share the same memory!");
701
702 TimeStamp ts_start;
703
704 if(Math::abs(alpha) < Math::eps<DT_>())
705 {
706 r.copy(y);
707 return;
708 }
709
710 Statistics::add_flops( (this->used_elements() + this->rows()) * 2 );
711 Arch::Apply::dense_transposed(r.elements(), alpha, DT_(1), y.elements(), this->elements(),
712 x.elements(), this->rows(), this->columns());
713
714 TimeStamp ts_stop;
715 Statistics::add_time_blas2(ts_stop.elapsed(ts_start));
716 }
717
724 DT_ max_rel_diff(const DenseMatrix& x) const
725 {
726 XASSERTM(x.used_elements() == this->used_elements(), "Nonzero count does not match!");
727 TimeStamp ts_start;
728
729 DataType max_rel_diff = Arch::MaxRelDiff::value(this->elements(), x.elements(), this->used_elements());
730
731 TimeStamp ts_stop;
732 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
733
734 return max_rel_diff;
735 }
736
745 bool same_layout(const DenseMatrix& x) const
746 {
747 if(this->size() == 0 && x.size() == 0 && this->get_elements().size() == 0 && x.get_elements().size() == 0)
748 return true;
749
750 if (this->size() != x.size())
751 return false;
752 if (this->get_elements().size() != x.get_elements().size())
753 return false;
754 if (this->get_indices().size() != x.get_indices().size())
755 return false;
756 if (this->rows() != x.rows())
757 return false;
758 if (this->columns() != x.columns())
759 return false;
760
761 return true;
762 }
763
764
765
770 {
771 XASSERTM(x.columns() == y.rows(), "dimension mismatch!");
772 XASSERTM(this->rows() == x.rows(), "dimension mismatch!");
773 XASSERTM(this->columns() == y.columns(), "dimension mismatch!");
774
775 TimeStamp ts_start;
777
778 Arch::ProductMatMat::dense(this->elements(), DT_(1.0), DT_(0.0), x.elements(),
779 y.elements(), this->elements(), this->rows(), this->columns(), x.columns());
780
781 TimeStamp ts_stop;
782 Statistics::add_time_blas3(ts_stop.elapsed(ts_start));
783 }
784
789 {
790 XASSERTM(x.columns() == y.rows(), "dimension mismatch!");
791 XASSERTM(this->rows() == x.rows(), "dimension mismatch!");
792 XASSERTM(this->columns() == y.columns(), "dimension mismatch!");
793
794 TimeStamp ts_start;
795 //Statistics::add_flops(x.used_elements() * y.columns()*2);
796
797 Arch::ProductMatMat::dsd(this->elements(), DT_(1.0), DT_(0.0), x.val(), x.col_ind(), x.row_ptr(), x.used_elements(),
798 y.elements(), this->rows(), this->columns(), x.columns());
799
800 TimeStamp ts_stop;
801 Statistics::add_time_blas3(ts_stop.elapsed(ts_start));
802 }
803
813 const DenseMatrix & x,
814 const DenseMatrix & y,
815 const DT_ alpha = DT_(1),
816 const DT_ beta = DT_(1))
817 {
818 XASSERTM(x.columns() == y.rows(), "dimension mismatch!");
819 XASSERTM(this->rows() == x.rows(), "dimension mismatch!");
820 XASSERTM(this->columns() == y.columns(), "dimension mismatch!");
821
822 TimeStamp ts_start;
823
824 Statistics::add_flops(this->size() * 2);
825 Arch::ProductMatMat::dense(this->elements(), alpha, beta, x.elements(),
826 y.elements(), this->elements(), this->rows(), this->columns(), x.columns());
827
828 TimeStamp ts_stop;
829 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
830 }
831
842 const DenseMatrix & y,
843 const DT_ alpha = DT_(1),
844 const DT_ beta = DT_(1))
845 {
846 XASSERTM(x.columns() == y.rows(), "dimension mismatch!");
847 XASSERTM(this->rows() == x.rows(), "dimension mismatch!");
848 XASSERTM(this->columns() == y.columns(), "dimension mismatch!");
849
850 TimeStamp ts_start;
851
853 Arch::ProductMatMat::dsd(this->elements(), alpha, beta, x.val(), x.col_ind(), x.row_ptr(), x.used_elements(),
854 y.elements(), this->rows(), this->columns(), x.columns());
855
856 TimeStamp ts_stop;
857 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
858 }
859
861 void invert()
862 {
863 XASSERTM(this->rows() == this->columns(), "matrix must be square!");
864
865 TimeStamp ts_start;
866 Statistics::add_flops(this->used_elements() * this->columns()*2);
867
868 IT_ * temp = new IT_[this->rows()];
869 Math::invert_matrix((IT_)this->rows(), (IT_)this->rows(), this->elements(), temp);
870 delete[] temp;
871
872 TimeStamp ts_stop;
873 Statistics::add_time_blas3(ts_stop.elapsed(ts_start));
874 }
875
878 {
879 DenseMatrix result;
880 result.clone(*this);
881 result.invert();
882 return result;
883 }
884
891 {
892 DenseMatrix x_t;
893 x_t.transpose(*this);
894 return x_t;
895 }
896
904 void transpose(const DenseMatrix & x)
905 {
906 if (rows() == x.columns() && columns() == x.rows())
907 {
908 Arch::Transpose::value(this->elements(), x.elements(), x.rows(), x.columns());
909 }
910 else
911 {
912 DenseMatrix r(x.columns(), x.rows());
913 Arch::Transpose::value(r.elements(), x.elements(), x.rows(), x.columns());
914 this->move(std::move(r));
915 }
916 }
917
924 {
925 Arch::Transpose::value(this->elements(), this->elements(), this->rows(), this->columns());
926
927 Index t(this->rows());
928 this->_rows() = this->columns();
929 this->_columns() = t;
930 }
931
933
935
937 void set_line(const Index row, DT_ * const pval_set, IT_ * const pcol_set,
938 const Index col_start, const Index stride = 1) const
939 {
940 const DT_ * pval(this->elements());
941
942 for (Index i(0); i < columns(); ++i)
943 {
944 pval_set[i * stride] = pval[columns() * row + i];
945 pcol_set[i * stride] = IT_(i) + IT_(col_start);
946 }
947 }
948
949 void set_line_reverse(const Index row, DT_ * const pval_set, const Index stride = 1)
950 {
951 const DT_ * pval(this->elements());
952
953 for (Index i(0); i < columns(); ++i)
954 {
955 pval_set[i * stride] = pval[columns() * row + i];
956 }
957 }
959
966 friend std::ostream & operator<< (std::ostream & lhs, const DenseMatrix & b)
967 {
968 lhs << "[\n";
969 for (Index i(0) ; i < b.rows() ; ++i)
970 {
971 lhs << "[";
972 for (Index j(0) ; j < b.columns() ; ++j)
973 {
974 lhs << " " << stringify(b(i, j));
975 }
976 lhs << "]\n";
977 }
978 lhs << "]\n";
979
980 return lhs;
981 }
982 };
983 } // namespace LAFEM
984} // 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.
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
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
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
std::vector< Index > _scalar_index
List of scalars with datatype index.
Definition: container.hpp:234
Dense data matrix class template.
void operator()(Index row, Index col, DT_ value)
Set specific matrix element.
void multiply(const DenseMatrix &x, const DenseMatrix &y, const DT_ alpha=DT_(1), const DT_ beta=DT_(1))
Calculate .
DenseMatrix(DenseMatrix &&other)
Move Constructor.
void read_from(FileMode mode, const String &filename)
Read in matrix from file.
DenseMatrix(Index rows_in, Index columns_in, DT_ value)
Constructor.
DT_ * elements()
Get a pointer to the data array.
DenseMatrix(std::vector< char > input)
Constructor.
void apply(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x) const
Calculate .
void apply_transposed(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x) const
Calculate .
void invert()
Invert the matrix insitu.
void copy(const DenseMatrix &x, bool full=false)
Performs .
static String name()
Returns a descriptive string.
bool same_layout(const DenseMatrix &x) const
Checks if the structural layout of this matrix matches that of another matrix. This excludes comparis...
const DT_ operator()(Index row, Index col) const
Retrieve specific matrix element.
void multiply(DenseMatrix &x, DenseMatrix &y)
Calculate .
DenseMatrix & operator=(DenseMatrix &&other)
Move operator.
void read_from(FileMode mode, std::istream &file)
Read in matrix from file.
DenseMatrix(FileMode mode, String filename)
Constructor.
DenseVector< DT_, IT_ > VectorTypeR
Compatible R-vector type.
VectorTypeR create_vector_r() const
Returns a new compatible R-Vector.
DenseMatrix(FileMode mode, std::istream &file)
Constructor.
DenseMatrix clone(CloneMode clone_mode=CloneMode::Deep) const
Clone operation.
void axpy(const DenseMatrix &x, const DT_ alpha=DT_(1))
Calculate .
void transpose(const DenseMatrix &x)
Calculate .
void clone(const DenseMatrix< DT2_, IT2_ > &other, CloneMode clone_mode=CloneMode::Deep)
Clone operation.
DenseMatrix transpose() const
Calculate .
void write_out(FileMode mode, std::ostream &file) const
Write outmatrix to file.
DenseMatrix inverse() const
Create an inverse of the current matrix.
Index rows() const
Retrieve matrix row count.
void multiply(const SparseMatrixCSR< DT_, IT_ > &x, const DenseMatrix &y, const DT_ alpha=DT_(1), const DT_ beta=DT_(1))
Calculate .
void write_out(FileMode mode, const String &filename) const
Write out matrix to file.
DT_ DataType
Our datatype.
friend std::ostream & operator<<(std::ostream &lhs, const DenseMatrix &b)
DenseMatrix streaming operator.
IT_ IndexType
Our indextype.
VectorTypeL create_vector_l() const
Returns a new compatible L-Vector.
DT_ norm_frobenius() const
Calculates the Frobenius norm of this matrix.
DenseVector< DT_, IT_ > VectorTypeL
Compatible L-vector type.
DenseMatrix(Index rows_in, Index columns_in)
Constructor.
std::vector< char > serialize(const LAFEM::SerialConfig &config=LAFEM::SerialConfig()) const
Serialization of complete container entity.
void apply_transposed(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
void multiply(SparseMatrixCSR< DT_, IT_ > &x, DenseMatrix &y)
Calculate .
DT_ max_rel_diff(const DenseMatrix &x) const
Retrieve the maximum relative difference of this matrix and another one y.max_rel_diff(x) returns .
void convert(const DenseMatrix< DT2_, IT2_ > &other)
Conversion method.
void scale(const DenseMatrix &x, const DT_ alpha)
Calculate .
Index columns() const
Retrieve matrix column count.
void transpose_inplace()
Calculate inplace.
Index get_length_of_line(const Index) const
Returns the number of NNZ-elements of the selected row.
void apply(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
void deserialize(std::vector< char > input)
Deserialization of complete container entity.
Dense data vector class template.
DT_ * elements()
Get a pointer to the data array.
void copy(const VT_ &a)
Performs .
Config class for serialize parameter.
Definition: container.hpp:47
CSR based sparse matrix.
IT_ * col_ind()
Retrieve column indices array.
DT_ * val()
Retrieve non zero element array.
Index rows() const
Retrieve matrix row count.
Index columns() const
Retrieve matrix column count.
Index used_elements() const
Retrieve non zero element count.
IT_ * row_ptr()
Retrieve row start index array.
static void set_memory(DT_ *address, const DT_ val, const Index count=1)
set memory to specific value
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
DT_ invert_matrix(const IT_ n, const IT_ stride, DT_ a[], IT_ p[])
Inverts a matrix and returns its determinant.
Definition: math.hpp:1292
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.