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/tensor_array.h"
18 #include <vector>
19 #include "abstract/primitive_infer_map.h"
20
21 namespace mindspore {
22 namespace ops {
23 constexpr auto kTensorArrayDynamicSize = "dynamic_size";
24 constexpr auto kTensorArrayIdenticalElementShapes = "identical_element_shapes";
25 constexpr auto kTensorArrayElementShape = "element_shape";
26 constexpr auto kTensorArrayDataType = "data_type";
27
Init(bool dynamic_size,bool identical_element_shapes,const std::vector<int> & element_shape,int data_type)28 void TensorArray::Init(bool dynamic_size, bool identical_element_shapes, const std::vector<int> &element_shape,
29 int data_type) {
30 this->set_dynamic_size(dynamic_size);
31 this->set_identical_element_shapes(identical_element_shapes);
32 this->set_element_shape(element_shape);
33 this->set_data_type(data_type);
34 }
35
set_dynamic_size(bool dynamic_size)36 void TensorArray::set_dynamic_size(bool dynamic_size) {
37 (void)this->AddAttr(kTensorArrayDynamicSize, MakeValue(dynamic_size));
38 }
39
set_identical_element_shapes(bool identical_element_shapes)40 void TensorArray::set_identical_element_shapes(bool identical_element_shapes) {
41 (void)this->AddAttr(kTensorArrayIdenticalElementShapes, MakeValue(identical_element_shapes));
42 }
43
set_element_shape(const std::vector<int> & element_shape)44 void TensorArray::set_element_shape(const std::vector<int> &element_shape) {
45 (void)this->AddAttr(kTensorArrayElementShape, MakeValue(element_shape));
46 }
47
set_data_type(int data_type)48 void TensorArray::set_data_type(int data_type) { (void)this->AddAttr(kTensorArrayDataType, MakeValue(data_type)); }
49
get_dynamic_size() const50 bool TensorArray::get_dynamic_size() const {
51 auto value_ptr = GetAttr(kTensorArrayDynamicSize);
52 return GetValue<bool>(value_ptr);
53 }
54
get_identical_element_shapes() const55 bool TensorArray::get_identical_element_shapes() const {
56 auto value_ptr = GetAttr(kTensorArrayIdenticalElementShapes);
57 return GetValue<bool>(value_ptr);
58 }
59
get_element_shape() const60 const std::vector<int> TensorArray::get_element_shape() const {
61 auto value_ptr = GetAttr(kTensorArrayElementShape);
62 return GetValue<std::vector<int>>(value_ptr);
63 }
64
get_data_type() const65 int TensorArray::get_data_type() const {
66 auto value_ptr = GetAttr(kTensorArrayDataType);
67 return GetValue<int>(value_ptr);
68 }
69
70 REGISTER_PRIMITIVE_C(kNameTensorArray, TensorArray);
71 } // namespace ops
72 } // namespace mindspore
73