Blaze 3.9
DVecSoftmaxExpr.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_EXPRESSIONS_DVECSOFTMAXEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DVECSOFTMAXEXPR_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
44
45
46namespace blaze {
47
48//=================================================================================================
49//
50// GLOBAL FUNCTIONS
51//
52//=================================================================================================
53
54//*************************************************************************************************
65template< typename VT // Type of the dense vector
66 , bool TF > // Transpose flag
67auto softmax( const DenseVector<VT,TF>& dv )
68{
69 auto tmp( evaluate( exp( *dv - max( *dv ) ) ) );
70 const auto scalar( sum( *tmp ) );
71 tmp /= scalar;
72 return tmp;
73}
74//*************************************************************************************************
75
76} // namespace blaze
77
78#endif
Base class for N-dimensional dense vectors.
Definition: DenseVector.h:77
Header file for the DenseVector base class.
decltype(auto) exp(const DenseMatrix< MT, SO > &dm)
Computes for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1801
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1375
decltype(auto) sum(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of addition.
Definition: DMatReduceExpr.h:2156
auto softmax(const DenseVector< VT, TF > &dv)
Computes the softmax function for the given dense vector.
Definition: DVecSoftmaxExpr.h:67
MT::ResultType evaluate(const Matrix< MT, SO > &matrix)
Evaluates the given matrix expression.
Definition: Matrix.h:1282