parameters: (handle)
return_statement: return ret_function
docstring: Create a NDArray function from the FunctionHandle.
docstring_summary: Create a NDArray function from the FunctionHandle.
docstring_tokens: Create a NDArray function from the FunctionHandle .
function: def _make_ndarray_function(handle):
      """Create a NDArray function from the FunctionHandle."""
      NDARRAY_ARG_BEFORE_SCALAR = 1
      ACCEPT_EMPTY_MUTATE_TARGET = 1 << 2
      # Get the property of NDArray
      n_used_vars = mx_uint()
      n_scalars = mx_uint()
      n_mutate_vars = mx_uint()
      type_mask = ctypes.c_int()
      check_call(_LIB.MXFuncDescribe(
          handle,
          ctypes.byref(n_used_vars),
          ctypes.byref(n_scalars),
          ctypes.byref(n_mutate_vars),
          ctypes.byref(type_mask)))
      n_mutate_vars = n_mutate_vars.value
      n_used_vars = n_used_vars.value
      n_scalars = n_scalars.value
      type_mask = type_mask.value
      accept_empty_mutate = (type_mask & ACCEPT_EMPTY_MUTATE_TARGET) != 0
      # infer type of the function
      if (type_mask & NDARRAY_ARG_BEFORE_SCALAR) != 0:
          use_vars_range = range(0, n_used_vars)
          scalar_range = range(n_used_vars, n_used_vars + n_scalars)
      else:
          scalar_range = range(0, n_scalars)
          use_vars_range = range(n_scalars, n_used_vars + n_scalars)
  
      # Get the information from the function
      name = ctypes.c_char_p()
      desc = ctypes.c_char_p()
      num_args = mx_uint()
      arg_names = ctypes.POINTER(ctypes.c_char_p)()
      arg_types = ctypes.POINTER(ctypes.c_char_p)()
      arg_descs = ctypes.POINTER(ctypes.c_char_p)()
      ret_type = ctypes.c_char_p()
  
      check_call(_LIB.MXFuncGetInfo(
          handle, ctypes.byref(name), ctypes.byref(desc),
          ctypes.byref(num_args),
          ctypes.byref(arg_names),
          ctypes.byref(arg_types),
          ctypes.byref(arg_descs),
          ctypes.byref(ret_type)))
      func_name = py_str(name.value)
      param_str = ctypes2docstring(num_args, arg_names, arg_types, arg_descs)
      doc_str = ('%s\n\n' +
                 '%s\n' +
                 'out : NDArray, optional\n' +
                 '    The output NDArray to hold the result.\n\n'+
                 'Returns\n' +
                 '-------\n' +
                 'out : NDArray\n'+
                 '    The output of binary function.')
      doc_str = doc_str % (py_str(desc.value), param_str)
  
      # Definition of internal functions.
      def binary_ndarray_function(lhs, rhs, out=None):
          """Internal binary function
          """
          if out:
              if isinstance(out, NDArray) == False:
                  raise TypeError('out must be NDArray')
              if not out.writable:
                  raise TypeError('out must be writable')
          else:
              if not accept_empty_mutate:
                  raise TypeError('argument out is required to call %s' % func_name)
              out = NDArray(_new_empty_handle())
          check_call(_LIB.MXFuncInvokeEx(handle,
                                         c_array(NDArrayHandle, (lhs.handle, rhs.handle)),
                                         c_array(mx_float, ()),
                                         c_array(NDArrayHandle, (out.handle,)),
                                         ctypes.c_int(0),
                                         c_array(ctypes.c_char_p, []),
                                         c_array(ctypes.c_char_p, [])))
          return out
  
      def unary_ndarray_function(src, out=None):
          """internal NDArray function"""
          if out:
              if isinstance(out, NDArray) == False:
                  raise TypeError('out must be NDArray')
              if not out.writable:
                  raise TypeError('out must be writable')
          else:
              if not accept_empty_mutate:
                  raise TypeError('argument out is required to call %s' % func_name)
              out = NDArray(_new_empty_handle())
          check_call(_LIB.MXFuncInvokeEx( \
                  handle, \
                  c_array(NDArrayHandle, (src.handle,)), \
                  c_array(mx_float, ()), \
                  c_array(NDArrayHandle, (out.handle,)), \
                  ctypes.c_int(0), \
                  c_array(ctypes.c_char_p, []), \
                  c_array(ctypes.c_char_p, [])))
          return out
  
      def generic_ndarray_function(*args, **kwargs):
          """Invoke this function by passing in parameters
  
          Parameters
          ----------
          *args
              Positional arguments of input scalars and NDArray
          out : NDArray or tuple of NDArray, optional
              Output NDArray, used to hold the output result.
  
          Returns
          -------
          out : NDArray
              The result NDArray(tuple) of result of computation.
          """
          if 'out' in kwargs:
              mutate_vars = kwargs['out']
              if isinstance(mutate_vars, NDArray):
                  mutate_vars = (mutate_vars,)
              if len(mutate_vars) != n_mutate_vars:
                  raise TypeError('expect %d out in %s', n_mutate_vars, func_name)
              del kwargs['out']
          else:
              if accept_empty_mutate:
                  mutate_vars = tuple(
                      NDArray(_new_empty_handle()) for i in range(n_mutate_vars))
              else:
                  raise TypeError('argument out is required to call %s' % func_name)
          check_call(_LIB.MXFuncInvokeEx( \
                  handle, \
                  c_array(NDArrayHandle, [args[i].handle for i in use_vars_range]), \
                  c_array(mx_float, [args[i] for i in scalar_range]), \
                  c_array(NDArrayHandle, [v.handle for v in mutate_vars]), \
                  ctypes.c_int(len(kwargs)), \
                  c_array(ctypes.c_char_p, kwargs.keys()), \
                  c_array(ctypes.c_char_p, [str(i) for i in kwargs.values()])))
          if n_mutate_vars == 1:
              return mutate_vars[0]
          else:
              return mutate_vars
      # End of function declaration
      if n_mutate_vars == 1 and n_used_vars == 2 and n_scalars == 0:
          ret_function = binary_ndarray_function
      elif n_mutate_vars == 1 and n_used_vars == 1 and n_scalars == 0:
          ret_function = unary_ndarray_function
      else:
          ret_function = generic_ndarray_function
      ret_function.__name__ = func_name
      ret_function.__doc__ = doc_str
      return ret_function
function_tokens: def _make_ndarray_function ( handle ) : NDARRAY_ARG_BEFORE_SCALAR = 1 ACCEPT_EMPTY_MUTATE_TARGET = 1 << 2 # Get the property of NDArray n_used_vars = mx_uint ( ) n_scalars = mx_uint ( ) n_mutate_vars = mx_uint ( ) type_mask = ctypes . c_int ( ) check_call ( _LIB . MXFuncDescribe ( handle , ctypes . byref ( n_used_vars ) , ctypes . byref ( n_scalars ) , ctypes . byref ( n_mutate_vars ) , ctypes . byref ( type_mask ) ) ) n_mutate_vars = n_mutate_vars . value n_used_vars = n_used_vars . value n_scalars = n_scalars . value type_mask = type_mask . value accept_empty_mutate = ( type_mask & ACCEPT_EMPTY_MUTATE_TARGET ) != 0 # infer type of the function if ( type_mask & NDARRAY_ARG_BEFORE_SCALAR ) != 0 : use_vars_range = range ( 0 , n_used_vars ) scalar_range = range ( n_used_vars , n_used_vars + n_scalars ) else : scalar_range = range ( 0 , n_scalars ) use_vars_range = range ( n_scalars , n_used_vars + n_scalars ) # Get the information from the function name = ctypes . c_char_p ( ) desc = ctypes . c_char_p ( ) num_args = mx_uint ( ) arg_names = ctypes . POINTER ( ctypes . c_char_p ) ( ) arg_types = ctypes . POINTER ( ctypes . c_char_p ) ( ) arg_descs = ctypes . POINTER ( ctypes . c_char_p ) ( ) ret_type = ctypes . c_char_p ( ) check_call ( _LIB . MXFuncGetInfo ( handle , ctypes . byref ( name ) , ctypes . byref ( desc ) , ctypes . byref ( num_args ) , ctypes . byref ( arg_names ) , ctypes . byref ( arg_types ) , ctypes . byref ( arg_descs ) , ctypes . byref ( ret_type ) ) ) func_name = py_str ( name . value ) param_str = ctypes2docstring ( num_args , arg_names , arg_types , arg_descs ) doc_str = ( '%s\n\n' + '%s\n' + 'out : NDArray, optional\n' + '    The output NDArray to hold the result.\n\n' + 'Returns\n' + '-------\n' + 'out : NDArray\n' + '    The output of binary function.' ) doc_str = doc_str % ( py_str ( desc . value ) , param_str ) # Definition of internal functions. def binary_ndarray_function ( lhs , rhs , out = None ) : """Internal binary function
          """ if out : if isinstance ( out , NDArray ) == False : raise TypeError ( 'out must be NDArray' ) if not out . writable : raise TypeError ( 'out must be writable' ) else : if not accept_empty_mutate : raise TypeError ( 'argument out is required to call %s' % func_name ) out = NDArray ( _new_empty_handle ( ) ) check_call ( _LIB . MXFuncInvokeEx ( handle , c_array ( NDArrayHandle , ( lhs . handle , rhs . handle ) ) , c_array ( mx_float , ( ) ) , c_array ( NDArrayHandle , ( out . handle , ) ) , ctypes . c_int ( 0 ) , c_array ( ctypes . c_char_p , [ ] ) , c_array ( ctypes . c_char_p , [ ] ) ) ) return out def unary_ndarray_function ( src , out = None ) : """internal NDArray function""" if out : if isinstance ( out , NDArray ) == False : raise TypeError ( 'out must be NDArray' ) if not out . writable : raise TypeError ( 'out must be writable' ) else : if not accept_empty_mutate : raise TypeError ( 'argument out is required to call %s' % func_name ) out = NDArray ( _new_empty_handle ( ) ) check_call ( _LIB . MXFuncInvokeEx ( handle , c_array ( NDArrayHandle , ( src . handle , ) ) , c_array ( mx_float , ( ) ) , c_array ( NDArrayHandle , ( out . handle , ) ) , ctypes . c_int ( 0 ) , c_array ( ctypes . c_char_p , [ ] ) , c_array ( ctypes . c_char_p , [ ] ) ) ) return out def generic_ndarray_function ( * args , * * kwargs ) : """Invoke this function by passing in parameters
  
          Parameters
          ----------
          *args
              Positional arguments of input scalars and NDArray
          out : NDArray or tuple of NDArray, optional
              Output NDArray, used to hold the output result.
  
          Returns
          -------
          out : NDArray
              The result NDArray(tuple) of result of computation.
          """ if 'out' in kwargs : mutate_vars = kwargs [ 'out' ] if isinstance ( mutate_vars , NDArray ) : mutate_vars = ( mutate_vars , ) if len ( mutate_vars ) != n_mutate_vars : raise TypeError ( 'expect %d out in %s' , n_mutate_vars , func_name ) del kwargs [ 'out' ] else : if accept_empty_mutate : mutate_vars = tuple ( NDArray ( _new_empty_handle ( ) ) for i in range ( n_mutate_vars ) ) else : raise TypeError ( 'argument out is required to call %s' % func_name ) check_call ( _LIB . MXFuncInvokeEx ( handle , c_array ( NDArrayHandle , [ args [ i ] . handle for i in use_vars_range ] ) , c_array ( mx_float , [ args [ i ] for i in scalar_range ] ) , c_array ( NDArrayHandle , [ v . handle for v in mutate_vars ] ) , ctypes . c_int ( len ( kwargs ) ) , c_array ( ctypes . c_char_p , kwargs . keys ( ) ) , c_array ( ctypes . c_char_p , [ str ( i ) for i in kwargs . values ( ) ] ) ) ) if n_mutate_vars == 1 : return mutate_vars [ 0 ] else : return mutate_vars # End of function declaration if n_mutate_vars == 1 and n_used_vars == 2 and n_scalars == 0 : ret_function = binary_ndarray_function elif n_mutate_vars == 1 and n_used_vars == 1 and n_scalars == 0 : ret_function = unary_ndarray_function else : ret_function = generic_ndarray_function ret_function . __name__ = func_name ret_function . __doc__ = doc_str return ret_function