code: def row_sparse_array(arg1, shape=None, ctx=None, dtype=None):
      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:
              _check_shape(arg1, shape)
              return empty('row_sparse', arg1, ctx=ctx, dtype=dtype)
          else:
              if isinstance(arg1[0], integer_types) and isinstance(arg1[1], integer_types):
                  _check_shape(arg1, shape)
                  return empty('row_sparse', arg1, ctx=ctx, dtype=dtype)
              else:
                  return _row_sparse_ndarray_from_definition(arg1[0], arg1[1], shape=shape,
                                                             ctx=ctx, dtype=dtype)
      else:
          if isinstance(arg1, RowSparseNDArray):
              _check_shape(arg1.shape, shape)
              return array(arg1, ctx=ctx, dtype=dtype)
          elif isinstance(arg1, CSRNDArray):
              raise ValueError("Unexpected input type: CSRNDArray")
          else:
              dtype = _prepare_default_dtype(arg1, dtype)
              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')