\doxysection{matrix\+\_\+assembly\+\_\+data.\+hpp}
\hypertarget{matrix__assembly__data_8hpp_source}{}\label{matrix__assembly__data_8hpp_source}\index{ginkgo/core/base/matrix\_assembly\_data.hpp@{ginkgo/core/base/matrix\_assembly\_data.hpp}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{//\ SPDX-\/FileCopyrightText:\ 2017\ -\/\ 2025\ The\ Ginkgo\ authors}}
\DoxyCodeLine{00002\ \textcolor{comment}{//}}
\DoxyCodeLine{00003\ \textcolor{comment}{//\ SPDX-\/License-\/Identifier:\ BSD-\/3-\/Clause}}
\DoxyCodeLine{00004\ }
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#ifndef\ GKO\_PUBLIC\_CORE\_BASE\_MATRIX\_ASSEMBLY\_DATA\_HPP\_}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#define\ GKO\_PUBLIC\_CORE\_BASE\_MATRIX\_ASSEMBLY\_DATA\_HPP\_}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ }
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#include\ <algorithm>}}
\DoxyCodeLine{00010\ \textcolor{preprocessor}{\#include\ <iterator>}}
\DoxyCodeLine{00011\ \textcolor{preprocessor}{\#include\ <numeric>}}
\DoxyCodeLine{00012\ \textcolor{preprocessor}{\#include\ <tuple>}}
\DoxyCodeLine{00013\ \textcolor{preprocessor}{\#include\ <unordered\_map>}}
\DoxyCodeLine{00014\ }
\DoxyCodeLine{00015\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/dim.hpp>}}
\DoxyCodeLine{00016\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/math.hpp>}}
\DoxyCodeLine{00017\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/matrix\_data.hpp>}}
\DoxyCodeLine{00018\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/types.hpp>}}
\DoxyCodeLine{00019\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/utils.hpp>}}
\DoxyCodeLine{00020\ }
\DoxyCodeLine{00021\ }
\DoxyCodeLine{00022\ \textcolor{keyword}{namespace\ }\doxymbox{\hyperlink{namespacegko}{gko}}\ \{}
\DoxyCodeLine{00023\ \textcolor{keyword}{namespace\ }detail\ \{}
\DoxyCodeLine{00024\ }
\DoxyCodeLine{00025\ }
\DoxyCodeLine{00026\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ IndexType>}
\DoxyCodeLine{00027\ \textcolor{keyword}{struct\ }symbolic\_nonzero\_hash\ \{}
\DoxyCodeLine{00028\ \ \ \ \ symbolic\_nonzero\_hash()\ =\ \textcolor{keywordflow}{default};}
\DoxyCodeLine{00029\ }
\DoxyCodeLine{00030\ \ \ \ \ \textcolor{keyword}{explicit}\ symbolic\_nonzero\_hash(\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ num\_cols)\ noexcept}
\DoxyCodeLine{00031\ \ \ \ \ \ \ \ \ :\ num\_cols\_\{num\_cols\}}
\DoxyCodeLine{00032\ \ \ \ \ \{\}}
\DoxyCodeLine{00033\ }
\DoxyCodeLine{00034\ \ \ \ \ std::size\_t\ operator()(std::pair<IndexType,\ IndexType>\ nnz)\ \textcolor{keyword}{const}\ \textcolor{keyword}{noexcept}}
\DoxyCodeLine{00035\ \ \ \ \ \{}
\DoxyCodeLine{00036\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{static\_cast<}std::size\_t\textcolor{keyword}{>}(nnz.first)\ *\ num\_cols\_\ +\ nnz.second;}
\DoxyCodeLine{00037\ \ \ \ \ \}}
\DoxyCodeLine{00038\ }
\DoxyCodeLine{00039\ \ \ \ \ \doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ num\_cols\_;}
\DoxyCodeLine{00040\ \};}
\DoxyCodeLine{00041\ }
\DoxyCodeLine{00042\ }
\DoxyCodeLine{00043\ \}\ \ \textcolor{comment}{//\ namespace\ detail}}
\DoxyCodeLine{00044\ }
\DoxyCodeLine{00045\ }
\DoxyCodeLine{00058\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType\ =\ default\_precision,\ \textcolor{keyword}{typename}\ IndexType\ =\ \textcolor{keywordtype}{int}32>}
\DoxyCodeLine{00059\ \textcolor{keyword}{class\ }matrix\_assembly\_data\ \{}
\DoxyCodeLine{00060\ \ \ \ \ GKO\_ASSERT\_SUPPORTED\_VALUE\_TYPE;}
\DoxyCodeLine{00061\ }
\DoxyCodeLine{00062\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00063\ \ \ \ \ \textcolor{keyword}{using\ }value\_type\ =\ ValueType;}
\DoxyCodeLine{00064\ \ \ \ \ \textcolor{keyword}{using\ }index\_type\ =\ IndexType;}
\DoxyCodeLine{00065\ }
\DoxyCodeLine{00066\ \ \ \ \ \textcolor{keyword}{explicit}\ matrix\_assembly\_data(\doxymbox{\hyperlink{structgko_1_1dim}{dim<2>}}\ size)}
\DoxyCodeLine{00067\ \ \ \ \ \ \ \ \ :\ size\_\{size\},}
\DoxyCodeLine{00068\ \ \ \ \ \ \ \ \ \ \ nonzeros\_(0,\ detail::symbolic\_nonzero\_hash<index\_type>(size\_[1]))}
\DoxyCodeLine{00069\ \ \ \ \ \{\}}
\DoxyCodeLine{00070\ }
\DoxyCodeLine{00080\ \ \ \ \ \textcolor{keywordtype}{void}\ \doxymbox{\hyperlink{classgko_1_1matrix__assembly__data_a0927a396f936167366bce13745156cf5}{add\_value}}(index\_type\ row,\ index\_type\ col,\ value\_type\ val)}
\DoxyCodeLine{00081\ \ \ \ \ \{}
\DoxyCodeLine{00082\ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ ind\ =\ std::make\_pair(row,\ col);}
\DoxyCodeLine{00083\ \ \ \ \ \ \ \ \ nonzeros\_[ind]\ +=\ val;}
\DoxyCodeLine{00084\ \ \ \ \ \}}
\DoxyCodeLine{00085\ }
\DoxyCodeLine{00094\ \ \ \ \ \textcolor{keywordtype}{void}\ \doxymbox{\hyperlink{classgko_1_1matrix__assembly__data_a2860092246c1184546610e903ac1b94b}{set\_value}}(index\_type\ row,\ index\_type\ col,\ value\_type\ val)}
\DoxyCodeLine{00095\ \ \ \ \ \{}
\DoxyCodeLine{00096\ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ ind\ =\ std::make\_pair(row,\ col);}
\DoxyCodeLine{00097\ \ \ \ \ \ \ \ \ nonzeros\_[ind]\ =\ val;}
\DoxyCodeLine{00098\ \ \ \ \ \}}
\DoxyCodeLine{00099\ }
\DoxyCodeLine{00107\ \ \ \ \ value\_type\ \doxymbox{\hyperlink{classgko_1_1matrix__assembly__data_a55c82c5c099a6a77c0dfb3930148f09c}{get\_value}}(index\_type\ row,\ index\_type\ col)}
\DoxyCodeLine{00108\ \ \ \ \ \{}
\DoxyCodeLine{00109\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ it\ =\ nonzeros\_.find(std::make\_pair(row,\ col));}
\DoxyCodeLine{00110\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (it\ ==\ nonzeros\_.end())\ \{}
\DoxyCodeLine{00111\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{namespacegko_a70dbe01ff95c7b953d3d737424c6feb5}{zero<value\_type>}}();}
\DoxyCodeLine{00112\ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00113\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ it-\/>second;}
\DoxyCodeLine{00114\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00115\ \ \ \ \ \}}
\DoxyCodeLine{00116\ }
\DoxyCodeLine{00124\ \ \ \ \ \textcolor{keywordtype}{bool}\ \doxymbox{\hyperlink{classgko_1_1matrix__assembly__data_a38a6b452ac3c028ed0c7f2eeac4616e8}{contains}}(index\_type\ row,\ index\_type\ col)}
\DoxyCodeLine{00125\ \ \ \ \ \{}
\DoxyCodeLine{00126\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ nonzeros\_.find(std::make\_pair(row,\ col))\ !=\ nonzeros\_.end();}
\DoxyCodeLine{00127\ \ \ \ \ \}}
\DoxyCodeLine{00128\ }
\DoxyCodeLine{00130\ \ \ \ \ \doxymbox{\hyperlink{structgko_1_1dim}{dim<2>}}\ \doxymbox{\hyperlink{classgko_1_1matrix__assembly__data_a740d347282ce8588ab21637a6728bd9f}{get\_size}}()\ const\ noexcept\ \{\ \textcolor{keywordflow}{return}\ size\_;\ \}}
\DoxyCodeLine{00131\ }
\DoxyCodeLine{00133\ \ \ \ \ \doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ \doxymbox{\hyperlink{classgko_1_1matrix__assembly__data_a300e1722d1853b50fb2c196a2457d0f2}{get\_num\_stored\_elements}}()\ const\ noexcept}
\DoxyCodeLine{00134\ \ \ \ \ \{}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ nonzeros\_.size();}
\DoxyCodeLine{00136\ \ \ \ \ \}}
\DoxyCodeLine{00137\ }
\DoxyCodeLine{00142\ \ \ \ \ \doxymbox{\hyperlink{structgko_1_1matrix__data}{matrix\_data<ValueType,\ IndexType>}}\ \doxymbox{\hyperlink{classgko_1_1matrix__assembly__data_a9a86018a5bd6475d8bd3c4ea229aee1d}{get\_ordered\_data}}()\textcolor{keyword}{\ const}}
\DoxyCodeLine{00143\ \textcolor{keyword}{\ \ \ \ }\{}
\DoxyCodeLine{00144\ \ \ \ \ \ \ \ \ \textcolor{keyword}{using\ }output\_type\ =\ \doxymbox{\hyperlink{structgko_1_1matrix__data}{matrix\_data<ValueType,\ IndexType>}};}
\DoxyCodeLine{00145\ \ \ \ \ \ \ \ \ \textcolor{keyword}{using\ }nonzero\_type\ =\ \textcolor{keyword}{typename}\ output\_type::nonzero\_type;}
\DoxyCodeLine{00146\ \ \ \ \ \ \ \ \ \textcolor{keyword}{using\ }entry\_type\ =}
\DoxyCodeLine{00147\ \ \ \ \ \ \ \ \ \ \ \ \ std::pair<std::pair<index\_type,\ index\_type>,\ value\_type>;}
\DoxyCodeLine{00148\ \ \ \ \ \ \ \ \ output\_type\ data\{size\_\};}
\DoxyCodeLine{00149\ \ \ \ \ \ \ \ \ data.\doxymbox{\hyperlink{structgko_1_1matrix__data_a4f6be92270fa96bccdc502c83d248dc0}{nonzeros}}.reserve(nonzeros\_.size());}
\DoxyCodeLine{00150\ \ \ \ \ \ \ \ \ std::transform(nonzeros\_.begin(),\ nonzeros\_.end(),}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::back\_inserter(data.nonzeros),\ [](entry\_type\ entry)\ \{}
\DoxyCodeLine{00152\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ return\ nonzero\_type\{entry.first.first,}
\DoxyCodeLine{00153\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ entry.first.second,}
\DoxyCodeLine{00154\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ entry.second\};}
\DoxyCodeLine{00155\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \});}
\DoxyCodeLine{00156\ \ \ \ \ \ \ \ \ data.sort\_row\_major();}
\DoxyCodeLine{00157\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ data;}
\DoxyCodeLine{00158\ \ \ \ \ \}}
\DoxyCodeLine{00159\ }
\DoxyCodeLine{00160\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00164\ \ \ \ \ dim<2>\ size\_;}
\DoxyCodeLine{00165\ }
\DoxyCodeLine{00173\ \ \ \ \ std::unordered\_map<std::pair<index\_type,\ index\_type>,\ value\_type,}
\DoxyCodeLine{00174\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ detail::symbolic\_nonzero\_hash<index\_type>>}
\DoxyCodeLine{00175\ \ \ \ \ \ \ \ \ nonzeros\_;}
\DoxyCodeLine{00176\ \};}
\DoxyCodeLine{00177\ }
\DoxyCodeLine{00178\ }
\DoxyCodeLine{00179\ \}\ \ \textcolor{comment}{//\ namespace\ gko}}
\DoxyCodeLine{00180\ }
\DoxyCodeLine{00181\ }
\DoxyCodeLine{00182\ \textcolor{preprocessor}{\#endif\ \ }\textcolor{comment}{//\ GKO\_PUBLIC\_CORE\_BASE\_MATRIX\_ASSEMBLY\_DATA\_HPP\_}}

\end{DoxyCode}
