FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
sparse_matrix_csr.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/memory_arbiter.hpp>
14#include <kernel/util/statistics.hpp>
15#include <kernel/util/time_stamp.hpp>
16#include <kernel/adjacency/graph.hpp>
17#include <kernel/adjacency/permutation.hpp>
18#include <kernel/lafem/forward.hpp>
19#include <kernel/lafem/container.hpp>
20#include <kernel/lafem/dense_vector.hpp>
21#include <kernel/lafem/sparse_layout.hpp>
22#include <kernel/lafem/arch/axpy_dense.hpp>
23#include <kernel/lafem/arch/diagonal_csr.hpp>
24#include <kernel/lafem/arch/lumping_csr.hpp>
25#include <kernel/lafem/arch/matvecmult_csr_block.hpp>
26#include <kernel/lafem/arch/matvecmult_csr_dense.hpp>
27#include <kernel/lafem/arch/norm2_dense.hpp>
28#include <kernel/lafem/arch/row_norm2_csr.hpp>
29#include <kernel/lafem/arch/scale_col_csr.hpp>
30#include <kernel/lafem/arch/scale_dense.hpp>
31#include <kernel/lafem/arch/scale_row_csr.hpp>
32
33// includes, system
34#include <fstream>
35
36namespace FEAT
37{
38 namespace LAFEM
39 {
60 template <typename DT_, typename IT_ = Index>
61 class SparseMatrixCSR : public Container<DT_, IT_>
62 {
63 public:
65 typedef DT_ DataType;
67 typedef IT_ IndexType;
69 typedef DT_ ValueType;
77 template <typename DT2_ = DT_, typename IT2_ = IT_>
79
81 template <typename DataType2_, typename IndexType2_>
83
85 static constexpr bool is_global = false;
86
88 static constexpr bool is_local = true;
89
90 protected:
91 Index & _rows()
92 {
93 return this->_scalar_index.at(0);
94 }
95
96 Index & _cols()
97 {
98 return this->_scalar_index.at(1);
99 }
100
101 Index & _nzes()
102 {
103 return this->_scalar_index.at(2);
104 }
105
106 public:
113 {
114 this->_scalar_index.push_back(0);
115 this->_scalar_index.push_back(0);
116 this->_scalar_index.push_back(0);
117 }
118
130 explicit SparseMatrixCSR(Index rows_in, Index columns_in)
131 {
132 this->_scalar_index.push_back(rows_in);
133 this->_scalar_index.push_back(columns_in);
134 this->_scalar_index.push_back(0);
135 }
136
148 explicit SparseMatrixCSR(Index rows_in, Index columns_in, Index nonzeros_in)
149 {
150 XASSERT(rows_in > Index(0));
151 XASSERT(columns_in > Index(0));
152
153 this->_scalar_index.push_back(rows_in);
154 this->_scalar_index.push_back(columns_in);
155 this->_scalar_index.push_back(nonzeros_in);
156
157 this->_indices.push_back(Memory::Arbiter(sizeof(IT_) * (rows_in + 1)));
158 this->_indices_size.push_back(rows_in + 1);
159
160 this->_indices.push_back(Memory::Arbiter(sizeof(IT_) * nonzeros_in));
161 this->_indices_size.push_back(nonzeros_in);
162
163 this->_elements.push_back(Memory::Arbiter(sizeof(DT_) * nonzeros_in));
164 this->_elements_size.push_back(nonzeros_in);
165 }
166
175 {
176 this->_indices_size.assign(layout_in._indices_size.begin(), layout_in._indices_size.end());
177 this->_scalar_index.assign(layout_in._scalar_index.begin(), layout_in._scalar_index.end());
178
179 for(const auto& idx : layout_in.get_indices())
180 this->_indices.push_back(idx.attach());
181
182 this->_elements.push_back(Memory::Arbiter(sizeof(DT_) * _nzes()));
183 this->_elements_size.push_back(_nzes());
184 }
185
193 template <typename MT_>
194 explicit SparseMatrixCSR(const MT_ & other)
195 {
196 this->convert(other);
197 }
198
206 explicit SparseMatrixCSR(const Adjacency::Graph & graph) :
207 SparseMatrixCSR(graph.get_num_nodes_domain(), graph.get_num_nodes_image(), graph.get_num_indices())
208 {
209 const Index num_nnze = graph.get_num_indices();
210 const Index num_rows = graph.get_num_nodes_domain();
211 const Index * dom_ptr(graph.get_domain_ptr());
212 const Index * img_idx(graph.get_image_idx());
213
214 Memory::TypedView<IT_> prow_ptr = this->row_ptr_view_w();
215 Memory::TypedView<IT_> pcol_idx = this->col_idx_view_w();
216
217 FEAT_PRAGMA_OMP(parallel for)
218 for(Index i = 0; i <= num_rows; ++i)
219 prow_ptr[i] = IT_(dom_ptr[i]);
220
221 FEAT_PRAGMA_OMP(parallel for)
222 for(Index i = 0; i < num_nnze; ++i)
223 pcol_idx[i] = IT_(img_idx[i]);
224 }
225
234 explicit SparseMatrixCSR(FileMode mode, const String& filename) :
235 Container<DT_, IT_>()
236 {
237 this->read_from(mode, filename);
238 }
239
248 explicit SparseMatrixCSR(FileMode mode, std::istream& file) :
249 Container<DT_, IT_>()
250 {
251 this->read_from(mode, file);
252 }
253
266 explicit SparseMatrixCSR(const Index rows_in, const Index columns_in,
267 DenseVector<IT_, IT_> & row_ptr_in, DenseVector<IT_, IT_> & col_idx_in, DenseVector<DT_, IT_> & val_in)
268 {
270 XASSERT(row_ptr_in.size() > 0);
271 XASSERT(col_idx_in.size() > 0);
272 XASSERT(col_idx_in.size() == val_in.size());
273
274 this->_scalar_index.push_back(rows_in);
275 this->_scalar_index.push_back(columns_in);
276 this->_scalar_index.push_back(val_in.size());
277
278 this->_indices.push_back(row_ptr_in.elements_arbiter().attach());
279 this->_indices_size.push_back(row_ptr_in.size());
280 this->_indices.push_back(col_idx_in.elements_arbiter().attach());
281 this->_indices_size.push_back(col_idx_in.size());
282 this->_elements.push_back(val_in.elements_arbiter().attach());
283 this->_elements_size.push_back(val_in.size());
284 }
285
293 template <typename DT2_ = DT_, typename IT2_ = IT_>
294 explicit SparseMatrixCSR(std::vector<char> input)
295 {
296 this->deserialize<DT2_, IT2_>(input);
297 }
298
307 Container<DT_, IT_>(std::forward<SparseMatrixCSR>(other))
308 {
309 }
310
319 {
320 this->move(std::forward<SparseMatrixCSR>(other));
321
322 return *this;
323 }
324
334 {
336 t.clone(*this, clone_mode);
337 return t;
338 }
339
348 template<typename DT2_, typename IT2_>
350 {
351 Container<DT_, IT_>::clone(other, clone_mode);
352 }
353
361 template <typename DT2_, typename IT2_>
363 {
364 this->assign(other);
365 }
366
374 void convert(const Adjacency::Graph & graph)
375 {
376 this->move(SparseMatrixCSR(graph));
377 }
378
386 template <typename DT2_, typename IT2_>
388 {
389 this->clear();
390
391 this->_scalar_index.push_back(other.num_rows());
392 this->_scalar_index.push_back(other.num_cols());
393 this->_scalar_index.push_back(other.num_nzes());
394
395 if (other.num_nzes() == 0)
396 return;
397
398 this->_indices.push_back(Memory::Arbiter(sizeof(IT_) * (_rows() + 1)));
399 this->_indices_size.push_back(_rows() + 1);
400 this->_indices.push_back(Memory::Arbiter(sizeof(IT_) * _nzes()));
401 this->_indices_size.push_back(_nzes());
402 this->_elements.push_back(Memory::Arbiter(sizeof(DT_) * _nzes()));
403 this->_elements_size.push_back(_nzes());
404
405 Memory::TypedView<IT_> row_ptr = this->row_ptr_view_w();
406 Memory::TypedView<IT_> col_idx = this->col_idx_view_w();
407 Memory::TypedView<DT_> val = this->val_view_w();
408
409 const Memory::TypedView<DT_> cval = other.val_view_r();
410 const Memory::TypedView<IT_> coffsets = other.offsets_view_r();
411 const Index nbands(other.num_bands());
412 const Index nrows(other.num_rows());
413 const Index ncols(other.num_cols());
414 //const Index nnzes(other.num_nzes());
415
416 row_ptr[0] = 0;
417
418 // Search first offset of the upper triangular matrix
419 Index k(0);
420 while (k < nbands && coffsets[k] + 1 < nrows)
421 {
422 ++k;
423 }
424
425 IT_ ue(0);
426 // iteration over all offsets of the lower triangular matrix
427 for (Index i(k + 1); i > 0;)
428 {
429 --i;
430
431 // iteration over all offsets of the upper triangular matrix
432 for (Index j(nbands + 1); j > 0;)
433 {
434 --j;
435
436 // iteration over all rows which contain the offsets between offset i and offset j
437 Index so1 = Index(0);
438 Index so2 = nrows;
439 Index eo1 = Index(0);
440 Index eo2 = nrows;
441 if(i < nbands)
442 so1 = Math::max(ncols + Index(1), nrows + ncols - Index(coffsets[i])) - ncols - Index(1);
443 if(j < nbands)
444 eo1 = Math::min(nrows, ncols + nrows - Index(coffsets[j]) - Index(1));
445 if(i > 0)
446 so2 = Math::max(ncols + Index(1), nrows + ncols - Index(coffsets[i-1])) - ncols - Index(1);
447 if(j > 0)
448 eo2 = Math::min(nrows, ncols + nrows - Index(coffsets[j-1]) - Index(1));
449
450 const Index start = Math::max(so1, eo1);
451 const Index end = Math::min(so2, eo2);
452
453 for (Index l(start); l < end; ++l)
454 {
455 for (Index a(i); a < j; ++a)
456 {
457 val[ue] = cval[a * nrows + l];
458 col_idx[ue] = IT_(l + coffsets[a] + 1 - nrows);
459 ++ue;
460 }
461 row_ptr[l + 1] = ue;
462 }
463 }
464 }
465 }
466
474 template <typename DT2_, typename IT2_, int block_height_, int block_width_>
476 {
477 this->clear();
478
479 this->_scalar_index.push_back(other.num_rows_raw());
480 this->_scalar_index.push_back(other.num_cols_raw());
481 this->_scalar_index.push_back(other.num_nzes_raw());
482
483 if (other.num_nzes_raw() == 0)
484 return;
485
486 this->_indices.push_back(Memory::Arbiter(sizeof(IT_) * (_rows() + 1)));
487 this->_indices_size.push_back(_rows() + 1);
488 this->_indices.push_back(Memory::Arbiter(sizeof(IT_) * _nzes()));
489 this->_indices_size.push_back(_nzes());
490 this->_elements.push_back(Memory::Arbiter(sizeof(DT_) * _nzes()));
491 this->_elements_size.push_back(_nzes());
492
493 Memory::TypedView<IT_> row_ptr = this->row_ptr_view_w();
494 Memory::TypedView<IT_> col_idx = this->col_idx_view_w();
495 Memory::TypedView<DT_> val = this->val_view_w();
496
497 const Memory::TypedView<IT_> brow_ptr = other.row_ptr_view_r();
498 const Memory::TypedView<IT_> bcol_idx = other.col_idx_view_r();
500 const Index brows = other.num_rows();
501
502 row_ptr[0] = IT_(0);
503 for (Index orow(0), ait(0) ; orow < brows ; ++orow)
504 {
505 for (int row(0) ; row < block_height_ ; ++row)
506 {
507 for(Index ocol(brow_ptr[orow]) ; ocol < brow_ptr[orow + 1] ; ++ocol)
508 {
509 for (int col(0) ; col < block_width_ ; ++col, ++ait)
510 {
511 val[ait] = bval[ocol](row,col);
512 col_idx[ait] = bcol_idx[ocol] * IT_(block_width_) + IT_(col);
513 }
514 }
515 row_ptr[orow * Index(block_height_) + Index(row) + 1] = IT_(ait);
516 }
517 }
518 }
519
527 template <typename MT_>
528 void convert(const MT_ & a)
529 {
530 XASSERT(a.num_nzes_raw() > 0);
531
532 const Index arows(a.num_rows_raw());
533 const Index acols(a.num_cols_raw());
534 const Index anzes(a.num_nzes_raw());
535
536 SparseMatrixCSR<DT_, IT_> csr(arows, acols, anzes);
537
538 Memory::TypedView<IT_> row_ptr = csr.row_ptr_view_w();
539 Memory::TypedView<IT_> col_idx = csr.col_idx_view_w();
540 Memory::TypedView<DT_> val = csr.val_view_w();
541
542 row_ptr[0] = IT_(0);
543 for (Index i(0); i < arows; ++i)
544 {
545 row_ptr[i + 1] = row_ptr[i] + IT_(a.row_degree(i));
546 }
547
548 for (Index i(0); i < arows; ++i)
549 {
550 a.get_row_col_indices(i, &col_idx[row_ptr[i]], IT_(0));
551 a.get_row_values(i, &val[row_ptr[i]]);
552 }
553
554 val.release();
555 col_idx.release();
556 row_ptr.release();
557
558 this->move(std::move(csr));
559 }
560
571 template <typename MT_>
572 void copy(const MT_ & source)
573 {
574 XASSERT(source.num_rows_raw() == this->num_rows());
575 XASSERT(source.num_cols_raw() == this->num_cols());
576 XASSERT(source.num_nzes_raw() == this->num_nzes());
577
578 const Memory::TypedView<IT_> row_ptr = this->row_ptr_view_r();
579 Memory::TypedView<DT_> val = this->val_view_w();
580
581 const Index nrows = this->num_rows();
582 for (Index i(0); i < nrows; ++i)
583 {
584 source.get_row_values(i, &val[row_ptr[i]]);
585 }
586 }
587
598 template <typename MT_>
599 void copy_to(MT_ & target) const
600 {
601 XASSERT(target.num_rows_raw() == this->num_rows());
602 XASSERT(target.num_cols_raw() == this->num_cols());
603 XASSERT(target.num_nzes_raw() == this->num_nzes());
604
605 const Memory::TypedView<IT_> row_ptr = this->row_ptr_view_r();
606 const Memory::TypedView<DT_> val = this->val_view_r();
607
608 const Index nrows = this->num_rows();
609 for (Index i(0); i < nrows; ++i)
610 {
611 target.set_row_values(i, &val[row_ptr[i]]);
612 }
613 }
614
623 {
624 this->_elements.clear();
625 this->_indices.clear();
626 this->_elements_size.clear();
627 this->_indices_size.clear();
628 this->_scalar_index.clear();
629
630 this->_indices_size.assign(layout_in._indices_size.begin(), layout_in._indices_size.end());
631 this->_scalar_index.assign(layout_in._scalar_index.begin(), layout_in._scalar_index.end());
632
633 for(const auto& idx : layout_in.get_indices())
634 this->_indices.push_back(idx.attach());
635
636 this->_elements.push_back(Memory::Arbiter(_nzes() * sizeof(DT_)));
637
638 this->_elements_size.push_back(_nzes());
639
640 return *this;
641 }
642
650 template <typename DT2_ = DT_, typename IT2_ = IT_>
651 void deserialize(std::vector<char> input)
652 {
653 this->template _deserialize<DT2_, IT2_>(FileMode::fm_csr, input);
654 }
655
666 template <typename DT2_ = DT_, typename IT2_ = IT_>
667 std::vector<char> serialize(const LAFEM::SerialConfig& config = SerialConfig()) const
668 {
669 return this->template _serialize<DT2_, IT2_>(FileMode::fm_csr, config);
670 }
671
678 void read_from(FileMode mode, const String& filename)
679 {
680 std::ios_base::openmode bin = std::ifstream::in | std::ifstream::binary;
681 if(mode == FileMode::fm_mtx)
682 bin = std::ifstream::in;
683 std::ifstream file(filename.c_str(), bin);
684 if (! file.is_open())
685 XABORTM("Unable to open Matrix file " + filename);
686 read_from(mode, file);
687 file.close();
688 }
689
696 void read_from(FileMode mode, std::istream& file)
697 {
698 switch(mode)
699 {
700 case FileMode::fm_mtx:
701 {
702 this->clear();
703 this->_scalar_index.push_back(0);
704 this->_scalar_index.push_back(0);
705 this->_scalar_index.push_back(0);
706
707 std::map<IT_, std::map<IT_, DT_> > entries; // map<row, map<column, value> >
708
709 Index ue(0);
710 String line;
711 std::getline(file, line);
712 const bool general((line.find("%%MatrixMarket matrix coordinate real general") != String::npos) ? true : false);
713 const bool symmetric((line.find("%%MatrixMarket matrix coordinate real symmetric") != String::npos) ? true : false);
714
715 if (symmetric == false && general == false)
716 {
717 XABORTM("Input-file is not a compatible mtx-file");
718 }
719
720 while(!file.eof())
721 {
722 std::getline(file,line);
723 if (file.eof())
724 XABORTM("Input-file is empty");
725
726 String::size_type begin(line.find_first_not_of(" "));
727 if (line.at(begin) != '%')
728 break;
729 }
730 {
731 String::size_type begin(line.find_first_not_of(" "));
732 line.erase(0, begin);
733 String::size_type end(line.find_first_of(" "));
734 String srow(line, 0, end);
735 Index row((Index)atol(srow.c_str()));
736 line.erase(0, end);
737
738 begin = line.find_first_not_of(" ");
739 line.erase(0, begin);
740 end = line.find_first_of(" ");
741 String scol(line, 0, end);
742 Index col((Index)atol(scol.c_str()));
743 line.erase(0, end);
744 _rows() = row;
745 _cols() = col;
746 }
747
748 while(!file.eof())
749 {
750 std::getline(file, line);
751 if (file.eof())
752 break;
753
754 String::size_type begin(line.find_first_not_of(" "));
755 line.erase(0, begin);
756 String::size_type end(line.find_first_of(" "));
757 String srow(line, 0, end);
758 IT_ row((IT_)atol(srow.c_str()));
759 --row;
760 line.erase(0, end);
761
762 begin = line.find_first_not_of(" ");
763 line.erase(0, begin);
764 end = line.find_first_of(" ");
765 String scol(line, 0, end);
766 IT_ col((IT_)atol(scol.c_str()));
767 --col;
768 line.erase(0, end);
769
770 begin = line.find_first_not_of(" ");
771 line.erase(0, begin);
772 end = line.find_first_of(" ");
773 String sval(line, 0, end);
774 DT_ tval((DT_)atof(sval.c_str()));
775
776 entries[IT_(row)].insert(std::pair<IT_, DT_>(col, tval));
777 ++ue;
778 if (symmetric == true && row != col)
779 {
780 entries[IT_(col)].insert(std::pair<IT_, DT_>(row, tval));
781 ++ue;
782 }
783 }
784 _nzes() = ue;
785
786 this->_indices.push_back(Memory::Arbiter(sizeof(IT_) * (_rows() + 1)));
787 this->_indices_size.push_back(num_rows() + 1);
788 this->_indices.push_back(Memory::Arbiter(sizeof(IT_) * _nzes()));
789 this->_indices_size.push_back(_nzes());
790 this->_elements.push_back(Memory::Arbiter(sizeof(DT_) * _nzes()));
791 this->_elements_size.push_back(_nzes());
792
793 Memory::TypedView<IT_> trow_ptr(this->row_ptr_view_w());
794 Memory::TypedView<IT_> tcol_idx(this->col_idx_view_w());
795 Memory::TypedView<DT_> tval(this->val_view_w());
796
797 IT_ idx(0);
798 Index row_idx(0);
799 for (auto row : entries)
800 {
801 trow_ptr[row_idx] = idx;
802 for (auto col : row.second)
803 {
804 tcol_idx[idx] = col.first;
805 tval[idx] = col.second;
806 ++idx;
807 }
808 row.second.clear();
809 ++row_idx;
810 }
811 trow_ptr[num_rows()] = IT_(ue);
812 entries.clear();
813
814 break;
815 }
816
817 case FileMode::fm_csr:
818 [[fallthrough]];
819
821 this->template _deserialize<double, std::uint64_t>(FileMode::fm_csr, file);
822 break;
823
824 default:
825 XABORTM("Filemode not supported!");
826 }
827 }
828
839 void write_out(FileMode mode, const String& filename, bool symmetric = false) const
840 {
841 std::ios_base::openmode bin = std::ofstream::out | std::ofstream::binary;
842 if(mode == FileMode::fm_mtx)
843 bin = std::ofstream::out;
844 std::ofstream file;
845 char* buff = nullptr;
846 if(mode == FileMode::fm_mtx)
847 {
848 buff = new char[LAFEM::file_out_stream_buffer_size];
849 file.rdbuf()->pubsetbuf(buff, LAFEM::file_out_stream_buffer_size);
850 }
851 file.open(filename.c_str(), bin);
852 if(! file.is_open())
853 XABORTM("Unable to open Matrix file " + filename);
854 write_out(mode, file, symmetric);
855 file.close();
856 delete[] buff;
857 }
858
869 void write_out(FileMode mode, std::ostream& file, bool symmetric = false) const
870 {
871 switch(mode)
872 {
873 case FileMode::fm_csr:
874 [[fallthrough]];
875
877 this->template _serialize<double, std::uint64_t>(FileMode::fm_csr, file);
878 break;
879
880 case FileMode::fm_mtx:
881 {
882 const Memory::TypedView<IT_> trow_ptr = this->row_ptr_view_r();
883 const Memory::TypedView<IT_> tcol_idx = this->col_idx_view_r();
884 const Memory::TypedView<DT_> tval = this->val_view_r();
885
886 if (symmetric)
887 {
888 file << "%%MatrixMarket matrix coordinate real symmetric\n";
889 std::vector<IT_> rowv;
890 std::vector<IT_> colv;
891 std::vector<DT_> valv;
892
893 for (Index row(0) ; row < num_rows() ; ++row)
894 {
895 const IT_ end(trow_ptr[row + 1]);
896 for (IT_ i(trow_ptr[row]) ; i < end ; ++i)
897 {
898 const IT_ col(tcol_idx[i]);
899 if (row >= col)
900 {
901 rowv.push_back(IT_(row + 1));
902 colv.push_back(col + 1);
903 valv.push_back(tval[i]);
904 }
905 }
906 }
907 file << this->num_rows() << " " << this->num_cols() << " " << valv.size() << "\n";
908 for (Index i(0) ; i < valv.size() ; ++i)
909 {
910 file << rowv.at(i) << " " << colv.at(i) << " " << valv.at(i) << "\n";
911 }
912 }
913 else
914 {
915 file << "%%MatrixMarket matrix coordinate real general\n";
916 file << this->num_rows() << " " << this->num_cols() << " " << this->num_nzes() << "\n";
917
918 for (Index row(0) ; row < num_rows() ; ++row)
919 {
920 const IT_ end(trow_ptr[row + 1]);
921 for (IT_ i(trow_ptr[row]) ; i < end ; ++i)
922 {
923 file << row + 1 << " " << tcol_idx[i] + 1 << " " << tval[i] << "\n";
924 }
925 }
926 }
927 break;
928 }
929
930 default:
931 XABORTM("Filemode not supported!");
932 }
933 }
934
941 {
943 }
944
946 bool empty() const
947 {
948 return this->_scalar_index.empty() || (this->_scalar_index.at(0) == Index(0));
949 }
950
952 bool hollow() const
953 {
954 return this->_scalar_index.empty() || (this->_scalar_index.at(2) == Index(0));
955 }
956
963 {
964 return this->_scalar_index.empty() ? Index(0) : this->_scalar_index.at(0);
965 }
966
973 {
974 return this->_scalar_index.empty() ? Index(0) : this->_scalar_index.at(1);
975 }
976
983 {
984 return this->_scalar_index.empty() ? Index(0) : this->_scalar_index.at(2);
985 }
986
989 {
990 return this->num_rows();
991 }
992
995 {
996 return this->num_cols();
997 }
998
1001 {
1002 return this->num_nzes();
1003 }
1004
1007 {
1008 return this->_indices.at(0);
1009 }
1010
1013 {
1014 return this->_indices.at(0);
1015 }
1016
1019 {
1020 return this->_indices.at(1);
1021 }
1022
1025 {
1026 return this->_indices.at(1);
1027 }
1028
1031 {
1032 return this->_elements.front();
1033 }
1034
1037 {
1038 return this->_elements.front();
1039 }
1040
1042 {
1043 if(this->_elements.empty())
1044 return Memory::TypedView<DT_>();
1045 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, Memory::Access::read));
1046 }
1047
1049 {
1050 if(this->_elements.empty())
1051 return Memory::TypedView<DT_>();
1052 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, Memory::Access::write));
1053 }
1054
1055 Memory::TypedView<DT_> val_view_rw(Memory::Location loc = Memory::Location::main)
1056 {
1057 if(this->_elements.empty())
1058 return Memory::TypedView<DT_>();
1059 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, Memory::Access::read_write));
1060 }
1061
1062 Memory::TypedView<DT_> val_view(Memory::Location loc, Memory::Access acc)
1063 {
1064 if(this->_elements.empty())
1065 return Memory::TypedView<DT_>();
1066 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, acc));
1067 }
1068
1069 Memory::TypedView<IT_> row_ptr_view_r(Memory::Location loc = Memory::Location::main) const
1070 {
1071 if(this->_indices.empty())
1072 return Memory::TypedView<IT_>();
1073 return Memory::TypedView<IT_>(this->_indices.at(0).view(loc, Memory::Access::read));
1074 }
1075
1076 Memory::TypedView<IT_> row_ptr_view_w(Memory::Location loc = Memory::Location::main)
1077 {
1078 if(this->_indices.empty())
1079 return Memory::TypedView<IT_>();
1080 return Memory::TypedView<IT_>(this->_indices.at(0).view(loc, Memory::Access::write));
1081 }
1082
1083 Memory::TypedView<IT_> row_ptr_view_rw(Memory::Location loc = Memory::Location::main)
1084 {
1085 if(this->_indices.empty())
1086 return Memory::TypedView<IT_>();
1087 return Memory::TypedView<IT_>(this->_indices.at(0).view(loc, Memory::Access::read_write));
1088 }
1089
1090 Memory::TypedView<IT_> row_ptr_view(Memory::Location loc, Memory::Access acc)
1091 {
1092 if(this->_indices.empty())
1093 return Memory::TypedView<IT_>();
1094 return Memory::TypedView<IT_>(this->_indices.at(0).view(loc, acc));
1095 }
1096
1097 Memory::TypedView<IT_> col_idx_view_r(Memory::Location loc = Memory::Location::main) const
1098 {
1099 if(this->_indices.empty())
1100 return Memory::TypedView<IT_>();
1101 return Memory::TypedView<IT_>(this->_indices.at(1).view(loc, Memory::Access::read));
1102 }
1103
1104 Memory::TypedView<IT_> col_idx_view_w(Memory::Location loc = Memory::Location::main)
1105 {
1106 if(this->_indices.empty())
1107 return Memory::TypedView<IT_>();
1108 return Memory::TypedView<IT_>(this->_indices.at(1).view(loc, Memory::Access::write));
1109 }
1110
1111 Memory::TypedView<IT_> col_idx_view_rw(Memory::Location loc = Memory::Location::main)
1112 {
1113 if(this->_indices.empty())
1114 return Memory::TypedView<IT_>();
1115 return Memory::TypedView<IT_>(this->_indices.at(1).view(loc, Memory::Access::read_write));
1116 }
1117
1118 Memory::TypedView<IT_> col_idx_view(Memory::Location loc, Memory::Access acc)
1119 {
1120 if(this->_indices.empty())
1121 return Memory::TypedView<IT_>();
1122 return Memory::TypedView<IT_>(this->_indices.at(1).view(loc, acc));
1123 }
1124
1131 void bandwidth_row(Index & bandw, Index & bandw_i) const
1132 {
1133 XASSERT(!this->empty());
1134
1135 const Memory::TypedView<IT_> row_ptr = this->row_ptr_view_r();
1136 const Memory::TypedView<IT_> col_idx = this->col_idx_view_r();
1137 bandw = 0;
1138 bandw_i = 0;
1139 for (Index row(0) ; row < num_rows() ; ++row)
1140 {
1141 if (row_ptr[row+1] == row_ptr[row])
1142 continue;
1143
1144 Index temp = col_idx[row_ptr[row+1]-1] - col_idx[row_ptr[row]] + 1;
1145 if(temp > bandw)
1146 {
1147 bandw = temp;
1148 bandw_i = row;
1149 }
1150 }
1151 }
1152
1159 //void bandwidth_column(Index & bandw, Index & bandw_i) const
1160 //{
1161 // /// \todo implement this properly
1162 // SparseMatrixCSR<DT_, IT_> temp;
1163 // temp.transpose(*this);
1164 // temp.bandwidth_row(bandw, bandw_i);
1165 //}
1166
1175 void radius_row(Index & radius, Index & radius_i) const
1176 {
1177 XASSERT(!this->empty());
1178
1179 const Memory::TypedView<IT_> row_ptr = this->row_ptr_view_r();
1180 const Memory::TypedView<IT_> col_idx = this->col_idx_view_r();
1181 radius = 0;
1182 radius_i = 0;
1183
1184 for (Index row(0) ; row < num_rows() ; ++row)
1185 {
1186 if (row_ptr[row+1] == row_ptr[row])
1187 continue;
1188
1189 if (row_ptr[row+1] > 0)
1190 {
1191 Index temp1 = col_idx[row_ptr[row+1]-1];
1192 if(Math::max(temp1,row) - Math::min(temp1, row) > radius)
1193 {
1194 radius = Math::max(temp1,row) - Math::min(temp1, row);
1195 radius_i = row;
1196 }
1197 }
1198 Index temp2 = col_idx[row_ptr[row]];
1199 if(Math::max(temp2,row) - Math::min(temp2, row) > radius)
1200 {
1201 radius = Math::max(temp2,row) - Math::min(temp2, row);
1202 radius_i = row;
1203 }
1204 }
1205 }
1206
1218 void init_workspace() const
1219 {
1220 #ifdef FEAT_HAVE_CUDA
1221 Arch::MatVecMultCSRDense::init_workspace_cuda<DT_, IT_>(
1222 this->_backend_workspaces[to_underlying(BackendIdx::cuda)],
1223 this->val_arbiter(), this->col_idx_arbiter(), this->row_ptr_arbiter(),
1224 this->num_rows(), this->num_cols(), this->num_nzes(), false);
1225 #endif
1226 }
1227
1236 //void radius_column(Index & radius, Index & radius_i) const
1237 //{
1238 // /// \todo implement this properly
1239 // SparseMatrixCSR<DT_, IT_> temp(this->clone());
1240 // temp.transpose(temp);
1241 // temp.radius_row(radius, radius_i);
1242 //}
1243
1249 static String name()
1250 {
1251 return "SparseMatrixCSR";
1252 }
1253
1260 void copy(const SparseMatrixCSR & x, bool full = false)
1261 {
1262 this->_copy_content(x, full);
1263 }
1264
1267
1276 void axpy(const SparseMatrixCSR & x, const DT_ alpha = DT_(1))
1277 {
1278 XASSERTM(x.num_rows() == this->num_rows(), "Matrix rows do not match!");
1279 XASSERTM(x.num_cols() == this->num_cols(), "Matrix columns do not match!");
1280 XASSERTM(x.num_nzes() == this->num_nzes(), "Matrix nonzeros do not match!");
1281
1282 if(this->empty())
1283 return;
1284
1285 TimeStamp ts_start;
1286
1287 Arch::AxpyDense::template exec<DT_>(this->val_arbiter(), alpha, x.val_arbiter(), this->num_nzes());
1288
1289 TimeStamp ts_stop;
1290
1291 Statistics::add_flops(this->num_nzes() * 2);
1292 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
1293 }
1294
1301 void scale(const SparseMatrixCSR & x, const DT_ alpha)
1302 {
1303 XASSERTM(x.num_rows() == this->num_rows(), "Row count does not match!");
1304 XASSERTM(x.num_cols() == this->num_cols(), "Column count does not match!");
1305 XASSERTM(x.num_nzes() == this->num_nzes(), "Nonzero count does not match!");
1306
1307 if(this->empty())
1308 return;
1309
1310 TimeStamp ts_start;
1311
1312 Arch::ScaleDense::template exec<DT_>(this->val_arbiter(), x.val_arbiter(), alpha, this->num_nzes());
1313
1314 TimeStamp ts_stop;
1315
1317 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
1318 }
1319
1325 DT_ norm_frobenius() const
1326 {
1327 XASSERT(!this->empty());
1328
1329 TimeStamp ts_start;
1330
1331 DT_ result = Arch::Norm2Dense::template exec<DT_>(this->val_arbiter(), this->num_nzes());
1332
1333 TimeStamp ts_stop;
1334
1335 Statistics::add_flops(this->num_nzes() * 2);
1336 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
1337
1338 return result;
1339 }
1340
1347 void row_norm2(VectorTypeL& row_norms) const
1348 {
1349 ASSERTM(row_norms.size() == this->num_rows(), "Matrix/Vector dimension mismatch");
1350
1351 if(this->empty())
1352 return;
1353
1354 TimeStamp ts_start;
1355
1356 Arch::RowNorm2CSR::template exec<DT_, IT_>(row_norms.elements_arbiter(), this->val_arbiter(),
1357 this->col_idx_arbiter(), this->row_ptr_arbiter(), this->num_rows(), false);
1358
1359 TimeStamp ts_stop;
1360
1362 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
1363 }
1364
1371 void row_norm2sqr(VectorTypeL& row_norms) const
1372 {
1373 ASSERTM(row_norms.size() == this->num_rows(), "Matrix/Vector dimension mismatch");
1374
1375 if(this->empty())
1376 return;
1377
1378 TimeStamp ts_start;
1379
1380 Arch::RowNorm2CSR::template exec<DT_, IT_>(row_norms.elements_arbiter(), this->val_arbiter(),
1381 this->col_idx_arbiter(), this->row_ptr_arbiter(), this->num_rows(), true);
1382
1383 TimeStamp ts_stop;
1384
1385 Statistics::add_flops(this->num_nzes() * 2);
1386 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
1387 }
1388
1395 {
1396 XASSERT(!this->empty());
1397
1398 TimeStamp ts_start;
1399
1400 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->val_arbiter(), this->num_nzes(), false, true);
1401
1402 TimeStamp ts_stop;
1403 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
1404
1405 return result;
1406 }
1407
1414 {
1415 XASSERT(!this->empty());
1416
1417 TimeStamp ts_start;
1418
1419 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->val_arbiter(), this->num_nzes(), true, true);
1420
1421 TimeStamp ts_stop;
1422 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
1423
1424 return result;
1425 }
1426
1432 DT_ max_element() const
1433 {
1434 XASSERT(!this->empty());
1435
1436 TimeStamp ts_start;
1437
1438 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->val_arbiter(), this->num_nzes(), false, false);
1439
1440 TimeStamp ts_stop;
1441 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
1442
1443 return result;
1444 }
1445
1451 DT_ min_element() const
1452 {
1453 XASSERT(!this->empty());
1454
1455 TimeStamp ts_start;
1456
1457 DT_ result = Arch::MinMaxValueDense::template exec<DT_>(this->val_arbiter(), this->num_nzes(), true, false);
1458
1459 TimeStamp ts_stop;
1460 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
1461
1462 return result;
1463 }
1464
1474 DT_ max_rel_diff(const SparseMatrixCSR & x) const
1475 {
1476 XASSERTM(x.num_nzes() == this->num_nzes(), "Nonzero count does not match!");
1477 XASSERT(!this->empty());
1478
1479 TimeStamp ts_start;
1480
1481 DT_ result = Arch::MaxRelDiffDense::template exec<DT_>(this->val_arbiter(), x.val_arbiter(), this->num_nzes());
1482
1483 TimeStamp ts_stop;
1484 Statistics::add_time_reduction(ts_stop.elapsed(ts_start));
1485
1486 return result;
1487 }
1488
1497 bool same_layout(const SparseMatrixCSR& x) const
1498 {
1499 if (this->num_rows() != x.num_rows())
1500 return false;
1501 if (this->num_cols() != x.num_cols())
1502 return false;
1503 if (this->num_nzes() != x.num_nzes())
1504 return false;
1505
1506 if(this->num_nzes() == Index(0))
1507 return true;
1508
1509 // check if the arbiters for row_ptr and col_idx are the same
1510 if((this->row_ptr_arbiter() == x.row_ptr_arbiter()) && (this->col_idx_arbiter() == x.col_idx_arbiter()))
1511 return true;
1512
1513 const Memory::TypedView<IT_> row_ptr_a = this->row_ptr_view_r();
1514 const Memory::TypedView<IT_> col_idx_a = this->col_idx_view_r();
1515 const Memory::TypedView<IT_> row_ptr_b = x.row_ptr_view_r();
1516 const Memory::TypedView<IT_> col_idx_b = x.col_idx_view_r();
1517
1518 const Index n = this->num_rows();
1519 for (Index i(0) ; i <= n; ++i)
1520 {
1521 if (row_ptr_a[i] != row_ptr_b[i])
1522 {
1523 return false;
1524 }
1525 }
1526
1527 const Index nze = this->num_nzes();
1528 for (Index i(0) ; i < nze ; ++i)
1529 {
1530 if (col_idx_a[i] != col_idx_b[i])
1531 {
1532 return false;
1533 }
1534 }
1535
1536 return true;
1537 }
1538
1545 {
1546 const Index txrows(this->num_rows());
1547 const Index txcolumns(this->num_cols());
1548 const Index txnonzeros(this->num_nzes());
1549
1550 if(txnonzeros <= Index(0))
1551 return SparseMatrixCSR(txcolumns, txrows);
1552
1553 SparseMatrixCSR<DT_, IT_> trans_mat(txcolumns, txrows, txnonzeros);
1554
1555 {
1556 const Memory::TypedView<IT_> ptxcol_idx(this->col_idx_view_r());
1557 const Memory::TypedView<IT_> ptxrow_ptr(this->row_ptr_view_r());
1558 const Memory::TypedView<DT_> ptxval(this->val_view_r());
1559
1560 Memory::TypedView<IT_> ptrow_ptr(trans_mat.row_ptr_view_w());
1561 Memory::TypedView<IT_> ptcol_idx(trans_mat.col_idx_view_w());
1562 Memory::TypedView<DT_> ptval(trans_mat.val_view_w());
1563
1564 for (Index i(0); i <= txcolumns; ++i)
1565 {
1566 ptrow_ptr[i] = IT_(0);
1567 }
1568
1569 for (Index i(0); i < txnonzeros; ++i)
1570 {
1571 ++ptrow_ptr[ptxcol_idx[i] + 1];
1572 }
1573
1574 for (Index i(1); i < txcolumns; ++i)
1575 {
1576 ptrow_ptr[i + 1] += ptrow_ptr[i];
1577 }
1578
1579 for (Index i(0); i < txrows; ++i)
1580 {
1581 for (IT_ k(ptxrow_ptr[i]); k < ptxrow_ptr[i+1]; ++k)
1582 {
1583 const IT_ l(ptxcol_idx[k]);
1584 const IT_ j(ptrow_ptr[l]);
1585 ptval[j] = ptxval[k];
1586 ptcol_idx[j] = IT_(i);
1587 ++ptrow_ptr[l];
1588 }
1589 }
1590
1591 for (Index i(txcolumns); i > 0; --i)
1592 {
1593 ptrow_ptr[i] = ptrow_ptr[i - 1];
1594 }
1595 ptrow_ptr[0] = 0;
1596 }
1597
1598 return trans_mat;
1599 }
1600
1607 {
1608 this->move(x.transpose());
1609 }
1610
1618 {
1619 XASSERTM(x.num_rows() == this->num_rows(), "Row count does not match!");
1620 XASSERTM(x.num_cols() == this->num_cols(), "Column count does not match!");
1621 XASSERTM(x.num_nzes() == this->num_nzes(), "Nonzero count does not match!");
1622 XASSERTM(s.size() == this->num_rows(), "Vector size does not match!");
1623
1624 if(this->empty())
1625 return;
1626
1627 TimeStamp ts_start;
1628
1629 Arch::ScaleRowCSR::template exec<DT_, IT_>(this->val_arbiter(), x.val_arbiter(), this->col_idx_arbiter(),
1630 this->row_ptr_arbiter(), s.elements_arbiter(), this->num_rows(), this->num_cols(), this->num_nzes());
1631
1632 TimeStamp ts_stop;
1633
1635 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
1636 }
1637
1645 {
1646 XASSERTM(x.num_rows() == this->num_rows(), "Row count does not match!");
1647 XASSERTM(x.num_cols() == this->num_cols(), "Column count does not match!");
1648 XASSERTM(x.num_nzes() == this->num_nzes(), "Nonzero count does not match!");
1649 XASSERTM(s.size() == this->num_cols(), "Vector size does not match!");
1650
1651 if(this->empty())
1652 return;
1653
1654 TimeStamp ts_start;
1655
1656 Arch::ScaleColCSR::template exec<DT_, IT_>(this->val_arbiter(), x.val_arbiter(), this->col_idx_arbiter(),
1657 this->row_ptr_arbiter(), s.elements_arbiter(), this->num_rows(), this->num_cols(), this->num_nzes());
1658
1659 TimeStamp ts_stop;
1660
1662 Statistics::add_time_axpy(ts_stop.elapsed(ts_start));
1663 }
1664
1674 {
1675 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
1676 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
1677
1678 if(this->empty())
1679 return;
1680 else if(this->hollow())
1681 {
1682 r.format();
1683 return;
1684 }
1685
1686 XASSERTM(r.elements_arbiter() != x.elements_arbiter(), "Vector x and r must not share the same memory!");
1687
1688 TimeStamp ts_start;
1689
1690 Arch::MatVecMultCSRDense::template exec<DT_, IT_>(this->_backend_workspaces, r.elements_arbiter(), DT_(1), x.elements_arbiter(), Memory::Arbiter(),
1691 this->val_arbiter(), this->col_idx_arbiter(), this->row_ptr_arbiter(),
1692 this->num_rows(), this->num_cols(), this->num_nzes(), false);
1693
1694 TimeStamp ts_stop;
1695
1696 Statistics::add_flops(this->num_nzes() * 2);
1697 Statistics::add_time_blas2(ts_stop.elapsed(ts_start));
1698 }
1699
1709 {
1710 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
1711 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
1712
1713 if(this->empty())
1714 return;
1715 else if(this->hollow())
1716 {
1717 r.format();
1718 return;
1719 }
1720
1721 XASSERTM(r.elements_arbiter() != x.elements_arbiter(), "Vector x and r must not share the same memory!");
1722
1723 TimeStamp ts_start;
1724
1725 Arch::MatVecMultCSRDense::template exec<DT_, IT_>(this->_backend_workspaces, r.elements_arbiter(), DT_(1), x.elements_arbiter(), Memory::Arbiter(),
1726 this->val_arbiter(), this->col_idx_arbiter(), this->row_ptr_arbiter(),
1727 this->num_rows(), this->num_cols(), this->num_nzes(), true);
1728
1729 TimeStamp ts_stop;
1730 Statistics::add_flops(this->num_nzes() * 2);
1731 Statistics::add_time_blas2(ts_stop.elapsed(ts_start));
1732 }
1733
1744 template<int block_size_>
1746 {
1747 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
1748 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
1749
1750 if(this->empty())
1751 return;
1752 else if(this->hollow())
1753 {
1754 r.format();
1755 return;
1756 }
1757
1758 XASSERTM(r.elements_arbiter() != x.elements_arbiter(), "Vector x and r must not share the same memory!");
1759
1760 TimeStamp ts_start;
1761
1762 Arch::MatVecMultCSRBlock::template exec<DT_, IT_, block_size_>(r.elements_arbiter(), DT_(1), x.elements_arbiter(),
1763 Memory::Arbiter(), this->val_arbiter(), this->col_idx_arbiter(), this->row_ptr_arbiter(),
1764 this->num_rows(), this->num_cols(), this->num_nzes(), false);
1765
1766 TimeStamp ts_stop;
1767
1768 Statistics::add_flops(this->num_nzes() * 2 * block_size_);
1769 Statistics::add_time_blas2(ts_stop.elapsed(ts_start));
1770 }
1771
1783 void apply(
1785 const DenseVector<DT_, IT_> & x,
1786 const DenseVector<DT_, IT_> & y,
1787 const DT_ alpha = DT_(1)) const
1788 {
1789 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
1790 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
1791 XASSERTM(y.size() == this->num_rows(), "Vector size of y does not match!");
1792
1793 if(this->empty())
1794 return;
1795 // we check alpha strictly for equality to 0, because testing if |alpha| < eps may
1796 // lead to false triggers if the matrix/vector contents are also < eps
1797 else if((this->hollow()) || (alpha == DT_(0)))
1798 {
1799 r.copy(y);
1800 return;
1801 }
1802
1803 XASSERTM(r.elements_arbiter() != x.elements_arbiter(), "Vector x and r must not share the same memory!");
1804
1805 TimeStamp ts_start;
1806
1807 Arch::MatVecMultCSRDense::template exec<DT_, IT_>(this->_backend_workspaces, r.elements_arbiter(), alpha, x.elements_arbiter(), y.elements_arbiter(),
1808 this->val_arbiter(), this->col_idx_arbiter(), this->row_ptr_arbiter(),
1809 this->num_rows(), this->num_cols(), this->num_nzes(), false);
1810
1811 TimeStamp ts_stop;
1812
1813 Statistics::add_flops( 2 * (this->num_nzes() + this->num_rows()) );
1814 Statistics::add_time_blas2(ts_stop.elapsed(ts_start));
1815 }
1816
1830 const DenseVector<DT_, IT_> & x,
1831 const DenseVector<DT_, IT_> & y,
1832 const DT_ alpha = DT_(1)) const
1833 {
1834 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
1835 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
1836 XASSERTM(y.size() == this->num_cols(), "Vector size of y does not match!");
1837
1838 if(this->empty())
1839 return;
1840 // we check alpha strictly for equality to 0, because testing if |alpha| < eps may
1841 // lead to false triggers if the matrix/vector contents are also < eps
1842 else if((this->hollow()) || (alpha == DT_(0)))
1843 {
1844 r.copy(y);
1845 return;
1846 }
1847
1848 XASSERTM(r.elements_arbiter() != x.elements_arbiter(), "Vector x and r must not share the same memory!");
1849
1850 TimeStamp ts_start;
1851
1852 Arch::MatVecMultCSRDense::template exec<DT_, IT_>(this->_backend_workspaces, r.elements_arbiter(), alpha, x.elements_arbiter(), y.elements_arbiter(),
1853 this->val_arbiter(), this->col_idx_arbiter(), this->row_ptr_arbiter(),
1854 this->num_rows(), this->num_cols(), this->num_nzes(), true);
1855
1856 TimeStamp ts_stop;
1857 Statistics::add_flops( 2 * (this->num_nzes() + this->num_rows()) );
1858 Statistics::add_time_blas2(ts_stop.elapsed(ts_start));
1859 }
1860
1874 template<int block_size_>
1875 void apply(
1879 const DT_ alpha = DT_(1)) const
1880 {
1881 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
1882 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
1883 XASSERTM(y.size() == this->num_rows(), "Vector size of y does not match!");
1884
1885 if(this->empty())
1886 return;
1887 // we check alpha strictly for equality to 0, because testing if |alpha| < eps may
1888 // lead to false triggers if the matrix/vector contents are also < eps
1889 else if((this->hollow()) || (alpha == DT_(0)))
1890 {
1891 r.copy(y);
1892 return;
1893 }
1894
1895 XASSERTM(r.elements_arbiter() != x.elements_arbiter(), "Vector x and r must not share the same memory!");
1896
1897 TimeStamp ts_start;
1898
1899 Arch::MatVecMultCSRBlock::template exec<DT_, IT_, block_size_>(r.elements_arbiter(),alpha, x.elements_arbiter(),
1900 y.elements_arbiter(), this->val_arbiter(), this->col_idx_arbiter(), this->row_ptr_arbiter(),
1901 this->num_rows(), this->num_cols(), this->num_nzes(), false);
1902
1903 TimeStamp ts_stop;
1904
1905 Statistics::add_flops( (this->num_nzes() + this->num_rows()) * 2 * block_size_);
1906 Statistics::add_time_blas2(ts_stop.elapsed(ts_start));
1907 }
1908
1945 const DT_ alpha = DT_(1),
1946 const bool allow_incomplete = false)
1947 {
1948 // validate matrix dimensions
1949 XASSERT(this->num_rows() == d.num_rows());
1950 XASSERT(d.num_cols() == a.num_rows());
1951 XASSERT(a.num_cols() == b.num_rows());
1952 XASSERT(b.num_cols() == this->num_cols());
1953
1954 // fetch matrix arrays:
1955 Memory::TypedView<DT_> data_x = this->val_view_rw();
1956 const Memory::TypedView<DT_> data_d = d.val_view_r();
1957 const Memory::TypedView<DT_> data_a = a.val_view_r();
1958 const Memory::TypedView<DT_> data_b = b.val_view_r();
1959 const Memory::TypedView<IT_> row_ptr_x = this->row_ptr_view_r();
1960 const Memory::TypedView<IT_> col_idx_x = this->col_idx_view_r();
1961 const Memory::TypedView<IT_> row_ptr_d = d.row_ptr_view_r();
1962 const Memory::TypedView<IT_> col_idx_d = d.col_idx_view_r();
1963 const Memory::TypedView<IT_> row_ptr_a = a.row_ptr_view_r();
1964 const Memory::TypedView<IT_> col_idx_a = a.col_idx_view_r();
1965 const Memory::TypedView<IT_> row_ptr_b = b.row_ptr_view_r();
1966 const Memory::TypedView<IT_> col_idx_b = b.col_idx_view_r();
1967
1968 // loop over all rows of D and X, resp.
1969 for(IT_ i(0); i < IT_(this->num_rows()); ++i)
1970 {
1971 // loop over all non-zeros D_ik in row i of D
1972 for(IT_ ik(row_ptr_d[i]); ik < row_ptr_d[i+1]; ++ik)
1973 {
1974 // get column index k
1975 const IT_ k = col_idx_d[ik];
1976
1977 // loop over all non-zeros A_kl in row k of A
1978 for(IT_ kl(row_ptr_a[k]); kl < row_ptr_a[k+1]; ++kl)
1979 {
1980 // get column index l
1981 const IT_ l = col_idx_a[kl];
1982
1983 // pre-compute factor (alpha * D_ik * A_kl)
1984 const DT_ omega = alpha * data_d[ik] * data_a[kl];
1985
1986 // loop over all non-zeros B_lj in row j of B and
1987 // loop over all non-zeros X_ij in row i of X and
1988 // perform a "sparse axpy" of B_l onto X_i, i.e.:
1989 // X_i. += (alpha * D_ik * A_kl) * B_l.
1990 IT_ ij = row_ptr_x[i];
1991 IT_ lj = row_ptr_b[l];
1992 while(lj < row_ptr_b[l+1])
1993 {
1994 if(ij >= row_ptr_x[i+1])
1995 {
1996 // we have reached the end of row X_i, but there is at least
1997 // one entry in row B_l left, so the pattern of X is incomplete
1998 // We let the caller decide whether this is a valid case or not:
1999 if(allow_incomplete)
2000 break; // continue with next row
2001 else
2002 XABORTM("Incomplete output matrix structure");
2003 }
2004 else if(col_idx_x[ij] == col_idx_b[lj])
2005 {
2006 // okay: B_lj contributes to X_ij
2007 data_x[ij] += omega * data_b[lj];
2008 ++ij;
2009 ++lj;
2010 }
2011 else if(col_idx_x[ij] < col_idx_b[lj])
2012 {
2013 // entry X_ij exists, but B_lj is missing:
2014 // this is a perfectly valid case, so continue with the next non-zero of X_i
2015 ++ij;
2016 }
2017 else //if(col_idx_x[ij] > col_idx_b[lj])
2018 {
2019 // If we come out here, then the sparsity pattern of X is incomplete:
2020 // B_lj is meant to be added onto X_ij, but the entry X_ij is missing
2021 // We let the caller decide whether this is a valid case or not:
2022 if(allow_incomplete)
2023 ++lj;
2024 else
2025 XABORTM("Incomplete output matrix structure");
2026 }
2027 }
2028 }
2029 }
2030 }
2031 }
2032
2072 const DT_ alpha = DT_(1),
2073 const bool allow_incomplete = false)
2074 {
2075 // validate matrix dimensions
2076 XASSERT(this->num_rows() == d.num_rows());
2077 XASSERT(d.num_cols() == a.size());
2078 XASSERT(a.size() == b.num_rows());
2079 XASSERT(b.num_cols() == this->num_cols());
2080
2081 // fetch matrix arrays:
2082 Memory::TypedView<DT_> data_x = this->val_view_rw();
2083 const Memory::TypedView<DT_> data_d = d.val_view_r();
2084 const Memory::TypedView<DT_> data_a = a.elements_view_r();
2085 const Memory::TypedView<DT_> data_b = b.val_view_r();
2086 const Memory::TypedView<IT_> row_ptr_x = this->row_ptr_view_r();
2087 const Memory::TypedView<IT_> col_idx_x = this->col_idx_view_r();
2088 const Memory::TypedView<IT_> row_ptr_d = d.row_ptr_view_r();
2089 const Memory::TypedView<IT_> col_idx_d = d.col_idx_view_r();
2090 const Memory::TypedView<IT_> row_ptr_b = b.row_ptr_view_r();
2091 const Memory::TypedView<IT_> col_idx_b = b.col_idx_view_r();
2092
2093 // loop over all rows of D and X, resp.
2094 for(IT_ i(0); i < IT_(this->num_rows()); ++i)
2095 {
2096 // loop over all non-zeros D_ik in row i of D
2097 for(IT_ ik(row_ptr_d[i]); ik < row_ptr_d[i+1]; ++ik)
2098 {
2099 // get column index k
2100 const IT_ k = col_idx_d[ik];
2101
2102 // pre-compute factor (alpha * D_ik * A_kk)
2103 const DT_ omega = alpha * data_d[ik] * data_a[k];
2104
2105 // loop over all non-zeros B_kj in row j of B and
2106 // loop over all non-zeros X_ij in row i of X and
2107 // perform a "sparse axpy" of B_l onto X_i, i.e.:
2108 // X_i. += (alpha * D_ik * A_kk) * B_k.
2109 IT_ ij = row_ptr_x[i];
2110 IT_ kj = row_ptr_b[k];
2111 while(kj < row_ptr_b[k+1])
2112 {
2113 if(ij >= row_ptr_x[i+1])
2114 {
2115 // we have reached the end of row X_i, but there is at least
2116 // one entry in row B_l left, so the pattern of X is incomplete
2117 // We let the caller decide whether this is a valid case or not:
2118 if(allow_incomplete)
2119 break; // continue with next row
2120 else
2121 XABORTM("Incomplete output matrix structure");
2122 }
2123 else if(col_idx_x[ij] == col_idx_b[kj])
2124 {
2125 // okay: B_kj contributes to X_ij
2126 data_x[ij] += omega * data_b[kj];
2127 ++ij;
2128 ++kj;
2129 }
2130 else if(col_idx_x[ij] < col_idx_b[kj])
2131 {
2132 // entry X_ij exists, but B_kj is missing:
2133 // this is a perfectly valid case, so continue with the next non-zero of X_i
2134 ++ij;
2135 }
2136 else //if(col_idx_x[ij] > col_idx_b[kj])
2137 {
2138 // If we come out here, then the sparsity pattern of X is incomplete:
2139 // B_kj is meant to be added onto X_ij, but the entry X_ij is missing
2140 // We let the caller decide whether this is a valid case or not:
2141 if(allow_incomplete)
2142 ++kj;
2143 else
2144 XABORTM("Incomplete output matrix structure");
2145 }
2146 }
2147 }
2148 }
2149 }
2150
2186 template<int bs_>
2191 const DT_ alpha = DT_(1),
2192 const bool allow_incomplete = false)
2193 {
2194 // validate matrix dimensions
2195 XASSERT(this->num_rows() == d.num_rows());
2196 XASSERT(d.num_cols() == a.size());
2197 XASSERT(a.size() == b.num_rows());
2198 XASSERT(b.num_cols() == this->num_cols());
2199
2200 // fetch matrix arrays:
2201 Memory::TypedView<DT_> data_x = this->val_view_rw();
2202 const Memory::TypedView<Tiny::Matrix<DT_, 1, bs_>> data_d = d.val_view_r();
2203 const Memory::TypedView<Tiny::Vector<DT_, bs_>> data_a = a.elements_view_r();
2204 const Memory::TypedView<Tiny::Matrix<DT_, bs_, 1>> data_b = b.val_view_r();
2205 const Memory::TypedView<IT_> row_ptr_x = this->row_ptr_view_r();
2206 const Memory::TypedView<IT_> col_idx_x = this->col_idx_view_r();
2207 const Memory::TypedView<IT_> row_ptr_d = d.row_ptr_view_r();
2208 const Memory::TypedView<IT_> col_idx_d = d.col_idx_view_r();
2209 const Memory::TypedView<IT_> row_ptr_b = b.row_ptr_view_r();
2210 const Memory::TypedView<IT_> col_idx_b = b.col_idx_view_r();
2211
2212 // loop over all rows of D and X, resp.
2213 for(IT_ i(0); i < IT_(this->num_rows()); ++i)
2214 {
2215 // loop over all non-zeros D_ik in row i of D
2216 for(IT_ ik(row_ptr_d[i]); ik < row_ptr_d[i+1]; ++ik)
2217 {
2218 // get column index k
2219 const IT_ k = col_idx_d[ik];
2220
2221 // pre-compute factor (alpha * D_ik * A_kk)
2223 for(int l = 0; l < bs_; ++l)
2224 omega[l] = alpha * data_d[ik](0,l) * data_a[k][l];
2225
2226 // loop over all non-zeros B_kj in row j of B and
2227 // loop over all non-zeros X_ij in row i of X and
2228 // perform a "sparse axpy" of B_l onto X_i, i.e.:
2229 // X_i. += (alpha * D_ik * A_kk) * B_k.
2230 IT_ ij = row_ptr_x[i];
2231 IT_ kj = row_ptr_b[k];
2232 while(kj < row_ptr_b[k+1])
2233 {
2234 if(ij >= row_ptr_x[i+1])
2235 {
2236 // we have reached the end of row X_i, but there is at least
2237 // one entry in row B_l left, so the pattern of X is incomplete
2238 // We let the caller decide whether this is a valid case or not:
2239 if(allow_incomplete)
2240 break; // continue with next row
2241 else
2242 XABORTM("Incomplete output matrix structure");
2243 }
2244 else if(col_idx_x[ij] == col_idx_b[kj])
2245 {
2246 // okay: B_kj contributes to X_ij
2247 for(int l = 0; l < bs_; ++l)
2248 data_x[ij] += omega[l] * data_b[kj](l,0);
2249 ++ij;
2250 ++kj;
2251 }
2252 else if(col_idx_x[ij] < col_idx_b[kj])
2253 {
2254 // entry X_ij exists, but B_kj is missing:
2255 // this is a perfectly valid case, so continue with the next non-zero of X_i
2256 ++ij;
2257 }
2258 else //if(col_idx_x[ij] > col_idx_b[kj])
2259 {
2260 // If we come out here, then the sparsity pattern of X is incomplete:
2261 // B_kj is meant to be added onto X_ij, but the entry X_ij is missing
2262 // We let the caller decide whether this is a valid case or not:
2263 if(allow_incomplete)
2264 ++kj;
2265 else
2266 XABORTM("Incomplete output matrix structure");
2267 }
2268 }
2269 }
2270 }
2271 }
2272
2307 const DT_ alpha = DT_(1),
2308 const bool allow_incomplete = false)
2309 {
2310 // validate matrix dimensions
2311 XASSERT(this->num_rows() == d.num_rows());
2312 XASSERT(d.num_cols() == b.num_rows());
2313 XASSERT(b.num_cols() == this->num_cols());
2314
2315 // fetch matrix arrays:
2316 Memory::TypedView<DT_> data_x = this->val_view_rw();
2317 const Memory::TypedView<DT_> data_d = d.val_view_r();
2318 const Memory::TypedView<DT_> data_b = b.val_view_r();
2319 const Memory::TypedView<IT_> row_ptr_x = this->row_ptr_view_r();
2320 const Memory::TypedView<IT_> col_idx_x = this->col_idx_view_r();
2321 const Memory::TypedView<IT_> row_ptr_d = d.row_ptr_view_r();
2322 const Memory::TypedView<IT_> col_idx_d = d.col_idx_view_r();
2323 const Memory::TypedView<IT_> row_ptr_b = b.row_ptr_view_r();
2324 const Memory::TypedView<IT_> col_idx_b = b.col_idx_view_r();
2325
2326 // loop over all rows of D and X, resp.
2327 for(IT_ i(0); i < IT_(this->num_rows()); ++i)
2328 {
2329 // loop over all non-zeros D_ik in row i of D
2330 for(IT_ ik(row_ptr_d[i]); ik < row_ptr_d[i+1]; ++ik)
2331 {
2332 // get column index k
2333 const IT_ k = col_idx_d[ik];
2334
2335 // pre-compute factor (alpha * D_ik)
2336 const DT_ omega = alpha * data_d[ik];
2337
2338 // loop over all non-zeros B_kj in row j of B and
2339 // loop over all non-zeros X_ij in row i of X and
2340 // perform a "sparse axpy" of B_l onto X_i, i.e.:
2341 // X_i. += (alpha * D_ik) * B_k.
2342 IT_ ij = row_ptr_x[i];
2343 IT_ kj = row_ptr_b[k];
2344 while(kj < row_ptr_b[k+1])
2345 {
2346 if(ij >= row_ptr_x[i+1])
2347 {
2348 // we have reached the end of row X_i, but there is at least
2349 // one entry in row B_l left, so the pattern of X is incomplete
2350 // We let the caller decide whether this is a valid case or not:
2351 if(allow_incomplete)
2352 break; // continue with next row
2353 else
2354 XABORTM("Incomplete output matrix structure");
2355 }
2356 else if(col_idx_x[ij] == col_idx_b[kj])
2357 {
2358 // okay: B_kj contributes to X_ij
2359 data_x[ij] += omega * data_b[kj];
2360 ++ij;
2361 ++kj;
2362 }
2363 else if(col_idx_x[ij] < col_idx_b[kj])
2364 {
2365 // entry X_ij exists, but B_kj is missing:
2366 // this is a perfectly valid case, so continue with the next non-zero of X_i
2367 ++ij;
2368 }
2369 else //if(col_idx_x[ij] > col_idx_b[kj])
2370 {
2371 // If we come out here, then the sparsity pattern of X is incomplete:
2372 // B_kj is meant to be added onto X_ij, but the entry X_ij is missing
2373 // We let the caller decide whether this is a valid case or not:
2374 if(allow_incomplete)
2375 ++kj;
2376 else
2377 XABORTM("Incomplete output matrix structure");
2378 }
2379 }
2380 }
2381 }
2382 }
2384
2386 void lump_rows(VectorTypeL& lump) const
2387 {
2388 XASSERTM(lump.size() == num_rows(), "lump vector size does not match matrix row count!");
2389 if(this->empty())
2390 return;
2391
2392 Arch::LumpingCSR::template exec<DT_, IT_>(lump.elements_arbiter(), this->val_arbiter(),
2393 this->col_idx_arbiter(), this->row_ptr_arbiter(), this->num_rows());
2394 }
2395
2406 {
2408 lump_rows(lump);
2409 return lump;
2410 }
2411
2418 void extract_diag(VectorTypeL & diag) const
2419 {
2420 if(this->empty())
2421 return;
2422
2423 Arch::DiagonalCSR::template exec<DT_, IT_>(diag.elements_arbiter(), this->val_arbiter(),
2424 this->col_idx_arbiter(), this->row_ptr_arbiter(), this->num_rows());
2425 }
2426
2433 {
2435 extract_diag(diag);
2436 return diag;
2437 }
2438
2440 void permute(const Adjacency::Permutation & perm_row, const Adjacency::Permutation & perm_col)
2441 {
2442 if (perm_row.size() == 0 && perm_col.size() == 0)
2443 return;
2444
2445 XASSERTM(perm_row.size() == this->num_rows(), "Container rows does not match permutation size");
2446 XASSERTM(perm_col.size() == this->num_cols(), "Container columns does not match permutation size");
2447
2448 // http://de.mathworks.com/help/matlab/math/sparse-matrix-operations.html#f6-13070
2449 IT_ * temp_row_ptr = new IT_[num_rows() + 1];
2450 IT_ * temp_col_idx = new IT_[num_nzes()];
2451 DT_ * temp_val = new DT_[num_nzes()];
2452
2453 Memory::TypedView<IT_> row_ptr = this->row_ptr_view_rw();
2454 Memory::TypedView<IT_> col_idx = this->col_idx_view_rw();
2455 Memory::TypedView<DT_> val = this->val_view_rw();
2456
2457 const Index * perm_pos = perm_row.get_perm_pos();
2458
2459 //permute rows from source to temp_*
2460 Index new_start(0);
2461 temp_row_ptr[0] = 0;
2462 for (Index row(0) ; row < this->num_rows() ; ++row)
2463 {
2464 Index row_size(row_ptr[perm_pos[row] + 1] - row_ptr[perm_pos[row]]);
2465
2466 //iterate over all elements in single one new and old row
2467 for (Index i(new_start), j(row_ptr[perm_pos[row]]) ; i < new_start + row_size ; ++i, ++j)
2468 {
2469 temp_col_idx[i] = col_idx[j];
2470 temp_val[i] = val[j];
2471 }
2472
2473 new_start += row_size;
2474 temp_row_ptr[row+1] = (IT_)new_start;
2475 }
2476
2477 //use inverse col permutation as lookup table: i -> new location of i
2478 Adjacency::Permutation perm_col_inv = perm_col.inverse();
2479 perm_pos = perm_col_inv.get_perm_pos();
2480
2481 //permute columns from temp_* to result
2482 Memory::memcopy_main(row_ptr.get_w(), temp_row_ptr, (num_rows() + 1) * sizeof(IT_));
2483 Memory::memcopy_main(val.get_w(), temp_val, num_nzes() * sizeof(DT_));
2484 for (Index i(0) ; i < num_nzes() ; ++i)
2485 {
2486 col_idx[i] = (IT_)perm_pos[temp_col_idx[i]];
2487 }
2488
2489 delete[] temp_row_ptr;
2490 delete[] temp_col_idx;
2491 delete[] temp_val;
2492
2493 //sort columns in every row by column index
2494 IT_ swap_key;
2495 DT_ swap_val;
2496 for (Index row(0) ; row < num_rows() ; ++row)
2497 {
2498 Index offset(row_ptr[row]);
2499 Index row_size(row_ptr[row+1] - row_ptr[row]);
2500 for (Index i(1), j ; i < row_size ; ++i)
2501 {
2502 swap_key = col_idx[i + offset];
2503 swap_val = val[i + offset];
2504 j = i;
2505 while (j > 0 && col_idx[j - 1 + offset] > swap_key)
2506 {
2507 col_idx[j + offset] = col_idx[j - 1 + offset];
2508 val[j + offset] = val[j - 1 + offset];
2509 --j;
2510 }
2511 col_idx[j + offset] = swap_key;
2512 val[j + offset] = swap_val;
2513 }
2514 }
2515 }
2516
2518
2525 void shrink(DT_ eps)
2526 {
2527 const Memory::TypedView<IT_> row_ptr = this->row_ptr_view_r();
2528 const Memory::TypedView<IT_> col_idx = this->col_idx_view_r();
2529 const Memory::TypedView<DT_> val = this->val_view_r();
2530
2531 std::vector<IT_> row_entries(this->num_rows(), IT_(0));
2532 for (Index row(0) ; row < this->num_rows() ; ++row)
2533 {
2534 for (Index el(row_ptr[row]) ; el < row_ptr[row + 1] ; ++el)
2535 {
2536 if (Math::abs(val[el]) >= eps)
2537 {
2538 row_entries.at(row) += IT_(1);
2539 }
2540 }
2541 }
2542
2543 Index ue(0);
2544 for (auto& n : row_entries)
2545 {
2546 ue += n;
2547 }
2548 if (ue == Index(0))
2549 {
2550 this->move(SparseMatrixCSR<DT_, IT_>(this->num_rows(), this->num_cols()));
2551 return;
2552 }
2553
2554 DenseVector<IT_, IT_> new_row_ptr(this->num_rows() + 1);
2555 {
2556 Memory::TypedView<IT_> nrp = new_row_ptr.elements_view_w();
2557 nrp[0] = IT_(0);
2558 for (Index row(0) ; row < this->num_rows() ; ++row)
2559 {
2560 //new_row_ptr(row + 1, new_row_ptr(row) + row_entries.at(row));
2561 nrp[row + 1] = nrp[row] + row_entries.at(row);
2562 }
2563 }
2564
2565 row_entries.clear();
2566
2567 DenseVector<IT_, IT_> new_col_idx(ue);
2568 DenseVector<DT_, IT_> new_val(ue);
2569 Index counter(0);
2570 {
2571 Memory::TypedView<IT_> nci = new_col_idx.elements_view_w();
2572 Memory::TypedView<DT_> nval = new_val.elements_view_w();
2573 for (Index row(0) ; row < this->num_rows() ; ++row)
2574 {
2575 for (Index el(row_ptr[row]) ; el < row_ptr[row + 1] ; ++el)
2576 {
2577 if (Math::abs(val[el]) >= eps)
2578 {
2579 nci[counter] = col_idx[el];
2580 nval[counter] = val[el];
2581 ++counter;
2582 }
2583 }
2584 }
2585 }
2586
2587 // release views
2588 row_ptr.release();
2589 col_idx.release();
2590 val.release();
2591
2592 this->move(SparseMatrixCSR<DT_, IT_>(this->num_rows(), this->num_cols(), new_row_ptr, new_col_idx, new_val));
2593 }
2594
2597 {
2598 return VectorTypeL(this->num_rows());
2599 }
2600
2602 VectorTypeR create_vector_r() const
2603 {
2604 return VectorTypeR(this->num_cols());
2605 }
2606
2608 Index row_degree(const Index row) const
2609 {
2610 const Memory::TypedView<IT_> prow_ptr(this->row_ptr_view_r());
2611 return Index(prow_ptr[row + 1] - prow_ptr[row]);
2612 }
2613
2628 template<typename IT2_>
2629 Index get_row_col_indices(const Index row, IT2_ * const pcol_idx, const IT2_ col_offset) const
2630 {
2631 const Memory::TypedView<IT_> trow_ptr(this->row_ptr_view_r());
2632 const Memory::TypedView<IT_> tcol_idx(this->col_idx_view_r());
2633
2634 const Index start = Index(trow_ptr[row]);
2635 const Index end = Index(trow_ptr[row + 1] - trow_ptr[row]);
2636 for (Index i(0); i < end; ++i)
2637 {
2638 pcol_idx[i] = IT2_(tcol_idx[start + i]) + col_offset;
2639 }
2640 return end;
2641 }
2642
2654 template<typename DT2_>
2655 Index get_row_values(const Index row, DT2_ * const pvals) const
2656 {
2657 const Memory::TypedView<IT_> prow_ptr(this->row_ptr_view_r());
2658 const Memory::TypedView<DT_> pval(this->val_view_r());
2659
2660 const Index start = Index(prow_ptr[row]);
2661 const Index end = Index(prow_ptr[row + 1] - prow_ptr[row]);
2662 for (Index i(0); i < end; ++i)
2663 {
2664 pvals[i] = DT2_(pval[start + i]);
2665 }
2666 return end;
2667 }
2668
2680 template<typename DT2_>
2681 Index set_row_values(const Index row, const DT2_ * const pvals)
2682 {
2683 const Memory::TypedView<IT_> prow_ptr(this->row_ptr_view_r());
2684 Memory::TypedView<DT_> pval(this->val_view_rw());
2685
2686 const Index start = Index(prow_ptr[row]);
2687 const Index end = Index(prow_ptr[row + 1] - prow_ptr[row]);
2688 for (Index i(0); i < end; ++i)
2689 {
2690 pval[start + i] = DT_(pvals[i]);
2691 }
2692 return end;
2693 }
2694
2705 void print(std::ostream & os, bool print_dense) const
2706 {
2707 if(this->empty())
2708 {
2709 os << "[]";
2710 return;
2711 }
2712
2713 const Memory::TypedView<IT_> row_ptr = this->row_ptr_view_r();
2714 const Memory::TypedView<IT_> col_idx = this->col_idx_view_r();
2715 const Memory::TypedView<DT_> val = this->val_view_r();
2716 const Index nrows = this->num_rows();
2717 const Index ncols = this->num_cols();
2718
2719 os << "[\n";
2720 for (Index i(0) ; i < nrows ; ++i)
2721 {
2722 os << "[";
2723 IT_ k = 0;
2724 for(IT_ j = row_ptr[i]; j < row_ptr[i+1]; ++j)
2725 {
2726 // write leading zeros
2727 if(print_dense)
2728 {
2729 for(; k < col_idx[j]; ++k)
2730 os << " " << DT_(0);
2731 }
2732 else
2733 {
2734 os << " " << col_idx[j] << ':';
2735 }
2736
2737 // write value
2738 os << " " << val[j];
2739 ++k;
2740 }
2741
2742 // write trailing zeros
2743 if(print_dense)
2744 {
2745 for(; k < ncols; ++k)
2746 os << " " << DT_(0);
2747 }
2748 os << "]\n";
2749 }
2750 os << "]";
2751 }
2752
2759 friend std::ostream & operator<< (std::ostream & os, const SparseMatrixCSR & b)
2760 {
2761 b.print(os, true);
2762 return os;
2763 }
2764
2765 public:
2772 {
2773 public:
2775 typedef const IT_* ImageIterator;
2776
2777 private:
2778 const SparseMatrixCSR& _matrix;
2779 const Memory::TypedView<IT_> _row_ptr;
2780 const Memory::TypedView<IT_> _col_idx;
2781
2782 public:
2783 explicit Adjactor(const SparseMatrixCSR& matrix) :
2784 _matrix(matrix),
2785 _row_ptr(matrix.row_ptr_view_r()),
2786 _col_idx(matrix.col_idx_view_r())
2787 {
2788 }
2789
2790 Adjactor(const Adjactor&) = delete;
2791 Adjactor& operator=(const Adjactor&) = delete;
2792
2795 {
2796 return _matrix.num_rows();
2797 }
2798
2801 {
2802 return _matrix.num_cols();
2803 }
2804
2806 inline ImageIterator image_begin(Index domain_node) const
2807 {
2808 XASSERTM(domain_node < _matrix.num_rows(), "Domain node index out of range");
2809 return &_col_idx.get_r()[_row_ptr[domain_node]];
2810 }
2811
2813 inline ImageIterator image_end(Index domain_node) const
2814 {
2815 XASSERTM(domain_node < _matrix.num_rows(), "Domain node index out of range");
2816 return &_col_idx.get_r()[_row_ptr[domain_node + 1u]];
2817 }
2818 }; // class Adjactor
2819
2826 {
2827 public:
2829 typedef DT_ DataType;
2830 typedef IT_ IndexType;
2831
2832 private:
2833#ifdef DEBUG
2834 static constexpr IT_ _deadcode = ~IT_(0);
2835#endif
2836 const Index _num_rows;
2837 const Index _num_cols;
2838 Memory::Arbiter _col_ptr_arbiter;
2839 const Memory::TypedView<IT_> _row_ptr_view;
2840 const Memory::TypedView<IT_> _col_idx_view;
2841 Memory::TypedView<IT_> _col_ptr_view;
2842 Memory::TypedView<DT_> _data_view;
2843
2844 public:
2845 explicit ScatterAxpy(MatrixType& matrix) :
2846 _num_rows(matrix.num_rows()),
2847 _num_cols(matrix.num_cols()),
2848 _col_ptr_arbiter(_num_cols * sizeof(IT_), Memory::Location::main, Memory::Init::format_to_one),
2849 _row_ptr_view(matrix.row_ptr_view_r()),
2850 _col_idx_view(matrix.col_idx_view_r()),
2851 _col_ptr_view(_col_ptr_arbiter.view(Memory::Location::main, Memory::Access::read_write)),
2853 {
2854 }
2855
2856 template<typename LocalMatrix_, typename RowMapping_, typename ColMapping_>
2857 void operator()(const LocalMatrix_& loc_mat, const RowMapping_& row_map,
2858 const ColMapping_& col_map, DT_ alpha = DT_(1))
2859 {
2860 // note that initially all bits of _col_ptr_arbiter are formatted to 1,
2861 // which corresponds to the '_deadcode' value, so we don't need to reformat it here
2862
2863 // loop over all local row entries
2864 for(int i(0); i < row_map.get_num_local_dofs(); ++i)
2865 {
2866 // fetch row index
2867 const Index ix = row_map.get_index(i);
2868
2869 // build column pointer for this row entry contribution
2870 for(IT_ k(_row_ptr_view(ix)); k < _row_ptr_view(ix + 1); ++k)
2871 {
2872 _col_ptr_view[_col_idx_view(k)] = k;
2873 }
2874
2875 // loop over all local column entries
2876 for(int j(0); j < col_map.get_num_local_dofs(); ++j)
2877 {
2878 // fetch column index
2879 const Index jx = col_map.get_index(j);
2880
2881 // ensure that the column pointer is valid for this index
2882 ASSERTM(_col_ptr_view[jx] != _deadcode, "invalid column index");
2883
2884 // incorporate data into global matrix
2885 _data_view[_col_ptr_view[jx]] += alpha * loc_mat[i][j];
2886
2887 // continue with next column entry
2888 }
2889
2890#ifdef DEBUG
2891 // reformat column-pointer array
2892 for(IT_ k(_row_ptr_view(ix)); k < _row_ptr_view(ix + 1); ++k)
2893 {
2894 _col_ptr_view[_col_idx_view(k)] = _deadcode;
2895 }
2896#endif
2897 // continue with next row entry
2898 }
2899 }
2900 }; // class ScatterAxpy
2901
2908 {
2909 public:
2911 typedef DT_ DataType;
2912 typedef IT_ IndexType;
2913
2914 private:
2915#ifdef DEBUG
2916 static constexpr IT_ _deadcode = ~IT_(0);
2917#endif
2918 const Index _num_rows;
2919 const Index _num_cols;
2920 Memory::Arbiter _col_ptr_arbiter;
2921 const Memory::TypedView<IT_> _row_ptr_view;
2922 const Memory::TypedView<IT_> _col_idx_view;
2923 Memory::TypedView<IT_> _col_ptr_view;
2924 const Memory::TypedView<DT_> _data_view;
2925
2926 public:
2927 explicit GatherAxpy(const MatrixType& matrix) :
2928 _num_rows(matrix.num_rows()),
2929 _num_cols(matrix.num_cols()),
2930 _col_ptr_arbiter(_num_cols * sizeof(IT_), Memory::Location::main, Memory::Init::format_to_one),
2931 _row_ptr_view(matrix.row_ptr_view_r()),
2932 _col_idx_view(matrix.col_idx_view_r()),
2933 _col_ptr_view(_col_ptr_arbiter.view(Memory::Location::main, Memory::Access::read_write)),
2934 _data_view(matrix.val_view_r())
2935 {
2936 }
2937
2938 template<typename LocalMatrix_, typename RowMapping_, typename ColMapping_>
2939 void operator()(LocalMatrix_& loc_mat, const RowMapping_& row_map, const ColMapping_& col_map, DT_ alpha = DT_(1))
2940 {
2941 // note that initially all bits of _col_ptr_arbiter are formatted to 1,
2942 // which corresponds to the '_deadcode' value, so we don't need to reformat it here
2943
2944 // loop over all local row entries
2945 for(int i(0); i < row_map.get_num_local_dofs(); ++i)
2946 {
2947 // fetch row index
2948 const Index ix = row_map.get_index(i);
2949
2950 // build column pointer for this row entry contribution
2951 for(IT_ k(_row_ptr_view(ix)); k < _row_ptr_view(ix + 1); ++k)
2952 {
2953 _col_ptr_view[_col_idx_view(k)] = k;
2954 }
2955
2956 // loop over all local column entries
2957 for(int j(0); j < col_map.get_num_local_dofs(); ++j)
2958 {
2959 // fetch column index
2960 const Index jx = col_map.get_index(j);
2961
2962 // ensure that the column pointer is valid for this index
2963 ASSERTM(_col_ptr_view[jx] != _deadcode, "invalid column index");
2964
2965 // update local matrix data
2966 loc_mat[i][j] += alpha * _data_view[_col_ptr_view[jx]];
2967
2968 // continue with next column entry
2969 }
2970
2971#ifdef DEBUG
2972 // reformat column-pointer array
2973 for(IT_ k(_row_ptr_view(ix)); k < _row_ptr_view(ix + 1); ++k)
2974 {
2975 _col_ptr_view[_col_idx_view(k)] = _deadcode;
2976 }
2977#endif
2978
2979 // continue with next row entry
2980 }
2981 }
2982 }; // class GatherAxpy
2983
2984 Adjactor adjactor() const
2985 {
2986 return Adjactor(*this);
2987 }
2988 }; // class SparseMatrixCSR<...>
2989
2990#ifdef FEAT_EICKT
2991 extern template class SparseMatrixCSR<float, std::uint32_t>;
2992 extern template class SparseMatrixCSR<double, std::uint32_t>;
2993 extern template class SparseMatrixCSR<float, std::uint64_t>;
2994 extern template class SparseMatrixCSR<double, std::uint64_t>;
2995#endif
2996 } // namespace LAFEM
2997} // namespace FEAT
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
Definition: assertion.hpp:230
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
FEAT Kernel base header.
Adjacency Graph implementation.
Definition: graph.hpp:34
Index * get_domain_ptr()
Returns the domain pointer array.
Definition: graph.hpp:359
Index * get_image_idx()
Returns the image node index array.
Definition: graph.hpp:374
Index get_num_indices() const
Returns the total number indices.
Definition: graph.hpp:390
Index size() const
returns the size of the permutation
Index * get_perm_pos()
returns the permute-position array
Permutation inverse() const
Computes the inverse permutation.
Container base class.
Definition: container.hpp:224
std::array< std::shared_ptr< void >, to_underlying(BackendIdx::num_backends)> _backend_workspaces
List of backend workspaces.
Definition: container.hpp:243
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 > _indices
List of pointers to all IT_ dependent arrays.
Definition: container.hpp:232
virtual void clear()
Free all allocated arrays.
Definition: container.hpp:885
std::vector< Index > _indices_size
List of corresponding IT_ array sizes.
Definition: container.hpp:236
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
Blocked Dense data vector class template.
void copy(const DenseVectorBlocked &x, bool full=false)
Performs .
Index size() const
Returns the size of this vector, i.e. its number of entries.
Memory::Arbiter & elements_arbiter()
Returns a reference to the element array arbiter.
Dense data vector class template.
Memory::Arbiter & elements_arbiter()
Returns a reference to the element array arbiter.
void copy(const VT_ &a)
Performs .
Index size() const
Returns the size of this vector, i.e. its number of entries.
Config class for serialize parameter.
Definition: container.hpp:50
Layout scheme for sparse matrix containers.
const std::vector< Memory::Arbiter > & get_indices() const
Returns a list of all Index arrays.
CSR based blocked sparse matrix.
Index num_rows() const
Retrieve matrix row count.
Index num_rows_raw() const
Returns the scalar matrix row count.
Index num_nzes_raw() const
Returns the scalar matrix nonzero element count.
Index num_cols() const
Retrieve matrix column count.
Index num_cols_raw() const
Returns the scalar matrix column count.
Index num_nzes() const
Retrieve non zero element count.
Index num_cols() const
Retrieve matrix column count.
Index num_rows() const
Retrieve matrix row count.
Adjactor Wrapper for SparseMatrixCSR.
ImageIterator image_begin(Index domain_node) const
ImageIterator image_end(Index domain_node) const
const IT_ * ImageIterator
ImageIterator typedef for Adjactor interface implementation.
Gather-Axpy operation for SparseMatrixCSR.
Scatter-Axpy operation for SparseMatrixCSR.
CSR based sparse matrix.
void row_norm2(VectorTypeL &row_norms) const
Computes the 2-norm for every row.
void copy_to(MT_ &target) const
Copies the values of this matrix into the target matrix.
void extract_diag(VectorTypeL &diag) const
extract main diagonal vector from matrix
void apply_transposed(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x) const
Calculate .
VectorTypeR create_vector_r() const
Returns a new compatible R-Vector.
const Memory::Arbiter & col_idx_arbiter() const
Returns a reference to the column-index array arbiter.
void add_double_mat_product(const LAFEM::SparseMatrixCSR< DT_, IT_ > &d, const LAFEM::DenseVector< DT_, IT_ > &a, const LAFEM::SparseMatrixCSR< DT_, IT_ > &b, const DT_ alpha=DT_(1), const bool allow_incomplete=false)
Adds a double-matrix product onto this matrix.
DT_ norm_frobenius() const
Calculates the Frobenius norm of this matrix.
SparseMatrixCSR & operator=(SparseMatrixCSR &&other)
Move operator.
void bandwidth_row(Index &bandw, Index &bandw_i) const
Retrieve maximum bandwidth among all rows.
void radius_row(Index &radius, Index &radius_i) const
Retrieve maximum bandwidth among all columns.
bool hollow() const
Checks whether the matrix has no non-zero entries, i.e. whether it is a null matrix.
void scale(const SparseMatrixCSR &x, const DT_ alpha)
Calculate .
DenseVector< DT_, IT_ > VectorTypeL
Compatible L-vector type.
void apply(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
void clone(const SparseMatrixCSR< DT2_, IT2_ > &other, CloneMode clone_mode=CloneMode::Weak)
Clone operation.
void copy(const SparseMatrixCSR &x, bool full=false)
Performs .
void read_from(FileMode mode, const String &filename)
Read in matrix from file.
SparseMatrixCSR transpose() const
Calculate .
Index get_row_values(const Index row, DT2_ *const pvals) const
Extracts the values for a given row.
DT_ ValueType
Value type, meaning the type of each 'block'.
SparseMatrixCSR(const Adjacency::Graph &graph)
Constructor.
void add_mat_mat_product(const LAFEM::SparseMatrixCSR< DT_, IT_ > &d, const LAFEM::SparseMatrixCSR< DT_, IT_ > &b, const DT_ alpha=DT_(1), const bool allow_incomplete=false)
Adds a matrix-matrix product onto this matrix.
DT_ max_element() const
Retrieve the maximum value of this matrix.
DT_ max_abs_element() const
Retrieve the absolute maximum value of this matrix.
void add_double_mat_product(const LAFEM::SparseMatrixCSR< DT_, IT_ > &d, const LAFEM::SparseMatrixCSR< DT_, IT_ > &a, const LAFEM::SparseMatrixCSR< DT_, IT_ > &b, const DT_ alpha=DT_(1), const bool allow_incomplete=false)
Adds a double-matrix product onto this matrix.
void permute(const Adjacency::Permutation &perm_row, const Adjacency::Permutation &perm_col)
Permute matrix rows and columns according to the given Permutations.
void convert(const SparseMatrixCSR< DT2_, IT2_ > &other)
Conversion method.
void axpy(const SparseMatrixCSR &x, const DT_ alpha=DT_(1))
Calculate .
SparseMatrixCSR(SparseMatrixCSR &&other)
Move Constructor.
VectorTypeL extract_diag() const
extract main diagonal vector from matrix
void row_norm2sqr(VectorTypeL &row_norms) const
Computes the square of the 2-norm for every row.
void lump_rows(VectorTypeL &lump) const
SparseMatrixCSR(std::vector< char > input)
Constructor.
DT_ max_rel_diff(const SparseMatrixCSR &x) const
Retrieve the maximum relative difference of this matrix and another one y.max_rel_diff(x) returns .
std::vector< char > serialize(const LAFEM::SerialConfig &config=SerialConfig()) const
Serialization of complete container entity.
static constexpr bool is_global
this is not a global container
SparseMatrixCSR(const Index rows_in, const Index columns_in, DenseVector< IT_, IT_ > &row_ptr_in, DenseVector< IT_, IT_ > &col_idx_in, DenseVector< DT_, IT_ > &val_in)
Constructor.
void convert(const MT_ &a)
Conversion method.
void apply(DenseVectorBlocked< DT_, IT_, block_size_ > &r, const DenseVectorBlocked< DT_, IT_, block_size_ > &x, const DenseVectorBlocked< DT_, IT_, block_size_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
SparseMatrixCSR(FileMode mode, std::istream &file)
Constructor.
void apply(DenseVectorBlocked< DT_, IT_, block_size_ > &r, const DenseVectorBlocked< DT_, IT_, block_size_ > &x) const
Calculate .
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.
void write_out(FileMode mode, const String &filename, bool symmetric=false) const
Write out matrix to file.
DT_ min_element() const
Retrieve the minimum value of this matrix.
SparseMatrixCSR(Index rows_in, Index columns_in)
Constructor.
const Memory::Arbiter & val_arbiter() const
Returns a reference to the values array arbiter.
VectorTypeL create_vector_l() const
Returns a new compatible L-Vector.
Index num_nzes_raw() const
Returns the scalar matrix nonzero element count.
bool empty() const
Checks whether the matrix is empty, i.e. whether it is a 0x0 matrix.
Index set_row_values(const Index row, const DT2_ *const pvals)
Overwrites the values for a given row.
DenseVector< DT_, IT_ > VectorTypeR
Compatible R-vector type.
void deserialize(std::vector< char > input)
Deserialization of complete container entity.
SparseMatrixCSR clone(CloneMode clone_mode=CloneMode::Weak) const
Clone operation.
SparseMatrixCSR(Index rows_in, Index columns_in, Index nonzeros_in)
Constructor.
void init_workspace() const
Inits persistent workspace.
Memory::Arbiter & col_idx_arbiter()
Returns a reference to the column-index array arbiter.
Index num_nzes() const
Retrieve non zero element count.
SparseLayout< IT_, layout_id > layout() const
Retrieve convenient sparse matrix layout object.
DT_ min_abs_element() const
Retrieve the absolute minimum value of this matrix.
void print(std::ostream &os, bool print_dense) const
Prints this sparse matrix in human-readable format into an output stream.
void convert(const SparseMatrixBCSR< DT2_, IT2_, block_height_, block_width_ > &other)
Conversion method.
void add_double_mat_product(const LAFEM::SparseMatrixBCSR< DT_, IT_, 1, bs_ > &d, const LAFEM::DenseVectorBlocked< DT_, IT_, bs_ > &a, const LAFEM::SparseMatrixBCSR< DT_, IT_, bs_, 1 > &b, const DT_ alpha=DT_(1), const bool allow_incomplete=false)
Adds a double-matrix product onto this matrix.
void scale_rows(const SparseMatrixCSR &x, const DenseVector< DT_, IT_ > &s)
Calculate .
VectorTypeL lump_rows() const
Returns the lumped rows vector.
static constexpr SparseLayoutId layout_id
Our used layout type.
Index num_cols_raw() const
Returns the scalar matrix column count.
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 read_from(FileMode mode, std::istream &file)
Read in matrix from stream.
void apply(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x) const
Calculate .
void copy(const MT_ &source)
Copies the values of the input matrix into this matrix.
Index get_row_col_indices(const Index row, IT2_ *const pcol_idx, const IT2_ col_offset) const
Extracts the column indices for a given row.
bool same_layout(const SparseMatrixCSR &x) const
Checks if the structural layout of this matrix matches that of another matrix. This excludes comparis...
SparseMatrixCSR(FileMode mode, const String &filename)
Constructor.
void shrink(DT_ eps)
Shrink matrix and drop small values.
void scale_cols(const SparseMatrixCSR &x, const DenseVector< DT_, IT_ > &s)
Calculate .
void write_out(FileMode mode, std::ostream &file, bool symmetric=false) const
Write out matrix to file.
static constexpr bool is_local
this is a local container
const Memory::Arbiter & row_ptr_arbiter() const
Returns a reference to the row-pointer array arbiter.
SparseMatrixCSR(const SparseLayout< IT_, layout_id > &layout_in)
Constructor.
Index num_rows_raw() const
Returns the scalar matrix row count.
void transpose(const SparseMatrixCSR &x)
Calculate .
friend std::ostream & operator<<(std::ostream &os, const SparseMatrixCSR &b)
SparseMatrixCSR streaming operator.
void convert(const Adjacency::Graph &graph)
Conversion method.
void convert(const SparseMatrixBanded< DT2_, IT2_ > &other)
Conversion method.
Index row_degree(const Index row) const
Returns the number of NNZ-elements of the selected row.
SparseMatrixCSR(const MT_ &other)
Constructor.
static String name()
Retrieve maximum radius among all column.
Memory::Arbiter & row_ptr_arbiter()
Returns a reference to the row-pointer array arbiter.
Memory arbiter class.
Arbiter attach(std::size_t offset=0u, std::size_t size=full_size) const
Creates a new arbiter that is attached to the same memory block as this arbiter.
View view(Location mem_loc, Access access)
Maps a raw view to a memory block.
Typed memory view class.
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.
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
Tiny Vector class template.
constexpr std::size_t file_out_stream_buffer_size
OutStreamBufferSize.
Definition: base.hpp:105
SparseLayoutId
Definition: base.hpp:63
@ symmetric
matrix with symmetric structure and values
T_ abs(T_ x)
Returns the absolute value.
Definition: math.hpp:275
T_ min(T_ a, T_ b)
Returns the minimum of two values.
Definition: math.hpp:123
T_ max(T_ a, T_ b)
Returns the maximum of two values.
Definition: math.hpp:137
void memcopy_main(void *dst, const void *src, std::size_t bytes)
Copies a region of a main memory block into another main memory block.
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.
@ format_to_one
allocate and format all bits to one
FEAT namespace.
Definition: adjactor.hpp:12
constexpr auto to_underlying(E e) noexcept
Cast enum to underlying type.
std::uint64_t Index
Index data type.