code: def test_rnn_with_seq_lengths(self):
      dev = gpu_dev
  
      # params
      hidden_size = 7
      seq_length = 5
      batch_size = 6
      feature_size = 3
      directions = 2
      num_layers = 2
  
      # shapes
      x_s = (seq_length, batch_size, feature_size)
      y_s = (seq_length, batch_size, hidden_size)
      states_s = (num_layers * directions, batch_size, hidden_size)
  
      # tensors
      x = tensor.Tensor(x_s, dev).gaussian(0, 1)
      y = tensor.Tensor(y_s, dev).gaussian(0, 1)
      dy = tensor.Tensor(y_s, dev).gaussian(0, 1)
      dhy = tensor.Tensor(states_s, dev).gaussian(0, 1)
      dcy = tensor.Tensor(states_s, dev).gaussian(0, 1)
      hx = tensor.Tensor(states_s, dev).gaussian(0, 1)
      cx = tensor.Tensor(states_s, dev).gaussian(0, 1)
  
      # handle
      rnn_handle = singa_api.CudnnRNNHandle(x.data, hidden_size, 2)
      w = tensor.Tensor((rnn_handle.weights_size,), dev).gaussian(0, 1)
  
      # seq lengths
      seq_lengths = tensor.from_numpy(
          np.array([seq_length] * batch_size)
      )
  
      # operations
      (dx, dhx, dcx) = singa_api.GpuRNNBackwardxEx(
          y.data,
          dy.data,
          dhy.data,
          dcy.data,
          w.data,
          hx.data,
          cx.data,
          seq_lengths.data,
          rnn_handle,
      )
  
imports: from __future__ import division
  import unittest
  import math
  import numpy
  from singa import singa_wrap
  from singa import tensor
  from cuda_helper import gpu_dev, cpu_dev
label_desc: Use image node_id 40 for calling the TestAPI obj's underlying member method code with example usage: obj.test_rnn_with_seq_lengths() without return types