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 
44 #include <blaze/system/Inline.h>
45 #include <blaze/util/Assert.h>
46 #include <blaze/util/Complex.h>
47 
48 
49 namespace blaze {
50 
51 //=================================================================================================
52 //
53 // INV SHIMS
54 //
55 //=================================================================================================
56 
57 //*************************************************************************************************
69 BLAZE_ALWAYS_INLINE float inv( float a )
70 {
71  BLAZE_USER_ASSERT( a != 0.0F, "Division by zero detected" );
72  return ( 1.0F / a );
73 }
74 //*************************************************************************************************
75 
76 
77 //*************************************************************************************************
89 BLAZE_ALWAYS_INLINE double inv( double a )
90 {
91  BLAZE_USER_ASSERT( a != 0.0, "Division by zero detected" );
92  return ( 1.0 / a );
93 }
94 //*************************************************************************************************
95 
96 
97 //*************************************************************************************************
109 BLAZE_ALWAYS_INLINE long double inv( long double a )
110 {
111  BLAZE_USER_ASSERT( a != 0.0L, "Division by zero detected" );
112  return ( 1.0L / a );
113 }
114 //*************************************************************************************************
115 
116 
117 //*************************************************************************************************
130 BLAZE_ALWAYS_INLINE complex<float> inv( const complex<float>& a )
131 {
132  const float abs( sq( real(a) ) + sq( imag(a) ) );
133  BLAZE_USER_ASSERT( abs != 0.0F, "Division by zero detected" );
134 
135  const float iabs( 1.0F / abs );
136  return complex<float>( iabs*real(a), -iabs*imag(a) );
137 }
138 //*************************************************************************************************
139 
140 
141 //*************************************************************************************************
154 BLAZE_ALWAYS_INLINE complex<double> inv( const complex<double>& a )
155 {
156  const double abs( sq( real(a) ) + sq( imag(a) ) );
157  BLAZE_USER_ASSERT( abs != 0.0, "Division by zero detected" );
158 
159  const double iabs( 1.0 / abs );
160  return complex<double>( iabs*real(a), -iabs*imag(a) );
161 }
162 //*************************************************************************************************
163 
164 
165 //*************************************************************************************************
178 BLAZE_ALWAYS_INLINE complex<long double> inv( const complex<long double>& a )
179 {
180  const long double abs( sq( real(a) ) + sq( imag(a) ) );
181  BLAZE_USER_ASSERT( abs != 0.0L, "Division by zero detected" );
182 
183  const long double iabs( 1.0L / abs );
184  return complex<long double>( iabs*real(a), -iabs*imag(a) );
185 }
186 //*************************************************************************************************
187 
188 
189 
190 
191 //=================================================================================================
192 //
193 // INVERT SHIMS
194 //
195 //=================================================================================================
196 
197 //*************************************************************************************************
210 BLAZE_ALWAYS_INLINE void invert( float& a )
211 {
212  a = inv( a );
213 }
214 //*************************************************************************************************
215 
216 
217 //*************************************************************************************************
230 BLAZE_ALWAYS_INLINE void invert( double& a )
231 {
232  a = inv( a );
233 }
234 //*************************************************************************************************
235 
236 
237 //*************************************************************************************************
250 BLAZE_ALWAYS_INLINE void invert( long double& a )
251 {
252  a = inv( a );
253 }
254 //*************************************************************************************************
255 
256 
257 //*************************************************************************************************
270 BLAZE_ALWAYS_INLINE void invert( complex<float>& a )
271 {
272  a = inv( a );
273 }
274 //*************************************************************************************************
275 
276 
277 //*************************************************************************************************
290 BLAZE_ALWAYS_INLINE void invert( complex<double>& a )
291 {
292  a = inv( a );
293 }
294 //*************************************************************************************************
295 
296 
297 //*************************************************************************************************
310 BLAZE_ALWAYS_INLINE void invert( complex<long double>& a )
311 {
312  a = inv( a );
313 }
314 //*************************************************************************************************
315 
316 } // namespace blaze
317 
318 #endif
BLAZE_ALWAYS_INLINE const MultExprTrait< T, T >::Type sq(const T &a)
Squaring the given value/object.
Definition: Square.h:66
#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
Header file for the square shim.
const DMatAbsExpr< MT, SO > abs(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the absolute values of each single element of dm.
Definition: DMatAbsExpr.h:938
const ImagExprTrait< MT >::Type imag(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the imaginary part of each single element of dm.
Definition: DMatImagExpr.h:920
void invert(const HermitianProxy< MT > &proxy)
In-place inversion of the represented element.
Definition: HermitianProxy.h:767
Namespace of the Blaze C++ math library.
Definition: Blaze.h:57
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
const RealExprTrait< MT >::Type real(const DenseMatrix< MT, SO > &dm)
Returns a matrix containing the real part of each single element of dm.
Definition: DMatRealExpr.h:920
Header file for run time assertion macros.
Header file for the complex data type.
const DMatInvExpr< MT, SO > inv(const DenseMatrix< MT, SO > &dm)
Calculation of the inverse of the given dense matrix.
Definition: DMatInvExpr.h:375
System settings for the inline keywords.