Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
a36c7a1f
Commit
a36c7a1f
authored
Aug 24, 2018
by
wsttiger
Browse files
Added softmax file in onnx directory
parent
df78aadf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
0 deletions
+14
-0
src/onnx/softmax.h
src/onnx/softmax.h
+14
-0
No files found.
src/onnx/softmax.h
0 → 100644
View file @
a36c7a1f
#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.0
f
,
std
::
plus
<
T
>
());
std
::
transform
(
result
.
begin
(),
result
.
end
(),
result
.
begin
(),
[
=
](
auto
x
)
{
return
x
/
s
;
});
return
result
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment