\doxysection{mtx\+\_\+io.\+hpp}
\hypertarget{mtx__io_8hpp_source}{}\label{mtx__io_8hpp_source}\index{ginkgo/core/base/mtx\_io.hpp@{ginkgo/core/base/mtx\_io.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\_MTX\_IO\_HPP\_}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#define\ GKO\_PUBLIC\_CORE\_BASE\_MTX\_IO\_HPP\_}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ }
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#include\ <istream>}}
\DoxyCodeLine{00010\ }
\DoxyCodeLine{00011\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/matrix\_data.hpp>}}
\DoxyCodeLine{00012\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/utils\_helper.hpp>}}
\DoxyCodeLine{00013\ }
\DoxyCodeLine{00014\ }
\DoxyCodeLine{00015\ \textcolor{keyword}{namespace\ }\doxymbox{\hyperlink{namespacegko}{gko}}\ \{}
\DoxyCodeLine{00016\ }
\DoxyCodeLine{00017\ }
\DoxyCodeLine{00032\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType\ =\ default\_precision,\ \textcolor{keyword}{typename}\ IndexType\ =\ \textcolor{keywordtype}{int}32>}
\DoxyCodeLine{00033\ \doxymbox{\hyperlink{structgko_1_1matrix__data}{matrix\_data<ValueType,\ IndexType>}}\ \doxymbox{\hyperlink{namespacegko_afddd8179d8034cce9a2f7e02bae33fd7}{read\_raw}}(std::istream\&\ is);}
\DoxyCodeLine{00034\ }
\DoxyCodeLine{00035\ }
\DoxyCodeLine{00067\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType\ =\ default\_precision,\ \textcolor{keyword}{typename}\ IndexType\ =\ \textcolor{keywordtype}{int}32>}
\DoxyCodeLine{00068\ \doxymbox{\hyperlink{structgko_1_1matrix__data}{matrix\_data<ValueType,\ IndexType>}}\ \doxymbox{\hyperlink{namespacegko_a5e379ed0d74e7c7f8c33fbfe6816e697}{read\_binary\_raw}}(std::istream\&\ is);}
\DoxyCodeLine{00069\ }
\DoxyCodeLine{00070\ }
\DoxyCodeLine{00086\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType\ =\ default\_precision,\ \textcolor{keyword}{typename}\ IndexType\ =\ \textcolor{keywordtype}{int}32>}
\DoxyCodeLine{00087\ \doxymbox{\hyperlink{structgko_1_1matrix__data}{matrix\_data<ValueType,\ IndexType>}}\ \doxymbox{\hyperlink{namespacegko_a70492b519a55d1d62a3a11f6b297ecd9}{read\_generic\_raw}}(std::istream\&\ is);}
\DoxyCodeLine{00088\ }
\DoxyCodeLine{00089\ }
\DoxyCodeLine{00093\ \textcolor{keyword}{enum\ class}\ \doxymbox{\hyperlink{namespacegko_ae749a5ea11a93c1bcc9158d9a6e9fb68}{layout\_type}}\ \{}
\DoxyCodeLine{00097\ \ \ \ \ \doxymbox{\hyperlink{classgko_1_1array}{array}},}
\DoxyCodeLine{00101\ \ \ \ \ \doxymbox{\hyperlink{namespacegko_ae749a5ea11a93c1bcc9158d9a6e9fb68af5d7aa3ba4929cc12dc51a92c59fabd3}{coordinate}}}
\DoxyCodeLine{00102\ \};}
\DoxyCodeLine{00103\ }
\DoxyCodeLine{00104\ }
\DoxyCodeLine{00119\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType,\ \textcolor{keyword}{typename}\ IndexType>}
\DoxyCodeLine{00120\ \textcolor{keywordtype}{void}\ \doxymbox{\hyperlink{namespacegko_a2d4b63ce98a16dc2c48aacd534a7b8ba}{write\_raw}}(std::ostream\&\ os,\ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{structgko_1_1matrix__data}{matrix\_data<ValueType,\ IndexType>}}\&\ data,}
\DoxyCodeLine{00121\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacegko_ae749a5ea11a93c1bcc9158d9a6e9fb68}{layout\_type}}\ layout\ =\ \doxymbox{\hyperlink{namespacegko_ae749a5ea11a93c1bcc9158d9a6e9fb68af5d7aa3ba4929cc12dc51a92c59fabd3}{layout\_type::coordinate}});}
\DoxyCodeLine{00122\ }
\DoxyCodeLine{00123\ }
\DoxyCodeLine{00140\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType,\ \textcolor{keyword}{typename}\ IndexType>}
\DoxyCodeLine{00141\ \textcolor{keywordtype}{void}\ \doxymbox{\hyperlink{namespacegko_a3b27a0c0282115116c160884dc0a9468}{write\_binary\_raw}}(std::ostream\&\ os,}
\DoxyCodeLine{00142\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \doxymbox{\hyperlink{structgko_1_1matrix__data}{matrix\_data<ValueType,\ IndexType>}}\&\ data);}
\DoxyCodeLine{00143\ }
\DoxyCodeLine{00144\ }
\DoxyCodeLine{00159\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ MatrixType,\ \textcolor{keyword}{typename}\ StreamType,\ \textcolor{keyword}{typename}...\ MatrixArgs>}
\DoxyCodeLine{00160\ \textcolor{keyword}{inline}\ std::unique\_ptr<MatrixType>\ \doxymbox{\hyperlink{namespacegko_abc58509ecdcb48399e12f9a081ed7545}{read}}(StreamType\&\&\ is,\ MatrixArgs\&\&...\ args)}
\DoxyCodeLine{00161\ \{}
\DoxyCodeLine{00162\ \ \ \ \ \textcolor{keyword}{auto}\ mtx\ =\ MatrixType::create(std::forward<MatrixArgs>(args)...);}
\DoxyCodeLine{00163\ \ \ \ \ mtx-\/>read(\doxymbox{\hyperlink{namespacegko_afddd8179d8034cce9a2f7e02bae33fd7}{read\_raw}}<\textcolor{keyword}{typename}\ MatrixType::value\_type,}
\DoxyCodeLine{00164\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ MatrixType::index\_type>(is));}
\DoxyCodeLine{00165\ \ \ \ \ \textcolor{keywordflow}{return}\ mtx;}
\DoxyCodeLine{00166\ \}}
\DoxyCodeLine{00167\ }
\DoxyCodeLine{00168\ }
\DoxyCodeLine{00183\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ MatrixType,\ \textcolor{keyword}{typename}\ StreamType,\ \textcolor{keyword}{typename}...\ MatrixArgs>}
\DoxyCodeLine{00184\ \textcolor{keyword}{inline}\ std::unique\_ptr<MatrixType>\ \doxymbox{\hyperlink{namespacegko_a06b6aa3ec2d20b977d8730cc9cfdafd8}{read\_binary}}(StreamType\&\&\ is,}
\DoxyCodeLine{00185\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ MatrixArgs\&\&...\ args)}
\DoxyCodeLine{00186\ \{}
\DoxyCodeLine{00187\ \ \ \ \ \textcolor{keyword}{auto}\ mtx\ =\ MatrixType::create(std::forward<MatrixArgs>(args)...);}
\DoxyCodeLine{00188\ \ \ \ \ mtx-\/>read(\doxymbox{\hyperlink{namespacegko_a5e379ed0d74e7c7f8c33fbfe6816e697}{read\_binary\_raw}}<\textcolor{keyword}{typename}\ MatrixType::value\_type,}
\DoxyCodeLine{00189\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ MatrixType::index\_type>(is));}
\DoxyCodeLine{00190\ \ \ \ \ \textcolor{keywordflow}{return}\ mtx;}
\DoxyCodeLine{00191\ \}}
\DoxyCodeLine{00192\ }
\DoxyCodeLine{00193\ }
\DoxyCodeLine{00209\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ MatrixType,\ \textcolor{keyword}{typename}\ StreamType,\ \textcolor{keyword}{typename}...\ MatrixArgs>}
\DoxyCodeLine{00210\ \textcolor{keyword}{inline}\ std::unique\_ptr<MatrixType>\ \doxymbox{\hyperlink{namespacegko_a3c49cd22dbd4f0fa54597a950a145b63}{read\_generic}}(StreamType\&\&\ is,}
\DoxyCodeLine{00211\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ MatrixArgs\&\&...\ args)}
\DoxyCodeLine{00212\ \{}
\DoxyCodeLine{00213\ \ \ \ \ \textcolor{keyword}{auto}\ mtx\ =\ MatrixType::create(std::forward<MatrixArgs>(args)...);}
\DoxyCodeLine{00214\ \ \ \ \ mtx-\/>read(\doxymbox{\hyperlink{namespacegko_a70492b519a55d1d62a3a11f6b297ecd9}{read\_generic\_raw}}<\textcolor{keyword}{typename}\ MatrixType::value\_type,}
\DoxyCodeLine{00215\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ MatrixType::index\_type>(is));}
\DoxyCodeLine{00216\ \ \ \ \ \textcolor{keywordflow}{return}\ mtx;}
\DoxyCodeLine{00217\ \}}
\DoxyCodeLine{00218\ }
\DoxyCodeLine{00219\ }
\DoxyCodeLine{00220\ \textcolor{keyword}{namespace\ }matrix\ \{}
\DoxyCodeLine{00221\ }
\DoxyCodeLine{00222\ }
\DoxyCodeLine{00223\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType>}
\DoxyCodeLine{00224\ \textcolor{keyword}{class\ }Dense;}
\DoxyCodeLine{00225\ }
\DoxyCodeLine{00226\ }
\DoxyCodeLine{00227\ \textcolor{keyword}{class\ }Fft;}
\DoxyCodeLine{00228\ }
\DoxyCodeLine{00229\ }
\DoxyCodeLine{00230\ \textcolor{keyword}{class\ }Fft2;}
\DoxyCodeLine{00231\ }
\DoxyCodeLine{00232\ }
\DoxyCodeLine{00233\ \textcolor{keyword}{class\ }Fft3;}
\DoxyCodeLine{00234\ }
\DoxyCodeLine{00235\ }
\DoxyCodeLine{00236\ \}\ \ \textcolor{comment}{//\ namespace\ matrix}}
\DoxyCodeLine{00237\ }
\DoxyCodeLine{00238\ }
\DoxyCodeLine{00239\ \textcolor{keyword}{namespace\ }detail\ \{}
\DoxyCodeLine{00240\ }
\DoxyCodeLine{00241\ }
\DoxyCodeLine{00251\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ MatrixType>}
\DoxyCodeLine{00252\ \textcolor{keyword}{struct\ }mtx\_io\_traits\ \{}
\DoxyCodeLine{00253\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{auto}\ default\_layout\ =\ \doxymbox{\hyperlink{namespacegko_ae749a5ea11a93c1bcc9158d9a6e9fb68af5d7aa3ba4929cc12dc51a92c59fabd3}{layout\_type::coordinate}};}
\DoxyCodeLine{00254\ \};}
\DoxyCodeLine{00255\ }
\DoxyCodeLine{00256\ }
\DoxyCodeLine{00257\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ ValueType>}
\DoxyCodeLine{00258\ \textcolor{keyword}{struct\ }mtx\_io\_traits<gko::matrix::Dense<ValueType>>\ \{}
\DoxyCodeLine{00259\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{auto}\ default\_layout\ =\ \doxymbox{\hyperlink{namespacegko_ae749a5ea11a93c1bcc9158d9a6e9fb68af1f713c9e000f5d3f280adbd124df4f5}{layout\_type::array}};}
\DoxyCodeLine{00260\ \};}
\DoxyCodeLine{00261\ }
\DoxyCodeLine{00262\ }
\DoxyCodeLine{00263\ \textcolor{keyword}{template}\ <>}
\DoxyCodeLine{00264\ \textcolor{keyword}{struct\ }mtx\_io\_traits<gko::matrix::Fft>\ \{}
\DoxyCodeLine{00265\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{auto}\ default\_layout\ =\ \doxymbox{\hyperlink{namespacegko_ae749a5ea11a93c1bcc9158d9a6e9fb68af1f713c9e000f5d3f280adbd124df4f5}{layout\_type::array}};}
\DoxyCodeLine{00266\ \};}
\DoxyCodeLine{00267\ }
\DoxyCodeLine{00268\ }
\DoxyCodeLine{00269\ \textcolor{keyword}{template}\ <>}
\DoxyCodeLine{00270\ \textcolor{keyword}{struct\ }mtx\_io\_traits<gko::matrix::Fft2>\ \{}
\DoxyCodeLine{00271\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{auto}\ default\_layout\ =\ \doxymbox{\hyperlink{namespacegko_ae749a5ea11a93c1bcc9158d9a6e9fb68af1f713c9e000f5d3f280adbd124df4f5}{layout\_type::array}};}
\DoxyCodeLine{00272\ \};}
\DoxyCodeLine{00273\ }
\DoxyCodeLine{00274\ }
\DoxyCodeLine{00275\ \textcolor{keyword}{template}\ <>}
\DoxyCodeLine{00276\ \textcolor{keyword}{struct\ }mtx\_io\_traits<gko::matrix::Fft3>\ \{}
\DoxyCodeLine{00277\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{auto}\ default\_layout\ =\ \doxymbox{\hyperlink{namespacegko_ae749a5ea11a93c1bcc9158d9a6e9fb68af1f713c9e000f5d3f280adbd124df4f5}{layout\_type::array}};}
\DoxyCodeLine{00278\ \};}
\DoxyCodeLine{00279\ }
\DoxyCodeLine{00280\ }
\DoxyCodeLine{00281\ \}\ \ \textcolor{comment}{//\ namespace\ detail}}
\DoxyCodeLine{00282\ }
\DoxyCodeLine{00283\ }
\DoxyCodeLine{00295\ \textcolor{keyword}{template}\ <}
\DoxyCodeLine{00296\ \ \ \ \ \textcolor{keyword}{typename}\ MatrixPtrType,\ \textcolor{keyword}{typename}\ StreamType,}
\DoxyCodeLine{00297\ \ \ \ \ std::enable\_if\_t<!std::is\_same\_v<}
\DoxyCodeLine{00298\ \ \ \ \ \ \ \ \ std::remove\_cv\_t<detail::pointee<MatrixPtrType>>,\ \doxymbox{\hyperlink{classgko_1_1LinOp}{LinOp}}>>*\ =\ \textcolor{keyword}{nullptr}>}
\DoxyCodeLine{00299\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ \doxymbox{\hyperlink{namespacegko_af82d8f7795fefcf5f38a38895e316c02}{write}}(}
\DoxyCodeLine{00300\ \ \ \ \ StreamType\&\&\ os,\ MatrixPtrType\&\&\ \doxymbox{\hyperlink{namespacegko_1_1matrix}{matrix}},}
\DoxyCodeLine{00301\ \ \ \ \ \doxymbox{\hyperlink{namespacegko_ae749a5ea11a93c1bcc9158d9a6e9fb68}{layout\_type}}\ layout\ =\ detail::mtx\_io\_traits<}
\DoxyCodeLine{00302\ \ \ \ \ \ \ \ \ std::remove\_cv\_t<detail::pointee<MatrixPtrType>>>::default\_layout)}
\DoxyCodeLine{00303\ \{}
\DoxyCodeLine{00304\ \ \ \ \ \textcolor{keyword}{using\ }MatrixType\ =\ detail::pointee<MatrixPtrType>;}
\DoxyCodeLine{00305\ \ \ \ \ \doxymbox{\hyperlink{structgko_1_1matrix__data}{matrix\_data}}<\textcolor{keyword}{typename}\ MatrixType::value\_type,}
\DoxyCodeLine{00306\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ MatrixType::index\_type>}
\DoxyCodeLine{00307\ \ \ \ \ \ \ \ \ data\{\};}
\DoxyCodeLine{00308\ \ \ \ \ \doxymbox{\hyperlink{namespacegko_1_1matrix}{matrix}}-\/>write(data);}
\DoxyCodeLine{00309\ \ \ \ \ \doxymbox{\hyperlink{namespacegko_a2d4b63ce98a16dc2c48aacd534a7b8ba}{write\_raw}}(os,\ data,\ layout);}
\DoxyCodeLine{00310\ \}}
\DoxyCodeLine{00311\ }
\DoxyCodeLine{00320\ \textcolor{keywordtype}{void}\ \doxymbox{\hyperlink{namespacegko_af82d8f7795fefcf5f38a38895e316c02}{write}}(std::ostream\&\ os,\ \doxymbox{\hyperlink{classgko_1_1ptr__param}{ptr\_param<const\ LinOp>}}\ \doxymbox{\hyperlink{namespacegko_1_1matrix}{matrix}});}
\DoxyCodeLine{00321\ }
\DoxyCodeLine{00322\ }
\DoxyCodeLine{00336\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ MatrixPtrType,\ \textcolor{keyword}{typename}\ StreamType>}
\DoxyCodeLine{00337\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ \doxymbox{\hyperlink{namespacegko_aba9ca89ef08421197d3dbf84b0ad884c}{write\_binary}}(StreamType\&\&\ os,\ MatrixPtrType\&\&\ \doxymbox{\hyperlink{namespacegko_1_1matrix}{matrix}})}
\DoxyCodeLine{00338\ \{}
\DoxyCodeLine{00339\ \ \ \ \ \textcolor{keyword}{using\ }MatrixType\ =\ detail::pointee<MatrixPtrType>;}
\DoxyCodeLine{00340\ \ \ \ \ \doxymbox{\hyperlink{structgko_1_1matrix__data}{matrix\_data}}<\textcolor{keyword}{typename}\ MatrixType::value\_type,}
\DoxyCodeLine{00341\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ MatrixType::index\_type>}
\DoxyCodeLine{00342\ \ \ \ \ \ \ \ \ data\{\};}
\DoxyCodeLine{00343\ \ \ \ \ \doxymbox{\hyperlink{namespacegko_1_1matrix}{matrix}}-\/>write(data);}
\DoxyCodeLine{00344\ \ \ \ \ \doxymbox{\hyperlink{namespacegko_a3b27a0c0282115116c160884dc0a9468}{write\_binary\_raw}}(os,\ data);}
\DoxyCodeLine{00345\ \}}
\DoxyCodeLine{00346\ }
\DoxyCodeLine{00347\ }
\DoxyCodeLine{00348\ \}\ \ \textcolor{comment}{//\ namespace\ gko}}
\DoxyCodeLine{00349\ }
\DoxyCodeLine{00350\ }
\DoxyCodeLine{00351\ \textcolor{preprocessor}{\#endif\ \ }\textcolor{comment}{//\ GKO\_PUBLIC\_CORE\_BASE\_MTX\_IO\_HPP\_}}

\end{DoxyCode}
