Blaze  3.6
InvSqrt.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_SHIMS_INVSQRT_H_
36 #define _BLAZE_MATH_SHIMS_INVSQRT_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
44 #include <blaze/math/shims/Sqrt.h>
45 #include <blaze/util/Assert.h>
46 #include <blaze/util/Complex.h>
47 #include <blaze/util/EnableIf.h>
49 
50 
51 namespace blaze {
52 
53 //=================================================================================================
54 //
55 // INVSQRT SHIM
56 //
57 //=================================================================================================
58 
59 //*************************************************************************************************
69 template< typename T, typename = EnableIf_t< IsBuiltin_v<T> > >
70 inline auto invsqrt( T a ) noexcept -> decltype( inv( sqrt( a ) ) )
71 {
72  BLAZE_USER_ASSERT( a > T(0), "Invalid built-in value detected" );
73 
74  return inv( sqrt( a ) );
75 }
76 //*************************************************************************************************
77 
78 
79 //*************************************************************************************************
89 template< typename T, typename = EnableIf_t< IsBuiltin_v<T> > >
90 inline auto invsqrt( const complex<T>& a ) noexcept -> decltype( inv( sqrt( a ) ) )
91 {
92  BLAZE_USER_ASSERT( abs( a ) != T(0), "Invalid complex value detected" );
93 
94  return inv( sqrt( a ) );
95 }
96 //*************************************************************************************************
97 
98 } // namespace blaze
99 
100 #endif
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression,...
Definition: Assert.h:117
Header file for the invert shim.
Header file for the sqrt shim.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
decltype(auto) inv(const DenseMatrix< MT, SO > &dm)
Calculation of the inverse of the given dense matrix.
Definition: DMatInvExpr.h:423
Header file for the EnableIf class template.
decltype(auto) abs(const DenseMatrix< MT, SO > &dm)
Applies the abs() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1156
Header file for run time assertion macros.
decltype(auto) sqrt(const DenseMatrix< MT, SO > &dm)
Computes the square root of each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1448
Header file for the IsBuiltin type trait.
Header file for the complex data type.
decltype(auto) invsqrt(const DenseMatrix< MT, SO > &dm)
Computes the inverse square root of each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1479