You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

gru.cc 3.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Copyright 2020 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. #include "ops/gru.h"
  17. namespace mindspore {
  18. namespace ops {
  19. void GRU::Init(bool bidirectional, int64_t cell_depth, float keep_prob, float cell_clip, int64_t num_proj,
  20. bool time_major, bool reset_after, bool is_training, ActivationType activation,
  21. GateOrderMode gate_order) {
  22. this->set_bidirectional(bidirectional);
  23. this->set_cell_depth(cell_depth);
  24. this->set_keep_prob(keep_prob);
  25. this->set_cell_clip(cell_clip);
  26. this->set_num_proj(num_proj);
  27. this->set_time_major(time_major);
  28. this->set_reset_after(reset_after);
  29. this->set_is_training(is_training);
  30. this->set_activation(activation);
  31. this->set_gate_order(gate_order);
  32. }
  33. void GRU::set_bidirectional(bool bidirectional) { AddAttr(kBidirectional, MakeValue(bidirectional)); }
  34. void GRU::set_cell_depth(int64_t cell_depth) { AddAttr(kCellDepth, MakeValue(cell_depth)); }
  35. void GRU::set_keep_prob(float keep_prob) { AddAttr(kKeepProb, MakeValue(keep_prob)); }
  36. void GRU::set_cell_clip(float cell_clip) { AddAttr(kCellClip, MakeValue(cell_clip)); }
  37. void GRU::set_num_proj(int64_t num_proj) {
  38. CheckAndConvertUtils::CheckInteger(kNumProj, num_proj, kGreaterThan, 0, this->name());
  39. AddAttr(kNumProj, MakeValue(num_proj));
  40. }
  41. void GRU::set_time_major(bool time_major) { AddAttr(kTimeMajor, MakeValue(time_major)); }
  42. void GRU::set_reset_after(bool reset_after) { AddAttr(kResetAfter, MakeValue(reset_after)); }
  43. void GRU::set_is_training(bool is_training) { AddAttr(kIsTraining, MakeValue(is_training)); }
  44. void GRU::set_activation(ActivationType activation) {
  45. int64_t swi = activation;
  46. AddAttr(kActivation, MakeValue(swi));
  47. }
  48. void GRU::set_gate_order(GateOrderMode gate_order) {
  49. int64_t swi = gate_order;
  50. AddAttr(kGateOrder, MakeValue(swi));
  51. }
  52. bool GRU::get_bidirectional() const {
  53. auto value_ptr = this->GetAttr(kBidirectional);
  54. return GetValue<bool>(value_ptr);
  55. }
  56. int64_t GRU::get_cell_depth() const {
  57. auto value_ptr = this->GetAttr(kCellDepth);
  58. return GetValue<int64_t>(value_ptr);
  59. }
  60. float GRU::get_keep_prob() const {
  61. auto value_ptr = this->GetAttr(kKeepProb);
  62. return GetValue<float>(value_ptr);
  63. }
  64. float GRU::get_cell_clip() const {
  65. auto value_ptr = this->GetAttr(kCellClip);
  66. return GetValue<float>(value_ptr);
  67. }
  68. int64_t GRU::get_num_proj() const {
  69. auto value_ptr = this->GetAttr(kNumProj);
  70. return GetValue<int64_t>(value_ptr);
  71. }
  72. bool GRU::get_time_major() const {
  73. auto value_ptr = this->GetAttr(kTimeMajor);
  74. return GetValue<bool>(value_ptr);
  75. }
  76. bool GRU::get_reset_after() const {
  77. auto value_ptr = this->GetAttr(kResetAfter);
  78. return GetValue<bool>(value_ptr);
  79. }
  80. bool GRU::get_is_training() const {
  81. auto value_ptr = this->GetAttr(kIsTraining);
  82. return GetValue<bool>(value_ptr);
  83. }
  84. ActivationType GRU::get_activation() const {
  85. auto value_ptr = this->GetAttr(kActivation);
  86. return ActivationType(GetValue<int64_t>(value_ptr));
  87. }
  88. GateOrderMode GRU::get_gate_order() const {
  89. auto value_ptr = this->GetAttr(kGateOrder);
  90. return GateOrderMode(GetValue<int64_t>(value_ptr));
  91. }
  92. REGISTER_PRIMITIVE_C(kNameGRU, GRU);
  93. } // namespace ops
  94. } // namespace mindspore