Blaze  3.6
DMatMeanExpr.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_EXPRESSIONS_DMATMEANEXPR_H_
36 #define _BLAZE_MATH_EXPRESSIONS_DMATMEANEXPR_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/math/Exception.h>
50 #include <blaze/util/Assert.h>
54 #include <blaze/util/Types.h>
55 
56 
57 namespace blaze {
58 
59 //=================================================================================================
60 //
61 // GLOBAL FUNCTIONS
62 //
63 //=================================================================================================
64 
65 //*************************************************************************************************
73 template< typename MT // Type of the dense matrix
74  , bool SO > // Storage order
75 inline decltype(auto) mean_backend( const DenseMatrix<MT,SO>& dm, FalseType )
76 {
77  using BT = UnderlyingBuiltin_t<MT>;
78 
79  BLAZE_INTERNAL_ASSERT( size( ~dm ) > 0UL, "Invalid matrix size detected" );
80 
81  return sum( ~dm ) * inv( BT( size( ~dm ) ) );
82 }
84 //*************************************************************************************************
85 
86 
87 //*************************************************************************************************
95 template< typename MT // Type of the dense matrix
96  , bool SO > // Storage order
97 inline decltype(auto) mean_backend( const DenseMatrix<MT,SO>& dm, TrueType )
98 {
99  BLAZE_INTERNAL_ASSERT( size( ~dm ) > 0UL, "Invalid matrix size detected" );
100 
101  return (~dm)(0UL,0UL);
102 }
104 //*************************************************************************************************
105 
106 
107 //*************************************************************************************************
132 template< typename MT // Type of the dense matrix
133  , bool SO > // Storage order
134 inline decltype(auto) mean( const DenseMatrix<MT,SO>& dm )
135 {
137 
138  if( size( ~dm ) == 0UL ) {
139  BLAZE_THROW_INVALID_ARGUMENT( "Invalid input matrix" );
140  }
141 
142  return mean_backend( ~dm, IsUniform<MT>() );
143 }
144 //*************************************************************************************************
145 
146 
147 //*************************************************************************************************
155 template< size_t RF // Reduction flag
156  , typename MT // Type of the dense matrix
157  , bool SO > // Storage order
158 decltype(auto) mean_backend( const DenseMatrix<MT,SO>& dm, FalseType )
159 {
160  using BT = UnderlyingBuiltin_t<MT>;
161 
162  const size_t n( RF == rowwise ? columns( ~dm ) : rows( ~dm ) );
163 
164  BLAZE_INTERNAL_ASSERT( n > 0UL, "Invalid matrix size detected" );
165 
166  return sum<RF>( ~dm ) * inv( BT( n ) );
167 }
169 //*************************************************************************************************
170 
171 
172 //*************************************************************************************************
180 template< size_t RF // Reduction flag
181  , typename MT // Type of the dense matrix
182  , bool SO > // Storage order
183 decltype(auto) mean_backend( const DenseMatrix<MT,SO>& dm, TrueType )
184 {
185  const size_t n( RF == rowwise ? rows( ~dm ) : columns( ~dm ) );
186 
187  BLAZE_INTERNAL_ASSERT( n > 0UL, "Invalid matrix size detected" );
188 
189  constexpr bool TF( ( RF == rowwise ? columnVector : rowVector ) );
190 
191  return uniform<TF>( n, (~dm)(0UL,0UL) );
192 }
194 //*************************************************************************************************
195 
196 
197 //*************************************************************************************************
232 template< size_t RF // Reduction flag
233  , typename MT // Type of the dense matrix
234  , bool SO > // Storage order
235 decltype(auto) mean( const DenseMatrix<MT,SO>& dm )
236 {
238 
239  BLAZE_STATIC_ASSERT_MSG( RF < 2UL, "Invalid reduction flag" );
240 
241  const size_t n( RF == rowwise ? columns( ~dm ) : rows( ~dm ) );
242 
243  if( n == 0UL ) {
244  BLAZE_THROW_INVALID_ARGUMENT( "Invalid input matrix" );
245  }
246 
247  return mean_backend<RF>( ~dm, IsUniform<MT>() );
248 }
249 //*************************************************************************************************
250 
251 } // namespace blaze
252 
253 #endif
BoolConstant< false > FalseType
Type/value traits base class.The FalseType class is used as base class for type traits and value trai...
Definition: IntegralConstant.h:121
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.This macro encapsulates the default way o...
Definition: Exception.h:235
Header file for basic type definitions.
Header file for the implementation of a uniform vector.
Compile time check for uniform vectors and matrices.This type trait tests whether or not the given te...
Definition: IsUniform.h:105
Header file for the invert shim.
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: IntegralConstant.h:132
#define BLAZE_STATIC_ASSERT_MSG(expr, msg)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:123
constexpr size_t columns(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of columns of the matrix.
Definition: Matrix.h:514
Base class for dense matrices.The DenseMatrix class is a base class for all dense matrix classes....
Definition: DenseMatrix.h:81
constexpr bool rowVector
Transpose flag for row vectors.
Definition: TransposeFlag.h:73
Header file for the IsUniform type trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Compile time assertion.
Header file for the UnderlyingBuiltin type trait.
decltype(auto) sum(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of addition.
Definition: DMatReduceExpr.h:2147
Header file for the DenseMatrix base class.
decltype(auto) inv(const DenseMatrix< MT, SO > &dm)
Calculation of the inverse of the given dense matrix.
Definition: DMatInvExpr.h:423
constexpr bool columnVector
Transpose flag for column vectors.
Definition: TransposeFlag.h:58
Header file for the exception macros of the math module.
decltype(auto) mean(const DenseMatrix< MT, SO > &dm)
Computes the (arithmetic) mean for the given dense matrix.
Definition: DMatMeanExpr.h:134
Header file for run time assertion macros.
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:498
constexpr size_t rowwise
Reduction flag for row-wise reduction operations.
Definition: ReductionFlag.h:70
Header file for the IntegralConstant class template.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression,...
Definition: Assert.h:101
Header file for the reduction flags.
Header file for the function trace functionality.