Blaze 3.9
DVecVarExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DVECVAREXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DVECVAREXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
50#include <blaze/util/Assert.h>
54#include <blaze/util/Types.h>
55
56
57namespace blaze {
58
59//=================================================================================================
60//
61// GLOBAL FUNCTIONS
62//
63//=================================================================================================
64
65//*************************************************************************************************
73template< typename VT // Type of the dense vector
74 , bool TF > // Transpose flag
75decltype(auto) var_backend( const DenseVector<VT,TF>& dv, FalseType )
76{
77 using BT = UnderlyingBuiltin_t<VT>;
78
79 const size_t n( size( *dv ) );
80
81 BLAZE_INTERNAL_ASSERT( n > 1UL, "Invalid vector size detected" );
82
83 const auto m( uniform<TF>( n, mean( *dv ) ) );
84
85 return sum( map( (*dv) - m, Pow2() ) ) * inv( BT( n-1UL ) );
86}
88//*************************************************************************************************
89
90
91//*************************************************************************************************
99template< typename VT // Type of the dense vector
100 , bool TF > // Transpose flag
101decltype(auto) var_backend( const DenseVector<VT,TF>& dv, TrueType )
102{
103 MAYBE_UNUSED( dv );
104
105 BLAZE_INTERNAL_ASSERT( size( *dv ) > 1UL, "Invalid vector size detected" );
106
107 return ElementType_t<VT>();
108}
110//*************************************************************************************************
111
112
113//*************************************************************************************************
134template< typename VT // Type of the dense vector
135 , bool TF > // Transpose flag
136decltype(auto) var( const DenseVector<VT,TF>& dv )
137{
139
140 const size_t n( size( *dv ) );
141
142 if( n < 2UL ) {
143 BLAZE_THROW_INVALID_ARGUMENT( "Invalid input vector" );
144 }
145
146 return var_backend( *dv, IsUniform<VT>() );
147}
148//*************************************************************************************************
149
150} // namespace blaze
151
152#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 MAYBE_UNUSED function template.
Header file for the UnderlyingBuiltin type trait.
Base class for N-dimensional dense vectors.
Definition: DenseVector.h:77
Header file for the implementation of a uniform vector.
Header file for the DenseVector base class.
Header file for the Pow2 functor.
decltype(auto) mean(const DenseMatrix< MT, SO > &dm)
Computes the (arithmetic) mean for the given dense matrix.
Definition: DMatMeanExpr.h:134
decltype(auto) map(const DenseMatrix< MT1, SO > &lhs, const DenseMatrix< MT2, SO > &rhs, OP op)
Elementwise evaluation of the given binary operation on each single element of the dense matrices lhs...
Definition: DMatDMatMapExpr.h:1144
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) var(const DenseVector< VT, TF > &dv)
Computes the variance for the given dense vector.
Definition: DVecVarExpr.h:136
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 uniform vectors and matrices.
Definition: IsUniform.h:107
Header file for basic type definitions.