\doxysection{combination.\+hpp}
\hypertarget{combination_8hpp_source}{}\label{combination_8hpp_source}\index{ginkgo/core/base/combination.hpp@{ginkgo/core/base/combination.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\_COMBINATION\_HPP\_}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#define\ GKO\_PUBLIC\_CORE\_BASE\_COMBINATION\_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/lin\_op.hpp>}}
\DoxyCodeLine{00013\ }
\DoxyCodeLine{00014\ }
\DoxyCodeLine{00015\ \textcolor{keyword}{namespace\ }\doxymbox{\hyperlink{namespacegko}{gko}}\ \{}
\DoxyCodeLine{00016\ }
\DoxyCodeLine{00017\ }
\DoxyCodeLine{00030\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType\ =\ default\_precision>}
\DoxyCodeLine{00031\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}}\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1EnableLinOp}{EnableLinOp}}<Combination<ValueType>>,}
\DoxyCodeLine{00032\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1EnableCreateMethod}{EnableCreateMethod}}<Combination<ValueType>>,}
\DoxyCodeLine{00033\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1Transposable}{Transposable}}\ \{}
\DoxyCodeLine{00034\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1EnablePolymorphicObject}{EnablePolymorphicObject}}<\doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}},\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}>;}
\DoxyCodeLine{00035\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1EnableCreateMethod}{EnableCreateMethod}}<\doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}}>;}
\DoxyCodeLine{00036\ \ \ \ \ GKO\_ASSERT\_SUPPORTED\_VALUE\_TYPE;}
\DoxyCodeLine{00037\ }
\DoxyCodeLine{00038\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00039\ \ \ \ \ \textcolor{keyword}{using\ }value\_type\ =\ ValueType;}
\DoxyCodeLine{00040\ \ \ \ \ \textcolor{keyword}{using\ }transposed\_type\ =\ \doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination<ValueType>}};}
\DoxyCodeLine{00041\ }
\DoxyCodeLine{00047\ \ \ \ \ \textcolor{keyword}{const}\ std::vector<std::shared\_ptr<const\ LinOp>>\&\ \doxymbox{\hyperlink{classgko_1_1Combination_a9963998e7d267e5cbd7145167648e622}{get\_coefficients}}()}
\DoxyCodeLine{00048\ \ \ \ \ \ \ \ \ const\ noexcept}
\DoxyCodeLine{00049\ \ \ \ \ \{}
\DoxyCodeLine{00050\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ coefficients\_;}
\DoxyCodeLine{00051\ \ \ \ \ \}}
\DoxyCodeLine{00052\ }
\DoxyCodeLine{00058\ \ \ \ \ \textcolor{keyword}{const}\ std::vector<std::shared\_ptr<const\ LinOp>>\&\ \doxymbox{\hyperlink{classgko_1_1Combination_a881ebdcec75430a078cb88130ab93740}{get\_operators}}()}
\DoxyCodeLine{00059\ \ \ \ \ \ \ \ \ const\ noexcept}
\DoxyCodeLine{00060\ \ \ \ \ \{}
\DoxyCodeLine{00061\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ operators\_;}
\DoxyCodeLine{00062\ \ \ \ \ \}}
\DoxyCodeLine{00063\ }
\DoxyCodeLine{00064\ \ \ \ \ std::unique\_ptr<LinOp>\ \doxymbox{\hyperlink{classgko_1_1Combination_a1f3a24989680d5d722d07d589af06253}{transpose}}()\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00065\ }
\DoxyCodeLine{00066\ \ \ \ \ std::unique\_ptr<LinOp>\ \doxymbox{\hyperlink{classgko_1_1Combination_a18bdd88bcfa68b5c9858749c50426629}{conj\_transpose}}()\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00067\ }
\DoxyCodeLine{00072\ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}}\&\ \doxymbox{\hyperlink{classgko_1_1Combination_a16855c320729f31c0a271decf65a6133}{operator=}}(\textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}}\&);}
\DoxyCodeLine{00073\ }
\DoxyCodeLine{00080\ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}}\&\ \doxymbox{\hyperlink{classgko_1_1Combination_a583194a7a0180a584b68b2e71f62e876}{operator=}}(\doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}}\&\&);}
\DoxyCodeLine{00081\ }
\DoxyCodeLine{00086\ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}}(\textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}}\&);}
\DoxyCodeLine{00087\ }
\DoxyCodeLine{00093\ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1Combination_a48d42f2a23c7fa6d55805edac9e29ce8}{Combination}}(\doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}}\&\&);}
\DoxyCodeLine{00094\ }
\DoxyCodeLine{00095\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00096\ \ \ \ \ \textcolor{keywordtype}{void}\ add\_operators()\ \{\}}
\DoxyCodeLine{00097\ }
\DoxyCodeLine{00098\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}...\ Rest>}
\DoxyCodeLine{00099\ \ \ \ \ \textcolor{keywordtype}{void}\ add\_operators(std::shared\_ptr<const\ LinOp>\ coef,}
\DoxyCodeLine{00100\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::shared\_ptr<const\ LinOp>\ oper,\ Rest\&\&...\ rest)}
\DoxyCodeLine{00101\ \ \ \ \ \{}
\DoxyCodeLine{00102\ \ \ \ \ \ \ \ \ GKO\_ASSERT\_EQUAL\_DIMENSIONS(coef,\ \doxymbox{\hyperlink{structgko_1_1dim}{dim<2>}}(1,\ 1));}
\DoxyCodeLine{00103\ \ \ \ \ \ \ \ \ GKO\_ASSERT\_EQUAL\_DIMENSIONS(oper,\ this-\/>get\_size());}
\DoxyCodeLine{00104\ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ exec\ =\ this-\/>get\_executor();}
\DoxyCodeLine{00105\ \ \ \ \ \ \ \ \ coefficients\_.push\_back(std::move(coef));}
\DoxyCodeLine{00106\ \ \ \ \ \ \ \ \ operators\_.push\_back(std::move(oper));}
\DoxyCodeLine{00107\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (coefficients\_.back()-\/>get\_executor()\ !=\ exec)\ \{}
\DoxyCodeLine{00108\ \ \ \ \ \ \ \ \ \ \ \ \ coefficients\_.back()\ =\ \doxymbox{\hyperlink{namespacegko_aa194e34282452493231ca7b01ffb5e64}{gko::clone}}(exec,\ coefficients\_.back());}
\DoxyCodeLine{00109\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00110\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (operators\_.back()-\/>get\_executor()\ !=\ exec)\ \{}
\DoxyCodeLine{00111\ \ \ \ \ \ \ \ \ \ \ \ \ operators\_.back()\ =\ \doxymbox{\hyperlink{namespacegko_aa194e34282452493231ca7b01ffb5e64}{gko::clone}}(exec,\ operators\_.back());}
\DoxyCodeLine{00112\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00113\ \ \ \ \ \ \ \ \ add\_operators(std::forward<Rest>(rest)...);}
\DoxyCodeLine{00114\ \ \ \ \ \}}
\DoxyCodeLine{00115\ }
\DoxyCodeLine{00121\ \ \ \ \ \textcolor{keyword}{explicit}\ \doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}}(std::shared\_ptr<const\ Executor>\ exec)}
\DoxyCodeLine{00122\ \ \ \ \ \ \ \ \ :\ EnableLinOp<\doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}}>(exec)}
\DoxyCodeLine{00123\ \ \ \ \ \{\}}
\DoxyCodeLine{00124\ }
\DoxyCodeLine{00139\ \ \ \ \ \textcolor{keyword}{template}\ <}
\DoxyCodeLine{00140\ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ CoefficientIterator,\ \textcolor{keyword}{typename}\ OperatorIterator,}
\DoxyCodeLine{00141\ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ =\ std::void\_t<}
\DoxyCodeLine{00142\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ std::iterator\_traits<}
\DoxyCodeLine{00143\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ CoefficientIterator>::iterator\_category,}
\DoxyCodeLine{00144\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ std::iterator\_traits<OperatorIterator>::iterator\_category>>}
\DoxyCodeLine{00145\ \ \ \ \ \textcolor{keyword}{explicit}\ \doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}}(CoefficientIterator\ coefficient\_begin,}
\DoxyCodeLine{00146\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ CoefficientIterator\ coefficient\_end,}
\DoxyCodeLine{00147\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ OperatorIterator\ operator\_begin,}
\DoxyCodeLine{00148\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ OperatorIterator\ operator\_end)}
\DoxyCodeLine{00149\ \ \ \ \ \ \ \ \ :\ EnableLinOp<\doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}}>([\&]\ \{}
\DoxyCodeLine{00150\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (operator\_begin\ ==\ operator\_end)\ \{}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{throw}\ OutOfBoundsError(\_\_FILE\_\_,\ \_\_LINE\_\_,\ 1,\ 0);}
\DoxyCodeLine{00152\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00153\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ (*operator\_begin)-\/>get\_executor();}
\DoxyCodeLine{00154\ \ \ \ \ \ \ \ \ \ \ \}())}
\DoxyCodeLine{00155\ \ \ \ \ \{}
\DoxyCodeLine{00156\ \ \ \ \ \ \ \ \ GKO\_ASSERT\_EQ(std::distance(coefficient\_begin,\ coefficient\_end),}
\DoxyCodeLine{00157\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::distance(operator\_begin,\ operator\_end));}
\DoxyCodeLine{00158\ \ \ \ \ \ \ \ \ this-\/>set\_size((*operator\_begin)-\/>get\_size());}
\DoxyCodeLine{00159\ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ coefficient\_it\ =\ coefficient\_begin;}
\DoxyCodeLine{00160\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ operator\_it\ =\ operator\_begin;\ operator\_it\ !=\ operator\_end;}
\DoxyCodeLine{00161\ \ \ \ \ \ \ \ \ \ \ \ \ \ ++operator\_it)\ \{}
\DoxyCodeLine{00162\ \ \ \ \ \ \ \ \ \ \ \ \ add\_operators(*coefficient\_it,\ *operator\_it);}
\DoxyCodeLine{00163\ \ \ \ \ \ \ \ \ \ \ \ \ ++coefficient\_it;}
\DoxyCodeLine{00164\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00165\ \ \ \ \ \}}
\DoxyCodeLine{00166\ }
\DoxyCodeLine{00177\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}...\ Rest>}
\DoxyCodeLine{00178\ \ \ \ \ \textcolor{keyword}{explicit}\ \doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}}(std::shared\_ptr<const\ LinOp>\ coef,}
\DoxyCodeLine{00179\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::shared\_ptr<const\ LinOp>\ oper,\ Rest\&\&...\ rest)}
\DoxyCodeLine{00180\ \ \ \ \ \ \ \ \ :\ \doxymbox{\hyperlink{classgko_1_1Combination_ab7e353cbd03d724b65e63262852ea960}{Combination}}(oper-\/>get\_executor())}
\DoxyCodeLine{00181\ \ \ \ \ \{}
\DoxyCodeLine{00182\ \ \ \ \ \ \ \ \ this-\/>set\_size(oper-\/>get\_size());}
\DoxyCodeLine{00183\ \ \ \ \ \ \ \ \ add\_operators(std::move(coef),\ std::move(oper),}
\DoxyCodeLine{00184\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::forward<Rest>(rest)...);}
\DoxyCodeLine{00185\ \ \ \ \ \}}
\DoxyCodeLine{00186\ }
\DoxyCodeLine{00187\ \ \ \ \ \textcolor{keywordtype}{void}\ apply\_impl(\textcolor{keyword}{const}\ LinOp*\ b,\ LinOp*\ x)\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00188\ }
\DoxyCodeLine{00189\ \ \ \ \ \textcolor{keywordtype}{void}\ apply\_impl(\textcolor{keyword}{const}\ LinOp*\ alpha,\ \textcolor{keyword}{const}\ LinOp*\ b,\ \textcolor{keyword}{const}\ LinOp*\ beta,}
\DoxyCodeLine{00190\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ LinOp*\ x)\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00191\ }
\DoxyCodeLine{00192\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00193\ \ \ \ \ std::vector<std::shared\_ptr<const\ LinOp>>\ coefficients\_;}
\DoxyCodeLine{00194\ \ \ \ \ std::vector<std::shared\_ptr<const\ LinOp>>\ operators\_;}
\DoxyCodeLine{00195\ }
\DoxyCodeLine{00196\ \ \ \ \ \textcolor{comment}{//\ TODO:\ solve\ race\ conditions\ when\ multithreading}}
\DoxyCodeLine{00197\ \ \ \ \ \textcolor{keyword}{mutable}\ \textcolor{keyword}{struct\ }cache\_struct\ \{}
\DoxyCodeLine{00198\ \ \ \ \ \ \ \ \ cache\_struct()\ =\ \textcolor{keywordflow}{default};}
\DoxyCodeLine{00199\ \ \ \ \ \ \ \ \ \string~cache\_struct()\ =\ \textcolor{keywordflow}{default};}
\DoxyCodeLine{00200\ \ \ \ \ \ \ \ \ cache\_struct(\textcolor{keyword}{const}\ cache\_struct\&\ other)\ \{\}}
\DoxyCodeLine{00201\ \ \ \ \ \ \ \ \ cache\_struct\&\ operator=(\textcolor{keyword}{const}\ cache\_struct\&\ other)\ \{\ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};\ \}}
\DoxyCodeLine{00202\ }
\DoxyCodeLine{00203\ \ \ \ \ \ \ \ \ std::unique\_ptr<LinOp>\ zero;}
\DoxyCodeLine{00204\ \ \ \ \ \ \ \ \ std::unique\_ptr<LinOp>\ one;}
\DoxyCodeLine{00205\ \ \ \ \ \ \ \ \ std::unique\_ptr<LinOp>\ intermediate\_x;}
\DoxyCodeLine{00206\ \ \ \ \ \}\ cache\_;}
\DoxyCodeLine{00207\ \};}
\DoxyCodeLine{00208\ }
\DoxyCodeLine{00209\ }
\DoxyCodeLine{00210\ \}\ \ \textcolor{comment}{//\ namespace\ gko}}
\DoxyCodeLine{00211\ }
\DoxyCodeLine{00212\ }
\DoxyCodeLine{00213\ \textcolor{preprocessor}{\#endif\ \ }\textcolor{comment}{//\ GKO\_PUBLIC\_CORE\_BASE\_COMBINATION\_HPP\_}}

\end{DoxyCode}
