\doxysection{dim.\+hpp}
\hypertarget{dim_8hpp_source}{}\label{dim_8hpp_source}\index{ginkgo/core/base/dim.hpp@{ginkgo/core/base/dim.hpp}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{//\ SPDX-\/FileCopyrightText:\ 2017\ -\/\ 2024\ 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\_DIM\_HPP\_}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#define\ GKO\_PUBLIC\_CORE\_BASE\_DIM\_HPP\_}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ }
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#include\ <iostream>}}
\DoxyCodeLine{00010\ }
\DoxyCodeLine{00011\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/types.hpp>}}
\DoxyCodeLine{00012\ }
\DoxyCodeLine{00013\ }
\DoxyCodeLine{00014\ \textcolor{keyword}{namespace\ }\doxymbox{\hyperlink{namespacegko}{gko}}\ \{}
\DoxyCodeLine{00015\ }
\DoxyCodeLine{00016\ }
\DoxyCodeLine{00025\ \textcolor{keyword}{template}\ <\textcolor{keywordtype}{size\_t}ype\ Dimensionality,\ \textcolor{keyword}{typename}\ DimensionType\ =\ \textcolor{keywordtype}{size\_t}ype>}
\DoxyCodeLine{00026\ \textcolor{keyword}{struct\ }\doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim}}\ \{}
\DoxyCodeLine{00027\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ dimensionality\ =\ Dimensionality;}
\DoxyCodeLine{00028\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{struct\ }\doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim}}<dimensionality\ +\ 1>;}
\DoxyCodeLine{00029\ }
\DoxyCodeLine{00030\ \ \ \ \ \textcolor{keyword}{using\ }dimension\_type\ =\ DimensionType;}
\DoxyCodeLine{00031\ }
\DoxyCodeLine{00035\ \ \ \ \ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ \doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim}}()\ :\ \doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim}}\{dimension\_type\{\}\}\ \{\}}
\DoxyCodeLine{00036\ }
\DoxyCodeLine{00042\ \ \ \ \ \textcolor{keyword}{explicit}\ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ \doxymbox{\hyperlink{structgko_1_1dim_aaeb554ff56deeb0fabbe001c2c8521fe}{dim}}(\textcolor{keyword}{const}\ dimension\_type\&\ size)}
\DoxyCodeLine{00043\ \ \ \ \ \ \ \ \ :\ first\_\{size\},\ rest\_\{size\}}
\DoxyCodeLine{00044\ \ \ \ \ \{\}}
\DoxyCodeLine{00045\ }
\DoxyCodeLine{00059\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}...\ Rest,\ std::enable\_if\_t<\textcolor{keyword}{sizeof}...(Rest)\ ==}
\DoxyCodeLine{00060\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Dimensionality\ -\/\ 1>*\ =\ \textcolor{keyword}{nullptr}>}
\DoxyCodeLine{00061\ \ \ \ \ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ \doxymbox{\hyperlink{structgko_1_1dim_ad0e8a1b8a4cb9fc34ddcabea61f9149d}{dim}}(\textcolor{keyword}{const}\ dimension\_type\&\ first,}
\DoxyCodeLine{00062\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ Rest\&...\ rest)}
\DoxyCodeLine{00063\ \ \ \ \ \ \ \ \ :\ first\_\{first\},\ rest\_\{\textcolor{keyword}{static\_cast<}dimension\_type\textcolor{keyword}{>}(rest)...\}}
\DoxyCodeLine{00064\ \ \ \ \ \{\}}
\DoxyCodeLine{00065\ }
\DoxyCodeLine{00077\ \ \ \ \ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ \textcolor{keyword}{const}\ dimension\_type\&\ \doxymbox{\hyperlink{structgko_1_1dim_a8f62915634727b12aed8ebb6e3e62217}{operator[]}}(}
\DoxyCodeLine{00078\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\&\ dimension)\ \textcolor{keyword}{const}\ \textcolor{keyword}{noexcept}}
\DoxyCodeLine{00079\ \ \ \ \ \{}
\DoxyCodeLine{00080\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ GKO\_ASSERT(dimension\ <\ dimensionality),}
\DoxyCodeLine{00081\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ dimension\ ==\ 0\ ?\ first\_\ :\ rest\_[dimension\ -\/\ 1];}
\DoxyCodeLine{00082\ \ \ \ \ \}}
\DoxyCodeLine{00083\ }
\DoxyCodeLine{00087\ \ \ \ \ GKO\_ATTRIBUTES\ dimension\_type\&\ \doxymbox{\hyperlink{structgko_1_1dim_a9291ce5a513a65f1623822d584fef2e4}{operator[]}}(}
\DoxyCodeLine{00088\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\&\ dimension)\ \textcolor{keyword}{noexcept}}
\DoxyCodeLine{00089\ \ \ \ \ \{}
\DoxyCodeLine{00090\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ GKO\_ASSERT(dimension\ <\ dimensionality),}
\DoxyCodeLine{00091\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ dimension\ ==\ 0\ ?\ first\_\ :\ rest\_[dimension\ -\/\ 1];}
\DoxyCodeLine{00092\ \ \ \ \ \}}
\DoxyCodeLine{00093\ }
\DoxyCodeLine{00105\ \ \ \ \ \textcolor{keyword}{explicit}\ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ \textcolor{keyword}{operator}\ bool()\textcolor{keyword}{\ const}}
\DoxyCodeLine{00106\ \textcolor{keyword}{\ \ \ \ }\{}
\DoxyCodeLine{00107\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{bool}\textcolor{keyword}{>}(first\_)\ \&\&\ \textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{bool}\textcolor{keyword}{>}(rest\_);}
\DoxyCodeLine{00108\ \ \ \ \ \}}
\DoxyCodeLine{00109\ }
\DoxyCodeLine{00118\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ \textcolor{keywordtype}{bool}\ \doxymbox{\hyperlink{structgko_1_1dim_a5e2c1e99f1c12540aac8489127c5dfb6}{operator==}}(\textcolor{keyword}{const}\ \doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim}}\&\ x,\ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim}}\&\ y)}
\DoxyCodeLine{00119\ \ \ \ \ \{}
\DoxyCodeLine{00120\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ x.first\_\ ==\ y.first\_\ \&\&\ x.rest\_\ ==\ y.rest\_;}
\DoxyCodeLine{00121\ \ \ \ \ \}}
\DoxyCodeLine{00122\ }
\DoxyCodeLine{00131\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ \textcolor{keywordtype}{bool}\ \doxymbox{\hyperlink{structgko_1_1dim_a2fc2e8710193f9a9d911a230e63711a2}{operator!=}}(\textcolor{keyword}{const}\ \doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim}}\&\ x,\ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim}}\&\ y)}
\DoxyCodeLine{00132\ \ \ \ \ \{}
\DoxyCodeLine{00133\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ !(x\ ==\ y);}
\DoxyCodeLine{00134\ \ \ \ \ \}}
\DoxyCodeLine{00135\ }
\DoxyCodeLine{00144\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ \doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim}}\ \doxymbox{\hyperlink{structgko_1_1dim_a27d25e410396817b4ceafbae3d5df5c8}{operator*}}(\textcolor{keyword}{const}\ \doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim}}\&\ x,\ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim}}\&\ y)}
\DoxyCodeLine{00145\ \ \ \ \ \{}
\DoxyCodeLine{00146\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim}}(x.first\_\ *\ y.first\_,\ x.rest\_\ *\ y.rest\_);}
\DoxyCodeLine{00147\ \ \ \ \ \}}
\DoxyCodeLine{00148\ }
\DoxyCodeLine{00157\ \ \ \ \ \textcolor{keyword}{friend}\ std::ostream\&\ \doxymbox{\hyperlink{structgko_1_1dim_a6494433a0fd67659179d73029060bf17}{operator<<}}(std::ostream\&\ os,\ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim}}\&\ x)}
\DoxyCodeLine{00158\ \ \ \ \ \{}
\DoxyCodeLine{00159\ \ \ \ \ \ \ \ \ os\ <<\ \textcolor{stringliteral}{"{}("{}};}
\DoxyCodeLine{00160\ \ \ \ \ \ \ \ \ x.print\_to(os);}
\DoxyCodeLine{00161\ \ \ \ \ \ \ \ \ os\ <<\ \textcolor{stringliteral}{"{})"{}};}
\DoxyCodeLine{00162\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ os;}
\DoxyCodeLine{00163\ \ \ \ \ \}}
\DoxyCodeLine{00164\ }
\DoxyCodeLine{00165\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00166\ \ \ \ \ \textcolor{keywordtype}{void}\ \textcolor{keyword}{inline}\ print\_to(std::ostream\&\ os)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00167\ \textcolor{keyword}{\ \ \ \ }\{}
\DoxyCodeLine{00168\ \ \ \ \ \ \ \ \ os\ <<\ first\_\ <<\ \textcolor{stringliteral}{"{},\ "{}};}
\DoxyCodeLine{00169\ \ \ \ \ \ \ \ \ rest\_.print\_to(os);}
\DoxyCodeLine{00170\ \ \ \ \ \}}
\DoxyCodeLine{00171\ }
\DoxyCodeLine{00172\ }
\DoxyCodeLine{00173\ \ \ \ \ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ \doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim}}(\textcolor{keyword}{const}\ dimension\_type\ first,}
\DoxyCodeLine{00174\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim<dimensionality\ -\/\ 1>}}\ rest)}
\DoxyCodeLine{00175\ \ \ \ \ \ \ \ \ :\ first\_\{first\},\ rest\_\{rest\}}
\DoxyCodeLine{00176\ \ \ \ \ \{\}}
\DoxyCodeLine{00177\ }
\DoxyCodeLine{00178\ \ \ \ \ dimension\_type\ first\_;}
\DoxyCodeLine{00179\ \ \ \ \ \doxymbox{\hyperlink{structgko_1_1dim_a201dac73c419061a8a2dd2119c573a19}{dim}}<dimensionality\ -\/\ 1,\ dimension\_type>\ rest\_;}
\DoxyCodeLine{00180\ \};}
\DoxyCodeLine{00181\ }
\DoxyCodeLine{00182\ }
\DoxyCodeLine{00183\ \textcolor{comment}{//\ base\ case\ for\ dim\ recursive\ template}}
\DoxyCodeLine{00184\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ DimensionType>}
\DoxyCodeLine{00185\ \textcolor{keyword}{struct\ }dim<1u,\ DimensionType>\ \{}
\DoxyCodeLine{00186\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ dimensionality\ =\ 1u;}
\DoxyCodeLine{00187\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{struct\ }dim<2>;}
\DoxyCodeLine{00188\ }
\DoxyCodeLine{00189\ \ \ \ \ \textcolor{keyword}{using\ }dimension\_type\ =\ DimensionType;}
\DoxyCodeLine{00190\ }
\DoxyCodeLine{00191\ \ \ \ \ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ dim(\textcolor{keyword}{const}\ dimension\_type\&\ size\ =\ dimension\_type\{\})}
\DoxyCodeLine{00192\ \ \ \ \ \ \ \ \ :\ first\_\{size\}}
\DoxyCodeLine{00193\ \ \ \ \ \{\}}
\DoxyCodeLine{00194\ }
\DoxyCodeLine{00195\ \ \ \ \ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ \textcolor{keyword}{const}\ dimension\_type\&\ operator[](}
\DoxyCodeLine{00196\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\&\ dimension)\ \textcolor{keyword}{const}\ \textcolor{keyword}{noexcept}}
\DoxyCodeLine{00197\ \ \ \ \ \{}
\DoxyCodeLine{00198\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ GKO\_ASSERT(dimension\ ==\ 0),\ first\_;}
\DoxyCodeLine{00199\ \ \ \ \ \}}
\DoxyCodeLine{00200\ }
\DoxyCodeLine{00201\ \ \ \ \ GKO\_ATTRIBUTES\ dimension\_type\&\ operator[](\textcolor{keyword}{const}\ \doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\&\ dimension)}
\DoxyCodeLine{00202\ \ \ \ \ \{}
\DoxyCodeLine{00203\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ GKO\_ASSERT(dimension\ ==\ 0),\ first\_;}
\DoxyCodeLine{00204\ \ \ \ \ \}}
\DoxyCodeLine{00205\ }
\DoxyCodeLine{00206\ \ \ \ \ \textcolor{keyword}{explicit}\ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ \textcolor{keyword}{operator}\ bool()\textcolor{keyword}{\ const}}
\DoxyCodeLine{00207\ \textcolor{keyword}{\ \ \ \ }\{}
\DoxyCodeLine{00208\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{bool}\textcolor{keyword}{>}(first\_);}
\DoxyCodeLine{00209\ \ \ \ \ \}}
\DoxyCodeLine{00210\ }
\DoxyCodeLine{00211\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ \textcolor{keywordtype}{bool}\ operator==(\textcolor{keyword}{const}\ dim\&\ x,\ \textcolor{keyword}{const}\ dim\&\ y)}
\DoxyCodeLine{00212\ \ \ \ \ \{}
\DoxyCodeLine{00213\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ x.first\_\ ==\ y.first\_;}
\DoxyCodeLine{00214\ \ \ \ \ \}}
\DoxyCodeLine{00215\ }
\DoxyCodeLine{00216\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ \textcolor{keywordtype}{bool}\ operator!=(\textcolor{keyword}{const}\ dim\&\ x,\ \textcolor{keyword}{const}\ dim\&\ y)}
\DoxyCodeLine{00217\ \ \ \ \ \{}
\DoxyCodeLine{00218\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ !(x\ ==\ y);}
\DoxyCodeLine{00219\ \ \ \ \ \}}
\DoxyCodeLine{00220\ }
\DoxyCodeLine{00221\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ dim\ operator*(\textcolor{keyword}{const}\ dim\&\ x,\ \textcolor{keyword}{const}\ dim\&\ y)}
\DoxyCodeLine{00222\ \ \ \ \ \{}
\DoxyCodeLine{00223\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ dim(x.first\_\ *\ y.first\_);}
\DoxyCodeLine{00224\ \ \ \ \ \}}
\DoxyCodeLine{00225\ }
\DoxyCodeLine{00226\ \ \ \ \ \textcolor{keyword}{friend}\ std::ostream\&\ operator<<(std::ostream\&\ os,\ \textcolor{keyword}{const}\ dim\&\ x)}
\DoxyCodeLine{00227\ \ \ \ \ \{}
\DoxyCodeLine{00228\ \ \ \ \ \ \ \ \ os\ <<\ \textcolor{stringliteral}{"{}("{}};}
\DoxyCodeLine{00229\ \ \ \ \ \ \ \ \ x.print\_to(os);}
\DoxyCodeLine{00230\ \ \ \ \ \ \ \ \ os\ <<\ \textcolor{stringliteral}{"{})"{}};}
\DoxyCodeLine{00231\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ os;}
\DoxyCodeLine{00232\ \ \ \ \ \}}
\DoxyCodeLine{00233\ }
\DoxyCodeLine{00234\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00235\ \ \ \ \ \textcolor{keywordtype}{void}\ \textcolor{keyword}{inline}\ print\_to(std::ostream\&\ os)\textcolor{keyword}{\ const\ }\{\ os\ <<\ first\_;\ \}}
\DoxyCodeLine{00236\ }
\DoxyCodeLine{00237\ \ \ \ \ dimension\_type\ first\_;}
\DoxyCodeLine{00238\ \};}
\DoxyCodeLine{00239\ }
\DoxyCodeLine{00240\ }
\DoxyCodeLine{00250\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ DimensionType>}
\DoxyCodeLine{00251\ \textcolor{keyword}{constexpr}\ GKO\_ATTRIBUTES\ GKO\_INLINE\ \doxymbox{\hyperlink{structgko_1_1dim}{dim<2,\ DimensionType>}}\ \doxymbox{\hyperlink{namespacegko_aacad7f87b38d3f26674ed034d442a1a0}{transpose}}(}
\DoxyCodeLine{00252\ \ \ \ \ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{structgko_1_1dim}{dim<2,\ DimensionType>}}\&\ dimensions)\ \textcolor{keyword}{noexcept}}
\DoxyCodeLine{00253\ \{}
\DoxyCodeLine{00254\ \ \ \ \ \textcolor{keywordflow}{return}\ \{dimensions[1],\ dimensions[0]\};}
\DoxyCodeLine{00255\ \}}
\DoxyCodeLine{00256\ }
\DoxyCodeLine{00257\ }
\DoxyCodeLine{00258\ \}\ \ \textcolor{comment}{//\ namespace\ gko}}
\DoxyCodeLine{00259\ }
\DoxyCodeLine{00260\ }
\DoxyCodeLine{00261\ \textcolor{preprocessor}{\#endif\ \ }\textcolor{comment}{//\ GKO\_PUBLIC\_CORE\_BASE\_DIM\_HPP\_}}

\end{DoxyCode}
