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
11#include <kernel/util/math.hpp>
12#include <kernel/lafem/forward.hpp>
13#include <kernel/lafem/container.hpp>
14#include <kernel/lafem/dense_vector.hpp>
15#include <kernel/lafem/arch/axpy_dense.hpp>
16#include <kernel/lafem/arch/matmatmult_dense_dense.hpp>
17#include <kernel/lafem/arch/matmatmult_sparse_dense.hpp>
18#include <kernel/lafem/arch/matvecmult_dense_dense.hpp>
19#include <kernel/lafem/arch/norm2_dense.hpp>
20#include <kernel/lafem/arch/scale_dense.hpp>
21#include <kernel/lafem/arch/transpose_dense.hpp>
22
23namespace FEAT
24{
25 namespace LAFEM
26 {
44 template <typename DT_, typename IT_ = Index>
45 class DenseMatrix : public Container<DT_, IT_>
46 {
47 public:
49 typedef DT_ DataType;
51 typedef IT_ IndexType;
57 template <typename DT2_ = DT_, typename IT2_ = IT_>
59
60 protected:
61 Index & _rows()
62 {
63 return this->_scalar_index.at(0);
64 }
65
66 Index & _cols()
67 {
68 return this->_scalar_index.at(1);
69 }
70
71 public:
77 DenseMatrix() = default;
78
87 explicit DenseMatrix(Index rows_in, Index columns_in)
88 {
89 XASSERT(rows_in != Index(0) && columns_in != Index(0));
90
91 this->_scalar_index.push_back(rows_in);
92 this->_scalar_index.push_back(columns_in);
93
94 this->_elements.push_back(Memory::Arbiter(sizeof(DT_) * rows_in * columns_in));
95 this->_elements_size.push_back(rows_in * columns_in);
96 }
97
107 explicit DenseMatrix(Index rows_in, Index columns_in, DT_ value) :
108 DenseMatrix(rows_in, columns_in)
109 {
110 this->format(value);
111 }
112
120 template <typename DT2_ = DT_, typename IT2_ = IT_>
121 explicit DenseMatrix(std::vector<char> input)
122 {
123 this->deserialize<DT2_, IT2_>(input);
124 }
125
126 //Just a test:
133 explicit DenseMatrix(FileMode mode, String filename)
134 {
135 this->read_from(mode, filename);
136 }
137
144 explicit DenseMatrix(FileMode mode, std::istream& file)
145 {
146 this->read_from(mode, file);
147 }
148
157 Container<DT_, IT_>(std::forward<DenseMatrix>(other))
158 {
159 }
160
169 {
170 this->move(std::forward<DenseMatrix>(other));
171
172 return *this;
173 }
174
184 {
185 DenseMatrix t;
186 t.clone(*this, clone_mode);
187 return t;
188 }
189
198 template<typename DT2_, typename IT2_>
199 void clone(const DenseMatrix<DT2_, IT2_> & other, CloneMode clone_mode = CloneMode::Deep)
200 {
201 Container<DT_, IT_>::clone(other, clone_mode);
202 }
203
211 template <typename DT2_, typename IT2_>
213 {
214 this->assign(other);
215 }
216
224 template <typename DT2_ = DT_, typename IT2_ = IT_>
225 void deserialize(std::vector<char> input)
226 {
227 this->template _deserialize<DT2_, IT2_>(FileMode::fm_dm, input);
228 }
229
242 template <typename DT2_ = DT_, typename IT2_ = IT_>
243 std::vector<char> serialize(const LAFEM::SerialConfig& config = LAFEM::SerialConfig()) const
244 {
245 return this->template _serialize<DT2_, IT2_>(FileMode::fm_dm, config);
246 }
247
254 void read_from(FileMode mode, const String& filename)
255 {
256 std::ios_base::openmode bin = std::ifstream::in | std::ifstream::binary;
257 if(mode == FileMode::fm_mtx)
258 bin = std::ifstream::in;
259 std::ifstream file(filename.c_str(), bin);
260 if(! file.is_open())
261 XABORTM("Unable to open Matrix file " + filename);
262 read_from(mode, file);
263 file.close();
264 }
265
272 void read_from(FileMode mode, std::istream& file)
273 {
274 this->clear();
275
276 switch(mode)
277 {
278 case FileMode::fm_mtx:
279 {
280 Index trows, tcols;
281 String line;
282 std::getline(file, line); // !!? Test on overflow error... could be an enormous matrix... !??
283 //for now, just array real general (aka dense) matrices
284 const bool array_format((line.find("%%MatrixMarket matrix array real general") != String::npos) ? true : false);
285 if (array_format == false)
286 {
287 XABORTM("Input-file is not a compatible array real mtx-file");
288 }
289
290 while(!file.eof())
291 {
292 std::getline(file,line);
293 if (file.eof())
294 XABORTM("Input-file is empty");
295
296 String::size_type begin(line.find_first_not_of(" "));
297 if (line.at(begin) != '%')
298 break;
299 }
300 //Read in number of num_rows and num_cols
301 {
302 String::size_type begin(line.find_first_not_of(" "));
303 line.erase(0, begin);
304 String::size_type end(line.find_first_of(" "));
305 String srow(line, 0, end);
306 trows = Index(atol(srow.c_str()));
307 line.erase(0, end);
308
309 begin = line.find_first_not_of(" ");
310 line.erase(0, begin);
311 end = line.find_first_of(" ");
312 String scol(line, 0, end);
313 tcols = Index(atol(scol.c_str()));
314 line.erase(0, end);
315 }
316
317 DenseMatrix<DT_, IT_> tmp(Index(trows), tcols);
318 Index i(0);
319 Memory::TypedView<DT_> tmp_view(tmp.elements_view_w());
320
321 //Read in value of lines:
322 while(!file.eof())
323 {
324 std::getline(file, line);
325 if(file.eof())
326 break;
327
328 String::size_type begin = line.find_first_not_of(" ");
329 line.erase(0, begin);
330 String::size_type end = line.find_first_of(" ");
331 String sval(line, 0, end);
332 DT_ tval((DT_)atof(sval.c_str()));
333
334 tmp_view[i] = tval;
335
336 ++i;
337 }
338 XASSERTM(i == trows * tcols, "Dense MTX file did not contain enough entries!");
339
340 tmp_view.release();
341 this->move(std::move(tmp));
342
343 }
344 break;
345
346 case FileMode::fm_dm:
347 [[fallthrough]];
348
350 this->template _deserialize<double, std::uint64_t>(FileMode::fm_dm, file);
351 break;
352
353 default:
354 XABORTM("Filemode not supported!");
355 }
356 }
357
364 void write_out(FileMode mode, const String& filename) const
365 {
366 std::ios_base::openmode bin = std::ofstream::out | std::ofstream::binary;
367 if(mode == FileMode::fm_mtx)
368 bin = std::ofstream::out;
369 std::ofstream file;
370 char* buff = nullptr;
371 if(mode == FileMode::fm_mtx)
372 {
373 buff = new char[LAFEM::file_out_stream_buffer_size];
374 file.rdbuf()->pubsetbuf(buff, LAFEM::file_out_stream_buffer_size);
375 }
376 file.open(filename.c_str(), bin);
377 if(! file.is_open())
378 XABORTM("Unable to open Matrix file " + filename);
379 write_out(mode, file);
380 file.close();
381 delete[] buff;
382 }
383
390 void write_out(FileMode mode, std::ostream& file) const
391 {
392 switch(mode)
393 {
394 case FileMode::fm_mtx:
395 {
396 file << "%%MatrixMarket matrix array real general\n";
397 file << this->num_rows() << " " << this->num_cols() << " " << this->num_nzes() << "\n";
398 file << std::scientific << std::setprecision(Type::Traits<DT_>::format_precision);
399
400 Memory::TypedView<DT_> elem_view(this->elements_view_r());
401 Index tsize = this->num_rows() * this->num_cols();
402 for (Index i(0); i < tsize; ++i)
403 {
404 file << elem_view(i) << "\n";
405 }
406 break;
407 }
408
409 case FileMode::fm_dm:
410 [[fallthrough]];
411
413 this->template _serialize<double, std::uint64_t>(FileMode::fm_dm, file);
414 break;
415
416 default:
417 XABORTM("Filemode not supported!");
418 }
419 }
420 //end of test
421
424 {
425 return this->_scalar_index.empty() ? Index(0) : this->_scalar_index.at(0);
426 }
427
430 {
431 return this->_scalar_index.empty() ? Index(0) : this->_scalar_index.at(1);
432 }
433
436 {
437 return this->_scalar_index.empty() ? Index(0) : this->_scalar_index.at(0) * this->_scalar_index.at(1);
438 }
439
441 Index size() const
442 {
443 return this->num_nzes();
444 }
445
447 bool empty() const
448 {
449 return this->_elements_size.empty() || (this->_elements_size.at(0) <= Index(0));
450 }
451
454 {
455 return this->_elements.front();
456 }
457
460 {
461 return this->_elements.front();
462 }
463
465 {
466 if(this->_elements.empty())
467 return Memory::TypedView<DT_>();
468 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, Memory::Access::read));
469 }
470
472 {
473 if(this->_elements.empty())
474 return Memory::TypedView<DT_>();
475 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, Memory::Access::write));
476 }
477
478 Memory::TypedView<DT_> elements_view_rw(Memory::Location loc = Memory::Location::main)
479 {
480 if(this->_elements.empty())
481 return Memory::TypedView<DT_>();
482 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, Memory::Access::read_write));
483 }
484
485 Memory::TypedView<DT_> elements_view(Memory::Location loc, Memory::Access acc)
486 {
487 if(this->_elements.empty())
488 return Memory::TypedView<DT_>();
489 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, acc));
490 }
491
497 static String name()
498 {
499 return "DenseMatrix";
500 }
501
508 void copy(const DenseMatrix & x, bool full = false)
509 {
510 this->_copy_content(x, full);
511 }
512
515 {
516 return VectorTypeL(this->num_rows());
517 }
518
520 VectorTypeR create_vector_r() const
521 {
522 return VectorTypeR(this->num_cols());
523 }
524
527
533 void scale(const DenseMatrix & x, const DT_ alpha)
534 {
535 XASSERTM(x.num_rows() == this->num_rows(), "Row count does not match!");
536 XASSERTM(x.num_cols() == this->num_cols(), "Column count does not match!");
537
538 if(this->empty())
539 return;
540
541 TimeStamp ts_start;
542
543 Arch::AxpyDense::template exec<DT_>(this->elements_arbiter(), alpha, x.elements_arbiter(), this->num_nzes());
544
545 TimeStamp ts_stop;
546
548 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
549 }
550
556 DT_ norm_frobenius() const
557 {
558 XASSERT(!this->empty());
559
560 TimeStamp ts_start;
561
562 DataType result = Arch::Norm2Dense::template exec<DT_>(this->elements_arbiter(), this->num_nzes());
563
564 TimeStamp ts_stop;
565
566 Statistics::add_flops(this->num_nzes() * 2);
567 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
568
569 return result;
570 }
571
579 void axpy(const DenseMatrix & x, const DT_ alpha = DT_(1))
580 {
581 XASSERTM(x.num_rows() == this->num_rows(), "Matrix row count does not match!");
582 XASSERTM(x.num_cols() == this->num_cols(), "Matrix column count does not match!");
583
584 if(this->empty())
585 return;
586
587 TimeStamp ts_start;
588
589 Arch::AxpyDense::template exec<DT_>(this->elements_arbiter(), alpha, x.elements_arbiter(), this->num_nzes());
590
591 TimeStamp ts_stop;
592
593 Statistics::add_flops(this->size() * 2);
594 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
595 }
596
604 {
605 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
606 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
607
608 if(this->empty())
609 return;
610
611 XASSERTM(r.elements_arbiter() != x.elements_arbiter(), "Vector x and r must not share the same memory!");
612
613 TimeStamp ts_start;
614
615 Arch::MatVecMultDenseDense::template exec<DT_>(r.elements_arbiter(), DT_(1), Memory::Arbiter(),
616 this->elements_arbiter(), x.elements_arbiter(), this->num_rows(), this->num_cols(), false);
617
618 TimeStamp ts_stop;
619
620 Statistics::add_flops(this->num_nzes() * 2);
621 Statistics::add_time_blas2(ts_stop.elapsed(ts_start));
622 }
623
631 {
632 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
633 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
634
635 if(this->empty())
636 return;
637
638 XASSERTM(r.elements_arbiter() != x.elements_arbiter(), "Vector x and r must not share the same memory!");
639
640 TimeStamp ts_start;
641
642 Arch::MatVecMultDenseDense::template exec<DT_>(r.elements_arbiter(), DT_(1), Memory::Arbiter(),
643 this->elements_arbiter(), x.elements_arbiter(), this->num_rows(), this->num_cols(), true);
644
645 TimeStamp ts_stop;
646
647 Statistics::add_flops(this->num_nzes() * 2);
648 Statistics::add_time_blas2(ts_stop.elapsed(ts_start));
649 }
650
659 void apply(DenseVector<DT_, IT_> & r, const DenseVector<DT_, IT_> & x, const DenseVector<DT_, IT_> & y, const DT_ alpha = DT_(1)) const
660 {
661 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
662 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
663 XASSERTM(y.size() == this->num_rows(), "Vector size of y does not match!");
664
665 if(this->empty())
666 return;
667
668 XASSERTM(r.elements_arbiter() != x.elements_arbiter(), "Vector x and r must not share the same memory!");
669
670 TimeStamp ts_start;
671
672 Arch::MatVecMultDenseDense::template exec<DT_>(r.elements_arbiter(), alpha, y.elements_arbiter(),
673 this->elements_arbiter(), x.elements_arbiter(), this->num_rows(), this->num_cols(), false);
674
675 TimeStamp ts_stop;
676
677 Statistics::add_flops( (this->num_nzes() + this->num_rows()) * 2 );
678 Statistics::add_time_blas2(ts_stop.elapsed(ts_start));
679 }
680
691 const DenseVector<DT_, IT_> & x,
692 const DenseVector<DT_, IT_> & y,
693 const DT_ alpha = DT_(1)) const
694 {
695 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
696 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
697 XASSERTM(y.size() == this->num_cols(), "Vector size of y does not match!");
698
699 if(this->empty())
700 return;
701
702 XASSERTM(r.elements_arbiter() != x.elements_arbiter(), "Vector x and r must not share the same memory!");
703
704 TimeStamp ts_start;
705
706 Arch::MatVecMultDenseDense::template exec<DT_>(r.elements_arbiter(), alpha, y.elements_arbiter(),
707 this->elements_arbiter(), x.elements_arbiter(), this->num_rows(), this->num_cols(), true);
708
709 TimeStamp ts_stop;
710
711 Statistics::add_flops( (this->num_nzes() + this->num_rows()) * 2 );
712 Statistics::add_time_blas2(ts_stop.elapsed(ts_start));
713 }
714
721 DT_ max_rel_diff(const DenseMatrix& x) const
722 {
723 XASSERTM(x.num_rows() == this->num_rows(), "Matrix row count does not match!");
724 XASSERTM(x.num_cols() == this->num_cols(), "Matrix column count does not match!");
725 XASSERT(!this->empty());
726
727 TimeStamp ts_start;
728
729 DataType max_rel_diff = Arch::MaxRelDiffDense::template exec<DT_>(this->elements_arbiter(), x.elements_arbiter(), this->num_nzes());
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->num_rows() != x.num_rows())
748 return false;
749 if (this->num_cols() != x.num_cols())
750 return false;
751
752 return true;
753 }
754
759 {
760 XASSERTM(x.num_cols() == y.num_rows(), "dimension mismatch!");
761 XASSERTM(this->num_rows() == x.num_rows(), "dimension mismatch!");
762 XASSERTM(this->num_cols() == y.num_cols(), "dimension mismatch!");
763
764 if(this->empty())
765 return;
766
767 TimeStamp ts_start;
768
769 Arch::MatMatMultDenseDense::template exec<DT_>(this->elements_arbiter(), DT_(1), x.elements_arbiter(),
770 y.elements_arbiter(), Memory::Arbiter(), this->num_rows(), this->num_cols(), x.num_cols());
771
772 TimeStamp ts_stop;
774 Statistics::add_time_blas3(ts_stop.elapsed(ts_start));
775 }
776
783 {
784 XASSERTM(x.num_cols() == y.num_rows(), "dimension mismatch!");
785 XASSERTM(this->num_rows() == x.num_rows(), "dimension mismatch!");
786 XASSERTM(this->num_cols() == y.num_cols(), "dimension mismatch!");
787
788 if(this->empty())
789 return;
790
791 TimeStamp ts_start;
792
793 Arch::MatMatMultSparseDense::template exec<DT_, IT_>(this->elements_arbiter(), DT_(1), x.val_arbiter(),
795 this->num_rows(), this->num_cols(), x.num_cols());
796
797 TimeStamp ts_stop;
798 //Statistics::add_flops(x.num_nzes() * y.num_cols()*2);
799 Statistics::add_time_blas3(ts_stop.elapsed(ts_start));
800 }
801
810 const DenseMatrix & x,
811 const DenseMatrix & y,
812 const DT_ alpha = DT_(1))
813 {
814 XASSERTM(x.num_cols() == y.num_rows(), "dimension mismatch!");
815 XASSERTM(this->num_rows() == x.num_rows(), "dimension mismatch!");
816 XASSERTM(this->num_cols() == y.num_cols(), "dimension mismatch!");
817
818 if(this->empty())
819 return;
820
821 TimeStamp ts_start;
822
823 Arch::MatMatMultDenseDense::template exec<DT_>(this->elements_arbiter(), alpha, x.elements_arbiter(),
824 y.elements_arbiter(), this->elements_arbiter(), this->num_rows(), this->num_cols(), x.num_cols());
825
826 TimeStamp ts_stop;
827
828 Statistics::add_flops(this->size() * 2);
829 Statistics::add_time_blas3(ts_stop.elapsed(ts_start));
830 }
831
842 const DenseMatrix & y,
843 const DT_ alpha = DT_(1))
844 {
845 XASSERTM(x.num_cols() == y.num_rows(), "dimension mismatch!");
846 XASSERTM(this->num_rows() == x.num_rows(), "dimension mismatch!");
847 XASSERTM(this->num_cols() == y.num_cols(), "dimension mismatch!");
848
849 if(this->empty())
850 return;
851
852 TimeStamp ts_start;
853
854 Arch::MatMatMultSparseDense::template exec<DT_, IT_>(this->elements_arbiter(), alpha, x.val_arbiter(),
855 x.col_idx_arbiter(), x.row_ptr_arbiter(), x.num_nzes(), y.elements_arbiter(), this->elements_arbiter(),
856 this->num_rows(), this->num_cols(), x.num_cols());
857
858 TimeStamp ts_stop;
859
861 Statistics::add_time_blas3(ts_stop.elapsed(ts_start));
862 }
863
865 void invert()
866 {
867 XASSERTM(this->num_rows() == this->num_cols(), "matrix must be square!");
868 XASSERT(!this->empty());
869
870 Memory::TypedView<DT_> val = this->elements_view_rw();
871 std::vector<IT_> temp(this->num_rows());
872
873 TimeStamp ts_start;
874
875 Math::invert_matrix((IT_)this->num_rows(), (IT_)this->num_rows(), val.get_w(), temp.data());
877
878 TimeStamp ts_stop;
879
880 Statistics::add_flops(this->num_nzes() * this->num_cols()*2);
881 Statistics::add_time_blas3(ts_stop.elapsed(ts_start));
882 }
883
886 {
887 DenseMatrix result;
888 result.clone(*this);
889 result.invert();
890 return result;
891 }
892
899 {
900 DenseMatrix r(this->num_cols(), this->num_rows());
901 Arch::TransposeDense::template exec<DT_>(r.elements_arbiter(), this->elements_arbiter(), this->num_rows(), this->num_cols());
902 return r;
903 }
904
906
913 friend std::ostream & operator<< (std::ostream & lhs, const DenseMatrix & b)
914 {
915 const Memory::TypedView<DT_> val = b.elements_view_r();
916
917 lhs << "[\n";
918 const Index m = b.num_rows();
919 const Index n = b.num_cols();
920 for (Index i(0) ; i < m ; ++i)
921 {
922 lhs << "[";
923 for (Index j(0) ; j < n ; ++j)
924 {
925 lhs << " " << val(i*n + j);
926 }
927 lhs << "]\n";
928 }
929 lhs << "]\n";
930
931 return lhs;
932 }
933 };
934 } // namespace LAFEM
935} // namespace FEAT
#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: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
virtual void clear()
Free all allocated arrays.
Definition: container.hpp:885
std::vector< Memory::Arbiter > _elements
List of pointers to all datatype dependent arrays.
Definition: container.hpp:230
std::vector< Index > _scalar_index
List of scalars with datatype index.
Definition: container.hpp:238
Dense data matrix class template.
DenseMatrix(DenseMatrix &&other)
Move Constructor.
void read_from(FileMode mode, const String &filename)
Read in matrix from file.
void set_product(DenseMatrix &x, DenseMatrix &y)
Calculate .
DenseMatrix(Index rows_in, Index columns_in, DT_ value)
Constructor.
DenseMatrix(std::vector< char > input)
Constructor.
Index num_cols() const
Retrieve matrix column count.
DenseMatrix()=default
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...
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.
Index size() const
Retrieve matrix element count.
void add_product(const DenseMatrix &x, const DenseMatrix &y, const DT_ alpha=DT_(1))
Calculate .
Memory::Arbiter & elements_arbiter()
Returns a reference to the element array arbiter.
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.
Index num_rows() const
Retrieve matrix row count.
void axpy(const DenseMatrix &x, const DT_ alpha=DT_(1))
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 num_nzes() const
Retrieve matrix non-zero element count.
void write_out(FileMode mode, const String &filename) const
Write out matrix to file.
bool empty() const
Checks whether the vector is empty, i.e. if it has size 0.
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 add_product(const SparseMatrixCSR< DT_, IT_ > &x, const DenseMatrix &y, const DT_ alpha=DT_(1))
Calculate .
void apply_transposed(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
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 .
const Memory::Arbiter & elements_arbiter() const
Returns a reference to the element array arbiter.
void set_product(SparseMatrixCSR< DT_, IT_ > &x, DenseMatrix &y)
Calculate .
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.
Memory::Arbiter & elements_arbiter()
Returns a reference to the element array arbiter.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Config class for serialize parameter.
Definition: container.hpp:50
CSR based sparse matrix.
Memory::Arbiter & val_arbiter()
Returns a reference to the values array arbiter.
Index num_cols() const
Retrieve matrix column count.
Index num_rows() const
Retrieve matrix row count.
Memory::Arbiter & col_idx_arbiter()
Returns a reference to the column-index array arbiter.
Index num_nzes() const
Retrieve non zero element count.
Memory::Arbiter & row_ptr_arbiter()
Returns a reference to the row-pointer array arbiter.
Memory arbiter class.
Typed memory view class.
T_ * get_w()
Returns a typed pointer to the array that grants write (and read) access.
void release() const
Releases this view.
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
DT_ invert_matrix(const IT_ n, const IT_ stride, DT_ a[], IT_ p[])
Inverts a matrix and returns its determinant.
Definition: math.hpp:1292
Access
Memory access enumeration.
@ read_write
read-write access
@ 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