Invert.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_SHIMS_INVERT_H_
36 #define _BLAZE_MATH_SHIMS_INVERT_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/shims/Pow2.h>
44 #include <blaze/system/Inline.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 // INV SHIMS
56 //
57 //=================================================================================================
58 
59 //*************************************************************************************************
71 template< typename T >
72 BLAZE_ALWAYS_INLINE constexpr EnableIf_t< IsIntegral_v<T>, double > inv( T a ) noexcept
73 {
74  BLAZE_USER_ASSERT( a != T(0), "Division by zero detected" );
75  return ( 1.0 / a );
76 }
77 //*************************************************************************************************
78 
79 
80 //*************************************************************************************************
92 BLAZE_ALWAYS_INLINE constexpr float inv( float a ) noexcept
93 {
94  BLAZE_USER_ASSERT( a != 0.0F, "Division by zero detected" );
95  return ( 1.0F / a );
96 }
97 //*************************************************************************************************
98 
99 
100 //*************************************************************************************************
112 BLAZE_ALWAYS_INLINE constexpr double inv( double a ) noexcept
113 {
114  BLAZE_USER_ASSERT( a != 0.0, "Division by zero detected" );
115  return ( 1.0 / a );
116 }
117 //*************************************************************************************************
118 
119 
120 //*************************************************************************************************
132 BLAZE_ALWAYS_INLINE constexpr long double inv( long double a ) noexcept
133 {
134  BLAZE_USER_ASSERT( a != 0.0L, "Division by zero detected" );
135  return ( 1.0L / a );
136 }
137 //*************************************************************************************************
138 
139 
140 //*************************************************************************************************
153 BLAZE_ALWAYS_INLINE constexpr complex<float> inv( const complex<float>& a ) noexcept
154 {
155  const float abs( pow2( real(a) ) + pow2( imag(a) ) );
156  BLAZE_USER_ASSERT( abs != 0.0F, "Division by zero detected" );
157 
158  const float iabs( 1.0F / abs );
159  return complex<float>( iabs*real(a), -iabs*imag(a) );
160 }
161 //*************************************************************************************************
162 
163 
164 //*************************************************************************************************
177 BLAZE_ALWAYS_INLINE constexpr complex<double> inv( const complex<double>& a ) noexcept
178 {
179  const double abs( pow2( real(a) ) + pow2( imag(a) ) );
180  BLAZE_USER_ASSERT( abs != 0.0, "Division by zero detected" );
181 
182  const double iabs( 1.0 / abs );
183  return complex<double>( iabs*real(a), -iabs*imag(a) );
184 }
185 //*************************************************************************************************
186 
187 
188 //*************************************************************************************************
201 BLAZE_ALWAYS_INLINE constexpr complex<long double> inv( const complex<long double>& a ) noexcept
202 {
203  const long double abs( pow2( real(a) ) + pow2( imag(a) ) );
204  BLAZE_USER_ASSERT( abs != 0.0L, "Division by zero detected" );
205 
206  const long double iabs( 1.0L / abs );
207  return complex<long double>( iabs*real(a), -iabs*imag(a) );
208 }
209 //*************************************************************************************************
210 
211 
212 
213 
214 //=================================================================================================
215 //
216 // INVERT SHIMS
217 //
218 //=================================================================================================
219 
220 //*************************************************************************************************
233 BLAZE_ALWAYS_INLINE void invert( float& a ) noexcept
234 {
235  a = inv( a );
236 }
237 //*************************************************************************************************
238 
239 
240 //*************************************************************************************************
253 BLAZE_ALWAYS_INLINE void invert( double& a ) noexcept
254 {
255  a = inv( a );
256 }
257 //*************************************************************************************************
258 
259 
260 //*************************************************************************************************
273 BLAZE_ALWAYS_INLINE void invert( long double& a ) noexcept
274 {
275  a = inv( a );
276 }
277 //*************************************************************************************************
278 
279 
280 //*************************************************************************************************
293 BLAZE_ALWAYS_INLINE void invert( complex<float>& a ) noexcept
294 {
295  a = inv( a );
296 }
297 //*************************************************************************************************
298 
299 
300 //*************************************************************************************************
313 BLAZE_ALWAYS_INLINE void invert( complex<double>& a ) noexcept
314 {
315  a = inv( a );
316 }
317 //*************************************************************************************************
318 
319 
320 //*************************************************************************************************
333 BLAZE_ALWAYS_INLINE void invert( complex<long double>& a ) noexcept
334 {
335  a = inv( a );
336 }
337 //*************************************************************************************************
338 
339 } // namespace blaze
340 
341 #endif
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
decltype(auto) real(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the real part of each single element of dm.
Definition: DMatMapExpr.h:1392
Header file for the IsIntegral type trait.
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.The EnableIf_t alias declaration provides a convenient...
Definition: EnableIf.h:138
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:775
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
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 pow2 shim.
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:1152
Header file for run time assertion macros.
decltype(auto) pow2(const Proxy< PT, RT > &proxy)
Computing the square value of the represented element.
Definition: Proxy.h:1384
Header file for the complex data type.
decltype(auto) imag(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the imaginary part of each single element of dm.
Definition: DMatMapExpr.h:1421
System settings for the inline keywords.