Blaze  3.6
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 
46 namespace blaze {
47 
48 //=================================================================================================
49 //
50 // GLOBAL FUNCTIONS
51 //
52 //=================================================================================================
53 
54 //*************************************************************************************************
65 template< typename VT // Type of the dense vector
66  , bool TF > // Transpose flag
67 auto softmax( const DenseVector<VT,TF>& dv )
68 {
69  auto tmp( evaluate( exp( ~dv ) ) );
70  const auto scalar( sum( ~tmp ) );
71  tmp /= scalar;
72  return tmp;
73 }
74 //*************************************************************************************************
75 
76 } // namespace blaze
77 
78 #endif
Header file for the DenseVector base class.
const MT::ResultType evaluate(const Matrix< MT, SO > &matrix)
Evaluates the given matrix expression.
Definition: Matrix.h:912
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
decltype(auto) sum(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of addition.
Definition: DMatReduceExpr.h:2147
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
decltype(auto) exp(const DenseMatrix< MT, SO > &dm)
Computes for each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1632
auto softmax(const DenseMatrix< MT, SO > &dm)
Computes the softmax function for the given dense matrix.
Definition: DMatSoftmaxExpr.h:88