nodes: 0, module; 1, function_definition; 2, function_name:row_sparse_array; 3, parameters; 4, block; 5, identifier:arg1; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, comment:# construct a row sparse array from (D0, D1 ..) or (data, indices); 11, if_statement; 12, identifier:shape; 13, None; 14, identifier:ctx; 15, None; 16, identifier:dtype; 17, None; 18, comment:"""Creates a `RowSparseNDArray`, a multidimensional row sparse array with a set of \
      tensor slices at given indices.
  
      The RowSparseNDArray can be instantiated in several ways:
  
      - row_sparse_array(D):
          to construct a RowSparseNDArray with a dense ndarray ``D``
          -  **D** (*array_like*) - An object exposing the array interface, an object whose \
          `__array__` method returns an array, or any (nested) sequence.
          - **ctx** (*Context, optional*) - Device context \
          (default is the current default context).
          - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. \
          The default dtype is ``D.dtype`` if ``D`` is an NDArray or numpy.ndarray, \
          float32 otherwise.
  
      - row_sparse_array(S)
          to construct a RowSparseNDArray with a sparse ndarray ``S``
          -  **S** (*RowSparseNDArray*) - A sparse ndarray.
          - **ctx** (*Context, optional*) - Device context \
          (default is the current default context).
          - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. \
          The default dtype is ``S.dtype``.
  
      - row_sparse_array((D0, D1 .. Dn))
          to construct an empty RowSparseNDArray with shape ``(D0, D1, ... Dn)``
          -  **D0, D1 .. Dn** (*int*) - The shape of the ndarray
          - **ctx** (*Context, optional*) - Device context \
          (default is the current default context).
          - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. \
              The default dtype is float32.
  
      - row_sparse_array((data, indices))
          to construct a RowSparseNDArray based on the definition of row sparse format \
          using two separate arrays, \
          where the `indices` stores the indices of the row slices with non-zeros,
          while the values are stored in `data`. The corresponding NDArray ``dense``
          represented by RowSparseNDArray ``rsp`` has \
          ``dense[rsp.indices[i], :, :, :, ...] = rsp.data[i, :, :, :, ...]``
          The row indices for are expected to be **sorted in ascending order.** \
          - **data** (*array_like*) - An object exposing the array interface, which \
          holds all the non-zero row slices of the array.
          - **indices** (*array_like*) - An object exposing the array interface, which \
          stores the row index for each row slice with non-zero elements.
          - **shape** (*tuple of int, optional*) - The shape of the array. The default \
          shape is inferred from the indices and indptr arrays.
          - **ctx** (*Context, optional*) - Device context \
          (default is the current default context).
          - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. \
          The default dtype is float32.
  
      Parameters
      ----------
      arg1 : NDArray, numpy.ndarray, RowSparseNDArray, tuple of int or tuple of array_like
          The argument to help instantiate the row sparse ndarray. See above for further details.
      shape : tuple of int, optional
          The shape of the row sparse ndarray. (Default value = None)
      ctx : Context, optional
          Device context (default is the current default context).
      dtype : str or numpy.dtype, optional
          The data type of the output array. (Default value = None)
  
      Returns
      -------
      RowSparseNDArray
          An `RowSparseNDArray` with the `row_sparse` storage representation.
  
      Examples
      --------
      >>> a = mx.nd.sparse.row_sparse_array(([[1, 2], [3, 4]], [1, 4]), shape=(6, 2))
      >>> a.asnumpy()
      array([[ 0.,  0.],
             [ 1.,  2.],
             [ 0.,  0.],
             [ 0.,  0.],
             [ 3.,  4.],
             [ 0.,  0.]], dtype=float32)
  
      See Also
      --------
      RowSparseNDArray : MXNet NDArray in row sparse format.
      """; 19, call; 20, block; 21, else_clause; 22, identifier:isinstance; 23, argument_list; 24, expression_statement; 25, if_statement; 26, comment:# construct a row sparse ndarray from a dense / sparse array; 27, block; 28, identifier:arg1; 29, identifier:tuple; 30, assignment; 31, comparison_operator:arg_len < 2; 32, block; 33, elif_clause; 34, else_clause; 35, if_statement; 36, identifier:arg_len; 37, call; 38, identifier:arg_len; 39, integer:2; 40, raise_statement; 41, comparison_operator:arg_len > 2; 42, comment:# empty ndarray with shape; 43, block; 44, comment:# len(arg1) = 2, is either shape or (data, indices); 45, block; 46, call; 47, comment:# construct a row sparse ndarray from RowSparseNDArray; 48, block; 49, elif_clause; 50, else_clause; 51, identifier:len; 52, argument_list; 53, call; 54, identifier:arg_len; 55, integer:2; 56, expression_statement; 57, return_statement; 58, if_statement; 59, identifier:isinstance; 60, argument_list; 61, expression_statement; 62, return_statement; 63, call; 64, block; 65, comment:# construct a csr matrix from a dense one; 66, comment:# prepare default dtype since mx.nd.array doesn't use default values; 67, comment:# based on source_array; 68, block; 69, identifier:arg1; 70, identifier:ValueError; 71, argument_list; 72, call; 73, call; 74, boolean_operator; 75, comment:# empty ndarray with shape; 76, block; 77, else_clause; 78, identifier:arg1; 79, identifier:RowSparseNDArray; 80, call; 81, call; 82, identifier:isinstance; 83, argument_list; 84, raise_statement; 85, expression_statement; 86, comment:# create dns array with provided dtype. ctx is not passed since copy across; 87, comment:# ctx requires dtype to be the same; 88, expression_statement; 89, if_statement; 90, expression_statement; 91, return_statement; 92, binary_operator:"Unexpected length of input tuple: " + str(arg_len); 93, identifier:_check_shape; 94, argument_list; 95, identifier:empty; 96, argument_list; 97, call; 98, call; 99, expression_statement; 100, return_statement; 101, comment:# data, indices, indptr; 102, block; 103, identifier:_check_shape; 104, argument_list; 105, identifier:array; 106, argument_list; 107, identifier:arg1; 108, identifier:CSRNDArray; 109, call; 110, assignment; 111, assignment; 112, boolean_operator; 113, block; 114, call; 115, call; 116, string:"Unexpected length of input tuple: "; 117, call; 118, identifier:arg1; 119, identifier:shape; 120, string; 121, identifier:arg1; 122, keyword_argument; 123, keyword_argument; 124, identifier:isinstance; 125, argument_list; 126, identifier:isinstance; 127, argument_list; 128, call; 129, call; 130, return_statement; 131, attribute; 132, identifier:shape; 133, identifier:arg1; 134, keyword_argument; 135, keyword_argument; 136, identifier:ValueError; 137, argument_list; 138, identifier:dtype; 139, call; 140, identifier:dns; 141, call; 142, comparison_operator:ctx is not None; 143, comparison_operator:dns.context != ctx; 144, expression_statement; 145, identifier:_check_shape; 146, argument_list; 147, attribute; 148, argument_list; 149, identifier:str; 150, argument_list; 151, string_content:row_sparse; 152, identifier:ctx; 153, identifier:ctx; 154, identifier:dtype; 155, identifier:dtype; 156, subscript; 157, identifier:integer_types; 158, subscript; 159, identifier:integer_types; 160, identifier:_check_shape; 161, argument_list; 162, identifier:empty; 163, argument_list; 164, call; 165, identifier:arg1; 166, identifier:shape; 167, identifier:ctx; 168, identifier:ctx; 169, identifier:dtype; 170, identifier:dtype; 171, string:"Unexpected input type: CSRNDArray"; 172, identifier:_prepare_default_dtype; 173, argument_list; 174, identifier:_array; 175, argument_list; 176, identifier:ctx; 177, None; 178, attribute; 179, identifier:ctx; 180, assignment; 181, attribute; 182, identifier:shape; 183, identifier:dns; 184, identifier:tostype; 185, string; 186, identifier:arg_len; 187, identifier:arg1; 188, integer:0; 189, identifier:arg1; 190, integer:1; 191, identifier:arg1; 192, identifier:shape; 193, string; 194, identifier:arg1; 195, keyword_argument; 196, keyword_argument; 197, identifier:_row_sparse_ndarray_from_definition; 198, argument_list; 199, identifier:arg1; 200, identifier:dtype; 201, identifier:arg1; 202, keyword_argument; 203, identifier:dns; 204, identifier:context; 205, identifier:dns; 206, call; 207, identifier:dns; 208, identifier:shape; 209, string_content:row_sparse; 210, string_content:row_sparse; 211, identifier:ctx; 212, identifier:ctx; 213, identifier:dtype; 214, identifier:dtype; 215, subscript; 216, subscript; 217, keyword_argument; 218, keyword_argument; 219, keyword_argument; 220, identifier:dtype; 221, identifier:dtype; 222, attribute; 223, argument_list; 224, identifier:arg1; 225, integer:0; 226, identifier:arg1; 227, integer:1; 228, identifier:shape; 229, identifier:shape; 230, identifier:ctx; 231, identifier:ctx; 232, identifier:dtype; 233, identifier:dtype; 234, identifier:dns; 235, identifier:as_in_context; 236, identifier:ctx
code: def row_sparse_array(arg1, shape=None, ctx=None, dtype=None):
      """Creates a `RowSparseNDArray`, a multidimensional row sparse array with a set of \
      tensor slices at given indices.
  
      The RowSparseNDArray can be instantiated in several ways:
  
      - row_sparse_array(D):
          to construct a RowSparseNDArray with a dense ndarray ``D``
          -  **D** (*array_like*) - An object exposing the array interface, an object whose \
          `__array__` method returns an array, or any (nested) sequence.
          - **ctx** (*Context, optional*) - Device context \
          (default is the current default context).
          - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. \
          The default dtype is ``D.dtype`` if ``D`` is an NDArray or numpy.ndarray, \
          float32 otherwise.
  
      - row_sparse_array(S)
          to construct a RowSparseNDArray with a sparse ndarray ``S``
          -  **S** (*RowSparseNDArray*) - A sparse ndarray.
          - **ctx** (*Context, optional*) - Device context \
          (default is the current default context).
          - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. \
          The default dtype is ``S.dtype``.
  
      - row_sparse_array((D0, D1 .. Dn))
          to construct an empty RowSparseNDArray with shape ``(D0, D1, ... Dn)``
          -  **D0, D1 .. Dn** (*int*) - The shape of the ndarray
          - **ctx** (*Context, optional*) - Device context \
          (default is the current default context).
          - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. \
              The default dtype is float32.
  
      - row_sparse_array((data, indices))
          to construct a RowSparseNDArray based on the definition of row sparse format \
          using two separate arrays, \
          where the `indices` stores the indices of the row slices with non-zeros,
          while the values are stored in `data`. The corresponding NDArray ``dense``
          represented by RowSparseNDArray ``rsp`` has \
          ``dense[rsp.indices[i], :, :, :, ...] = rsp.data[i, :, :, :, ...]``
          The row indices for are expected to be **sorted in ascending order.** \
          - **data** (*array_like*) - An object exposing the array interface, which \
          holds all the non-zero row slices of the array.
          - **indices** (*array_like*) - An object exposing the array interface, which \
          stores the row index for each row slice with non-zero elements.
          - **shape** (*tuple of int, optional*) - The shape of the array. The default \
          shape is inferred from the indices and indptr arrays.
          - **ctx** (*Context, optional*) - Device context \
          (default is the current default context).
          - **dtype** (*str or numpy.dtype, optional*) - The data type of the output array. \
          The default dtype is float32.
  
      Parameters
      ----------
      arg1 : NDArray, numpy.ndarray, RowSparseNDArray, tuple of int or tuple of array_like
          The argument to help instantiate the row sparse ndarray. See above for further details.
      shape : tuple of int, optional
          The shape of the row sparse ndarray. (Default value = None)
      ctx : Context, optional
          Device context (default is the current default context).
      dtype : str or numpy.dtype, optional
          The data type of the output array. (Default value = None)
  
      Returns
      -------
      RowSparseNDArray
          An `RowSparseNDArray` with the `row_sparse` storage representation.
  
      Examples
      --------
      >>> a = mx.nd.sparse.row_sparse_array(([[1, 2], [3, 4]], [1, 4]), shape=(6, 2))
      >>> a.asnumpy()
      array([[ 0.,  0.],
             [ 1.,  2.],
             [ 0.,  0.],
             [ 0.,  0.],
             [ 3.,  4.],
             [ 0.,  0.]], dtype=float32)
  
      See Also
      --------
      RowSparseNDArray : MXNet NDArray in row sparse format.
      """
      # construct a row sparse array from (D0, D1 ..) or (data, indices)
      if isinstance(arg1, tuple):
          arg_len = len(arg1)
          if arg_len < 2:
              raise ValueError("Unexpected length of input tuple: " + str(arg_len))
          elif arg_len > 2:
              # empty ndarray with shape
              _check_shape(arg1, shape)
              return empty('row_sparse', arg1, ctx=ctx, dtype=dtype)
          else:
              # len(arg1) = 2, is either shape or (data, indices)
              if isinstance(arg1[0], integer_types) and isinstance(arg1[1], integer_types):
                  # empty ndarray with shape
                  _check_shape(arg1, shape)
                  return empty('row_sparse', arg1, ctx=ctx, dtype=dtype)
              else:
                  # data, indices, indptr
                  return _row_sparse_ndarray_from_definition(arg1[0], arg1[1], shape=shape,
                                                             ctx=ctx, dtype=dtype)
      else:
          # construct a row sparse ndarray from a dense / sparse array
          if isinstance(arg1, RowSparseNDArray):
              # construct a row sparse ndarray from RowSparseNDArray
              _check_shape(arg1.shape, shape)
              return array(arg1, ctx=ctx, dtype=dtype)
          elif isinstance(arg1, CSRNDArray):
              raise ValueError("Unexpected input type: CSRNDArray")
          else:
              # construct a csr matrix from a dense one
              # prepare default dtype since mx.nd.array doesn't use default values
              # based on source_array
              dtype = _prepare_default_dtype(arg1, dtype)
              # create dns array with provided dtype. ctx is not passed since copy across
              # ctx requires dtype to be the same
              dns = _array(arg1, dtype=dtype)
              if ctx is not None and dns.context != ctx:
                  dns = dns.as_in_context(ctx)
              _check_shape(dns.shape, shape)
              return dns.tostype('row_sparse')