ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Abs.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 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 "Abs.h"
18#include "Common.h"
19
20#include <mir/ShapeRange.h>
21#include <mir/Tensor.h>
22
23#include <cmath>
24
25namespace mir_interpreter
26{
27
28template <typename T> struct AbsImpl
29{
30 static void run(const mir::TensorVariant &arg, mir::TensorVariant &result)
31 {
32 mir::Tensor<T> arg_accessor(arg);
33 mir::Tensor<T> res_accessor(result);
34
35 for (const auto &index : mir::ShapeRange(result.getShape()))
36 {
37 res_accessor.at(index) = std::abs(arg_accessor.at(index));
38 }
39 }
40};
41
42template <> struct AbsImpl<uint8_t>
43{
44 static void run(const mir::TensorVariant &arg, mir::TensorVariant &result)
45 {
46 throw std::runtime_error{"NYI"};
47 }
48};
49
50void Abs(const mir::TensorVariant &arg, mir::TensorVariant &result)
51{
52 dispatch<AbsImpl>(arg.getElementType(), arg, result);
53};
54
55} // namespace mir_interpreter
T at(const Index &id) const
Definition Tensor.h:31
void Abs(const mir::TensorVariant &arg, mir::TensorVariant &result)
Definition Abs.cpp:50
static void run(const mir::TensorVariant &arg, mir::TensorVariant &result)
Definition Abs.cpp:44
static void run(const mir::TensorVariant &arg, mir::TensorVariant &result)
Definition Abs.cpp:30