SSCMA-Micro CPP SDK  v2.0.0
SSCMA-Micro is a cross-platform machine learning inference framework designed for embedded devices.
ma_math_vectors.cpp File Reference
#include "ma_math_vectors.h"
#include <climits>
#include <cmath>
#include "ma_math_scalars.h"
Include dependency graph for ma_math_vectors.cpp:

Namespaces

 ma
 
 ma::math
 

Macros

#define MA_MATH_FAST_SOFTMAX_IMPL(data, size, exp_f)
 

Functions

void ma::math::softmax (float *data, size_t size)
 
void ma::math::fastSoftmax (float *data, size_t size)
 

Macro Definition Documentation

◆ MA_MATH_FAST_SOFTMAX_IMPL

#define MA_MATH_FAST_SOFTMAX_IMPL (   data,
  size,
  exp_f 
)
Value:
{ \
if (!data) [[unlikely]] { \
return; \
} \
\
float sum{0.f}; \
\
for (size_t i = 0; i < size; ++i) { \
auto& data_i = data[i]; \
const auto exp_i = exp_f(data_i); \
sum += exp_i; \
data_i = exp_i; \
} \
\
if (std::abs(sum) < std::numeric_limits<float>::epsilon()) { \
sum = std::numeric_limits<float>::epsilon(); \
} \
\
for (size_t i = 0; i < size; ++i) { \
data[i] /= sum; \
} \
}