Commit a36c7a1f authored by wsttiger's avatar wsttiger
Browse files

Added softmax file in onnx directory

parent df78aadf
#include <vector>
#include <algorithm>
#include <cmath>
template <typename T>
std::vector<T> softmax(const std::vector<T>& p)
{
size_t n = p.size();
std::vector<T> result(n);
std::transform(p.begin(), p.end(), result.begin(), [](auto x) { return std::exp(x); });
T s = std::accumulate(result.begin(), result.end(), 0.0f, std::plus<T>());
std::transform(result.begin(), result.end(), result.begin(), [=](auto x) { return x / s; });
return result;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment