ONE - On-device Neural Engine
Loading...
Searching...
No Matches
mir_interpreter::SoftmaxImpl< T > Struct Template Reference

Static Public Member Functions

static void run (const mir::TensorVariant &arg, int axis, mir::TensorVariant &result)
 

Detailed Description

template<typename T>
struct mir_interpreter::SoftmaxImpl< T >

Definition at line 38 of file Softmax.cpp.

Member Function Documentation

◆ run()

template<typename T >
void mir_interpreter::SoftmaxImpl< T >::run ( const mir::TensorVariant arg,
int  axis,
mir::TensorVariant result 
)
static

Definition at line 44 of file Softmax.cpp.

45{
46 mir::Tensor<T> arg_accessor(arg);
47 mir::Tensor<T> res_accessor(result);
48
49 mir::Shape expsum_shape = arg.getShape();
50 expsum_shape.dim(axis) = 1;
51 mir::TensorType expsum_type(arg.getElementType(), expsum_shape);
52 mir::TensorVariant expsum(expsum_type);
53 mir::Tensor<T> expsum_accessor(expsum);
54
55 for (const auto &expsum_index : mir::ShapeRange(expsum_shape))
56 {
57 T sum = 0;
58 mir::Index arg_index = expsum_index;
59 std::int32_t axis_size = arg.getShape().dim(axis);
60 for (std::int32_t i = 0; i < axis_size; ++i)
61 {
62 arg_index.at(axis) = i;
63 sum += std::exp(arg_accessor.at(arg_index));
64 }
65 expsum_accessor.at(expsum_index) = sum;
66 }
67
68 for (const auto &res_index : mir::ShapeRange(result.getShape()))
69 {
70 mir::Index expsum_index = res_index;
71 expsum_index.at(axis) = 0;
72 res_accessor.at(res_index) =
73 std::exp(arg_accessor.at(res_index)) / expsum_accessor.at(expsum_index);
74 }
75}
int32_t & at(int32_t axis)
return position on given axis
Definition Index.h:64
int32_t & dim(int32_t axis) noexcept
Definition Shape.h:47
result
Definition infer.py:103
nnfw::cker::Shape getShape(const IPortableTensor *tensor)

References mir::Tensor< T >::at(), mir::Index::at(), and mir::Shape::dim().

Referenced by package.infer.session::inference().


The documentation for this struct was generated from the following file: