\doxysection{half.\+hpp}
\hypertarget{half_8hpp_source}{}\label{half_8hpp_source}\index{ginkgo/core/base/half.hpp@{ginkgo/core/base/half.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\_HALF\_HPP\_}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#define\ GKO\_PUBLIC\_CORE\_BASE\_HALF\_HPP\_}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ }
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#include\ <climits>}}
\DoxyCodeLine{00010\ \textcolor{preprocessor}{\#include\ <complex>}}
\DoxyCodeLine{00011\ \textcolor{preprocessor}{\#include\ <cstdint>}}
\DoxyCodeLine{00012\ \textcolor{preprocessor}{\#include\ <cstring>}}
\DoxyCodeLine{00013\ \textcolor{preprocessor}{\#include\ <type\_traits>}}
\DoxyCodeLine{00014\ }
\DoxyCodeLine{00015\ }
\DoxyCodeLine{00016\ \textcolor{keyword}{class\ }\_\_half;}
\DoxyCodeLine{00017\ }
\DoxyCodeLine{00018\ }
\DoxyCodeLine{00019\ \textcolor{keyword}{namespace\ }\doxymbox{\hyperlink{namespacegko}{gko}}\ \{}
\DoxyCodeLine{00020\ }
\DoxyCodeLine{00021\ }
\DoxyCodeLine{00022\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename},\ std::\textcolor{keywordtype}{size\_t},\ std::\textcolor{keywordtype}{size\_t}>}
\DoxyCodeLine{00023\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1truncated}{truncated}};}
\DoxyCodeLine{00024\ }
\DoxyCodeLine{00025\ }
\DoxyCodeLine{00026\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1half}{half}};}
\DoxyCodeLine{00027\ }
\DoxyCodeLine{00028\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1bfloat16}{bfloat16}};}
\DoxyCodeLine{00029\ }
\DoxyCodeLine{00030\ }
\DoxyCodeLine{00031\ \textcolor{keyword}{namespace\ }detail\ \{}
\DoxyCodeLine{00032\ }
\DoxyCodeLine{00033\ }
\DoxyCodeLine{00034\ \textcolor{keyword}{constexpr}\ std::size\_t\ \doxymbox{\hyperlink{namespacegko_acae2e648052ec788bd8ba9e0192652a6}{byte\_size}}\ =\ CHAR\_BIT;}
\DoxyCodeLine{00035\ }
\DoxyCodeLine{00036\ \textcolor{keyword}{template}\ <std::\textcolor{keywordtype}{size\_t},\ \textcolor{keyword}{typename}\ =\ \textcolor{keywordtype}{void}>}
\DoxyCodeLine{00037\ \textcolor{keyword}{struct\ }uint\_of\_impl\ \{\};}
\DoxyCodeLine{00038\ }
\DoxyCodeLine{00039\ \textcolor{keyword}{template}\ <std::\textcolor{keywordtype}{size\_t}\ Bits>}
\DoxyCodeLine{00040\ \textcolor{keyword}{struct\ }uint\_of\_impl<Bits,\ \doxymbox{\hyperlink{namespacestd}{std}}::enable\_if\_t<(Bits\ <=\ 16)>>\ \{}
\DoxyCodeLine{00041\ \ \ \ \ \textcolor{keyword}{using\ }type\ =\ std::uint16\_t;}
\DoxyCodeLine{00042\ \};}
\DoxyCodeLine{00043\ }
\DoxyCodeLine{00044\ \textcolor{keyword}{template}\ <std::\textcolor{keywordtype}{size\_t}\ Bits>}
\DoxyCodeLine{00045\ \textcolor{keyword}{struct\ }uint\_of\_impl<Bits,\ \doxymbox{\hyperlink{namespacestd}{std}}::enable\_if\_t<(16\ <\ Bits\ \&\&\ Bits\ <=\ 32)>>\ \{}
\DoxyCodeLine{00046\ \ \ \ \ using\ type\ =\ std::uint32\_t;}
\DoxyCodeLine{00047\ \};}
\DoxyCodeLine{00048\ }
\DoxyCodeLine{00049\ template\ <std::size\_t\ Bits>}
\DoxyCodeLine{00050\ struct\ uint\_of\_impl<Bits,\ std::enable\_if\_t<(32\ <\ Bits)\ \&\&\ (Bits\ <=\ 64)>>\ \{}
\DoxyCodeLine{00051\ \ \ \ \ using\ type\ =\ std::uint64\_t;}
\DoxyCodeLine{00052\ \};}
\DoxyCodeLine{00053\ }
\DoxyCodeLine{00054\ template\ <std::size\_t\ Bits>}
\DoxyCodeLine{00055\ using\ uint\_of\ =\ typename\ uint\_of\_impl<Bits>::type;}
\DoxyCodeLine{00056\ }
\DoxyCodeLine{00057\ }
\DoxyCodeLine{00058\ template\ <typename\ T>}
\DoxyCodeLine{00059\ struct\ basic\_float\_traits\ \{\};}
\DoxyCodeLine{00060\ }
\DoxyCodeLine{00061\ template\ <>}
\DoxyCodeLine{00062\ struct\ basic\_float\_traits<half>\ \{}
\DoxyCodeLine{00063\ \ \ \ \ using\ type\ =\ half;}
\DoxyCodeLine{00064\ \ \ \ \ static\ constexpr\ int\ sign\_bits\ =\ 1;}
\DoxyCodeLine{00065\ \ \ \ \ static\ constexpr\ int\ significand\_bits\ =\ 10;}
\DoxyCodeLine{00066\ \ \ \ \ static\ constexpr\ int\ exponent\_bits\ =\ 5;}
\DoxyCodeLine{00067\ \ \ \ \ static\ constexpr\ bool\ rounds\_to\_nearest\ =\ true;}
\DoxyCodeLine{00068\ \};}
\DoxyCodeLine{00069\ }
\DoxyCodeLine{00070\ template\ <>}
\DoxyCodeLine{00071\ struct\ basic\_float\_traits<\_\_half>\ \{}
\DoxyCodeLine{00072\ \ \ \ \ using\ type\ =\ \_\_half;}
\DoxyCodeLine{00073\ \ \ \ \ static\ constexpr\ int\ sign\_bits\ =\ 1;}
\DoxyCodeLine{00074\ \ \ \ \ static\ constexpr\ int\ significand\_bits\ =\ 10;}
\DoxyCodeLine{00075\ \ \ \ \ static\ constexpr\ int\ exponent\_bits\ =\ 5;}
\DoxyCodeLine{00076\ \ \ \ \ static\ constexpr\ bool\ rounds\_to\_nearest\ =\ true;}
\DoxyCodeLine{00077\ \};}
\DoxyCodeLine{00078\ }
\DoxyCodeLine{00079\ template\ <>}
\DoxyCodeLine{00080\ struct\ basic\_float\_traits<float>\ \{}
\DoxyCodeLine{00081\ \ \ \ \ using\ type\ =\ float;}
\DoxyCodeLine{00082\ \ \ \ \ static\ constexpr\ int\ sign\_bits\ =\ 1;}
\DoxyCodeLine{00083\ \ \ \ \ static\ constexpr\ int\ significand\_bits\ =\ 23;}
\DoxyCodeLine{00084\ \ \ \ \ static\ constexpr\ int\ exponent\_bits\ =\ 8;}
\DoxyCodeLine{00085\ \ \ \ \ static\ constexpr\ bool\ rounds\_to\_nearest\ =\ true;}
\DoxyCodeLine{00086\ \};}
\DoxyCodeLine{00087\ }
\DoxyCodeLine{00088\ template\ <>}
\DoxyCodeLine{00089\ struct\ basic\_float\_traits<double>\ \{}
\DoxyCodeLine{00090\ \ \ \ \ using\ type\ =\ double;}
\DoxyCodeLine{00091\ \ \ \ \ static\ constexpr\ int\ sign\_bits\ =\ 1;}
\DoxyCodeLine{00092\ \ \ \ \ static\ constexpr\ int\ significand\_bits\ =\ 52;}
\DoxyCodeLine{00093\ \ \ \ \ static\ constexpr\ int\ exponent\_bits\ =\ 11;}
\DoxyCodeLine{00094\ \ \ \ \ static\ constexpr\ bool\ rounds\_to\_nearest\ =\ true;}
\DoxyCodeLine{00095\ \};}
\DoxyCodeLine{00096\ }
\DoxyCodeLine{00097\ template\ <typename\ FloatType,\ std::size\_t\ NumComponents,}
\DoxyCodeLine{00098\ \ \ \ \ \ \ \ \ \ \ std::size\_t\ ComponentId>}
\DoxyCodeLine{00099\ struct\ basic\_float\_traits<truncated<FloatType,\ NumComponents,\ ComponentId>>\ \{}
\DoxyCodeLine{00100\ \ \ \ \ using\ type\ =\ truncated<FloatType,\ NumComponents,\ ComponentId>;}
\DoxyCodeLine{00101\ \ \ \ \ static\ constexpr\ int\ sign\_bits\ =\ ComponentId\ ==\ 0\ ?\ 1\ :\ 0;}
\DoxyCodeLine{00102\ \ \ \ \ static\ constexpr\ int\ exponent\_bits\ =}
\DoxyCodeLine{00103\ \ \ \ \ \ \ \ \ ComponentId\ ==\ 0\ ?\ basic\_float\_traits<FloatType>::exponent\_bits\ :\ 0;}
\DoxyCodeLine{00104\ \ \ \ \ static\ constexpr\ int\ significand\_bits\ =}
\DoxyCodeLine{00105\ \ \ \ \ \ \ \ \ ComponentId\ ==\ 0\ ?\ sizeof(type)\ *\ byte\_size\ -\/\ exponent\_bits\ -\/\ 1}
\DoxyCodeLine{00106\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ :\ sizeof(type)\ *\ byte\_size;}
\DoxyCodeLine{00107\ \ \ \ \ static\ constexpr\ bool\ rounds\_to\_nearest\ =\ false;}
\DoxyCodeLine{00108\ \};}
\DoxyCodeLine{00109\ }
\DoxyCodeLine{00110\ }
\DoxyCodeLine{00111\ template\ <typename\ UintType>}
\DoxyCodeLine{00112\ constexpr\ UintType\ create\_ones(int\ n)}
\DoxyCodeLine{00113\ \{}
\DoxyCodeLine{00114\ \ \ \ \ return\ (n\ ==\ sizeof(UintType)\ *\ byte\_size\ ?\ static\_cast<UintType>(0)}
\DoxyCodeLine{00115\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ :\ static\_cast<UintType>(1)\ <<\ n)\ -\/}
\DoxyCodeLine{00116\ \ \ \ \ \ \ \ \ \ \ \ static\_cast<UintType>(1);}
\DoxyCodeLine{00117\ \}}
\DoxyCodeLine{00118\ }
\DoxyCodeLine{00119\ }
\DoxyCodeLine{00120\ template\ <typename\ T>}
\DoxyCodeLine{00121\ struct\ float\_traits\ \{}
\DoxyCodeLine{00122\ \ \ \ \ using\ type\ =\ typename\ basic\_float\_traits<T>::type;}
\DoxyCodeLine{00123\ \ \ \ \ using\ bits\_type\ =\ uint\_of<sizeof(type)\ *\ byte\_size>;}
\DoxyCodeLine{00124\ \ \ \ \ static\ constexpr\ int\ sign\_bits\ =\ basic\_float\_traits<T>::sign\_bits;}
\DoxyCodeLine{00125\ \ \ \ \ static\ constexpr\ int\ significand\_bits\ =}
\DoxyCodeLine{00126\ \ \ \ \ \ \ \ \ basic\_float\_traits<T>::significand\_bits;}
\DoxyCodeLine{00127\ \ \ \ \ static\ constexpr\ int\ exponent\_bits\ =\ basic\_float\_traits<T>::exponent\_bits;}
\DoxyCodeLine{00128\ \ \ \ \ static\ constexpr\ bits\_type\ significand\_mask\ =}
\DoxyCodeLine{00129\ \ \ \ \ \ \ \ \ create\_ones<bits\_type>(significand\_bits);}
\DoxyCodeLine{00130\ \ \ \ \ static\ constexpr\ bits\_type\ exponent\_mask\ =}
\DoxyCodeLine{00131\ \ \ \ \ \ \ \ \ create\_ones<bits\_type>(significand\_bits\ +\ exponent\_bits)\ -\/}
\DoxyCodeLine{00132\ \ \ \ \ \ \ \ \ significand\_mask;}
\DoxyCodeLine{00133\ \ \ \ \ static\ constexpr\ bits\_type\ bias\_mask\ =}
\DoxyCodeLine{00134\ \ \ \ \ \ \ \ \ create\_ones<bits\_type>(significand\_bits\ +\ exponent\_bits\ -\/\ 1)\ -\/}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \ \ significand\_mask;}
\DoxyCodeLine{00136\ \ \ \ \ static\ constexpr\ bits\_type\ sign\_mask\ =}
\DoxyCodeLine{00137\ \ \ \ \ \ \ \ \ create\_ones<bits\_type>(sign\_bits\ +\ significand\_bits\ +\ exponent\_bits)\ -\/}
\DoxyCodeLine{00138\ \ \ \ \ \ \ \ \ exponent\_mask\ -\/\ significand\_mask;}
\DoxyCodeLine{00139\ \ \ \ \ static\ constexpr\ bool\ rounds\_to\_nearest\ =}
\DoxyCodeLine{00140\ \ \ \ \ \ \ \ \ basic\_float\_traits<T>::rounds\_to\_nearest;}
\DoxyCodeLine{00141\ }
\DoxyCodeLine{00142\ \ \ \ \ static\ constexpr\ auto\ eps\ =}
\DoxyCodeLine{00143\ \ \ \ \ \ \ \ \ 1.0\ /\ (1ll\ <<\ (significand\_bits\ +\ rounds\_to\_nearest));}
\DoxyCodeLine{00144\ }
\DoxyCodeLine{00145\ \ \ \ \ static\ constexpr\ bool\ is\_inf(bits\_type\ data)}
\DoxyCodeLine{00146\ \ \ \ \ \{}
\DoxyCodeLine{00147\ \ \ \ \ \ \ \ \ return\ (data\ \&\ exponent\_mask)\ ==\ exponent\_mask\ \&\&}
\DoxyCodeLine{00148\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (data\ \&\ significand\_mask)\ ==\ bits\_type\{\};}
\DoxyCodeLine{00149\ \ \ \ \ \}}
\DoxyCodeLine{00150\ }
\DoxyCodeLine{00151\ \ \ \ \ static\ constexpr\ bool\ is\_nan(bits\_type\ data)}
\DoxyCodeLine{00152\ \ \ \ \ \{}
\DoxyCodeLine{00153\ \ \ \ \ \ \ \ \ return\ (data\ \&\ exponent\_mask)\ ==\ exponent\_mask\ \&\&}
\DoxyCodeLine{00154\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (data\ \&\ significand\_mask)\ !=\ bits\_type\{\};}
\DoxyCodeLine{00155\ \ \ \ \ \}}
\DoxyCodeLine{00156\ }
\DoxyCodeLine{00157\ \ \ \ \ static\ constexpr\ bool\ is\_denom(bits\_type\ data)}
\DoxyCodeLine{00158\ \ \ \ \ \{}
\DoxyCodeLine{00159\ \ \ \ \ \ \ \ \ return\ (data\ \&\ exponent\_mask)\ ==\ bits\_type\{\};}
\DoxyCodeLine{00160\ \ \ \ \ \}}
\DoxyCodeLine{00161\ \};}
\DoxyCodeLine{00162\ }
\DoxyCodeLine{00163\ }
\DoxyCodeLine{00164\ template\ <typename\ SourceType,\ typename\ ResultType,}
\DoxyCodeLine{00165\ \ \ \ \ \ \ \ \ \ \ bool\ =\ (sizeof(SourceType)\ <=\ sizeof(ResultType))>}
\DoxyCodeLine{00166\ struct\ precision\_converter;}
\DoxyCodeLine{00167\ }
\DoxyCodeLine{00168\ \textcolor{comment}{//\ upcasting\ implementation\ details}}
\DoxyCodeLine{00169\ template\ <typename\ SourceType,\ typename\ ResultType>}
\DoxyCodeLine{00170\ struct\ precision\_converter<SourceType,\ ResultType,\ true>\ \{}
\DoxyCodeLine{00171\ \ \ \ \ using\ source\_traits\ =\ float\_traits<SourceType>;}
\DoxyCodeLine{00172\ \ \ \ \ using\ result\_traits\ =\ float\_traits<ResultType>;}
\DoxyCodeLine{00173\ \ \ \ \ using\ source\_bits\ =\ typename\ source\_traits::bits\_type;}
\DoxyCodeLine{00174\ \ \ \ \ using\ result\_bits\ =\ typename\ result\_traits::bits\_type;}
\DoxyCodeLine{00175\ }
\DoxyCodeLine{00176\ \ \ \ \ static\_assert(source\_traits::exponent\_bits\ <=}
\DoxyCodeLine{00177\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ result\_traits::exponent\_bits\ \&\&}
\DoxyCodeLine{00178\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ source\_traits::significand\_bits\ <=}
\DoxyCodeLine{00179\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ result\_traits::significand\_bits,}
\DoxyCodeLine{00180\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ "{}SourceType\ has\ to\ have\ both\ lower\ range\ and\ precision\ or\ "{}}
\DoxyCodeLine{00181\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ "{}higher\ range\ and\ precision\ than\ ResultType"{});}
\DoxyCodeLine{00182\ }
\DoxyCodeLine{00183\ \ \ \ \ static\ constexpr\ int\ significand\_offset\ =}
\DoxyCodeLine{00184\ \ \ \ \ \ \ \ \ result\_traits::significand\_bits\ -\/\ source\_traits::significand\_bits;}
\DoxyCodeLine{00185\ \ \ \ \ static\ constexpr\ int\ exponent\_offset\ =\ significand\_offset;}
\DoxyCodeLine{00186\ \ \ \ \ static\ constexpr\ int\ sign\_offset\ =\ result\_traits::exponent\_bits\ -\/}
\DoxyCodeLine{00187\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ source\_traits::exponent\_bits\ +}
\DoxyCodeLine{00188\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ exponent\_offset;}
\DoxyCodeLine{00189\ \ \ \ \ static\ constexpr\ result\_bits\ bias\_change\ =}
\DoxyCodeLine{00190\ \ \ \ \ \ \ \ \ result\_traits::bias\_mask\ -\/}
\DoxyCodeLine{00191\ \ \ \ \ \ \ \ \ (static\_cast<result\_bits>(source\_traits::bias\_mask)\ <<\ exponent\_offset);}
\DoxyCodeLine{00192\ }
\DoxyCodeLine{00193\ \ \ \ \ static\ constexpr\ result\_bits\ shift\_significand(source\_bits\ data)\ noexcept}
\DoxyCodeLine{00194\ \ \ \ \ \{}
\DoxyCodeLine{00195\ \ \ \ \ \ \ \ \ return\ static\_cast<result\_bits>(data\ \&\ source\_traits::significand\_mask)}
\DoxyCodeLine{00196\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ significand\_offset;}
\DoxyCodeLine{00197\ \ \ \ \ \}}
\DoxyCodeLine{00198\ }
\DoxyCodeLine{00199\ \ \ \ \ static\ constexpr\ result\_bits\ shift\_exponent(source\_bits\ data)\ noexcept}
\DoxyCodeLine{00200\ \ \ \ \ \{}
\DoxyCodeLine{00201\ \ \ \ \ \ \ \ \ return\ update\_bias(}
\DoxyCodeLine{00202\ \ \ \ \ \ \ \ \ \ \ \ \ static\_cast<result\_bits>(data\ \&\ source\_traits::exponent\_mask)}
\DoxyCodeLine{00203\ \ \ \ \ \ \ \ \ \ \ \ \ <<\ exponent\_offset);}
\DoxyCodeLine{00204\ \ \ \ \ \}}
\DoxyCodeLine{00205\ }
\DoxyCodeLine{00206\ \ \ \ \ static\ constexpr\ result\_bits\ shift\_sign(source\_bits\ data)\ noexcept}
\DoxyCodeLine{00207\ \ \ \ \ \{}
\DoxyCodeLine{00208\ \ \ \ \ \ \ \ \ return\ static\_cast<result\_bits>(data\ \&\ source\_traits::sign\_mask)}
\DoxyCodeLine{00209\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ <<\ sign\_offset;}
\DoxyCodeLine{00210\ \ \ \ \ \}}
\DoxyCodeLine{00211\ }
\DoxyCodeLine{00212\ private:}
\DoxyCodeLine{00213\ \ \ \ \ static\ constexpr\ result\_bits\ update\_bias(result\_bits\ data)\ noexcept}
\DoxyCodeLine{00214\ \ \ \ \ \{}
\DoxyCodeLine{00215\ \ \ \ \ \ \ \ \ return\ data\ ==\ typename\ result\_traits::bits\_type\{\}\ ?\ data}
\DoxyCodeLine{00216\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ :\ data\ +\ bias\_change;}
\DoxyCodeLine{00217\ \ \ \ \ \}}
\DoxyCodeLine{00218\ \};}
\DoxyCodeLine{00219\ }
\DoxyCodeLine{00220\ \textcolor{comment}{//\ downcasting\ implementation\ details}}
\DoxyCodeLine{00221\ template\ <typename\ SourceType,\ typename\ ResultType>}
\DoxyCodeLine{00222\ struct\ precision\_converter<SourceType,\ ResultType,\ false>\ \{}
\DoxyCodeLine{00223\ \ \ \ \ using\ source\_traits\ =\ float\_traits<SourceType>;}
\DoxyCodeLine{00224\ \ \ \ \ using\ result\_traits\ =\ float\_traits<ResultType>;}
\DoxyCodeLine{00225\ \ \ \ \ using\ source\_bits\ =\ typename\ source\_traits::bits\_type;}
\DoxyCodeLine{00226\ \ \ \ \ using\ result\_bits\ =\ typename\ result\_traits::bits\_type;}
\DoxyCodeLine{00227\ }
\DoxyCodeLine{00228\ \ \ \ \ static\_assert(source\_traits::exponent\_bits\ >=}
\DoxyCodeLine{00229\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ result\_traits::exponent\_bits\ \&\&}
\DoxyCodeLine{00230\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ source\_traits::significand\_bits\ >=}
\DoxyCodeLine{00231\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ result\_traits::significand\_bits,}
\DoxyCodeLine{00232\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ "{}SourceType\ has\ to\ have\ both\ lower\ range\ and\ precision\ or\ "{}}
\DoxyCodeLine{00233\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ "{}higher\ range\ and\ precision\ than\ ResultType"{});}
\DoxyCodeLine{00234\ }
\DoxyCodeLine{00235\ \ \ \ \ static\ constexpr\ int\ significand\_offset\ =}
\DoxyCodeLine{00236\ \ \ \ \ \ \ \ \ source\_traits::significand\_bits\ -\/\ result\_traits::significand\_bits;}
\DoxyCodeLine{00237\ \ \ \ \ static\ constexpr\ int\ exponent\_offset\ =\ significand\_offset;}
\DoxyCodeLine{00238\ \ \ \ \ static\ constexpr\ int\ sign\_offset\ =\ source\_traits::exponent\_bits\ -\/}
\DoxyCodeLine{00239\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ result\_traits::exponent\_bits\ +}
\DoxyCodeLine{00240\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ exponent\_offset;}
\DoxyCodeLine{00241\ \ \ \ \ static\ constexpr\ source\_bits\ bias\_change\ =}
\DoxyCodeLine{00242\ \ \ \ \ \ \ \ \ (source\_traits::bias\_mask\ >>\ exponent\_offset)\ -\/}
\DoxyCodeLine{00243\ \ \ \ \ \ \ \ \ static\_cast<source\_bits>(result\_traits::bias\_mask);}
\DoxyCodeLine{00244\ }
\DoxyCodeLine{00245\ \ \ \ \ static\ constexpr\ result\_bits\ shift\_significand(source\_bits\ data)\ noexcept}
\DoxyCodeLine{00246\ \ \ \ \ \{}
\DoxyCodeLine{00247\ \ \ \ \ \ \ \ \ return\ static\_cast<result\_bits>(}
\DoxyCodeLine{00248\ \ \ \ \ \ \ \ \ \ \ \ \ (data\ \&\ source\_traits::significand\_mask)\ >>\ significand\_offset);}
\DoxyCodeLine{00249\ \ \ \ \ \}}
\DoxyCodeLine{00250\ }
\DoxyCodeLine{00251\ \ \ \ \ static\ constexpr\ result\_bits\ shift\_exponent(source\_bits\ data)\ noexcept}
\DoxyCodeLine{00252\ \ \ \ \ \{}
\DoxyCodeLine{00253\ \ \ \ \ \ \ \ \ return\ static\_cast<result\_bits>(update\_bias(}
\DoxyCodeLine{00254\ \ \ \ \ \ \ \ \ \ \ \ \ (data\ \&\ source\_traits::exponent\_mask)\ >>\ exponent\_offset));}
\DoxyCodeLine{00255\ \ \ \ \ \}}
\DoxyCodeLine{00256\ }
\DoxyCodeLine{00257\ \ \ \ \ static\ constexpr\ result\_bits\ shift\_sign(source\_bits\ data)\ noexcept}
\DoxyCodeLine{00258\ \ \ \ \ \{}
\DoxyCodeLine{00259\ \ \ \ \ \ \ \ \ return\ static\_cast<result\_bits>((data\ \&\ source\_traits::sign\_mask)\ >>}
\DoxyCodeLine{00260\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ sign\_offset);}
\DoxyCodeLine{00261\ \ \ \ \ \}}
\DoxyCodeLine{00262\ }
\DoxyCodeLine{00263\ private:}
\DoxyCodeLine{00264\ \ \ \ \ static\ constexpr\ source\_bits\ update\_bias(source\_bits\ data)\ noexcept}
\DoxyCodeLine{00265\ \ \ \ \ \{}
\DoxyCodeLine{00266\ \ \ \ \ \ \ \ \ return\ data\ <=\ bias\_change\ ?\ typename\ source\_traits::bits\_type\{\}}
\DoxyCodeLine{00267\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ :\ limit\_exponent(data\ -\/\ bias\_change);}
\DoxyCodeLine{00268\ \ \ \ \ \}}
\DoxyCodeLine{00269\ }
\DoxyCodeLine{00270\ \ \ \ \ static\ constexpr\ source\_bits\ limit\_exponent(source\_bits\ data)\ noexcept}
\DoxyCodeLine{00271\ \ \ \ \ \{}
\DoxyCodeLine{00272\ \ \ \ \ \ \ \ \ return\ data\ >=\ static\_cast<source\_bits>(result\_traits::exponent\_mask)}
\DoxyCodeLine{00273\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ?\ static\_cast<source\_bits>(result\_traits::exponent\_mask)}
\DoxyCodeLine{00274\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ :\ data;}
\DoxyCodeLine{00275\ \ \ \ \ \}}
\DoxyCodeLine{00276\ \};}
\DoxyCodeLine{00277\ }
\DoxyCodeLine{00278\ }
\DoxyCodeLine{00279\ \}\ \ \textcolor{comment}{//\ namespace\ detail}}
\DoxyCodeLine{00280\ }
\DoxyCodeLine{00281\ }
\DoxyCodeLine{00288\ class\ alignas(std::uint16\_t)\ half\ \{}
\DoxyCodeLine{00289\ public:}
\DoxyCodeLine{00290\ \ \ \ \ \textcolor{comment}{//\ create\ half\ value\ from\ the\ bits\ directly.}}
\DoxyCodeLine{00291\ \ \ \ \ static\ constexpr\ half\ create\_from\_bits(const\ std::uint16\_t\&\ bits)\ noexcept}
\DoxyCodeLine{00292\ \ \ \ \ \{}
\DoxyCodeLine{00293\ \ \ \ \ \ \ \ \ half\ result;}
\DoxyCodeLine{00294\ \ \ \ \ \ \ \ \ result.data\_\ =\ bits;}
\DoxyCodeLine{00295\ \ \ \ \ \ \ \ \ return\ result;}
\DoxyCodeLine{00296\ \ \ \ \ \}}
\DoxyCodeLine{00297\ }
\DoxyCodeLine{00298\ \ \ \ \ \textcolor{comment}{//\ TODO:\ NVHPC\ (host\ side)\ may\ not\ use\ zero\ initialization\ for\ the\ data}}
\DoxyCodeLine{00299\ \ \ \ \ \textcolor{comment}{//\ member\ by\ default\ constructor\ in\ some\ cases.\ Not\ sure\ whether\ it\ is}}
\DoxyCodeLine{00300\ \ \ \ \ \textcolor{comment}{//\ caused\ by\ something\ else\ in\ jacobi\ or\ isai.}}
\DoxyCodeLine{00301\ \ \ \ \ constexpr\ half()\ noexcept\ :\ data\_(0)\{\};}
\DoxyCodeLine{00302\ }
\DoxyCodeLine{00303\ \ \ \ \ template\ <typename\ T,}
\DoxyCodeLine{00304\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ typename\ =\ std::enable\_if\_t<std::is\_scalar<T>::value\ ||}
\DoxyCodeLine{00305\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::is\_same\_v<T,\ bfloat16>>>}
\DoxyCodeLine{00306\ \ \ \ \ half(const\ T\&\ val)\ :\ data\_(0)}
\DoxyCodeLine{00307\ \ \ \ \ \{}
\DoxyCodeLine{00308\ \ \ \ \ \ \ \ \ this-\/>float2half(static\_cast<float>(val));}
\DoxyCodeLine{00309\ \ \ \ \ \}}
\DoxyCodeLine{00310\ }
\DoxyCodeLine{00311\ \ \ \ \ template\ <typename\ V>}
\DoxyCodeLine{00312\ \ \ \ \ half\&\ operator=(const\ V\&\ val)}
\DoxyCodeLine{00313\ \ \ \ \ \{}
\DoxyCodeLine{00314\ \ \ \ \ \ \ \ \ this-\/>float2half(static\_cast<float>(val));}
\DoxyCodeLine{00315\ \ \ \ \ \ \ \ \ return\ *this;}
\DoxyCodeLine{00316\ \ \ \ \ \}}
\DoxyCodeLine{00317\ }
\DoxyCodeLine{00318\ \ \ \ \ operator\ float()\ const\ noexcept}
\DoxyCodeLine{00319\ \ \ \ \ \{}
\DoxyCodeLine{00320\ \ \ \ \ \ \ \ \ const\ auto\ bits\ =\ half2float(data\_);}
\DoxyCodeLine{00321\ \ \ \ \ \ \ \ \ float\ ans(0);}
\DoxyCodeLine{00322\ \ \ \ \ \ \ \ \ std::memcpy(\&ans,\ \&bits,\ sizeof(float));}
\DoxyCodeLine{00323\ \ \ \ \ \ \ \ \ return\ ans;}
\DoxyCodeLine{00324\ \ \ \ \ \}}
\DoxyCodeLine{00325\ }
\DoxyCodeLine{00326\ \ \ \ \ \textcolor{comment}{//\ can\ not\ use\ half\ operator\ \_op(const\ half)\ for\ half\ +\ half}}
\DoxyCodeLine{00327\ \ \ \ \ \textcolor{comment}{//\ operation\ will\ cast\ it\ to\ float\ and\ then\ do\ float\ operation\ such\ that\ it}}
\DoxyCodeLine{00328\ \ \ \ \ \textcolor{comment}{//\ becomes\ float\ in\ the\ end.}}
\DoxyCodeLine{00329\ \#define\ HALF\_OPERATOR(\_op,\ \_opeq)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00330\ \ \ \ \ friend\ half\ operator\ \_op(const\ half\&\ lhf,\ const\ half\&\ rhf)\ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00331\ \ \ \ \ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00332\ \ \ \ \ \ \ \ \ return\ static\_cast<half>(static\_cast<float>(lhf)\ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00333\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_op\ static\_cast<float>(rhf));\ \(\backslash\)}
\DoxyCodeLine{00334\ \ \ \ \ \}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00335\ \ \ \ \ half\&\ operator\ \_opeq(const\ half\&\ hf)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00336\ \ \ \ \ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00337\ \ \ \ \ \ \ \ \ auto\ result\ =\ *this\ \_op\ hf;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00338\ \ \ \ \ \ \ \ \ data\_\ =\ result.data\_;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00339\ \ \ \ \ \ \ \ \ return\ *this;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00340\ \ \ \ \ \}}
\DoxyCodeLine{00341\ }
\DoxyCodeLine{00342\ \ \ \ \ HALF\_OPERATOR(+,\ +=)}
\DoxyCodeLine{00343\ \ \ \ \ HALF\_OPERATOR(-\/,\ -\/=)}
\DoxyCodeLine{00344\ \ \ \ \ HALF\_OPERATOR(*,\ *=)}
\DoxyCodeLine{00345\ \ \ \ \ HALF\_OPERATOR(/,\ /=)}
\DoxyCodeLine{00346\ }
\DoxyCodeLine{00347\ \#undef\ HALF\_OPERATOR}
\DoxyCodeLine{00348\ }
\DoxyCodeLine{00349\ \ \ \ \ \textcolor{comment}{//\ Do\ operation\ with\ different\ type}}
\DoxyCodeLine{00350\ \ \ \ \ \textcolor{comment}{//\ If\ it\ is\ floating\ point,\ using\ floating\ point\ as\ type.}}
\DoxyCodeLine{00351\ \ \ \ \ \textcolor{comment}{//\ If\ it\ is\ integer,\ using\ half\ as\ type}}
\DoxyCodeLine{00352\ \ \ \ \ \textcolor{comment}{//\ Note:\ we\ do\ not\ define\ the\ operation\ with\ bfloat16,\ which\ is\ already}}
\DoxyCodeLine{00353\ \ \ \ \ \textcolor{comment}{//\ defined\ in\ bfloat16.hpp}}
\DoxyCodeLine{00354\ \#define\ HALF\_FRIEND\_OPERATOR(\_op,\ \_opeq)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00355\ \ \ \ \ template\ <typename\ T>\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00356\ \ \ \ \ friend\ std::enable\_if\_t<\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00357\ \ \ \ \ \ \ \ \ !std::is\_same<T,\ half>::value\ \&\&\ std::is\_scalar<T>::value,\ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00358\ \ \ \ \ \ \ \ \ std::conditional\_t<std::is\_floating\_point<T>::value,\ T,\ half>>\ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00359\ \ \ \ \ operator\ \_op(const\ half\&\ hf,\ const\ T\&\ val)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00360\ \ \ \ \ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00361\ \ \ \ \ \ \ \ \ using\ type\ =\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00362\ \ \ \ \ \ \ \ \ \ \ \ \ std::conditional\_t<std::is\_floating\_point<T>::value,\ T,\ half>;\ \(\backslash\)}
\DoxyCodeLine{00363\ \ \ \ \ \ \ \ \ auto\ result\ =\ static\_cast<type>(hf);\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00364\ \ \ \ \ \ \ \ \ result\ \_opeq\ static\_cast<type>(val);\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00365\ \ \ \ \ \ \ \ \ return\ result;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00366\ \ \ \ \ \}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00367\ \ \ \ \ template\ <typename\ T>\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00368\ \ \ \ \ friend\ std::enable\_if\_t<\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00369\ \ \ \ \ \ \ \ \ !std::is\_same<T,\ half>::value\ \&\&\ std::is\_scalar<T>::value,\ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00370\ \ \ \ \ \ \ \ \ std::conditional\_t<std::is\_floating\_point<T>::value,\ T,\ half>>\ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00371\ \ \ \ \ operator\ \_op(const\ T\&\ val,\ const\ half\&\ hf)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00372\ \ \ \ \ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00373\ \ \ \ \ \ \ \ \ using\ type\ =\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00374\ \ \ \ \ \ \ \ \ \ \ \ \ std::conditional\_t<std::is\_floating\_point<T>::value,\ T,\ half>;\ \(\backslash\)}
\DoxyCodeLine{00375\ \ \ \ \ \ \ \ \ auto\ result\ =\ static\_cast<type>(val);\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00376\ \ \ \ \ \ \ \ \ result\ \_opeq\ static\_cast<type>(hf);\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00377\ \ \ \ \ \ \ \ \ return\ result;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00378\ \ \ \ \ \}}
\DoxyCodeLine{00379\ }
\DoxyCodeLine{00380\ \ \ \ \ HALF\_FRIEND\_OPERATOR(+,\ +=)}
\DoxyCodeLine{00381\ \ \ \ \ HALF\_FRIEND\_OPERATOR(-\/,\ -\/=)}
\DoxyCodeLine{00382\ \ \ \ \ HALF\_FRIEND\_OPERATOR(*,\ *=)}
\DoxyCodeLine{00383\ \ \ \ \ HALF\_FRIEND\_OPERATOR(/,\ /=)}
\DoxyCodeLine{00384\ }
\DoxyCodeLine{00385\ \#undef\ HALF\_FRIEND\_OPERATOR}
\DoxyCodeLine{00386\ }
\DoxyCodeLine{00387\ \ \ \ \ \textcolor{comment}{//\ the\ negative}}
\DoxyCodeLine{00388\ \ \ \ \ half\ operator-\/()\ const}
\DoxyCodeLine{00389\ \ \ \ \ \{}
\DoxyCodeLine{00390\ \ \ \ \ \ \ \ \ auto\ val\ =\ 0.0f\ -\/\ *this;}
\DoxyCodeLine{00391\ \ \ \ \ \ \ \ \ return\ static\_cast<half>(val);}
\DoxyCodeLine{00392\ \ \ \ \ \}}
\DoxyCodeLine{00393\ }
\DoxyCodeLine{00394\ private:}
\DoxyCodeLine{00395\ \ \ \ \ using\ f16\_traits\ =\ detail::float\_traits<half>;}
\DoxyCodeLine{00396\ \ \ \ \ using\ f32\_traits\ =\ detail::float\_traits<float>;}
\DoxyCodeLine{00397\ }
\DoxyCodeLine{00398\ \ \ \ \ void\ float2half(const\ float\&\ val)\ noexcept}
\DoxyCodeLine{00399\ \ \ \ \ \{}
\DoxyCodeLine{00400\ \ \ \ \ \ \ \ \ std::uint32\_t\ bit\_val(0);}
\DoxyCodeLine{00401\ \ \ \ \ \ \ \ \ std::memcpy(\&bit\_val,\ \&val,\ sizeof(float));}
\DoxyCodeLine{00402\ \ \ \ \ \ \ \ \ data\_\ =\ float2half(bit\_val);}
\DoxyCodeLine{00403\ \ \ \ \ \}}
\DoxyCodeLine{00404\ }
\DoxyCodeLine{00405\ \ \ \ \ static\ constexpr\ std::uint16\_t\ float2half(std::uint32\_t\ data\_)\ noexcept}
\DoxyCodeLine{00406\ \ \ \ \ \{}
\DoxyCodeLine{00407\ \ \ \ \ \ \ \ \ using\ conv\ =\ detail::precision\_converter<float,\ half>;}
\DoxyCodeLine{00408\ \ \ \ \ \ \ \ \ if\ (f32\_traits::is\_inf(data\_))\ \{}
\DoxyCodeLine{00409\ \ \ \ \ \ \ \ \ \ \ \ \ return\ conv::shift\_sign(data\_)\ |\ f16\_traits::exponent\_mask;}
\DoxyCodeLine{00410\ \ \ \ \ \ \ \ \ \}\ else\ if\ (f32\_traits::is\_nan(data\_))\ \{}
\DoxyCodeLine{00411\ \ \ \ \ \ \ \ \ \ \ \ \ return\ conv::shift\_sign(data\_)\ |\ f16\_traits::exponent\_mask\ |}
\DoxyCodeLine{00412\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f16\_traits::significand\_mask;}
\DoxyCodeLine{00413\ \ \ \ \ \ \ \ \ \}\ else\ \{}
\DoxyCodeLine{00414\ \ \ \ \ \ \ \ \ \ \ \ \ const\ auto\ exp\ =\ conv::shift\_exponent(data\_);}
\DoxyCodeLine{00415\ \ \ \ \ \ \ \ \ \ \ \ \ if\ (f16\_traits::is\_inf(exp))\ \{}
\DoxyCodeLine{00416\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ return\ conv::shift\_sign(data\_)\ |\ exp;}
\DoxyCodeLine{00417\ \ \ \ \ \ \ \ \ \ \ \ \ \}\ else\ if\ (f16\_traits::is\_denom(exp))\ \{}
\DoxyCodeLine{00418\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ TODO:\ handle\ denormals}}
\DoxyCodeLine{00419\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ return\ conv::shift\_sign(data\_);}
\DoxyCodeLine{00420\ \ \ \ \ \ \ \ \ \ \ \ \ \}\ else\ \{}
\DoxyCodeLine{00421\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ Rounding\ to\ even}}
\DoxyCodeLine{00422\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ const\ auto\ result\ =\ conv::shift\_sign(data\_)\ |\ exp\ |}
\DoxyCodeLine{00423\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ conv::shift\_significand(data\_);}
\DoxyCodeLine{00424\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ const\ auto\ tail\ =}
\DoxyCodeLine{00425\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ data\_\ \&\ static\_cast<f32\_traits::bits\_type>(}
\DoxyCodeLine{00426\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (1\ <<\ conv::significand\_offset)\ -\/\ 1);}
\DoxyCodeLine{00427\ }
\DoxyCodeLine{00428\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ constexpr\ auto\ half\ =\ static\_cast<f32\_traits::bits\_type>(}
\DoxyCodeLine{00429\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 1\ <<\ (conv::significand\_offset\ -\/\ 1));}
\DoxyCodeLine{00430\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ return\ result\ +}
\DoxyCodeLine{00431\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (tail\ >\ half\ ||\ ((tail\ ==\ half)\ \&\&\ (result\ \&\ 1)));}
\DoxyCodeLine{00432\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00433\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00434\ \ \ \ \ \}}
\DoxyCodeLine{00435\ }
\DoxyCodeLine{00436\ \ \ \ \ static\ constexpr\ std::uint32\_t\ half2float(std::uint16\_t\ data\_)\ noexcept}
\DoxyCodeLine{00437\ \ \ \ \ \{}
\DoxyCodeLine{00438\ \ \ \ \ \ \ \ \ using\ conv\ =\ detail::precision\_converter<half,\ float>;}
\DoxyCodeLine{00439\ \ \ \ \ \ \ \ \ if\ (f16\_traits::is\_inf(data\_))\ \{}
\DoxyCodeLine{00440\ \ \ \ \ \ \ \ \ \ \ \ \ return\ conv::shift\_sign(data\_)\ |\ f32\_traits::exponent\_mask;}
\DoxyCodeLine{00441\ \ \ \ \ \ \ \ \ \}\ else\ if\ (f16\_traits::is\_nan(data\_))\ \{}
\DoxyCodeLine{00442\ \ \ \ \ \ \ \ \ \ \ \ \ return\ conv::shift\_sign(data\_)\ |\ f32\_traits::exponent\_mask\ |}
\DoxyCodeLine{00443\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f32\_traits::significand\_mask;}
\DoxyCodeLine{00444\ \ \ \ \ \ \ \ \ \}\ else\ if\ (f16\_traits::is\_denom(data\_))\ \{}
\DoxyCodeLine{00445\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ TODO:\ handle\ denormals}}
\DoxyCodeLine{00446\ \ \ \ \ \ \ \ \ \ \ \ \ return\ conv::shift\_sign(data\_);}
\DoxyCodeLine{00447\ \ \ \ \ \ \ \ \ \}\ else\ \{}
\DoxyCodeLine{00448\ \ \ \ \ \ \ \ \ \ \ \ \ return\ conv::shift\_sign(data\_)\ |\ conv::shift\_exponent(data\_)\ |}
\DoxyCodeLine{00449\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ conv::shift\_significand(data\_);}
\DoxyCodeLine{00450\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00451\ \ \ \ \ \}}
\DoxyCodeLine{00452\ }
\DoxyCodeLine{00453\ \ \ \ \ std::uint16\_t\ data\_;}
\DoxyCodeLine{00454\ \};}
\DoxyCodeLine{00455\ }
\DoxyCodeLine{00456\ }
\DoxyCodeLine{00457\ \}\ \ \textcolor{comment}{//\ namespace\ gko}}
\DoxyCodeLine{00458\ }
\DoxyCodeLine{00459\ }
\DoxyCodeLine{00460\ namespace\ std\ \{}
\DoxyCodeLine{00461\ }
\DoxyCodeLine{00462\ }
\DoxyCodeLine{00463\ template\ <>}
\DoxyCodeLine{00464\ class\ complex<gko::half>\ \{}
\DoxyCodeLine{00465\ public:}
\DoxyCodeLine{00466\ \ \ \ \ using\ value\_type\ =\ gko::half;}
\DoxyCodeLine{00467\ }
\DoxyCodeLine{00468\ \ \ \ \ complex(const\ value\_type\&\ real\ =\ value\_type(0.f),}
\DoxyCodeLine{00469\ \ \ \ \ \ \ \ \ \ \ \ \ const\ value\_type\&\ imag\ =\ value\_type(0.f))}
\DoxyCodeLine{00470\ \ \ \ \ \ \ \ \ :\ real\_(real),\ imag\_(imag)}
\DoxyCodeLine{00471\ \ \ \ \ \{\}}
\DoxyCodeLine{00472\ }
\DoxyCodeLine{00473\ \ \ \ \ template\ <}
\DoxyCodeLine{00474\ \ \ \ \ \ \ \ \ typename\ T,\ typename\ U,}
\DoxyCodeLine{00475\ \ \ \ \ \ \ \ \ typename\ =\ std::enable\_if\_t<}
\DoxyCodeLine{00476\ \ \ \ \ \ \ \ \ \ \ \ \ (std::is\_scalar<T>::value\ ||\ std::is\_same\_v<T,\ gko::bfloat16>)\&\&(}
\DoxyCodeLine{00477\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::is\_scalar<U>::value\ ||\ std::is\_same\_v<U,\ gko::bfloat16>)>>}
\DoxyCodeLine{00478\ \ \ \ \ explicit\ complex(const\ T\&\ real,\ const\ U\&\ imag)}
\DoxyCodeLine{00479\ \ \ \ \ \ \ \ \ :\ real\_(static\_cast<value\_type>(real)),}
\DoxyCodeLine{00480\ \ \ \ \ \ \ \ \ \ \ imag\_(static\_cast<value\_type>(imag))}
\DoxyCodeLine{00481\ \ \ \ \ \{\}}
\DoxyCodeLine{00482\ }
\DoxyCodeLine{00483\ \ \ \ \ template\ <typename\ T,}
\DoxyCodeLine{00484\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ typename\ =\ std::enable\_if\_t<std::is\_scalar<T>::value\ ||}
\DoxyCodeLine{00485\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::is\_same\_v<T,\ gko::bfloat16>>>}
\DoxyCodeLine{00486\ \ \ \ \ complex(const\ T\&\ real)}
\DoxyCodeLine{00487\ \ \ \ \ \ \ \ \ :\ real\_(static\_cast<value\_type>(real)),}
\DoxyCodeLine{00488\ \ \ \ \ \ \ \ \ \ \ imag\_(static\_cast<value\_type>(0.f))}
\DoxyCodeLine{00489\ \ \ \ \ \{\}}
\DoxyCodeLine{00490\ }
\DoxyCodeLine{00491\ \ \ \ \ \textcolor{comment}{//\ When\ using\ complex(real,\ imag),\ MSVC\ with\ CUDA\ try\ to\ recognize\ the}}
\DoxyCodeLine{00492\ \ \ \ \ \textcolor{comment}{//\ complex\ is\ a\ member\ not\ constructor.}}
\DoxyCodeLine{00493\ \ \ \ \ template\ <typename\ T,}
\DoxyCodeLine{00494\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ typename\ =\ std::enable\_if\_t<std::is\_scalar<T>::value\ ||}
\DoxyCodeLine{00495\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::is\_same\_v<T,\ gko::bfloat16>>>}
\DoxyCodeLine{00496\ \ \ \ \ explicit\ complex(const\ complex<T>\&\ other)}
\DoxyCodeLine{00497\ \ \ \ \ \ \ \ \ :\ real\_(static\_cast<value\_type>(other.real())),}
\DoxyCodeLine{00498\ \ \ \ \ \ \ \ \ \ \ imag\_(static\_cast<value\_type>(other.imag()))}
\DoxyCodeLine{00499\ \ \ \ \ \{\}}
\DoxyCodeLine{00500\ }
\DoxyCodeLine{00501\ \ \ \ \ value\_type\ real()\ const\ noexcept\ \{\ return\ real\_;\ \}}
\DoxyCodeLine{00502\ }
\DoxyCodeLine{00503\ \ \ \ \ value\_type\ imag()\ const\ noexcept\ \{\ return\ imag\_;\ \}}
\DoxyCodeLine{00504\ }
\DoxyCodeLine{00505\ \ \ \ \ operator\ std::complex<float>()\ const\ noexcept}
\DoxyCodeLine{00506\ \ \ \ \ \{}
\DoxyCodeLine{00507\ \ \ \ \ \ \ \ \ return\ std::complex<float>(static\_cast<float>(real\_),}
\DoxyCodeLine{00508\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ static\_cast<float>(imag\_));}
\DoxyCodeLine{00509\ \ \ \ \ \}}
\DoxyCodeLine{00510\ }
\DoxyCodeLine{00511\ \ \ \ \ template\ <typename\ V>}
\DoxyCodeLine{00512\ \ \ \ \ complex\&\ operator=(const\ V\&\ val)}
\DoxyCodeLine{00513\ \ \ \ \ \{}
\DoxyCodeLine{00514\ \ \ \ \ \ \ \ \ real\_\ =\ val;}
\DoxyCodeLine{00515\ \ \ \ \ \ \ \ \ imag\_\ =\ value\_type();}
\DoxyCodeLine{00516\ \ \ \ \ \ \ \ \ return\ *this;}
\DoxyCodeLine{00517\ \ \ \ \ \}}
\DoxyCodeLine{00518\ }
\DoxyCodeLine{00519\ \ \ \ \ template\ <typename\ V>}
\DoxyCodeLine{00520\ \ \ \ \ complex\&\ operator=(const\ std::complex<V>\&\ val)}
\DoxyCodeLine{00521\ \ \ \ \ \{}
\DoxyCodeLine{00522\ \ \ \ \ \ \ \ \ real\_\ =\ val.real();}
\DoxyCodeLine{00523\ \ \ \ \ \ \ \ \ imag\_\ =\ val.imag();}
\DoxyCodeLine{00524\ \ \ \ \ \ \ \ \ return\ *this;}
\DoxyCodeLine{00525\ \ \ \ \ \}}
\DoxyCodeLine{00526\ }
\DoxyCodeLine{00527\ \ \ \ \ complex\&\ operator+=(const\ value\_type\&\ real)}
\DoxyCodeLine{00528\ \ \ \ \ \{}
\DoxyCodeLine{00529\ \ \ \ \ \ \ \ \ real\_\ +=\ real;}
\DoxyCodeLine{00530\ \ \ \ \ \ \ \ \ return\ *this;}
\DoxyCodeLine{00531\ \ \ \ \ \}}
\DoxyCodeLine{00532\ }
\DoxyCodeLine{00533\ \ \ \ \ complex\&\ operator-\/=(const\ value\_type\&\ real)}
\DoxyCodeLine{00534\ \ \ \ \ \{}
\DoxyCodeLine{00535\ \ \ \ \ \ \ \ \ real\_\ -\/=\ real;}
\DoxyCodeLine{00536\ \ \ \ \ \ \ \ \ return\ *this;}
\DoxyCodeLine{00537\ \ \ \ \ \}}
\DoxyCodeLine{00538\ }
\DoxyCodeLine{00539\ \ \ \ \ complex\&\ operator*=(const\ value\_type\&\ real)}
\DoxyCodeLine{00540\ \ \ \ \ \{}
\DoxyCodeLine{00541\ \ \ \ \ \ \ \ \ real\_\ *=\ real;}
\DoxyCodeLine{00542\ \ \ \ \ \ \ \ \ imag\_\ *=\ real;}
\DoxyCodeLine{00543\ \ \ \ \ \ \ \ \ return\ *this;}
\DoxyCodeLine{00544\ \ \ \ \ \}}
\DoxyCodeLine{00545\ }
\DoxyCodeLine{00546\ \ \ \ \ complex\&\ operator/=(const\ value\_type\&\ real)}
\DoxyCodeLine{00547\ \ \ \ \ \{}
\DoxyCodeLine{00548\ \ \ \ \ \ \ \ \ real\_\ /=\ real;}
\DoxyCodeLine{00549\ \ \ \ \ \ \ \ \ imag\_\ /=\ real;}
\DoxyCodeLine{00550\ \ \ \ \ \ \ \ \ return\ *this;}
\DoxyCodeLine{00551\ \ \ \ \ \}}
\DoxyCodeLine{00552\ }
\DoxyCodeLine{00553\ \ \ \ \ template\ <typename\ T>}
\DoxyCodeLine{00554\ \ \ \ \ complex\&\ operator+=(const\ complex<T>\&\ val)}
\DoxyCodeLine{00555\ \ \ \ \ \{}
\DoxyCodeLine{00556\ \ \ \ \ \ \ \ \ real\_\ +=\ val.real();}
\DoxyCodeLine{00557\ \ \ \ \ \ \ \ \ imag\_\ +=\ val.imag();}
\DoxyCodeLine{00558\ \ \ \ \ \ \ \ \ return\ *this;}
\DoxyCodeLine{00559\ \ \ \ \ \}}
\DoxyCodeLine{00560\ }
\DoxyCodeLine{00561\ \ \ \ \ template\ <typename\ T>}
\DoxyCodeLine{00562\ \ \ \ \ complex\&\ operator-\/=(const\ complex<T>\&\ val)}
\DoxyCodeLine{00563\ \ \ \ \ \{}
\DoxyCodeLine{00564\ \ \ \ \ \ \ \ \ real\_\ -\/=\ val.real();}
\DoxyCodeLine{00565\ \ \ \ \ \ \ \ \ imag\_\ -\/=\ val.imag();}
\DoxyCodeLine{00566\ \ \ \ \ \ \ \ \ return\ *this;}
\DoxyCodeLine{00567\ \ \ \ \ \}}
\DoxyCodeLine{00568\ }
\DoxyCodeLine{00569\ \ \ \ \ template\ <typename\ T>}
\DoxyCodeLine{00570\ \ \ \ \ complex\&\ operator*=(const\ complex<T>\&\ val)}
\DoxyCodeLine{00571\ \ \ \ \ \{}
\DoxyCodeLine{00572\ \ \ \ \ \ \ \ \ auto\ val\_f\ =\ static\_cast<std::complex<float>>(val);}
\DoxyCodeLine{00573\ \ \ \ \ \ \ \ \ auto\ result\_f\ =\ static\_cast<std::complex<float>>(*this);}
\DoxyCodeLine{00574\ \ \ \ \ \ \ \ \ result\_f\ *=\ val\_f;}
\DoxyCodeLine{00575\ \ \ \ \ \ \ \ \ real\_\ =\ result\_f.real();}
\DoxyCodeLine{00576\ \ \ \ \ \ \ \ \ imag\_\ =\ result\_f.imag();}
\DoxyCodeLine{00577\ \ \ \ \ \ \ \ \ return\ *this;}
\DoxyCodeLine{00578\ \ \ \ \ \}}
\DoxyCodeLine{00579\ }
\DoxyCodeLine{00580\ \ \ \ \ template\ <typename\ T>}
\DoxyCodeLine{00581\ \ \ \ \ complex\&\ operator/=(const\ complex<T>\&\ val)}
\DoxyCodeLine{00582\ \ \ \ \ \{}
\DoxyCodeLine{00583\ \ \ \ \ \ \ \ \ auto\ val\_f\ =\ static\_cast<std::complex<float>>(val);}
\DoxyCodeLine{00584\ \ \ \ \ \ \ \ \ auto\ result\_f\ =\ static\_cast<std::complex<float>>(*this);}
\DoxyCodeLine{00585\ \ \ \ \ \ \ \ \ result\_f\ /=\ val\_f;}
\DoxyCodeLine{00586\ \ \ \ \ \ \ \ \ real\_\ =\ result\_f.real();}
\DoxyCodeLine{00587\ \ \ \ \ \ \ \ \ imag\_\ =\ result\_f.imag();}
\DoxyCodeLine{00588\ \ \ \ \ \ \ \ \ return\ *this;}
\DoxyCodeLine{00589\ \ \ \ \ \}}
\DoxyCodeLine{00590\ }
\DoxyCodeLine{00591\ \#define\ COMPLEX\_HALF\_OPERATOR(\_op,\ \_opeq)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00592\ \ \ \ \ friend\ complex\ operator\ \_op(const\ complex\&\ lhf,\ const\ complex\&\ rhf)\ \(\backslash\)}
\DoxyCodeLine{00593\ \ \ \ \ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00594\ \ \ \ \ \ \ \ \ auto\ a\ =\ lhf;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00595\ \ \ \ \ \ \ \ \ a\ \_opeq\ rhf;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00596\ \ \ \ \ \ \ \ \ return\ a;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}
\DoxyCodeLine{00597\ \ \ \ \ \}}
\DoxyCodeLine{00598\ }
\DoxyCodeLine{00599\ \ \ \ \ COMPLEX\_HALF\_OPERATOR(+,\ +=)}
\DoxyCodeLine{00600\ \ \ \ \ COMPLEX\_HALF\_OPERATOR(-\/,\ -\/=)}
\DoxyCodeLine{00601\ \ \ \ \ COMPLEX\_HALF\_OPERATOR(*,\ *=)}
\DoxyCodeLine{00602\ \ \ \ \ COMPLEX\_HALF\_OPERATOR(/,\ /=)}
\DoxyCodeLine{00603\ }
\DoxyCodeLine{00604\ \#undef\ COMPLEX\_HALF\_OPERATOR}
\DoxyCodeLine{00605\ }
\DoxyCodeLine{00606\ private:}
\DoxyCodeLine{00607\ \ \ \ \ value\_type\ real\_;}
\DoxyCodeLine{00608\ \ \ \ \ value\_type\ imag\_;}
\DoxyCodeLine{00609\ \};}
\DoxyCodeLine{00610\ }
\DoxyCodeLine{00611\ }
\DoxyCodeLine{00612\ template\ <>}
\DoxyCodeLine{00613\ struct\ numeric\_limits<gko::half>\ \{}
\DoxyCodeLine{00614\ \ \ \ \ static\ constexpr\ bool\ is\_specialized\{true\};}
\DoxyCodeLine{00615\ \ \ \ \ static\ constexpr\ bool\ is\_signed\{true\};}
\DoxyCodeLine{00616\ \ \ \ \ static\ constexpr\ bool\ is\_integer\{false\};}
\DoxyCodeLine{00617\ \ \ \ \ static\ constexpr\ bool\ is\_exact\{false\};}
\DoxyCodeLine{00618\ \ \ \ \ static\ constexpr\ bool\ is\_bounded\{true\};}
\DoxyCodeLine{00619\ \ \ \ \ static\ constexpr\ bool\ is\_modulo\{false\};}
\DoxyCodeLine{00620\ \ \ \ \ static\ constexpr\ int\ digits\{}
\DoxyCodeLine{00621\ \ \ \ \ \ \ \ \ gko::detail::float\_traits<gko::half>::significand\_bits\ +\ 1\};}
\DoxyCodeLine{00622\ \ \ \ \ \textcolor{comment}{//\ 3/10\ is\ approx.\ log\_10(2)}}
\DoxyCodeLine{00623\ \ \ \ \ static\ constexpr\ int\ digits10\{digits\ *\ 3\ /\ 10\};}
\DoxyCodeLine{00624\ }
\DoxyCodeLine{00625\ \ \ \ \ static\ constexpr\ gko::half\ epsilon()}
\DoxyCodeLine{00626\ \ \ \ \ \{}
\DoxyCodeLine{00627\ \ \ \ \ \ \ \ \ constexpr\ auto\ bits\ =\ static\_cast<std::uint16\_t>(0b0'00101'0000000000u);}
\DoxyCodeLine{00628\ \ \ \ \ \ \ \ \ return\ gko::half::create\_from\_bits(bits);}
\DoxyCodeLine{00629\ \ \ \ \ \}}
\DoxyCodeLine{00630\ }
\DoxyCodeLine{00631\ \ \ \ \ static\ constexpr\ gko::half\ infinity()}
\DoxyCodeLine{00632\ \ \ \ \ \{}
\DoxyCodeLine{00633\ \ \ \ \ \ \ \ \ constexpr\ auto\ bits\ =\ static\_cast<std::uint16\_t>(0b0'11111'0000000000u);}
\DoxyCodeLine{00634\ \ \ \ \ \ \ \ \ return\ gko::half::create\_from\_bits(bits);}
\DoxyCodeLine{00635\ \ \ \ \ \}}
\DoxyCodeLine{00636\ }
\DoxyCodeLine{00637\ \ \ \ \ static\ constexpr\ gko::half\ min()}
\DoxyCodeLine{00638\ \ \ \ \ \{}
\DoxyCodeLine{00639\ \ \ \ \ \ \ \ \ constexpr\ auto\ bits\ =\ static\_cast<std::uint16\_t>(0b0'00001'0000000000u);}
\DoxyCodeLine{00640\ \ \ \ \ \ \ \ \ return\ gko::half::create\_from\_bits(bits);}
\DoxyCodeLine{00641\ \ \ \ \ \}}
\DoxyCodeLine{00642\ }
\DoxyCodeLine{00643\ \ \ \ \ static\ constexpr\ gko::half\ max()}
\DoxyCodeLine{00644\ \ \ \ \ \{}
\DoxyCodeLine{00645\ \ \ \ \ \ \ \ \ constexpr\ auto\ bits\ =\ static\_cast<std::uint16\_t>(0b0'11110'1111111111u);}
\DoxyCodeLine{00646\ \ \ \ \ \ \ \ \ return\ gko::half::create\_from\_bits(bits);}
\DoxyCodeLine{00647\ \ \ \ \ \}}
\DoxyCodeLine{00648\ }
\DoxyCodeLine{00649\ \ \ \ \ static\ constexpr\ gko::half\ lowest()}
\DoxyCodeLine{00650\ \ \ \ \ \{}
\DoxyCodeLine{00651\ \ \ \ \ \ \ \ \ constexpr\ auto\ bits\ =\ static\_cast<std::uint16\_t>(0b1'11110'1111111111u);}
\DoxyCodeLine{00652\ \ \ \ \ \ \ \ \ return\ gko::half::create\_from\_bits(bits);}
\DoxyCodeLine{00653\ \ \ \ \ \};}
\DoxyCodeLine{00654\ }
\DoxyCodeLine{00655\ \ \ \ \ static\ constexpr\ gko::half\ quiet\_NaN()}
\DoxyCodeLine{00656\ \ \ \ \ \{}
\DoxyCodeLine{00657\ \ \ \ \ \ \ \ \ constexpr\ auto\ bits\ =\ static\_cast<std::uint16\_t>(0b0'11111'1111111111u);}
\DoxyCodeLine{00658\ \ \ \ \ \ \ \ \ return\ gko::half::create\_from\_bits(bits);}
\DoxyCodeLine{00659\ \ \ \ \ \}}
\DoxyCodeLine{00660\ \};}
\DoxyCodeLine{00661\ }
\DoxyCodeLine{00662\ }
\DoxyCodeLine{00663\ \textcolor{comment}{//\ complex\ using\ a\ template\ on\ operator=\ for\ any\ kind\ of\ complex<T>,\ so\ we\ can}}
\DoxyCodeLine{00664\ \textcolor{comment}{//\ do\ full\ specialization\ for\ half}}
\DoxyCodeLine{00665\ template\ <>}
\DoxyCodeLine{00666\ inline\ complex<double>\&\ complex<double>::operator=(}
\DoxyCodeLine{00667\ \ \ \ \ const\ std::complex<gko::half>\&\ a)}
\DoxyCodeLine{00668\ \{}
\DoxyCodeLine{00669\ \ \ \ \ complex<double>\ t(a.real(),\ a.imag());}
\DoxyCodeLine{00670\ \ \ \ \ operator=(t);}
\DoxyCodeLine{00671\ \ \ \ \ return\ *this;}
\DoxyCodeLine{00672\ \}}
\DoxyCodeLine{00673\ }
\DoxyCodeLine{00674\ }
\DoxyCodeLine{00675\ \textcolor{comment}{//\ For\ MSVC}}
\DoxyCodeLine{00676\ template\ <>}
\DoxyCodeLine{00677\ inline\ complex<float>\&\ complex<float>::operator=(}
\DoxyCodeLine{00678\ \ \ \ \ const\ std::complex<gko::half>\&\ a)}
\DoxyCodeLine{00679\ \{}
\DoxyCodeLine{00680\ \ \ \ \ complex<float>\ t(a.real(),\ a.imag());}
\DoxyCodeLine{00681\ \ \ \ \ operator=(t);}
\DoxyCodeLine{00682\ \ \ \ \ return\ *this;}
\DoxyCodeLine{00683\ \}}
\DoxyCodeLine{00684\ }
\DoxyCodeLine{00685\ }
\DoxyCodeLine{00686\ \}\ \ \textcolor{comment}{//\ namespace\ std}}
\DoxyCodeLine{00687\ }
\DoxyCodeLine{00688\ }
\DoxyCodeLine{00689\ \#endif\ \ \textcolor{comment}{//\ GKO\_PUBLIC\_CORE\_BASE\_HALF\_HPP\_}}

\end{DoxyCode}
