class_docstr: A `Dataset` that encodes dense inputs as ragged (w/ ragged_rank=0).
  
  In particular:
  
  * Any tf.Tensor elements with rank>0 are encoded as ragged tensors with
    ragged_rank=0.  This allows tensors with varying shape to be batched
    together.
  * Any other elements are left as-is.
class_docstr_tok: ["A","`","Dataset","`","that","encodes","dense","inputs","as","ragged","(","w\/","ragged_rank=0",")",".","In","particular",":","*","Any","tf.Tensor","elements","with","rank",">","0","are","encoded","as","ragged","tensors","with","ragged_rank=0",".","This","allows","tensors","with","varying","shape","to","be","batched","together",".","*","Any","other","elements","are","left","as-is","."]
docstr: Constructs a new _DenseToRaggedDataset.
  
  Args:
    input_dataset: The dataset whose tf.Tensor elements should be made ragged.
    row_splits_dtype: The dtype that should be used for the `row_splits` of
      any new ragged tensors.  Existing `tf.RaggedTensor` elements do *not*
      have their row_splits dtype changed.
    name: (Optional.) A string indicating a name for the `tf.data` operation.
docstr_tok: ["Constructs","a","new","_DenseToRaggedDataset",".","Args",":","input_dataset",":","The","dataset","whose","tf.Tensor","elements","should","be","made","ragged",".","row_splits_dtype",":","The","dtype","that","should","be","used","for","the","`","row_splits","`","of","any","new","ragged","tensors",".","Existing","`","tf.RaggedTensor","`","elements","do","*","not","*","have","their","row_splits","dtype","changed",".","name",":","(","Optional",".",")","A","string","indicating","a","name","for","the","`","tf.data","`","operation","."]
code: def __init__(self, input_dataset, row_splits_dtype, name=None):
      """Constructs a new _DenseToRaggedDataset.
  
      Args:
        input_dataset: The dataset whose tf.Tensor elements should be made ragged.
        row_splits_dtype: The dtype that should be used for the `row_splits` of
          any new ragged tensors.  Existing `tf.RaggedTensor` elements do *not*
          have their row_splits dtype changed.
        name: (Optional.) A string indicating a name for the `tf.data` operation.
      """
  
      # Replace each TensorSpec in the input dataset's structure with a
      # corresponding RaggedTensorSpec.
      def to_ragged_spec(spec):
          """Returns the new spec based on RaggedTensors."""
          if (
              not isinstance(spec, tensor.TensorSpec)
              or spec.shape.rank is None
              or spec.shape.is_fully_defined()
          ):
              return spec
          else:
              ragged_rank = max(
                  [
                      axis
                      for (axis, size) in enumerate(
                          spec.shape.as_list()
                      )
                      if size is None
                  ]
              )
              return ragged_tensor.RaggedTensorSpec(
                  shape=spec.shape,
                  dtype=spec.dtype,
                  ragged_rank=ragged_rank,
                  row_splits_dtype=row_splits_dtype,
              )
  
      self._structure = nest.map_structure(
          to_ragged_spec, input_dataset.element_spec
      )
  
      # Replace each tf.Tensor value in the input dataset with a variant-encoded
      # RaggedTensor. Since we're updating the corresponding structure to be
      # a RaggedTensorSpec, this variant-encoded tensor will be decoded with
      # RaggedTensorSpec._from_tensor_list.
      def to_ragged_variant(value):
          """Re-encode Tensors as RaggedTensors."""
          if (
              not isinstance(value, tensor.Tensor)
              or value.shape.rank is None
              or value.shape.is_fully_defined()
          ):
              return value
          else:
              spec = to_ragged_spec(
                  tensor.TensorSpec.from_tensor(value)
              )
              if (
                  spec._ragged_rank > 0
              ):  # pylint: disable=protected-access
                  value = ragged_tensor.RaggedTensor.from_tensor(
                      value, ragged_rank=spec._ragged_rank
                  )  # pylint: disable=protected-access
              return spec._to_tensor_list(value)[
                  0
              ]  # pylint: disable=protected-access
  
      # Tuples are automatically unpacked by `dataset.map` so we repack them.
      if structured_function._should_unpack(
          input_dataset.element_spec
      ):  # pylint: disable=protected-access
          map_fn = lambda *value: nest.map_structure(
              to_ragged_variant, value
          )
      else:
          map_fn = lambda value: nest.map_structure(
              to_ragged_variant, value
          )
  
      self._mapped_dataset = input_dataset.map(map_fn)
      self._name = name
      variant = (
          self._mapped_dataset._variant_tensor
      )  # pylint: disable=protected-access
      super().__init__(input_dataset, variant)
  
file_path: tensorflow/tensorflow/python/data/ops/ragged_batch_op.py
imports: from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.data.ops import structured_function
  from tensorflow.python.data.util import nest
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import tensor
  from tensorflow.python.ops.ragged import ragged_tensor
label_desc: Use image node_id 1 to create a new _DenseToRaggedDataset object from inherited base classes: dataset_ops with example: obj = _DenseToRaggedDataset(input_dataset, row_splits_dtype, name)