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/affine.h"
18 #include <vector>
19 #include "ops/op_utils.h"
20 namespace mindspore {
21 namespace ops {
Init(const std::vector<int64_t> & contexts,int64_t output_dim,bool transpose_a,bool transpose_b)22 void Affine::Init(const std::vector<int64_t> &contexts, int64_t output_dim, bool transpose_a, bool transpose_b) {
23 this->set_context(contexts);
24 this->set_output_dim(output_dim);
25 this->set_transpose_a(transpose_a);
26 this->set_transpose_b(transpose_b);
27 }
28
set_context(const std::vector<int64_t> & context)29 void Affine::set_context(const std::vector<int64_t> &context) {
30 (void)this->AddAttr(kAffineContext, MakeValue(context));
31 }
32
set_output_dim(int64_t output_dim)33 void Affine::set_output_dim(int64_t output_dim) { (void)this->AddAttr(kAffineOutputDim, MakeValue(output_dim)); }
34
set_transpose_a(bool transpose_a)35 void Affine::set_transpose_a(bool transpose_a) { (void)AddAttr(kTransposeA, MakeValue(transpose_a)); }
36
set_transpose_b(bool transpose_b)37 void Affine::set_transpose_b(bool transpose_b) { (void)AddAttr(kTransposeB, MakeValue(transpose_b)); }
38
set_activation_type(const ActivationType & activation_type)39 void Affine::set_activation_type(const ActivationType &activation_type) {
40 (void)this->AddAttr(kActivationType, MakeValue(static_cast<int64_t>(activation_type)));
41 }
42
get_transpose_a() const43 bool Affine::get_transpose_a() const {
44 auto value_ptr = GetAttr(kTransposeA);
45 return GetValue<bool>(value_ptr);
46 }
47
get_transpose_b() const48 bool Affine::get_transpose_b() const {
49 auto value_ptr = GetAttr(kTransposeB);
50 return GetValue<bool>(value_ptr);
51 }
52
get_context() const53 std::vector<int64_t> Affine::get_context() const {
54 auto value_ptr = GetAttr(kAffineContext);
55 return GetValue<std::vector<int64_t>>(value_ptr);
56 }
57
get_output_dim() const58 int64_t Affine::get_output_dim() const {
59 auto value_ptr = GetAttr(kAffineOutputDim);
60 return GetValue<int64_t>(value_ptr);
61 }
62
get_activation_type() const63 ActivationType Affine::get_activation_type() const {
64 auto value_ptr = GetAttr(kActivationType);
65 return ActivationType(GetValue<int64_t>(value_ptr));
66 }
67 REGISTER_PRIMITIVE_C(kNameAffine, Affine);
68 } // namespace ops
69 } // namespace mindspore
70