\doxysection{bfloat16.\+hpp}
\hypertarget{bfloat16_8hpp_source}{}\label{bfloat16_8hpp_source}\index{ginkgo/core/base/bfloat16.hpp@{ginkgo/core/base/bfloat16.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\_BFLOAT16\_HPP\_}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#define\ GKO\_PUBLIC\_CORE\_BASE\_BFLOAT16\_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\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/half.hpp>}}
\DoxyCodeLine{00016\ }
\DoxyCodeLine{00017\ }
\DoxyCodeLine{00018\ \textcolor{keyword}{class\ }\_\_nv\_bfloat16;}
\DoxyCodeLine{00019\ \textcolor{keyword}{class\ }hip\_bfloat16;}
\DoxyCodeLine{00020\ \textcolor{keyword}{class\ }\_\_hip\_bfloat16;}
\DoxyCodeLine{00021\ }
\DoxyCodeLine{00022\ }
\DoxyCodeLine{00023\ \textcolor{keyword}{namespace\ }\doxymbox{\hyperlink{namespacegko}{gko}}\ \{}
\DoxyCodeLine{00024\ }
\DoxyCodeLine{00025\ }
\DoxyCodeLine{00026\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1bfloat16}{bfloat16}};}
\DoxyCodeLine{00027\ }
\DoxyCodeLine{00028\ }
\DoxyCodeLine{00029\ \textcolor{keyword}{namespace\ }detail\ \{}
\DoxyCodeLine{00030\ \textcolor{keyword}{template}\ <>}
\DoxyCodeLine{00031\ \textcolor{keyword}{struct\ }basic\_float\_traits<bfloat16>\ \{}
\DoxyCodeLine{00032\ \ \ \ \ \textcolor{keyword}{using\ }type\ =\ bfloat16;}
\DoxyCodeLine{00033\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{int}\ sign\_bits\ =\ 1;}
\DoxyCodeLine{00034\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{int}\ significand\_bits\ =\ 7;}
\DoxyCodeLine{00035\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{int}\ exponent\_bits\ =\ 8;}
\DoxyCodeLine{00036\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{bool}\ rounds\_to\_nearest\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00037\ \};}
\DoxyCodeLine{00038\ }
\DoxyCodeLine{00039\ \textcolor{keyword}{template}\ <>}
\DoxyCodeLine{00040\ \textcolor{keyword}{struct\ }basic\_float\_traits<\_\_nv\_bfloat16>\ \{}
\DoxyCodeLine{00041\ \ \ \ \ \textcolor{keyword}{using\ }type\ =\ \_\_nv\_bfloat16;}
\DoxyCodeLine{00042\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{int}\ sign\_bits\ =\ 1;}
\DoxyCodeLine{00043\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{int}\ significand\_bits\ =\ 7;}
\DoxyCodeLine{00044\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{int}\ exponent\_bits\ =\ 8;}
\DoxyCodeLine{00045\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{bool}\ rounds\_to\_nearest\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00046\ \};}
\DoxyCodeLine{00047\ }
\DoxyCodeLine{00048\ \textcolor{keyword}{template}\ <>}
\DoxyCodeLine{00049\ \textcolor{keyword}{struct\ }basic\_float\_traits<hip\_bfloat16>\ \{}
\DoxyCodeLine{00050\ \ \ \ \ \textcolor{keyword}{using\ }type\ =\ hip\_bfloat16;}
\DoxyCodeLine{00051\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{int}\ sign\_bits\ =\ 1;}
\DoxyCodeLine{00052\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{int}\ significand\_bits\ =\ 7;}
\DoxyCodeLine{00053\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{int}\ exponent\_bits\ =\ 8;}
\DoxyCodeLine{00054\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{bool}\ rounds\_to\_nearest\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00055\ \};}
\DoxyCodeLine{00056\ }
\DoxyCodeLine{00057\ \textcolor{keyword}{template}\ <>}
\DoxyCodeLine{00058\ \textcolor{keyword}{struct\ }basic\_float\_traits<\_\_hip\_bfloat16>\ \{}
\DoxyCodeLine{00059\ \ \ \ \ \textcolor{keyword}{using\ }type\ =\ \_\_hip\_bfloat16;}
\DoxyCodeLine{00060\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{int}\ sign\_bits\ =\ 1;}
\DoxyCodeLine{00061\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{int}\ significand\_bits\ =\ 7;}
\DoxyCodeLine{00062\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{int}\ exponent\_bits\ =\ 8;}
\DoxyCodeLine{00063\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{bool}\ rounds\_to\_nearest\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00064\ \};}
\DoxyCodeLine{00065\ }
\DoxyCodeLine{00066\ }
\DoxyCodeLine{00067\ \}\ \ \textcolor{comment}{//\ namespace\ detail}}
\DoxyCodeLine{00068\ }
\DoxyCodeLine{00069\ }
\DoxyCodeLine{00076\ \textcolor{keyword}{class\ }\textcolor{keyword}{alignas}(std::uint16\_t)\ bfloat16\ \{}
\DoxyCodeLine{00077\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00078\ \ \ \ \ \textcolor{comment}{//\ create\ bfloat16\ value\ from\ the\ bits\ directly.}}
\DoxyCodeLine{00079\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ bfloat16\ create\_from\_bits(}
\DoxyCodeLine{00080\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ std::uint16\_t\&\ bits)\ \textcolor{keyword}{noexcept}}
\DoxyCodeLine{00081\ \ \ \ \ \{}
\DoxyCodeLine{00082\ \ \ \ \ \ \ \ \ bfloat16\ result;}
\DoxyCodeLine{00083\ \ \ \ \ \ \ \ \ result.data\_\ =\ bits;}
\DoxyCodeLine{00084\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ result;}
\DoxyCodeLine{00085\ \ \ \ \ \}}
\DoxyCodeLine{00086\ }
\DoxyCodeLine{00087\ \ \ \ \ \textcolor{comment}{//\ TODO:\ NVHPC\ (host\ side)\ may\ not\ use\ zero\ initialization\ for\ the\ data}}
\DoxyCodeLine{00088\ \ \ \ \ \textcolor{comment}{//\ member\ by\ default\ constructor\ in\ some\ cases.\ Not\ sure\ whether\ it\ is}}
\DoxyCodeLine{00089\ \ \ \ \ \textcolor{comment}{//\ caused\ by\ something\ else\ in\ jacobi\ or\ isai.}}
\DoxyCodeLine{00090\ \ \ \ \ \textcolor{keyword}{constexpr}\ bfloat16()\ noexcept\ :\ data\_(0)\{\};}
\DoxyCodeLine{00091\ }
\DoxyCodeLine{00092\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T,}
\DoxyCodeLine{00093\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ =\ std::enable\_if\_t<std::is\_scalar<T>::value\ ||}
\DoxyCodeLine{00094\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::is\_same\_v<T,\ half>>>}
\DoxyCodeLine{00095\ \ \ \ \ bfloat16(\textcolor{keyword}{const}\ T\&\ val)\ :\ data\_(0)}
\DoxyCodeLine{00096\ \ \ \ \ \{}
\DoxyCodeLine{00097\ \ \ \ \ \ \ \ \ this-\/>float2bfloat16(\textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{float}\textcolor{keyword}{>}(val));}
\DoxyCodeLine{00098\ \ \ \ \ \}}
\DoxyCodeLine{00099\ }
\DoxyCodeLine{00100\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ V>}
\DoxyCodeLine{00101\ \ \ \ \ bfloat16\&\ operator=(\textcolor{keyword}{const}\ V\&\ val)}
\DoxyCodeLine{00102\ \ \ \ \ \{}
\DoxyCodeLine{00103\ \ \ \ \ \ \ \ \ this-\/>float2bfloat16(\textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{float}\textcolor{keyword}{>}(val));}
\DoxyCodeLine{00104\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00105\ \ \ \ \ \}}
\DoxyCodeLine{00106\ }
\DoxyCodeLine{00107\ \ \ \ \ \textcolor{keyword}{operator}\ float()\ \textcolor{keyword}{const}\ \textcolor{keyword}{noexcept}}
\DoxyCodeLine{00108\ \ \ \ \ \{}
\DoxyCodeLine{00109\ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ bits\ =\ bfloat162float(data\_);}
\DoxyCodeLine{00110\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{float}\ ans(0);}
\DoxyCodeLine{00111\ \ \ \ \ \ \ \ \ std::memcpy(\&ans,\ \&bits,\ \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{float}));}
\DoxyCodeLine{00112\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ ans;}
\DoxyCodeLine{00113\ \ \ \ \ \}}
\DoxyCodeLine{00114\ }
\DoxyCodeLine{00115\ \ \ \ \ \textcolor{comment}{//\ can\ not\ use\ bfloat16\ operator\ \_op(const\ bfloat16)\ for\ bfloat16\ +\ bfloat16}}
\DoxyCodeLine{00116\ \ \ \ \ \textcolor{comment}{//\ operation\ will\ cast\ it\ to\ float\ and\ then\ do\ float\ operation\ such\ that\ it}}
\DoxyCodeLine{00117\ \ \ \ \ \textcolor{comment}{//\ becomes\ float\ in\ the\ end.}}
\DoxyCodeLine{00118\ \textcolor{preprocessor}{\#define\ BFLOAT16\_OPERATOR(\_op,\ \_opeq)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00119\ \textcolor{preprocessor}{\ \ \ \ friend\ bfloat16\ operator\ \_op(const\ bfloat16\&\ lhf,\ const\ bfloat16\&\ rhf)\ \(\backslash\)}}
\DoxyCodeLine{00120\ \textcolor{preprocessor}{\ \ \ \ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00121\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ return\ static\_cast<bfloat16>(static\_cast<float>(lhf)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00122\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_op\ static\_cast<float>(rhf));\ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00123\ \textcolor{preprocessor}{\ \ \ \ \}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00124\ \textcolor{preprocessor}{\ \ \ \ bfloat16\&\ operator\ \_opeq(const\ bfloat16\&\ hf)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00125\ \textcolor{preprocessor}{\ \ \ \ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00126\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ auto\ result\ =\ *this\ \_op\ hf;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00127\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ data\_\ =\ result.data\_;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00128\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ return\ *this;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00129\ \textcolor{preprocessor}{\ \ \ \ \}}}
\DoxyCodeLine{00130\ }
\DoxyCodeLine{00131\ \ \ \ \ BFLOAT16\_OPERATOR(+,\ +=)}
\DoxyCodeLine{00132\ \ \ \ \ BFLOAT16\_OPERATOR(-\/,\ -\/=)}
\DoxyCodeLine{00133\ \ \ \ \ BFLOAT16\_OPERATOR(*,\ *=)}
\DoxyCodeLine{00134\ \ \ \ \ BFLOAT16\_OPERATOR(/,\ /=)}
\DoxyCodeLine{00135\ }
\DoxyCodeLine{00136\ \textcolor{preprocessor}{\#undef\ BFLOAT16\_OPERATOR}}
\DoxyCodeLine{00137\ }
\DoxyCodeLine{00138\ \ \ \ \ \textcolor{comment}{//\ Do\ operation\ with\ different\ type}}
\DoxyCodeLine{00139\ \ \ \ \ \textcolor{comment}{//\ If\ it\ is\ floating\ point,\ using\ floating\ point\ as\ type.}}
\DoxyCodeLine{00140\ \ \ \ \ \textcolor{comment}{//\ If\ it\ is\ bfloat16,\ using\ float\ as\ type.}}
\DoxyCodeLine{00141\ \ \ \ \ \textcolor{comment}{//\ If\ it\ is\ integer,\ using\ bfloat16\ as\ type.}}
\DoxyCodeLine{00142\ \textcolor{preprocessor}{\#define\ BFLOAT16\_FRIEND\_OPERATOR(\_op,\ \_opeq)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00143\ \textcolor{preprocessor}{\ \ \ \ template\ <typename\ T>\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00144\ \textcolor{preprocessor}{\ \ \ \ friend\ std::enable\_if\_t<\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00145\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ !std::is\_same<T,\ bfloat16>::value\ \&\&\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00146\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ (std::is\_scalar<T>::value\ ||\ std::is\_same\_v<T,\ half>),\ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00147\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ std::conditional\_t<\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00148\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ std::is\_floating\_point<T>::value,\ T,\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00149\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ std::conditional\_t<std::is\_same\_v<T,\ half>,\ float,\ bfloat16>>>\ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00150\ \textcolor{preprocessor}{\ \ \ \ operator\ \_op(const\ bfloat16\&\ hf,\ const\ T\&\ val)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00151\ \textcolor{preprocessor}{\ \ \ \ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00152\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ using\ type\ =\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00153\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ std::conditional\_t<std::is\_floating\_point<T>::value,\ T,\ bfloat16>;\ \(\backslash\)}}
\DoxyCodeLine{00154\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ auto\ result\ =\ static\_cast<type>(hf);\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00155\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ result\ \_opeq\ static\_cast<type>(val);\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00156\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ return\ result;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00157\ \textcolor{preprocessor}{\ \ \ \ \}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00158\ \textcolor{preprocessor}{\ \ \ \ template\ <typename\ T>\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00159\ \textcolor{preprocessor}{\ \ \ \ friend\ std::enable\_if\_t<\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00160\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ !std::is\_same<T,\ bfloat16>::value\ \&\&\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00161\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ (std::is\_scalar<T>::value\ ||\ std::is\_same\_v<T,\ half>),\ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00162\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ std::conditional\_t<\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00163\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ std::is\_floating\_point<T>::value,\ T,\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00164\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ std::conditional\_t<std::is\_same\_v<T,\ half>,\ float,\ bfloat16>>>\ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00165\ \textcolor{preprocessor}{\ \ \ \ operator\ \_op(const\ T\&\ val,\ const\ bfloat16\&\ hf)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00166\ \textcolor{preprocessor}{\ \ \ \ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00167\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ using\ type\ =\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00168\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ \ \ \ \ std::conditional\_t<std::is\_floating\_point<T>::value,\ T,\ bfloat16>;\ \(\backslash\)}}
\DoxyCodeLine{00169\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ auto\ result\ =\ static\_cast<type>(val);\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00170\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ result\ \_opeq\ static\_cast<type>(hf);\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00171\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ return\ result;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00172\ \textcolor{preprocessor}{\ \ \ \ \}}}
\DoxyCodeLine{00173\ }
\DoxyCodeLine{00174\ \ \ \ \ BFLOAT16\_FRIEND\_OPERATOR(+,\ +=)}
\DoxyCodeLine{00175\ \ \ \ \ BFLOAT16\_FRIEND\_OPERATOR(-\/,\ -\/=)}
\DoxyCodeLine{00176\ \ \ \ \ BFLOAT16\_FRIEND\_OPERATOR(*,\ *=)}
\DoxyCodeLine{00177\ \ \ \ \ BFLOAT16\_FRIEND\_OPERATOR(/,\ /=)}
\DoxyCodeLine{00178\ }
\DoxyCodeLine{00179\ \textcolor{preprocessor}{\#undef\ BFLOAT16\_FRIEND\_OPERATOR}}
\DoxyCodeLine{00180\ }
\DoxyCodeLine{00181\ \ \ \ \ \textcolor{comment}{//\ the\ negative}}
\DoxyCodeLine{00182\ \ \ \ \ bfloat16\ operator-\/()\textcolor{keyword}{\ const}}
\DoxyCodeLine{00183\ \textcolor{keyword}{\ \ \ \ }\{}
\DoxyCodeLine{00184\ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ val\ =\ 0.0f\ -\/\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00185\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{static\_cast<}bfloat16\textcolor{keyword}{>}(val);}
\DoxyCodeLine{00186\ \ \ \ \ \}}
\DoxyCodeLine{00187\ }
\DoxyCodeLine{00188\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00189\ \ \ \ \ \textcolor{keyword}{using\ }f16\_traits\ =\ detail::float\_traits<bfloat16>;}
\DoxyCodeLine{00190\ \ \ \ \ \textcolor{keyword}{using\ }f32\_traits\ =\ detail::float\_traits<float>;}
\DoxyCodeLine{00191\ }
\DoxyCodeLine{00192\ \ \ \ \ \textcolor{keywordtype}{void}\ float2bfloat16(\textcolor{keyword}{const}\ \textcolor{keywordtype}{float}\&\ val)\ \textcolor{keyword}{noexcept}}
\DoxyCodeLine{00193\ \ \ \ \ \{}
\DoxyCodeLine{00194\ \ \ \ \ \ \ \ \ std::uint32\_t\ bit\_val(0);}
\DoxyCodeLine{00195\ \ \ \ \ \ \ \ \ std::memcpy(\&bit\_val,\ \&val,\ \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{float}));}
\DoxyCodeLine{00196\ \ \ \ \ \ \ \ \ data\_\ =\ float2bfloat16(bit\_val);}
\DoxyCodeLine{00197\ \ \ \ \ \}}
\DoxyCodeLine{00198\ }
\DoxyCodeLine{00199\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ std::uint16\_t\ float2bfloat16(std::uint32\_t\ data\_)\ \textcolor{keyword}{noexcept}}
\DoxyCodeLine{00200\ \ \ \ \ \{}
\DoxyCodeLine{00201\ \ \ \ \ \ \ \ \ \textcolor{keyword}{using\ }conv\ =\ detail::precision\_converter<float,\ bfloat16>;}
\DoxyCodeLine{00202\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (f32\_traits::is\_inf(data\_))\ \{}
\DoxyCodeLine{00203\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ conv::shift\_sign(data\_)\ |\ f16\_traits::exponent\_mask;}
\DoxyCodeLine{00204\ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (f32\_traits::is\_nan(data\_))\ \{}
\DoxyCodeLine{00205\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ conv::shift\_sign(data\_)\ |\ f16\_traits::exponent\_mask\ |}
\DoxyCodeLine{00206\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f16\_traits::significand\_mask;}
\DoxyCodeLine{00207\ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00208\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ exp\ =\ conv::shift\_exponent(data\_);}
\DoxyCodeLine{00209\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (f16\_traits::is\_inf(exp))\ \{}
\DoxyCodeLine{00210\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ conv::shift\_sign(data\_)\ |\ exp;}
\DoxyCodeLine{00211\ \ \ \ \ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (f16\_traits::is\_denom(exp))\ \{}
\DoxyCodeLine{00212\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ TODO:\ handle\ denormals}}
\DoxyCodeLine{00213\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ conv::shift\_sign(data\_);}
\DoxyCodeLine{00214\ \ \ \ \ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00215\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ Rounding\ to\ even}}
\DoxyCodeLine{00216\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ result\ =\ conv::shift\_sign(data\_)\ |\ exp\ |}
\DoxyCodeLine{00217\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ conv::shift\_significand(data\_);}
\DoxyCodeLine{00218\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{auto}\ tail\ =}
\DoxyCodeLine{00219\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ data\_\ \&\ \textcolor{keyword}{static\_cast<}f32\_traits::bits\_type\textcolor{keyword}{>}(}
\DoxyCodeLine{00220\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (1\ <<\ conv::significand\_offset)\ -\/\ 1);}
\DoxyCodeLine{00221\ }
\DoxyCodeLine{00222\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{auto}\ bfloat16\ =\ \textcolor{keyword}{static\_cast<}f32\_traits::bits\_type\textcolor{keyword}{>}(}
\DoxyCodeLine{00223\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 1\ <<\ (conv::significand\_offset\ -\/\ 1));}
\DoxyCodeLine{00224\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ result\ +\ (tail\ >\ bfloat16\ ||}
\DoxyCodeLine{00225\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ((tail\ ==\ bfloat16)\ \&\&\ (result\ \&\ 1)));}
\DoxyCodeLine{00226\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00227\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00228\ \ \ \ \ \}}
\DoxyCodeLine{00229\ }
\DoxyCodeLine{00230\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ std::uint32\_t\ bfloat162float(std::uint16\_t\ data\_)\ \textcolor{keyword}{noexcept}}
\DoxyCodeLine{00231\ \ \ \ \ \{}
\DoxyCodeLine{00232\ \ \ \ \ \ \ \ \ \textcolor{keyword}{using\ }conv\ =\ detail::precision\_converter<bfloat16,\ float>;}
\DoxyCodeLine{00233\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (f16\_traits::is\_inf(data\_))\ \{}
\DoxyCodeLine{00234\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ conv::shift\_sign(data\_)\ |\ f32\_traits::exponent\_mask;}
\DoxyCodeLine{00235\ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (f16\_traits::is\_nan(data\_))\ \{}
\DoxyCodeLine{00236\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ conv::shift\_sign(data\_)\ |\ f32\_traits::exponent\_mask\ |}
\DoxyCodeLine{00237\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ f32\_traits::significand\_mask;}
\DoxyCodeLine{00238\ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (f16\_traits::is\_denom(data\_))\ \{}
\DoxyCodeLine{00239\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ TODO:\ handle\ denormals}}
\DoxyCodeLine{00240\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ conv::shift\_sign(data\_);}
\DoxyCodeLine{00241\ \ \ \ \ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00242\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ conv::shift\_sign(data\_)\ |\ conv::shift\_exponent(data\_)\ |}
\DoxyCodeLine{00243\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ conv::shift\_significand(data\_);}
\DoxyCodeLine{00244\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00245\ \ \ \ \ \}}
\DoxyCodeLine{00246\ }
\DoxyCodeLine{00247\ \ \ \ \ std::uint16\_t\ data\_;}
\DoxyCodeLine{00248\ \};}
\DoxyCodeLine{00249\ }
\DoxyCodeLine{00250\ }
\DoxyCodeLine{00251\ \}\ \ \textcolor{comment}{//\ namespace\ gko}}
\DoxyCodeLine{00252\ }
\DoxyCodeLine{00253\ }
\DoxyCodeLine{00254\ \textcolor{keyword}{namespace\ }\doxymbox{\hyperlink{namespacestd}{std}}\ \{}
\DoxyCodeLine{00255\ }
\DoxyCodeLine{00256\ }
\DoxyCodeLine{00257\ \textcolor{keyword}{template}\ <>}
\DoxyCodeLine{00258\ \textcolor{keyword}{class\ }complex<\doxymbox{\hyperlink{namespacegko}{gko}}::bfloat16>\ \{}
\DoxyCodeLine{00259\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00260\ \ \ \ \ \textcolor{keyword}{using\ }value\_type\ =\ \doxymbox{\hyperlink{classgko_1_1bfloat16}{gko::bfloat16}};}
\DoxyCodeLine{00261\ }
\DoxyCodeLine{00262\ \ \ \ \ complex(\textcolor{keyword}{const}\ value\_type\&\ real\ =\ value\_type(0.f),}
\DoxyCodeLine{00263\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ value\_type\&\ imag\ =\ value\_type(0.f))}
\DoxyCodeLine{00264\ \ \ \ \ \ \ \ \ :\ real\_(real),\ imag\_(imag)}
\DoxyCodeLine{00265\ \ \ \ \ \{\}}
\DoxyCodeLine{00266\ }
\DoxyCodeLine{00267\ \ \ \ \ \textcolor{keyword}{template}\ <}
\DoxyCodeLine{00268\ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ T,\ \textcolor{keyword}{typename}\ U,}
\DoxyCodeLine{00269\ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ =\ std::enable\_if\_t<}
\DoxyCodeLine{00270\ \ \ \ \ \ \ \ \ \ \ \ \ (std::is\_scalar<T>::value\ ||\ std::is\_same\_v<T,\ gko::half>)\&\&(}
\DoxyCodeLine{00271\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::is\_scalar<U>::value\ ||\ std::is\_same\_v<U,\ gko::half>)>>}
\DoxyCodeLine{00272\ \ \ \ \ \textcolor{keyword}{explicit}\ complex(\textcolor{keyword}{const}\ T\&\ real,\ \textcolor{keyword}{const}\ U\&\ imag)}
\DoxyCodeLine{00273\ \ \ \ \ \ \ \ \ :\ real\_(static\_cast<value\_type>(\doxymbox{\hyperlink{namespacegko_af21648097306adbabc6234b4609ce297}{real}})),}
\DoxyCodeLine{00274\ \ \ \ \ \ \ \ \ \ \ imag\_(static\_cast<value\_type>(\doxymbox{\hyperlink{namespacegko_a795f649e3744fbfe128aec0b0f928aaa}{imag}}))}
\DoxyCodeLine{00275\ \ \ \ \ \{\}}
\DoxyCodeLine{00276\ }
\DoxyCodeLine{00277\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T,}
\DoxyCodeLine{00278\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ =\ std::enable\_if\_t<std::is\_scalar<T>::value\ ||}
\DoxyCodeLine{00279\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::is\_same\_v<T,\ gko::half>>>}
\DoxyCodeLine{00280\ \ \ \ \ complex(\textcolor{keyword}{const}\ T\&\ real)}
\DoxyCodeLine{00281\ \ \ \ \ \ \ \ \ :\ real\_(static\_cast<value\_type>(\doxymbox{\hyperlink{namespacegko_af21648097306adbabc6234b4609ce297}{real}})),}
\DoxyCodeLine{00282\ \ \ \ \ \ \ \ \ \ \ imag\_(static\_cast<value\_type>(0.f))}
\DoxyCodeLine{00283\ \ \ \ \ \{\}}
\DoxyCodeLine{00284\ }
\DoxyCodeLine{00285\ \ \ \ \ \textcolor{comment}{//\ When\ using\ complex(real,\ imag),\ MSVC\ with\ CUDA\ try\ to\ recognize\ the}}
\DoxyCodeLine{00286\ \ \ \ \ \textcolor{comment}{//\ complex\ is\ a\ member\ not\ constructor.}}
\DoxyCodeLine{00287\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T,}
\DoxyCodeLine{00288\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{typename}\ =\ std::enable\_if\_t<std::is\_scalar<T>::value\ ||}
\DoxyCodeLine{00289\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ std::is\_same\_v<T,\ gko::half>>>}
\DoxyCodeLine{00290\ \ \ \ \ \textcolor{keyword}{explicit}\ complex(\textcolor{keyword}{const}\ complex<T>\&\ other)}
\DoxyCodeLine{00291\ \ \ \ \ \ \ \ \ :\ real\_(static\_cast<value\_type>(other.\doxymbox{\hyperlink{namespacegko_af21648097306adbabc6234b4609ce297}{real}}())),}
\DoxyCodeLine{00292\ \ \ \ \ \ \ \ \ \ \ imag\_(static\_cast<value\_type>(other.\doxymbox{\hyperlink{namespacegko_a795f649e3744fbfe128aec0b0f928aaa}{imag}}()))}
\DoxyCodeLine{00293\ \ \ \ \ \{\}}
\DoxyCodeLine{00294\ }
\DoxyCodeLine{00295\ \ \ \ \ value\_type\ \doxymbox{\hyperlink{namespacegko_af21648097306adbabc6234b4609ce297}{real}}()\ const\ noexcept\ \{\ \textcolor{keywordflow}{return}\ real\_;\ \}}
\DoxyCodeLine{00296\ }
\DoxyCodeLine{00297\ \ \ \ \ value\_type\ \doxymbox{\hyperlink{namespacegko_a795f649e3744fbfe128aec0b0f928aaa}{imag}}()\ const\ noexcept\ \{\ \textcolor{keywordflow}{return}\ imag\_;\ \}}
\DoxyCodeLine{00298\ }
\DoxyCodeLine{00299\ \ \ \ \ \textcolor{keyword}{operator}\ std::complex<float>()\ const\ noexcept}
\DoxyCodeLine{00300\ \ \ \ \ \{}
\DoxyCodeLine{00301\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ std::complex<float>(\textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{float}\textcolor{keyword}{>}(real\_),}
\DoxyCodeLine{00302\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{float}\textcolor{keyword}{>}(imag\_));}
\DoxyCodeLine{00303\ \ \ \ \ \}}
\DoxyCodeLine{00304\ }
\DoxyCodeLine{00305\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ V>}
\DoxyCodeLine{00306\ \ \ \ \ complex\&\ operator=(\textcolor{keyword}{const}\ V\&\ val)}
\DoxyCodeLine{00307\ \ \ \ \ \{}
\DoxyCodeLine{00308\ \ \ \ \ \ \ \ \ real\_\ =\ val;}
\DoxyCodeLine{00309\ \ \ \ \ \ \ \ \ imag\_\ =\ value\_type();}
\DoxyCodeLine{00310\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00311\ \ \ \ \ \}}
\DoxyCodeLine{00312\ }
\DoxyCodeLine{00313\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ V>}
\DoxyCodeLine{00314\ \ \ \ \ complex\&\ operator=(\textcolor{keyword}{const}\ std::complex<V>\&\ val)}
\DoxyCodeLine{00315\ \ \ \ \ \{}
\DoxyCodeLine{00316\ \ \ \ \ \ \ \ \ real\_\ =\ val.real();}
\DoxyCodeLine{00317\ \ \ \ \ \ \ \ \ imag\_\ =\ val.imag();}
\DoxyCodeLine{00318\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00319\ \ \ \ \ \}}
\DoxyCodeLine{00320\ }
\DoxyCodeLine{00321\ \ \ \ \ complex\&\ operator+=(\textcolor{keyword}{const}\ value\_type\&\ real)}
\DoxyCodeLine{00322\ \ \ \ \ \{}
\DoxyCodeLine{00323\ \ \ \ \ \ \ \ \ real\_\ +=\ \doxymbox{\hyperlink{namespacegko_af21648097306adbabc6234b4609ce297}{real}};}
\DoxyCodeLine{00324\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00325\ \ \ \ \ \}}
\DoxyCodeLine{00326\ }
\DoxyCodeLine{00327\ \ \ \ \ complex\&\ operator-\/=(\textcolor{keyword}{const}\ value\_type\&\ real)}
\DoxyCodeLine{00328\ \ \ \ \ \{}
\DoxyCodeLine{00329\ \ \ \ \ \ \ \ \ real\_\ -\/=\ \doxymbox{\hyperlink{namespacegko_af21648097306adbabc6234b4609ce297}{real}};}
\DoxyCodeLine{00330\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00331\ \ \ \ \ \}}
\DoxyCodeLine{00332\ }
\DoxyCodeLine{00333\ \ \ \ \ complex\&\ operator*=(\textcolor{keyword}{const}\ value\_type\&\ real)}
\DoxyCodeLine{00334\ \ \ \ \ \{}
\DoxyCodeLine{00335\ \ \ \ \ \ \ \ \ real\_\ *=\ \doxymbox{\hyperlink{namespacegko_af21648097306adbabc6234b4609ce297}{real}};}
\DoxyCodeLine{00336\ \ \ \ \ \ \ \ \ imag\_\ *=\ \doxymbox{\hyperlink{namespacegko_af21648097306adbabc6234b4609ce297}{real}};}
\DoxyCodeLine{00337\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00338\ \ \ \ \ \}}
\DoxyCodeLine{00339\ }
\DoxyCodeLine{00340\ \ \ \ \ complex\&\ operator/=(\textcolor{keyword}{const}\ value\_type\&\ real)}
\DoxyCodeLine{00341\ \ \ \ \ \{}
\DoxyCodeLine{00342\ \ \ \ \ \ \ \ \ real\_\ /=\ \doxymbox{\hyperlink{namespacegko_af21648097306adbabc6234b4609ce297}{real}};}
\DoxyCodeLine{00343\ \ \ \ \ \ \ \ \ imag\_\ /=\ \doxymbox{\hyperlink{namespacegko_af21648097306adbabc6234b4609ce297}{real}};}
\DoxyCodeLine{00344\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00345\ \ \ \ \ \}}
\DoxyCodeLine{00346\ }
\DoxyCodeLine{00347\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00348\ \ \ \ \ complex\&\ operator+=(\textcolor{keyword}{const}\ complex<T>\&\ val)}
\DoxyCodeLine{00349\ \ \ \ \ \{}
\DoxyCodeLine{00350\ \ \ \ \ \ \ \ \ real\_\ +=\ val.real();}
\DoxyCodeLine{00351\ \ \ \ \ \ \ \ \ imag\_\ +=\ val.imag();}
\DoxyCodeLine{00352\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00353\ \ \ \ \ \}}
\DoxyCodeLine{00354\ }
\DoxyCodeLine{00355\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00356\ \ \ \ \ complex\&\ operator-\/=(\textcolor{keyword}{const}\ complex<T>\&\ val)}
\DoxyCodeLine{00357\ \ \ \ \ \{}
\DoxyCodeLine{00358\ \ \ \ \ \ \ \ \ real\_\ -\/=\ val.real();}
\DoxyCodeLine{00359\ \ \ \ \ \ \ \ \ imag\_\ -\/=\ val.imag();}
\DoxyCodeLine{00360\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00361\ \ \ \ \ \}}
\DoxyCodeLine{00362\ }
\DoxyCodeLine{00363\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00364\ \ \ \ \ complex\&\ operator*=(\textcolor{keyword}{const}\ complex<T>\&\ val)}
\DoxyCodeLine{00365\ \ \ \ \ \{}
\DoxyCodeLine{00366\ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ val\_f\ =\ \textcolor{keyword}{static\_cast<}std::complex<float>\textcolor{keyword}{>}(val);}
\DoxyCodeLine{00367\ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ result\_f\ =\ \textcolor{keyword}{static\_cast<}std::complex<float>\textcolor{keyword}{>}(*this);}
\DoxyCodeLine{00368\ \ \ \ \ \ \ \ \ result\_f\ *=\ val\_f;}
\DoxyCodeLine{00369\ \ \ \ \ \ \ \ \ real\_\ =\ result\_f.real();}
\DoxyCodeLine{00370\ \ \ \ \ \ \ \ \ imag\_\ =\ result\_f.imag();}
\DoxyCodeLine{00371\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00372\ \ \ \ \ \}}
\DoxyCodeLine{00373\ }
\DoxyCodeLine{00374\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00375\ \ \ \ \ complex\&\ operator/=(\textcolor{keyword}{const}\ complex<T>\&\ val)}
\DoxyCodeLine{00376\ \ \ \ \ \{}
\DoxyCodeLine{00377\ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ val\_f\ =\ \textcolor{keyword}{static\_cast<}std::complex<float>\textcolor{keyword}{>}(val);}
\DoxyCodeLine{00378\ \ \ \ \ \ \ \ \ \textcolor{keyword}{auto}\ result\_f\ =\ \textcolor{keyword}{static\_cast<}std::complex<float>\textcolor{keyword}{>}(*this);}
\DoxyCodeLine{00379\ \ \ \ \ \ \ \ \ result\_f\ /=\ val\_f;}
\DoxyCodeLine{00380\ \ \ \ \ \ \ \ \ real\_\ =\ result\_f.real();}
\DoxyCodeLine{00381\ \ \ \ \ \ \ \ \ imag\_\ =\ result\_f.imag();}
\DoxyCodeLine{00382\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00383\ \ \ \ \ \}}
\DoxyCodeLine{00384\ }
\DoxyCodeLine{00385\ \textcolor{preprocessor}{\#define\ COMPLEX\_BFLOAT16\_OPERATOR(\_op,\ \_opeq)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00386\ \textcolor{preprocessor}{\ \ \ \ friend\ complex\ operator\ \_op(const\ complex\&\ lhf,\ const\ complex\&\ rhf)\ \(\backslash\)}}
\DoxyCodeLine{00387\ \textcolor{preprocessor}{\ \ \ \ \{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00388\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ auto\ a\ =\ lhf;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00389\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ a\ \_opeq\ rhf;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00390\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ return\ a;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \(\backslash\)}}
\DoxyCodeLine{00391\ \textcolor{preprocessor}{\ \ \ \ \}}}
\DoxyCodeLine{00392\ }
\DoxyCodeLine{00393\ \ \ \ \ COMPLEX\_BFLOAT16\_OPERATOR(+,\ +=)}
\DoxyCodeLine{00394\ \ \ \ \ COMPLEX\_BFLOAT16\_OPERATOR(-\/,\ -\/=)}
\DoxyCodeLine{00395\ \ \ \ \ COMPLEX\_BFLOAT16\_OPERATOR(*,\ *=)}
\DoxyCodeLine{00396\ \ \ \ \ COMPLEX\_BFLOAT16\_OPERATOR(/,\ /=)}
\DoxyCodeLine{00397\ }
\DoxyCodeLine{00398\ \textcolor{preprocessor}{\#undef\ COMPLEX\_BFLOAT16\_OPERATOR}}
\DoxyCodeLine{00399\ }
\DoxyCodeLine{00400\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00401\ \ \ \ \ value\_type\ real\_;}
\DoxyCodeLine{00402\ \ \ \ \ value\_type\ imag\_;}
\DoxyCodeLine{00403\ \};}
\DoxyCodeLine{00404\ }
\DoxyCodeLine{00405\ }
\DoxyCodeLine{00406\ \textcolor{keyword}{template}\ <>}
\DoxyCodeLine{00407\ \textcolor{keyword}{struct\ }numeric\_limits<gko::bfloat16>\ \{}
\DoxyCodeLine{00408\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{bool}\ is\_specialized\{\textcolor{keyword}{true}\};}
\DoxyCodeLine{00409\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{bool}\ is\_signed\{\textcolor{keyword}{true}\};}
\DoxyCodeLine{00410\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{bool}\ is\_integer\{\textcolor{keyword}{false}\};}
\DoxyCodeLine{00411\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{bool}\ is\_exact\{\textcolor{keyword}{false}\};}
\DoxyCodeLine{00412\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{bool}\ is\_bounded\{\textcolor{keyword}{true}\};}
\DoxyCodeLine{00413\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{bool}\ is\_modulo\{\textcolor{keyword}{false}\};}
\DoxyCodeLine{00414\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{int}\ digits\{}
\DoxyCodeLine{00415\ \ \ \ \ \ \ \ \ gko::detail::float\_traits<gko::bfloat16>::significand\_bits\ +\ 1\};}
\DoxyCodeLine{00416\ \ \ \ \ \textcolor{comment}{//\ 3/10\ is\ approx.\ log\_10(2)}}
\DoxyCodeLine{00417\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ \textcolor{keywordtype}{int}\ digits10\{digits\ *\ 3\ /\ 10\};}
\DoxyCodeLine{00418\ }
\DoxyCodeLine{00419\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ gko::bfloat16\ epsilon()}
\DoxyCodeLine{00420\ \ \ \ \ \{}
\DoxyCodeLine{00421\ \ \ \ \ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{auto}\ bits\ =\ \textcolor{keyword}{static\_cast<}std::uint16\_t\textcolor{keyword}{>}(0b0'01111000'0000000u);}
\DoxyCodeLine{00422\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::bfloat16::create\_from\_bits(bits);}
\DoxyCodeLine{00423\ \ \ \ \ \}}
\DoxyCodeLine{00424\ }
\DoxyCodeLine{00425\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ gko::bfloat16\ infinity()}
\DoxyCodeLine{00426\ \ \ \ \ \{}
\DoxyCodeLine{00427\ \ \ \ \ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{auto}\ bits\ =\ \textcolor{keyword}{static\_cast<}std::uint16\_t\textcolor{keyword}{>}(0b0'11111111'0000000u);}
\DoxyCodeLine{00428\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::bfloat16::create\_from\_bits(bits);}
\DoxyCodeLine{00429\ \ \ \ \ \}}
\DoxyCodeLine{00430\ }
\DoxyCodeLine{00431\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ gko::bfloat16\ \doxymbox{\hyperlink{namespacegko_aaaf8487194bcb40b528969c187a413a0}{min}}()}
\DoxyCodeLine{00432\ \ \ \ \ \{}
\DoxyCodeLine{00433\ \ \ \ \ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{auto}\ bits\ =\ \textcolor{keyword}{static\_cast<}std::uint16\_t\textcolor{keyword}{>}(0b0'00000001'0000000u);}
\DoxyCodeLine{00434\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::bfloat16::create\_from\_bits(bits);}
\DoxyCodeLine{00435\ \ \ \ \ \}}
\DoxyCodeLine{00436\ }
\DoxyCodeLine{00437\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ gko::bfloat16\ \doxymbox{\hyperlink{namespacegko_af1812df45c6ec07780d579a12b64c753}{max}}()}
\DoxyCodeLine{00438\ \ \ \ \ \{}
\DoxyCodeLine{00439\ \ \ \ \ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{auto}\ bits\ =\ \textcolor{keyword}{static\_cast<}std::uint16\_t\textcolor{keyword}{>}(0b0'11111110'1111111u);}
\DoxyCodeLine{00440\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::bfloat16::create\_from\_bits(bits);}
\DoxyCodeLine{00441\ \ \ \ \ \}}
\DoxyCodeLine{00442\ }
\DoxyCodeLine{00443\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ gko::bfloat16\ lowest()}
\DoxyCodeLine{00444\ \ \ \ \ \{}
\DoxyCodeLine{00445\ \ \ \ \ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{auto}\ bits\ =\ \textcolor{keyword}{static\_cast<}std::uint16\_t\textcolor{keyword}{>}(0b1'11111110'1111111u);}
\DoxyCodeLine{00446\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::bfloat16::create\_from\_bits(bits);}
\DoxyCodeLine{00447\ \ \ \ \ \};}
\DoxyCodeLine{00448\ }
\DoxyCodeLine{00449\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{constexpr}\ gko::bfloat16\ quiet\_NaN()}
\DoxyCodeLine{00450\ \ \ \ \ \{}
\DoxyCodeLine{00451\ \ \ \ \ \ \ \ \ \textcolor{keyword}{constexpr}\ \textcolor{keyword}{auto}\ bits\ =\ \textcolor{keyword}{static\_cast<}std::uint16\_t\textcolor{keyword}{>}(0b0'11111111'1111111u);}
\DoxyCodeLine{00452\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ gko::bfloat16::create\_from\_bits(bits);}
\DoxyCodeLine{00453\ \ \ \ \ \}}
\DoxyCodeLine{00454\ \};}
\DoxyCodeLine{00455\ }
\DoxyCodeLine{00456\ }
\DoxyCodeLine{00457\ \textcolor{comment}{//\ complex\ using\ a\ template\ on\ operator=\ for\ any\ kind\ of\ complex<T>,\ so\ we\ can}}
\DoxyCodeLine{00458\ \textcolor{comment}{//\ do\ full\ specialization\ for\ bfloat16}}
\DoxyCodeLine{00459\ \textcolor{keyword}{template}\ <>}
\DoxyCodeLine{00460\ \textcolor{keyword}{inline}\ complex<double>\&\ complex<double>::operator=(}
\DoxyCodeLine{00461\ \ \ \ \ \textcolor{keyword}{const}\ std::complex<gko::bfloat16>\&\ a)}
\DoxyCodeLine{00462\ \{}
\DoxyCodeLine{00463\ \ \ \ \ complex<double>\ t(a.real(),\ a.imag());}
\DoxyCodeLine{00464\ \ \ \ \ \doxymbox{\hyperlink{namespacegko_1_1solver_ae5760acd16e9a702da395d689f237b33}{operator=}}(t);}
\DoxyCodeLine{00465\ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00466\ \}}
\DoxyCodeLine{00467\ }
\DoxyCodeLine{00468\ }
\DoxyCodeLine{00469\ \textcolor{comment}{//\ For\ MSVC}}
\DoxyCodeLine{00470\ \textcolor{keyword}{template}\ <>}
\DoxyCodeLine{00471\ \textcolor{keyword}{inline}\ complex<float>\&\ complex<float>::operator=(}
\DoxyCodeLine{00472\ \ \ \ \ \textcolor{keyword}{const}\ std::complex<gko::bfloat16>\&\ a)}
\DoxyCodeLine{00473\ \{}
\DoxyCodeLine{00474\ \ \ \ \ complex<float>\ t(a.real(),\ a.imag());}
\DoxyCodeLine{00475\ \ \ \ \ \doxymbox{\hyperlink{namespacegko_1_1solver_ae5760acd16e9a702da395d689f237b33}{operator=}}(t);}
\DoxyCodeLine{00476\ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00477\ \}}
\DoxyCodeLine{00478\ }
\DoxyCodeLine{00479\ }
\DoxyCodeLine{00480\ \}\ \ \textcolor{comment}{//\ namespace\ std}}
\DoxyCodeLine{00481\ }
\DoxyCodeLine{00482\ }
\DoxyCodeLine{00483\ \textcolor{preprocessor}{\#endif\ \ }\textcolor{comment}{//\ GKO\_PUBLIC\_CORE\_BASE\_bfloat16\_HPP\_}}

\end{DoxyCode}
