ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Tanh.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
17
#include "
Sigmoid.h
"
18
#include "
Common.h
"
19
20
#include <
mir/ShapeRange.h
>
21
#include <
mir/Tensor.h
>
22
23
#include <cmath>
24
25
namespace
mir_interpreter
26
{
27
28
template
<
typename
T>
struct
TanhImpl
29
{
30
static
void
run
(
const
mir::TensorVariant
&arg,
mir::TensorVariant
&result);
31
};
32
33
template
<
typename
T>
34
void
TanhImpl<T>::run
(
const
mir::TensorVariant
&arg,
mir::TensorVariant
&result)
35
{
36
mir::Tensor<T>
arg_accessor(arg);
37
mir::Tensor<T>
res_accessor(result);
38
39
for
(
const
auto
&index :
mir::ShapeRange
(result.getShape()))
40
{
41
res_accessor.
at
(index) = std::tanh(arg_accessor.
at
(index));
42
}
43
}
44
45
template
<>
struct
TanhImpl
<uint8_t>
46
{
47
static
void
run
(
const
mir::TensorVariant
&arg,
mir::TensorVariant
&result)
48
{
49
throw
std::runtime_error{
"NYI"
};
50
}
51
};
52
53
void
Tanh
(
const
mir::TensorVariant
&arg,
mir::TensorVariant
&result)
54
{
55
dispatch<TanhImpl>(arg.getElementType(), arg, result);
56
};
57
58
}
// namespace mir_interpreter
ShapeRange.h
mir::ShapeRange
Definition
ShapeRange.h:82
mir::Tensor
Definition
Tensor.h:27
mir::Tensor::at
T at(const Index &id) const
Definition
Tensor.h:31
mir::TensorVariant
Definition
TensorVariant.h:33
Tensor.h
Sigmoid.h
mir_interpreter
Definition
MirInterpreter.h:27
mir_interpreter::Tanh
void Tanh(const mir::TensorVariant &arg, mir::TensorVariant &result)
Definition
Tanh.cpp:53
Common.h
mir_interpreter::TanhImpl< uint8_t >::run
static void run(const mir::TensorVariant &arg, mir::TensorVariant &result)
Definition
Tanh.cpp:47
mir_interpreter::TanhImpl
Definition
Tanh.cpp:29
mir_interpreter::TanhImpl::run
static void run(const mir::TensorVariant &arg, mir::TensorVariant &result)
Definition
Tanh.cpp:34
compiler
mir-interpreter
src
ops
Tanh.cpp
Generated by
1.9.8