ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Convert.h
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#ifndef __CONVERT_H__
18#define __CONVERT_H__
19
20#include <mio/circle/schema_generated.h>
21
22#include <circlechef.pb.h>
23
24namespace circlechef
25{
26
27circlechef::TensorType as_circlechef_type(const circle::TensorType type);
28circlechef::Activation as_circlechef_activation(const circle::ActivationFunctionType type);
29circlechef::Padding as_circlechef_padding(const circle::Padding padding);
30
34template <typename DT> std::vector<DT> extract_buffer(const circle::Buffer *buffer)
35{
36 auto buffer_length = buffer->data()->size();
37 auto num_elements = buffer_length / sizeof(DT);
38 std::vector<DT> result(num_elements);
39 std::memcpy(result.data(), buffer->data()->data(), buffer_length);
40 return result;
41}
42
43template <typename T> std::vector<T> as_index_vector(const flatbuffers::Vector<T> *flat_array)
44{
45 if (flat_array == nullptr)
46 throw std::runtime_error("flat_array is nullptr");
47
48 std::vector<T> ret(flat_array->size());
49 for (uint32_t i = 0; i < flat_array->size(); i++)
50 {
51 ret[i] = flat_array->Get(i);
52 }
53 return ret;
54}
55
56} // namespace circlechef
57
58#endif // __CONVERT_H__
return_type Get(uoffset_t i) const
uoffset_t size() const
std::vector< T > as_index_vector(const flatbuffers::Vector< T > *flat_array)
Definition Convert.h:43
circlechef::Activation as_circlechef_activation(const circle::ActivationFunctionType type)
Definition Convert.cpp:55
std::vector< DT > extract_buffer(const circle::Buffer *buffer)
extract buffer data to std::vector<DT>
Definition Convert.h:34
circlechef::TensorType as_circlechef_type(const circle::TensorType type)
Definition Convert.cpp:22
circlechef::Padding as_circlechef_padding(const circle::Padding padding)
Definition Convert.cpp:74