Blaze 3.9
DVecMeanExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DVECMEANEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DVECMEANEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
48#include <blaze/util/Assert.h>
51#include <blaze/util/Types.h>
52
53
54namespace blaze {
55
56//=================================================================================================
57//
58// GLOBAL FUNCTIONS
59//
60//=================================================================================================
61
62//*************************************************************************************************
70template< typename VT // Type of the dense vector
71 , bool TF > // Transpose flag
72inline decltype(auto) mean_backend( const DenseVector<VT,TF>& dv, FalseType )
73{
74 using BT = UnderlyingBuiltin_t<VT>;
75
76 BLAZE_INTERNAL_ASSERT( size( *dv ) > 0UL, "Invalid vector size detected" );
77
78 return sum( *dv ) * inv( BT( size( *dv ) ) );
79}
81//*************************************************************************************************
82
83
84//*************************************************************************************************
92template< typename VT // Type of the dense vector
93 , bool TF > // Transpose flag
94inline decltype(auto) mean_backend( const DenseVector<VT,TF>& dv, TrueType )
95{
96 BLAZE_INTERNAL_ASSERT( size( *dv ) > 0UL, "Invalid vector size detected" );
97
98 return (*dv)[0];
99}
101//*************************************************************************************************
102
103
104//*************************************************************************************************
126template< typename VT // Type of the dense vector
127 , bool TF > // Transpose flag
128inline decltype(auto) mean( const DenseVector<VT,TF>& dv )
129{
131
132 if( size( *dv ) == 0UL ) {
133 BLAZE_THROW_INVALID_ARGUMENT( "Invalid input vector" );
134 }
135
136 return mean_backend( *dv, IsUniform<VT>() );
137}
138//*************************************************************************************************
139
140} // namespace blaze
141
142#endif
Header file for run time assertion macros.
Header file for the function trace functionality.
Header file for the IntegralConstant class template.
Header file for the invert shim.
Header file for the IsUniform type trait.
Header file for the UnderlyingBuiltin type trait.
Base class for N-dimensional dense vectors.
Definition: DenseVector.h:77
Header file for the DenseVector base class.
decltype(auto) inv(const DenseMatrix< MT, SO > &dm)
Calculation of the inverse of the given dense matrix.
Definition: DMatInvExpr.h:405
decltype(auto) sum(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of addition.
Definition: DMatReduceExpr.h:2156
decltype(auto) mean(const DenseVector< VT, TF > &dv)
Computes the (arithmetic) mean for the given dense vector.
Definition: DVecMeanExpr.h:128
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:676
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
BoolConstant< true > TrueType
Type traits base class.
Definition: IntegralConstant.h:132
BoolConstant< false > FalseType
Type/value traits base class.
Definition: IntegralConstant.h:121
#define BLAZE_THROW_INVALID_ARGUMENT(MESSAGE)
Macro for the emission of a std::invalid_argument exception.
Definition: Exception.h:235
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
Header file for the exception macros of the math module.
Compile time check for uniform vectors and matrices.
Definition: IsUniform.h:107
Header file for basic type definitions.