parameters: (self, x, hx=None, seq_length=None)
return_statement: return x_n.astype(x_dtype), (hx_n[0].astype(x_dtype), hx_n[1].astype(x_dtype))
docstring: Defines the RNN like operators performed
docstring_summary: Defines the RNN like operators performed
docstring_tokens: Defines the RNN like operators performed
function: def construct(self, x, hx=None, seq_length=None):
          '''Defines the RNN like operators performed'''
          max_batch_size = x.shape[0] if self.batch_first else x.shape[1]
          num_directions = 2 if self.bidirectional else 1
          _check_is_tensor("x", x, self.cls_name)
          x_dtype = x.dtype
          if hx is not None:
              if not self.is_lstm:
                  _check_is_tensor("h", hx, self.cls_name)
                  _check_input_dtype_same_and_valid(['x', 'hx'], [x_dtype, hx.dtype], \
                                                    [mstype.float32, mstype.float16], self.cls_name)
              else:
                  _check_is_tuple('hx', hx, self.cls_name)
                  _check_tuple_length('hx', hx, 2, self.cls_name)
                  _check_is_tensor('hx[0]', hx[0], self.cls_name)
                  _check_is_tensor('hx[1]', hx[1], self.cls_name)
                  _check_input_dtype_same_and_valid(['x', 'hx[0]', 'hx[1]'], [x_dtype, hx[0].dtype, hx[1].dtype], \
                                                   [mstype.float32, mstype.float16], self.cls_name)
          else:
              hx = _init_state((self.num_layers * num_directions, max_batch_size, self.hidden_size), \
                               x_dtype, self.is_lstm)
          if seq_length is not None:
              _check_input_dtype(seq_length.dtype, "seq_length", [mstype.int32, mstype.int64], self.cls_name)
              _check_seq_length_size(max_batch_size, seq_length.shape[0], self.cls_name)
          if self.batch_first:
              x = P.Transpose()(x, (1, 0, 2))
          if self.bidirectional:
              x_n, hx_n = self._stacked_bi_dynamic_rnn(x, hx, seq_length)
          else:
              x_n, hx_n = self._stacked_dynamic_rnn(x, hx, seq_length)
          if self.batch_first:
              x_n = P.Transpose()(x_n, (1, 0, 2))
          if not self.is_lstm:
              return x_n.astype(x_dtype), hx_n.astype(x_dtype)
          return x_n.astype(x_dtype), (hx_n[0].astype(x_dtype), hx_n[1].astype(x_dtype))
function_tokens: def construct ( self , x , hx = None , seq_length = None ) : max_batch_size = x . shape [ 0 ] if self . batch_first else x . shape [ 1 ] num_directions = 2 if self . bidirectional else 1 _check_is_tensor ( "x" , x , self . cls_name ) x_dtype = x . dtype if hx is not None : if not self . is_lstm : _check_is_tensor ( "h" , hx , self . cls_name ) _check_input_dtype_same_and_valid ( [ 'x' , 'hx' ] , [ x_dtype , hx . dtype ] , [ mstype . float32 , mstype . float16 ] , self . cls_name ) else : _check_is_tuple ( 'hx' , hx , self . cls_name ) _check_tuple_length ( 'hx' , hx , 2 , self . cls_name ) _check_is_tensor ( 'hx[0]' , hx [ 0 ] , self . cls_name ) _check_is_tensor ( 'hx[1]' , hx [ 1 ] , self . cls_name ) _check_input_dtype_same_and_valid ( [ 'x' , 'hx[0]' , 'hx[1]' ] , [ x_dtype , hx [ 0 ] . dtype , hx [ 1 ] . dtype ] , [ mstype . float32 , mstype . float16 ] , self . cls_name ) else : hx = _init_state ( ( self . num_layers * num_directions , max_batch_size , self . hidden_size ) , x_dtype , self . is_lstm ) if seq_length is not None : _check_input_dtype ( seq_length . dtype , "seq_length" , [ mstype . int32 , mstype . int64 ] , self . cls_name ) _check_seq_length_size ( max_batch_size , seq_length . shape [ 0 ] , self . cls_name ) if self . batch_first : x = P . Transpose ( ) ( x , ( 1 , 0 , 2 ) ) if self . bidirectional : x_n , hx_n = self . _stacked_bi_dynamic_rnn ( x , hx , seq_length ) else : x_n , hx_n = self . _stacked_dynamic_rnn ( x , hx , seq_length ) if self . batch_first : x_n = P . Transpose ( ) ( x_n , ( 1 , 0 , 2 ) ) if not self . is_lstm : return x_n . astype ( x_dtype ) , hx_n . astype ( x_dtype ) return x_n . astype ( x_dtype ) , ( hx_n [ 0 ] . astype ( x_dtype ) , hx_n [ 1 ] . astype ( x_dtype ) )