ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Slice.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3
* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*/
17
18
#ifndef __NNFW_CKER_SLICE_H__
19
#define __NNFW_CKER_SLICE_H__
20
21
#include "
cker/Shape.h
"
22
#include "
cker/Types.h
"
23
#include "
cker/Utils.h
"
24
25
namespace
nnfw
26
{
27
namespace
cker
28
{
29
30
template
<
typename
T>
31
inline
void
Slice
(
const
SliceParams
&op_params,
const
Shape
&input_shape,
32
SequentialTensorWriter<T>
*writer)
33
{
34
// TODO(dkalenichenko): This op only supports 4D tensors or smaller.
35
assert(op_params.
begin_count
<= 4);
36
assert(op_params.
size_count
<= 4);
37
38
const
int
begin_count
= op_params.
begin_count
;
39
const
int
size_count
= op_params.
size_count
;
40
// We front-pad the begin and size vectors.
41
const
int
start_b = 4 -
begin_count
> 0 ? 0 : op_params.
begin
[0];
42
const
int
stop_b = (4 -
size_count
> 0 || op_params.
size
[0] == -1) ? input_shape.
Dims
(0)
43
: start_b + op_params.
size
[0];
44
const
int
start_h =
begin_count
< 3 ? 0 : op_params.
begin
[
begin_count
- 3];
45
const
int
stop_h = (
size_count
< 3 || op_params.
size
[
size_count
- 3] == -1)
46
? input_shape.
Dims
(1)
47
: start_h + op_params.
size
[
size_count
- 3];
48
const
int
start_w =
begin_count
< 2 ? 0 : op_params.
begin
[
begin_count
- 2];
49
const
int
stop_w = (
size_count
< 2 || op_params.
size
[
size_count
- 2] == -1)
50
? input_shape.
Dims
(2)
51
: start_w + op_params.
size
[
size_count
- 2];
52
const
int
start_d =
begin_count
< 1 ? 0 : op_params.
begin
[
begin_count
- 1];
53
const
int
stop_d = (
size_count
< 1 || op_params.
size
[
size_count
- 1] == -1)
54
? input_shape.
Dims
(3)
55
: start_d + op_params.
size
[
size_count
- 1];
56
57
for
(
int
in_b = start_b; in_b < stop_b; ++in_b)
58
{
59
for
(
int
in_h = start_h; in_h < stop_h; ++in_h)
60
{
61
for
(
int
in_w = start_w; in_w < stop_w; ++in_w)
62
{
63
const
int
len = stop_d - start_d;
64
if
(len > 0)
65
writer->
WriteN
(
Offset
(input_shape, in_b, in_h, in_w, start_d), len);
66
}
67
}
68
}
69
}
70
71
template
<
typename
T>
72
inline
void
Slice
(
const
SliceParams
&op_params,
const
Shape
&input_shape,
const
T *input_data,
73
T *output_data)
74
{
75
SequentialTensorWriter<T>
writer(input_data, output_data);
76
return
Slice
(op_params, input_shape, &writer);
77
}
78
79
}
// namespace cker
80
}
// namespace nnfw
81
82
#endif
// __NNFW_CKER_SLICE_H__
nnfw::cker::SequentialTensorWriter
Definition
Utils.h:467
nnfw::cker::SequentialTensorWriter::WriteN
void WriteN(int position, int len)
Definition
Utils.h:475
nnfw::cker::Shape
Definition
Shape.h:32
nnfw::cker::Shape::Dims
int32_t Dims(int i) const
Definition
Shape.h:92
Shape.h
Types.h
Utils.h
nnfw::cker::Offset
int Offset(const Shape &shape, int i0, int i1, int i2, int i3)
Definition
Shape.h:237
nnfw::cker::Slice
void Slice(const SliceParams &op_params, const Shape &input_shape, SequentialTensorWriter< T > *writer)
Definition
Slice.h:31
nnfw
Definition
topk_v2.h:30
size_count
int8_t size_count
Definition
Slice.cpp:34
begin_count
int8_t begin_count
Definition
Slice.cpp:32
nnfw::cker::SliceParams
Definition
Types.h:355
nnfw::cker::SliceParams::size
int32_t size[4]
Definition
Types.h:359
nnfw::cker::SliceParams::begin
int32_t begin[4]
Definition
Types.h:357
nnfw::cker::SliceParams::begin_count
int8_t begin_count
Definition
Types.h:356
nnfw::cker::SliceParams::size_count
int8_t size_count
Definition
Types.h:358
compute
cker
include
cker
operation
Slice.h
Generated by
1.9.8