\doxysection{composition.\+hpp}
\hypertarget{composition_8hpp_source}{}\label{composition_8hpp_source}\index{ginkgo/core/base/composition.hpp@{ginkgo/core/base/composition.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\_COMPOSITION\_HPP\_}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#define\ GKO\_PUBLIC\_CORE\_BASE\_COMPOSITION\_HPP\_}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ }
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#include\ <type\_traits>}}
\DoxyCodeLine{00010\ \textcolor{preprocessor}{\#include\ <vector>}}
\DoxyCodeLine{00011\ }
\DoxyCodeLine{00012\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/executor.hpp>}}
\DoxyCodeLine{00013\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/lin\_op.hpp>}}
\DoxyCodeLine{00014\ }
\DoxyCodeLine{00015\ }
\DoxyCodeLine{00016\ \textcolor{keyword}{namespace\ }\doxymbox{\hyperlink{namespacegko}{gko}}\ \{}
\DoxyCodeLine{00017\ }
\DoxyCodeLine{00018\ }
\DoxyCodeLine{00038\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType\ =\ default\_precision>}
\DoxyCodeLine{00039\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}}\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1EnableLinOp}{EnableLinOp}}<Composition<ValueType>>,}
\DoxyCodeLine{00040\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1EnableCreateMethod}{EnableCreateMethod}}<Composition<ValueType>>,}
\DoxyCodeLine{00041\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1Transposable}{Transposable}}\ \{}
\DoxyCodeLine{00042\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1EnablePolymorphicObject}{EnablePolymorphicObject}}<\doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}},\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}>;}
\DoxyCodeLine{00043\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1EnableCreateMethod}{EnableCreateMethod}}<\doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}}>;}
\DoxyCodeLine{00044\ \ \ \ \ GKO\_ASSERT\_SUPPORTED\_VALUE\_TYPE;}
\DoxyCodeLine{00045\ }
\DoxyCodeLine{00046\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00047\ \ \ \ \ \textcolor{keyword}{using\ }value\_type\ =\ ValueType;}
\DoxyCodeLine{00048\ \ \ \ \ \textcolor{keyword}{using\ }transposed\_type\ =\ \doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition<ValueType>}};}
\DoxyCodeLine{00049\ }
\DoxyCodeLine{00055\ \ \ \ \ \textcolor{keyword}{const}\ std::vector<std::shared\_ptr<const\ LinOp>>\&\ \doxymbox{\hyperlink{classgko_1_1Composition_aec22562876d3f5346ae78c96a436d525}{get\_operators}}()}
\DoxyCodeLine{00056\ \ \ \ \ \ \ \ \ const\ noexcept}
\DoxyCodeLine{00057\ \ \ \ \ \{}
\DoxyCodeLine{00058\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ operators\_;}
\DoxyCodeLine{00059\ \ \ \ \ \}}
\DoxyCodeLine{00060\ }
\DoxyCodeLine{00061\ \ \ \ \ std::unique\_ptr<LinOp>\ \doxymbox{\hyperlink{classgko_1_1Composition_a773045a3e20b724cdc0390c5c154f35c}{transpose}}()\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00062\ }
\DoxyCodeLine{00063\ \ \ \ \ std::unique\_ptr<LinOp>\ \doxymbox{\hyperlink{classgko_1_1Composition_ae9d4e8a318c21b265cdcd7ed33175e52}{conj\_transpose}}()\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00064\ }
\DoxyCodeLine{00069\ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}}\&\ \doxymbox{\hyperlink{classgko_1_1Composition_a23a085f270d9df7842c33ede65f3a693}{operator=}}(\textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}}\&);}
\DoxyCodeLine{00070\ }
\DoxyCodeLine{00077\ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}}\&\ \doxymbox{\hyperlink{classgko_1_1Composition_abfdf4c66506dba0b899974ed7687dc76}{operator=}}(\doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}}\&\&);}
\DoxyCodeLine{00078\ }
\DoxyCodeLine{00083\ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}}(\textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}}\&);}
\DoxyCodeLine{00084\ }
\DoxyCodeLine{00090\ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1Composition_a48b33990c9e3d5a060990b832e5d7787}{Composition}}(\doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}}\&\&);}
\DoxyCodeLine{00091\ }
\DoxyCodeLine{00092\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00093\ \ \ \ \ \textcolor{keywordtype}{void}\ add\_operators()\ \{\}}
\DoxyCodeLine{00094\ }
\DoxyCodeLine{00095\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}...\ Rest>}
\DoxyCodeLine{00096\ \ \ \ \ \textcolor{keywordtype}{void}\ add\_operators(std::shared\_ptr<const\ LinOp>\ oper,\ Rest\&\&...\ rest)}
\DoxyCodeLine{00097\ \ \ \ \ \{}
\DoxyCodeLine{00098\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!operators\_.empty())\ \{}
\DoxyCodeLine{00099\ \ \ \ \ \ \ \ \ \ \ \ \ GKO\_ASSERT\_CONFORMANT(\textcolor{keyword}{this},\ oper);}
\DoxyCodeLine{00100\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00101\ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ exec\ =\ this-\/>get\_executor();}
\DoxyCodeLine{00102\ \ \ \ \ \ \ \ \ operators\_.push\_back(std::move(oper));}
\DoxyCodeLine{00103\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (operators\_.back()-\/>get\_executor()\ !=\ exec)\ \{}
\DoxyCodeLine{00104\ \ \ \ \ \ \ \ \ \ \ \ \ operators\_.back()\ =\ \doxymbox{\hyperlink{namespacegko_aa194e34282452493231ca7b01ffb5e64}{gko::clone}}(exec,\ operators\_.back());}
\DoxyCodeLine{00105\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00106\ \ \ \ \ \ \ \ \ this-\/>set\_size(dim<2>\{operators\_.front()-\/>get\_size()[0],}
\DoxyCodeLine{00107\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ operators\_.back()-\/>get\_size()[1]\});}
\DoxyCodeLine{00108\ \ \ \ \ \ \ \ \ add\_operators(std::forward<Rest>(rest)...);}
\DoxyCodeLine{00109\ \ \ \ \ \}}
\DoxyCodeLine{00110\ }
\DoxyCodeLine{00116\ \ \ \ \ \textcolor{keyword}{explicit}\ \doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}}(std::shared\_ptr<const\ Executor>\ exec)}
\DoxyCodeLine{00117\ \ \ \ \ \ \ \ \ :\ EnableLinOp<\doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}}>(exec),\ storage\_\{exec\}}
\DoxyCodeLine{00118\ \ \ \ \ \{\}}
\DoxyCodeLine{00119\ }
\DoxyCodeLine{00129\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ Iterator,}
\DoxyCodeLine{00130\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ =\ std::void\_t<}
\DoxyCodeLine{00131\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ std::iterator\_traits<Iterator>::iterator\_category>>}
\DoxyCodeLine{00132\ \ \ \ \ \textcolor{keyword}{explicit}\ \doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}}(Iterator\ begin,\ Iterator\ end)}
\DoxyCodeLine{00133\ \ \ \ \ \ \ \ \ :\ EnableLinOp<\doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}}>([\&]\ \{}
\DoxyCodeLine{00134\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (begin\ ==\ end)\ \{}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{throw}\ OutOfBoundsError(\_\_FILE\_\_,\ \_\_LINE\_\_,\ 1,\ 0);}
\DoxyCodeLine{00136\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00137\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ (*begin)-\/>get\_executor();}
\DoxyCodeLine{00138\ \ \ \ \ \ \ \ \ \ \ \}()),}
\DoxyCodeLine{00139\ \ \ \ \ \ \ \ \ \ \ storage\_\{this-\/>get\_executor()\}}
\DoxyCodeLine{00140\ \ \ \ \ \{}
\DoxyCodeLine{00141\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ it\ =\ begin;\ it\ !=\ end;\ ++it)\ \{}
\DoxyCodeLine{00142\ \ \ \ \ \ \ \ \ \ \ \ \ add\_operators(*it);}
\DoxyCodeLine{00143\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00144\ \ \ \ \ \}}
\DoxyCodeLine{00145\ }
\DoxyCodeLine{00154\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}...\ Rest>}
\DoxyCodeLine{00155\ \ \ \ \ \textcolor{keyword}{explicit}\ \doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}}(std::shared\_ptr<const\ LinOp>\ oper,\ Rest\&\&...\ rest)}
\DoxyCodeLine{00156\ \ \ \ \ \ \ \ \ :\ \doxymbox{\hyperlink{classgko_1_1Composition_aad32bb5f4c1e90100eafa20be5c6f297}{Composition}}(oper-\/>get\_executor())}
\DoxyCodeLine{00157\ \ \ \ \ \{}
\DoxyCodeLine{00158\ \ \ \ \ \ \ \ \ add\_operators(std::move(oper),\ std::forward<Rest>(rest)...);}
\DoxyCodeLine{00159\ \ \ \ \ \}}
\DoxyCodeLine{00160\ }
\DoxyCodeLine{00161\ \ \ \ \ \textcolor{keywordtype}{void}\ apply\_impl(\textcolor{keyword}{const}\ LinOp*\ b,\ LinOp*\ x)\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00162\ }
\DoxyCodeLine{00163\ \ \ \ \ \textcolor{keywordtype}{void}\ apply\_impl(\textcolor{keyword}{const}\ LinOp*\ alpha,\ \textcolor{keyword}{const}\ LinOp*\ b,\ \textcolor{keyword}{const}\ LinOp*\ beta,}
\DoxyCodeLine{00164\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ LinOp*\ x)\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00165\ }
\DoxyCodeLine{00166\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00167\ \ \ \ \ std::vector<std::shared\_ptr<const\ LinOp>>\ operators\_;}
\DoxyCodeLine{00168\ \ \ \ \ \textcolor{keyword}{mutable}\ \doxymbox{\hyperlink{namespacegko_ae749a5ea11a93c1bcc9158d9a6e9fb68af1f713c9e000f5d3f280adbd124df4f5}{array<ValueType>}}\ storage\_;}
\DoxyCodeLine{00169\ \};}
\DoxyCodeLine{00170\ }
\DoxyCodeLine{00171\ }
\DoxyCodeLine{00178\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType\ =\ default\_precision>}
\DoxyCodeLine{00179\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1UseComposition}{UseComposition}}\ \{}
\DoxyCodeLine{00180\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00181\ \ \ \ \ \textcolor{keyword}{using\ }value\_type\ =\ ValueType;}
\DoxyCodeLine{00187\ \ \ \ \ std::shared\_ptr<Composition<ValueType>>\ \doxymbox{\hyperlink{classgko_1_1UseComposition_a81d7f1c982c43df853ed9b9074e45409}{get\_composition}}()\textcolor{keyword}{\ const}}
\DoxyCodeLine{00188\ \textcolor{keyword}{\ \ \ \ }\{}
\DoxyCodeLine{00189\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ composition\_;}
\DoxyCodeLine{00190\ \ \ \ \ \}}
\DoxyCodeLine{00191\ }
\DoxyCodeLine{00204\ \ \ \ \ std::shared\_ptr<const\ LinOp>\ \doxymbox{\hyperlink{classgko_1_1UseComposition_a46d5ea836edce6f0c0738d0218dd394b}{get\_operator\_at}}(\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ index)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00205\ \textcolor{keyword}{\ \ \ \ }\{}
\DoxyCodeLine{00206\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (composition\_\ ==\ \textcolor{keyword}{nullptr})\ \{}
\DoxyCodeLine{00207\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{nullptr};}
\DoxyCodeLine{00208\ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00209\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ composition\_-\/>get\_operators().at(index);}
\DoxyCodeLine{00210\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00211\ \ \ \ \ \}}
\DoxyCodeLine{00212\ }
\DoxyCodeLine{00213\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00217\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}...\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}>}
\DoxyCodeLine{00218\ \ \ \ \ \textcolor{keywordtype}{void}\ set\_composition(\doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}\&\&...\ linop)}
\DoxyCodeLine{00219\ \ \ \ \ \{}
\DoxyCodeLine{00220\ \ \ \ \ \ \ \ \ composition\_\ =}
\DoxyCodeLine{00221\ \ \ \ \ \ \ \ \ \ \ \ \ Composition<ValueType>::create(std::forward<LinOp>(linop)...);}
\DoxyCodeLine{00222\ \ \ \ \ \}}
\DoxyCodeLine{00223\ }
\DoxyCodeLine{00224\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00225\ \ \ \ \ std::shared\_ptr<Composition<ValueType>>\ composition\_;}
\DoxyCodeLine{00226\ \};}
\DoxyCodeLine{00227\ }
\DoxyCodeLine{00228\ }
\DoxyCodeLine{00229\ \}\ \ \textcolor{comment}{//\ namespace\ gko}}
\DoxyCodeLine{00230\ }
\DoxyCodeLine{00231\ }
\DoxyCodeLine{00232\ \textcolor{preprocessor}{\#endif\ \ }\textcolor{comment}{//\ GKO\_PUBLIC\_CORE\_BASE\_COMPOSITION\_HPP\_}}

\end{DoxyCode}
