1 /**
2 * Copyright 2021 Huawei Technologies Co., Ltd
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 "ops/split_with_overlap.h"
18
19 #include "mindapi/base/shared_ptr.h"
20 #include "mindapi/ir/value.h"
21 #include "mindapi/src/helper.h"
22 #include "ops/op_name.h"
23 #include "ops/primitive_c.h"
24 #include "utils/log_adapter.h"
25
26 namespace mindspore {
27 namespace ops {
28 MIND_API_OPERATOR_IMPL(SplitWithOverlap, BaseOperator);
Init(int64_t number_split,const std::vector<int64_t> & ratio,const std::vector<int64_t> & extend_top,const std::vector<int64_t> & extend_bottom,int64_t split_dim,int64_t stride,int64_t pad_top,bool trans_format)29 void SplitWithOverlap::Init(int64_t number_split, const std::vector<int64_t> &ratio,
30 const std::vector<int64_t> &extend_top, const std::vector<int64_t> &extend_bottom,
31 int64_t split_dim, int64_t stride, int64_t pad_top, bool trans_format) {
32 this->set_number_split(number_split);
33 this->set_ratio(ratio);
34 this->set_extend_top(extend_top);
35 this->set_extend_bottom(extend_bottom);
36 this->set_split_dim(split_dim);
37 this->set_split_stride(stride);
38 this->set_pad_top(pad_top);
39 this->set_trans_format(trans_format);
40 }
41
set_ratio(const std::vector<int64_t> & ratio)42 void SplitWithOverlap::set_ratio(const std::vector<int64_t> &ratio) {
43 (void)this->AddAttr(kRatio, api::MakeValue(ratio));
44 }
45
set_extend_top(const std::vector<int64_t> & extend_top)46 void SplitWithOverlap::set_extend_top(const std::vector<int64_t> &extend_top) {
47 (void)this->AddAttr(kExtendTop, api::MakeValue(extend_top));
48 }
49
set_extend_bottom(const std::vector<int64_t> & extend_bottom)50 void SplitWithOverlap::set_extend_bottom(const std::vector<int64_t> &extend_bottom) {
51 (void)this->AddAttr(kExtendBottom, api::MakeValue(extend_bottom));
52 }
53
set_number_split(int64_t number_split)54 void SplitWithOverlap::set_number_split(int64_t number_split) {
55 (void)this->AddAttr(kNumberSplit, api::MakeValue(number_split));
56 }
57
set_split_dim(int64_t split_dim)58 void SplitWithOverlap::set_split_dim(int64_t split_dim) { (void)this->AddAttr(kSplitDim, api::MakeValue(split_dim)); }
59
set_split_stride(int64_t stride)60 void SplitWithOverlap::set_split_stride(int64_t stride) { (void)this->AddAttr(kSplitStride, api::MakeValue(stride)); }
61
set_pad_top(int64_t pad_top)62 void SplitWithOverlap::set_pad_top(int64_t pad_top) { (void)this->AddAttr(kPadTop, api::MakeValue(pad_top)); }
63
set_trans_format(bool trans_format)64 void SplitWithOverlap::set_trans_format(bool trans_format) {
65 (void)this->AddAttr(kTransFormat, api::MakeValue(trans_format));
66 }
67
get_ratio() const68 std::vector<int64_t> SplitWithOverlap::get_ratio() const {
69 auto value_ptr = GetAttr(kRatio);
70 return GetValue<std::vector<int64_t>>(value_ptr);
71 }
72
get_extend_top() const73 std::vector<int64_t> SplitWithOverlap::get_extend_top() const {
74 auto value_ptr = GetAttr(kExtendTop);
75 return GetValue<std::vector<int64_t>>(value_ptr);
76 }
77
get_extend_bottom() const78 std::vector<int64_t> SplitWithOverlap::get_extend_bottom() const {
79 auto value_ptr = GetAttr(kExtendBottom);
80 return GetValue<std::vector<int64_t>>(value_ptr);
81 }
82
get_number_split() const83 int64_t SplitWithOverlap::get_number_split() const {
84 auto value_ptr = GetAttr(kNumberSplit);
85 return GetValue<int64_t>(value_ptr);
86 }
87
get_split_dim() const88 int64_t SplitWithOverlap::get_split_dim() const {
89 auto value_ptr = GetAttr(kSplitDim);
90 return GetValue<int64_t>(value_ptr);
91 }
92
get_split_stride() const93 int64_t SplitWithOverlap::get_split_stride() const {
94 auto value_ptr = GetAttr(kSplitStride);
95 return GetValue<int64_t>(value_ptr);
96 }
97
get_pad_top() const98 int64_t SplitWithOverlap::get_pad_top() const {
99 auto value_ptr = GetAttr(kPadTop);
100 return GetValue<int64_t>(value_ptr);
101 }
102
get_trans_format() const103 bool SplitWithOverlap::get_trans_format() const {
104 auto value_ptr = GetAttr(kTransFormat);
105 return GetValue<bool>(value_ptr);
106 }
107
108 REGISTER_PRIMITIVE_C(kNameSplitWithOverlap, SplitWithOverlap);
109 } // namespace ops
110 } // namespace mindspore
111