code: def _nary_tree_lstm(func, *inputs):
      cs = inputs[: len(inputs) // 2]
      hs = inputs[len(inputs) // 2 : -1]
      x = inputs[-1]
      device = backend.get_device_from_array(x)
      with chainer.using_device(device):
          xp = device.xp
          W_x = func.W_x.W.data.T
          b_x = func.W_x.b.data
          W_h_list = [
              getattr(func, "W_h{}".format(i)).W.data.T
              for i in range(1, func.n_ary + 1)
          ]
  
          W_xs = xp.split(W_x, 3 + func.n_ary, 1)
          W_xa, W_xi, W_xo, W_xfs = W_xs[0], W_xs[1], W_xs[2], W_xs[3:]
          b_xs = xp.split(b_x[None,], 3 + func.n_ary, 1)
          b_a, b_i, b_o, b_fs = b_xs[0], b_xs[1], b_xs[2], b_xs[3:]
          W_ha_list = [
              xp.split(W_h, 3 + func.n_ary, 1)[0] for W_h in W_h_list
          ]
          W_hi_list = [
              xp.split(W_h, 3 + func.n_ary, 1)[1] for W_h in W_h_list
          ]
          W_ho_list = [
              xp.split(W_h, 3 + func.n_ary, 1)[2] for W_h in W_h_list
          ]
          W_hfs_list = [
              xp.split(W_h, 3 + func.n_ary, 1)[3:] for W_h in W_h_list
          ]
          assert all(
              len(W_hfs_list) == len(W_hfs) for W_hfs in W_hfs_list
          )
  
          a = (
              x.dot(W_xa)
              + b_a
              + sum(h.dot(W_ha) for h, W_ha in zip(hs, W_ha_list))
          )
          i = (
              x.dot(W_xi)
              + b_i
              + sum(h.dot(W_hi) for h, W_hi in zip(hs, W_hi_list))
          )
          o = (
              x.dot(W_xo)
              + b_o
              + sum(h.dot(W_ho) for h, W_ho in zip(hs, W_ho_list))
          )
          f_list = [
              x.dot(W_xf)
              + b_f
              + sum(h.dot(W_hf) for h, W_hf in zip(hs, W_hf_list))
              for W_xf, b_f, W_hf_list in zip(
                  W_xfs, b_fs, zip(*W_hfs_list)
              )
          ]
  
          a = xp.tanh(a)
          i = _sigmoid(i)
          o = _sigmoid(o)
          f_list = [_sigmoid(f) for f in f_list]
  
          c_next = a * i + sum(f * c for f, c in zip(f_list, cs))
          y = o * xp.tanh(c_next)
      return c_next, y
  
imports: import unittest
  import numpy
  import chainer
  from chainer import backend
  from chainer.backends import cuda
  from chainer import gradient_check
  from chainer import links
  from chainer import testing
  from chainer.testing import attr
  from chainer.testing import condition
label_desc: Use image node_id 3 for calling a global function with example usage: _nary_tree_lstm(func) and returns: c_next,  y