\doxysection{perturbation.\+hpp}
\hypertarget{perturbation_8hpp_source}{}\label{perturbation_8hpp_source}\index{ginkgo/core/base/perturbation.hpp@{ginkgo/core/base/perturbation.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\_PERTURBATION\_HPP\_}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#define\ GKO\_PUBLIC\_CORE\_BASE\_PERTURBATION\_HPP\_}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ }
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#include\ <memory>}}
\DoxyCodeLine{00010\ }
\DoxyCodeLine{00011\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/lin\_op.hpp>}}
\DoxyCodeLine{00012\ \textcolor{preprocessor}{\#include\ <ginkgo/core/matrix/dense.hpp>}}
\DoxyCodeLine{00013\ }
\DoxyCodeLine{00014\ }
\DoxyCodeLine{00015\ \textcolor{keyword}{namespace\ }\doxymbox{\hyperlink{namespacegko}{gko}}\ \{}
\DoxyCodeLine{00016\ }
\DoxyCodeLine{00017\ }
\DoxyCodeLine{00037\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType\ =\ default\_precision>}
\DoxyCodeLine{00038\ \textcolor{keyword}{class\ }Perturbation\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1EnableLinOp}{EnableLinOp}}<Perturbation<ValueType>>,}
\DoxyCodeLine{00039\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1EnableCreateMethod}{EnableCreateMethod}}<Perturbation<ValueType>>\ \{}
\DoxyCodeLine{00040\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1EnablePolymorphicObject}{EnablePolymorphicObject}}<Perturbation,\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}>;}
\DoxyCodeLine{00041\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1EnableCreateMethod}{EnableCreateMethod}}<Perturbation>;}
\DoxyCodeLine{00042\ \ \ \ \ GKO\_ASSERT\_SUPPORTED\_VALUE\_TYPE;}
\DoxyCodeLine{00043\ }
\DoxyCodeLine{00044\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00045\ \ \ \ \ \textcolor{keyword}{using\ }value\_type\ =\ ValueType;}
\DoxyCodeLine{00046\ }
\DoxyCodeLine{00052\ \ \ \ \ \textcolor{keyword}{const}\ std::shared\_ptr<const\ LinOp>\ \doxymbox{\hyperlink{classgko_1_1Perturbation_a0de2213a0e5351749e090f3d2312ca02}{get\_basis}}()\ const\ noexcept}
\DoxyCodeLine{00053\ \ \ \ \ \{}
\DoxyCodeLine{00054\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ basis\_;}
\DoxyCodeLine{00055\ \ \ \ \ \}}
\DoxyCodeLine{00056\ }
\DoxyCodeLine{00062\ \ \ \ \ \textcolor{keyword}{const}\ std::shared\_ptr<const\ LinOp>\ \doxymbox{\hyperlink{classgko_1_1Perturbation_a217aee89800e8b2bc499b1b67d5345fc}{get\_projector}}()\ const\ noexcept}
\DoxyCodeLine{00063\ \ \ \ \ \{}
\DoxyCodeLine{00064\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ projector\_;}
\DoxyCodeLine{00065\ \ \ \ \ \}}
\DoxyCodeLine{00066\ }
\DoxyCodeLine{00072\ \ \ \ \ \textcolor{keyword}{const}\ std::shared\_ptr<const\ LinOp>\ \doxymbox{\hyperlink{classgko_1_1Perturbation_aa3a1a2c11ad2670e09384df7bce6eba5}{get\_scalar}}()\ const\ noexcept}
\DoxyCodeLine{00073\ \ \ \ \ \{}
\DoxyCodeLine{00074\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ scalar\_;}
\DoxyCodeLine{00075\ \ \ \ \ \}}
\DoxyCodeLine{00076\ }
\DoxyCodeLine{00077\ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1Perturbation}{Perturbation}}\&\ operator=(\textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1Perturbation}{Perturbation}}\&\ other);}
\DoxyCodeLine{00078\ }
\DoxyCodeLine{00079\ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1Perturbation}{Perturbation}}\&\ operator=(\doxymbox{\hyperlink{classgko_1_1Perturbation}{Perturbation}}\&\&\ other);}
\DoxyCodeLine{00080\ }
\DoxyCodeLine{00081\ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1Perturbation}{Perturbation}}(\textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1Perturbation}{Perturbation}}\&\ other);}
\DoxyCodeLine{00082\ }
\DoxyCodeLine{00083\ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1Perturbation}{Perturbation}}(\doxymbox{\hyperlink{classgko_1_1Perturbation}{Perturbation}}\&\&\ other);}
\DoxyCodeLine{00084\ }
\DoxyCodeLine{00092\ \ \ \ \ \textcolor{keyword}{static}\ std::unique\_ptr<Perturbation>\ \doxymbox{\hyperlink{classgko_1_1Perturbation_a5140f0e3f2bc5d265c802f902ca903bf}{create}}(}
\DoxyCodeLine{00093\ \ \ \ \ \ \ \ \ std::shared\_ptr<const\ Executor>\ exec);}
\DoxyCodeLine{00094\ }
\DoxyCodeLine{00105\ \ \ \ \ \textcolor{keyword}{static}\ std::unique\_ptr<Perturbation>\ \doxymbox{\hyperlink{classgko_1_1Perturbation_a9c67e8e64a92899b7f4f0037e51e0db0}{create}}(}
\DoxyCodeLine{00106\ \ \ \ \ \ \ \ \ std::shared\_ptr<const\ LinOp>\ scalar,}
\DoxyCodeLine{00107\ \ \ \ \ \ \ \ \ std::shared\_ptr<const\ LinOp>\ basis);}
\DoxyCodeLine{00108\ }
\DoxyCodeLine{00118\ \ \ \ \ \textcolor{keyword}{static}\ std::unique\_ptr<Perturbation>\ \doxymbox{\hyperlink{classgko_1_1Perturbation_aa760012b6390cfba0b7923090f70f91f}{create}}(}
\DoxyCodeLine{00119\ \ \ \ \ \ \ \ \ std::shared\_ptr<const\ LinOp>\ scalar,\ std::shared\_ptr<const\ LinOp>\ basis,}
\DoxyCodeLine{00120\ \ \ \ \ \ \ \ \ std::shared\_ptr<const\ LinOp>\ projector);}
\DoxyCodeLine{00121\ }
\DoxyCodeLine{00122\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00123\ \ \ \ \ \textcolor{keyword}{explicit}\ Perturbation(std::shared\_ptr<const\ Executor>\ exec);}
\DoxyCodeLine{00124\ }
\DoxyCodeLine{00125\ \ \ \ \ \textcolor{keyword}{explicit}\ Perturbation(std::shared\_ptr<const\ LinOp>\ scalar,}
\DoxyCodeLine{00126\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::shared\_ptr<const\ LinOp>\ basis);}
\DoxyCodeLine{00127\ }
\DoxyCodeLine{00128\ \ \ \ \ \textcolor{keyword}{explicit}\ Perturbation(std::shared\_ptr<const\ LinOp>\ scalar,}
\DoxyCodeLine{00129\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::shared\_ptr<const\ LinOp>\ basis,}
\DoxyCodeLine{00130\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::shared\_ptr<const\ LinOp>\ projector);}
\DoxyCodeLine{00131\ }
\DoxyCodeLine{00132\ \ \ \ \ \textcolor{keywordtype}{void}\ apply\_impl(\textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}*\ b,\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}*\ x)\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00133\ }
\DoxyCodeLine{00134\ \ \ \ \ \textcolor{keywordtype}{void}\ apply\_impl(\textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}*\ alpha,\ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}*\ b,\ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}*\ beta,}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}*\ x)\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00136\ }
\DoxyCodeLine{00142\ \ \ \ \ \textcolor{keywordtype}{void}\ validate\_perturbation();}
\DoxyCodeLine{00143\ }
\DoxyCodeLine{00144\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00145\ \ \ \ \ std::shared\_ptr<const\ LinOp>\ basis\_;}
\DoxyCodeLine{00146\ \ \ \ \ std::shared\_ptr<const\ LinOp>\ projector\_;}
\DoxyCodeLine{00147\ \ \ \ \ std::shared\_ptr<const\ LinOp>\ scalar\_;}
\DoxyCodeLine{00148\ }
\DoxyCodeLine{00149\ \ \ \ \ \textcolor{comment}{//\ TODO:\ solve\ race\ conditions\ when\ multithreading}}
\DoxyCodeLine{00150\ \ \ \ \ \textcolor{keyword}{mutable}\ \textcolor{keyword}{struct\ }cache\_struct\ \{}
\DoxyCodeLine{00151\ \ \ \ \ \ \ \ \ cache\_struct()\ =\ \textcolor{keywordflow}{default};}
\DoxyCodeLine{00152\ \ \ \ \ \ \ \ \ \string~cache\_struct()\ =\ \textcolor{keywordflow}{default};}
\DoxyCodeLine{00153\ \ \ \ \ \ \ \ \ cache\_struct(\textcolor{keyword}{const}\ cache\_struct\&\ other)\ \{\}}
\DoxyCodeLine{00154\ \ \ \ \ \ \ \ \ cache\_struct\&\ operator=(\textcolor{keyword}{const}\ cache\_struct\&\ other)\ \{\ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};\ \}}
\DoxyCodeLine{00155\ }
\DoxyCodeLine{00156\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ allocate\ linops\ of\ cache.\ The\ dimension\ of\ \`{}intermediate`\ is}}
\DoxyCodeLine{00157\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ (the\ number\ of\ rows\ of\ projector,\ the\ number\ of\ columns\ of\ b).\ Others}}
\DoxyCodeLine{00158\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ are\ 1x1\ scalar.}}
\DoxyCodeLine{00159\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ allocate(std::shared\_ptr<const\ Executor>\ exec,\ dim<2>\ size)}
\DoxyCodeLine{00160\ \ \ \ \ \ \ \ \ \{}
\DoxyCodeLine{00161\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{using\ }vec\ =\ \doxymbox{\hyperlink{classgko_1_1matrix_1_1Dense}{gko::matrix::Dense<ValueType>}};}
\DoxyCodeLine{00162\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (\doxymbox{\hyperlink{namespacegko_a0059e27f8f4bc348ff65c1e60caf47c8}{one}}\ ==\ \textcolor{keyword}{nullptr})\ \{}
\DoxyCodeLine{00163\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacegko_a0059e27f8f4bc348ff65c1e60caf47c8}{one}}\ =\ \doxymbox{\hyperlink{group__LinOp_ga70851b4c3c9b01bb667b3a8e438fb6d2}{initialize<vec>}}(\{\doxymbox{\hyperlink{namespacegko_a0059e27f8f4bc348ff65c1e60caf47c8}{gko::one<ValueType>}}()\},\ exec);}
\DoxyCodeLine{00164\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00165\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (alpha\_scalar\ ==\ \textcolor{keyword}{nullptr})\ \{}
\DoxyCodeLine{00166\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ alpha\_scalar\ =\ vec::create(exec,\ gko::dim<2>(1));}
\DoxyCodeLine{00167\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00168\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (intermediate\ ==\ \textcolor{keyword}{nullptr}\ ||\ intermediate-\/>get\_size()\ !=\ size)\ \{}
\DoxyCodeLine{00169\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ intermediate\ =\ vec::create(exec,\ size);}
\DoxyCodeLine{00170\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00171\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00172\ }
\DoxyCodeLine{00173\ \ \ \ \ \ \ \ \ std::unique\_ptr<LinOp>\ intermediate;}
\DoxyCodeLine{00174\ \ \ \ \ \ \ \ \ std::unique\_ptr<LinOp>\ one;}
\DoxyCodeLine{00175\ \ \ \ \ \ \ \ \ std::unique\_ptr<LinOp>\ alpha\_scalar;}
\DoxyCodeLine{00176\ \ \ \ \ \}\ cache\_;}
\DoxyCodeLine{00177\ \};}
\DoxyCodeLine{00178\ }
\DoxyCodeLine{00179\ }
\DoxyCodeLine{00180\ \}\ \ \textcolor{comment}{//\ namespace\ gko}}
\DoxyCodeLine{00181\ }
\DoxyCodeLine{00182\ }
\DoxyCodeLine{00183\ \textcolor{preprocessor}{\#endif\ \ }\textcolor{comment}{//\ GKO\_PUBLIC\_CORE\_BASE\_PERTURBATION\_HPP\_}}

\end{DoxyCode}
