\doxysection{gko::\+Lin\+Op\+Factory Class Reference}
\hypertarget{classgko_1_1LinOpFactory}{}\label{classgko_1_1LinOpFactory}\index{gko::LinOpFactory@{gko::LinOpFactory}}


A \doxylink{classgko_1_1LinOpFactory}{Lin\+Op\+Factory} represents a higher order mapping which transforms one linear operator into another.  




{\ttfamily \+\#include $<$ginkgo/\+core/\+base/\+lin\+\_\+op.\+hpp$>$}



Inheritance diagram for gko::\+Lin\+Op\+Factory:\+
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classgko_1_1LinOpFactory__inherit__graph}
\end{center}
\end{figure}


Collaboration diagram for gko::\+Lin\+Op\+Factory:\+
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classgko_1_1LinOpFactory__coll__graph}
\end{center}
\end{figure}
\doxysubsubsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\Hypertarget{classgko_1_1LinOpFactory_aee9d77b2dedfee385d7de013a760a2e2}\label{classgko_1_1LinOpFactory_aee9d77b2dedfee385d7de013a760a2e2} 
std::\+unique\+\_\+ptr$<$ \doxymbox{\hyperlink{classgko_1_1LinOp}{Lin\+Op}} $>$ {\bfseries generate} (std::\+shared\+\_\+ptr$<$ const \doxymbox{\hyperlink{classgko_1_1LinOp}{Lin\+Op}} $>$ input) const
\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
A \doxylink{classgko_1_1LinOpFactory}{Lin\+Op\+Factory} represents a higher order mapping which transforms one linear operator into another. 

In Ginkgo, every linear solver is viewed as a mapping. For example, given an s.\+p.\+d linear system $Ax = b$, the solution $x = A^{-1}b$ can be computed using the CG method. This algorithm can be represented in terms of linear operators and mappings between them as follows:\+


\begin{DoxyItemize}
\item A Cg::\+\+Factory is a higher order mapping which, given an input operator $A$, returns a new linear operator $A^{-1}$ stored in "{}\+CG        format"{}
\item Storing the operator $A^{-1}$ in "{}\+CG format"{} means that the data structure used to store the operator is just a simple pointer to the original matrix $A$. The application $x = A^{-1}b$ of such an operator can then be implemented by solving the linear system $Ax = b$ using the CG method. This is achieved in code by having a special class for each of those "{}formats"{} (e.\+g. the "{}\+Cg"{} class defines such a format for the CG solver).
\end{DoxyItemize}

Another example of a \doxylink{classgko_1_1LinOpFactory}{Lin\+Op\+Factory} is a preconditioner. A preconditioner for a linear operator $A$ is a linear operator $M^{-1}$, which approximates $A^{-1}$. In addition, it is stored in a way such that both the data of $M^{-1}$ is cheap to compute from $A$, and the operation $x = M^{-1}b$ can be computed quickly. These operators are useful to accelerate the convergence of Krylov solvers. Thus, a preconditioner also fits into the \doxylink{classgko_1_1LinOpFactory}{Lin\+Op\+Factory} framework:\+


\begin{DoxyItemize}
\item The factory maps a linear operator $A$ into a preconditioner $M^{-1}$ which is stored in suitable format (e.\+g. as a product of two factors in case of ILU preconditioners).
\item The resulting linear operator implements the application operation $x = M^{-1}b$ depending on the format the preconditioner is stored in (e.\+g. as two triangular solves in case of ILU)
\end{DoxyItemize}\hypertarget{classgko_1_1LinOpFactory_autotoc_md74}{}\doxysubsubsection{\texorpdfstring{Example:\+ using CG in Ginkgo}{Example:\+ using CG in Ginkgo}}\label{classgko_1_1LinOpFactory_autotoc_md74}

\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{comment}{//\ Suppose\ A\ is\ a\ matrix,\ b\ a\ rhs\ vector,\ and\ x\ an\ initial\ guess}}
\DoxyCodeLine{\textcolor{comment}{//\ Create\ a\ CG\ which\ runs\ for\ at\ most\ 1000\ iterations,\ and\ stops\ after}}
\DoxyCodeLine{\textcolor{comment}{//\ reducing\ the\ residual\ norm\ by\ 6\ orders\ of\ magnitude}}
\DoxyCodeLine{\textcolor{keyword}{auto}\ cg\_factory\ =\ solver::Cg<>::build()}
\DoxyCodeLine{\ \ \ \ .with\_max\_iters(1000)}
\DoxyCodeLine{\ \ \ \ .with\_rel\_residual\_goal(1e-\/6)}
\DoxyCodeLine{\ \ \ \ .on(cuda);}
\DoxyCodeLine{\textcolor{comment}{//\ create\ a\ linear\ operator\ which\ represents\ the\ solver}}
\DoxyCodeLine{\textcolor{keyword}{auto}\ cg\ =\ cg\_factory-\/>generate(A);}
\DoxyCodeLine{\textcolor{comment}{//\ solve\ the\ system}}
\DoxyCodeLine{cg-\/>apply(b,\ x);}

\end{DoxyCode}
 

The documentation for this class was generated from the following file:\+\begin{DoxyCompactItemize}
\item 
ginkgo/\+core/\+base/\+lin\+\_\+op.\+hpp\end{DoxyCompactItemize}
