Blaze 3.9
SVecMeanExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_SVECMEANEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_SVECMEANEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
48#include <blaze/util/Assert.h>
52#include <blaze/util/Types.h>
53
54
55namespace blaze {
56
57//=================================================================================================
58//
59// GLOBAL FUNCTIONS
60//
61//=================================================================================================
62
63//*************************************************************************************************
71template< typename VT // Type of the sparse vector
72 , bool TF > // Transpose flag
73inline decltype(auto) mean_backend( const SparseVector<VT,TF>& sv, FalseType )
74{
75 using BT = UnderlyingBuiltin_t<VT>;
76
77 BLAZE_INTERNAL_ASSERT( size( *sv ) > 0UL, "Invalid vector size detected" );
78
79 return sum( *sv ) * inv( BT( size( *sv ) ) );
80}
82//*************************************************************************************************
83
84
85//*************************************************************************************************
93template< typename VT // Type of the sparse vector
94 , bool TF > // Transpose flag
95inline decltype(auto) mean_backend( const SparseVector<VT,TF>& sv, TrueType )
96{
97 MAYBE_UNUSED( sv );
98
99 BLAZE_INTERNAL_ASSERT( size( *sv ) > 0UL, "Invalid vector size detected" );
100
101 return ElementType_t<VT>();
102}
104//*************************************************************************************************
105
106
107//*************************************************************************************************
130template< typename VT // Type of the sparse vector
131 , bool TF > // Transpose flag
132inline decltype(auto) mean( const SparseVector<VT,TF>& sv )
133{
135
136 if( size( *sv ) == 0UL ) {
137 BLAZE_THROW_INVALID_ARGUMENT( "Invalid input vector" );
138 }
139
140 return mean_backend( *sv, IsZero<VT>() );
141}
142//*************************************************************************************************
143
144} // namespace blaze
145
146#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 MAYBE_UNUSED function template.
Header file for the UnderlyingBuiltin type trait.
Base class for sparse vectors.
Definition: SparseVector.h:72
Header file for the SparseVector base class.
decltype(auto) mean(const DenseMatrix< MT, SO > &dm)
Computes the (arithmetic) mean for the given dense matrix.
Definition: DMatMeanExpr.h:134
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
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
constexpr void MAYBE_UNUSED(const Args &...)
Suppression of unused parameter warnings.
Definition: MaybeUnused.h:81
#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 zero vectors or matrices.
Definition: IsZero.h:109
Header file for the IsZero type trait.
Header file for basic type definitions.