parameters: (data)
docstring: Return a tensor to use for input data.
  
    The incoming features can be a dict where keys are the string names of the
    columns, which we turn into a single 2-D tensor.
  
    Args:
      data: `Tensor` or `dict` of `Tensor` objects.
  
    Returns:
      A 2-D tensor for input to tensor_forest, a keys tensor for the
      tf.Examples if they exist, and a list of the type of each column
      (e.g. continuous float, categorical).
docstring_summary: Return a tensor to use for input data.
docstring_tokens: Return a tensor to use for input data .
function: def ParseDataTensorOrDict(data):
    """Return a tensor to use for input data.
  
    The incoming features can be a dict where keys are the string names of the
    columns, which we turn into a single 2-D tensor.
  
    Args:
      data: `Tensor` or `dict` of `Tensor` objects.
  
    Returns:
      A 2-D tensor for input to tensor_forest, a keys tensor for the
      tf.Examples if they exist, and a list of the type of each column
      (e.g. continuous float, categorical).
    """
    data_spec = TensorForestDataSpec()
    if isinstance(data, dict):
      dense_features_size = 0
      dense_features = []
      sparse_features = []
      for k in sorted(data.keys()):
        is_sparse = isinstance(data[k], sparse_tensor.SparseTensor)
        if is_sparse:
          # TODO(gilberth): support sparse continuous.
          if data[k].dtype == dtypes.float32:
            logging.info('TensorForest does not support sparse continuous.')
            continue
          elif data_spec.sparse.size() == 0:
            col_spec = data_spec.sparse.add()
            col_spec.original_type = DATA_CATEGORICAL
            col_spec.name = 'all_sparse'
            col_spec.size = -1
          sparse_features.append(
              sparse_tensor.SparseTensor(data[
                  k].indices, CastToFloat(data[k].values), data[k].dense_shape))
        else:
          col_spec = data_spec.dense.add()
  
          col_spec.original_type = DTYPE_TO_FTYPE[data[k].dtype]
          col_spec.name = GetColumnName(k, len(dense_features))
          # the second dimension of get_shape should always be known.
          shape = data[k].get_shape()
          if len(shape) == 1:
            col_spec.size = 1
          else:
            col_spec.size = shape[1].value
  
          dense_features_size += col_spec.size
          dense_features.append(CastToFloat(data[k]))
  
      processed_dense_features = None
      processed_sparse_features = None
      if dense_features:
        processed_dense_features = array_ops.concat(dense_features, 1)
        data_spec.dense_features_size = dense_features_size
      if sparse_features:
        processed_sparse_features = sparse_ops.sparse_concat(1, sparse_features)
      logging.info(data_spec.SerializeToString())
      return processed_dense_features, processed_sparse_features, data_spec
    elif isinstance(data, sparse_tensor.SparseTensor):
      col_spec = data_spec.sparse.add()
      col_spec.name = 'sparse_features'
      col_spec.original_type = DTYPE_TO_FTYPE[data.dtype]
      col_spec.size = -1
      data_spec.dense_features_size = 0
      return None, data, data_spec
    else:
      data = ops.convert_to_tensor(data)
      col_spec = data_spec.dense.add()
      col_spec.name = 'dense_features'
      col_spec.original_type = DTYPE_TO_FTYPE[data.dtype]
      col_spec.size = data.get_shape()[1]
      data_spec.dense_features_size = col_spec.size
      return data, None, data_spec
function_tokens: def ParseDataTensorOrDict ( data ) : data_spec = TensorForestDataSpec ( ) if isinstance ( data , dict ) : dense_features_size = 0 dense_features = [ ] sparse_features = [ ] for k in sorted ( data . keys ( ) ) : is_sparse = isinstance ( data [ k ] , sparse_tensor . SparseTensor ) if is_sparse : # TODO(gilberth): support sparse continuous. if data [ k ] . dtype == dtypes . float32 : logging . info ( 'TensorForest does not support sparse continuous.' ) continue elif data_spec . sparse . size ( ) == 0 : col_spec = data_spec . sparse . add ( ) col_spec . original_type = DATA_CATEGORICAL col_spec . name = 'all_sparse' col_spec . size = - 1 sparse_features . append ( sparse_tensor . SparseTensor ( data [ k ] . indices , CastToFloat ( data [ k ] . values ) , data [ k ] . dense_shape ) ) else : col_spec = data_spec . dense . add ( ) col_spec . original_type = DTYPE_TO_FTYPE [ data [ k ] . dtype ] col_spec . name = GetColumnName ( k , len ( dense_features ) ) # the second dimension of get_shape should always be known. shape = data [ k ] . get_shape ( ) if len ( shape ) == 1 : col_spec . size = 1 else : col_spec . size = shape [ 1 ] . value dense_features_size += col_spec . size dense_features . append ( CastToFloat ( data [ k ] ) ) processed_dense_features = None processed_sparse_features = None if dense_features : processed_dense_features = array_ops . concat ( dense_features , 1 ) data_spec . dense_features_size = dense_features_size if sparse_features : processed_sparse_features = sparse_ops . sparse_concat ( 1 , sparse_features ) logging . info ( data_spec . SerializeToString ( ) ) return processed_dense_features , processed_sparse_features , data_spec elif isinstance ( data , sparse_tensor . SparseTensor ) : col_spec = data_spec . sparse . add ( ) col_spec . name = 'sparse_features' col_spec . original_type = DTYPE_TO_FTYPE [ data . dtype ] col_spec . size = - 1 data_spec . dense_features_size = 0 return None , data , data_spec else : data = ops . convert_to_tensor ( data ) col_spec = data_spec . dense . add ( ) col_spec . name = 'dense_features' col_spec . original_type = DTYPE_TO_FTYPE [ data . dtype ] col_spec . size = data . get_shape ( ) [ 1 ] data_spec . dense_features_size = col_spec . size return data , None , data_spec