2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "nnfw_experimental.h"
19 #include "flatbuffers/flexbuffers.h"
24 extern "C" void FillFromEval(nnfw_custom_kernel_params *params, char *userdata,
27 auto userdata_root = flexbuffers::GetRoot(reinterpret_cast<uint8_t *>(userdata), userdata_size);
29 auto attr_map = userdata_root.AsMap();
31 auto idx = attr_map["idx"].AsInt32();
32 auto val = attr_map["val"].AsFloat();
34 int32_t flat_size = 1;
35 for (int32_t i = 0; i < params->inputs[0].type.rank; ++i)
37 flat_size *= params->inputs[0].type.dims[i];
40 if (!(0 <= idx && idx < flat_size))
41 throw std::runtime_error("Value of attr Idx is out of range");
43 auto output_flat = static_cast<float *>(params->outputs[0].allocation);
44 auto input_flat = static_cast<float *>(params->inputs[0].allocation);
46 for (int32_t i = 0; i < idx; ++i)
48 output_flat[i] = input_flat[i];
51 for (int32_t i = idx; i < flat_size; ++i)