ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Fill.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 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#ifndef _NNC_CORE_BACKEND_INTERPRETER_FILL_
18#define _NNC_CORE_BACKEND_INTERPRETER_FILL_
19
20#include "Common.h"
21
22#include "mir/ShapeRange.h"
23#include "mir/Tensor.h"
24
25namespace mir_interpreter
26{
27
28template <typename T> struct FillImpl
29{
30 template <typename F> static void run(mir::TensorVariant &res, F f)
31 {
32 mir::Tensor<T> res_accessor(res);
33
34 for (const auto &index : mir::ShapeRange(res.getShape()))
35 {
36 res_accessor.at(index) = f(index);
37 }
38 }
39};
40
41template <typename F> void Fill(mir::TensorVariant &t, F f)
42{
43 dispatch<FillImpl>(t.getElementType(), t, f);
44}
45
46} // namespace mir_interpreter
47
48#endif //_NNC_CORE_BACKEND_INTERPRETER_FILL_
T at(const Index &id) const
Definition Tensor.h:31
const Shape & getShape() const
DataType getElementType() const
void Fill(mir::TensorVariant &t, F f)
Definition Fill.h:41
static void run(mir::TensorVariant &res, F f)
Definition Fill.h:30