
    AVhX                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dd	l
mZ dd
lmZ ddlmZ  ed      ej                   dd              Z ed      ej                   	 	 dd              Zy)z6Ops for converting between row_splits and segment_ids.    )dtypes)ops)tensor)tensor_shape)tensor_util)	array_ops)math_ops)ragged_util)dispatch)	tf_exportz ragged.row_splits_to_segment_idsNc                    t        j                  |d| g      5 }t        j                  | dt        j                        } | j
                  t        j                  t        j                  fvrt        d      | j                  j                  d       t        j                  | j                  d         dk(  rt        d      || j
                  }nt        j                  |      }| dd | dd	 z
  }t        j                  | |
      d	   dz
  }t        j                  |      }t!        j"                  ||d      cddd       S # 1 sw Y   yxY w)a  Generates the segmentation corresponding to a RaggedTensor `row_splits`.

  Returns an integer vector `segment_ids`, where `segment_ids[i] == j` if
  `splits[j] <= i < splits[j+1]`.  Example:

  >>> print(tf.ragged.row_splits_to_segment_ids([0, 3, 3, 5, 6, 9]))
   tf.Tensor([0 0 0 2 2 3 4 4 4], shape=(9,), dtype=int64)

  Args:
    splits: A sorted 1-D integer Tensor.  `splits[0]` must be zero.
    name: A name prefix for the returned tensor (optional).
    out_type: The dtype for the return value.  Defaults to `splits.dtype`,
      or `tf.int64` if `splits` does not have a dtype.

  Returns:
    A sorted 1-D integer Tensor, with `shape=[splits[-1]]`

  Raises:
    ValueError: If `splits` is invalid.
  RaggedSplitsToSegmentIdssplits)namepreferred_dtypez%splits must have dtype int32 or int64   r   zInvalid row_splits: []N)out_type)repeatsaxis)r   
name_scopeconvert_to_tensorr   int64dtypeint32
ValueErrorshapeassert_has_rankr   dimension_valueas_dtyper   r	   ranger
   repeat)r   r   r   row_lengthsnrowsindicess         [/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/ragged/segment_id_ops.pyrow_splits_to_segment_idsr'      s   . ~~d6A DT""X&F ||FLL&,,77>??
LL  ###FLLO49/00h*h*vcr{*KOOFX6r:Q>EnnU#Gg{C!D D Ds   D!EEz ragged.segment_ids_to_row_splitsc                 h   ddl m} |_t        | t        j                        r| j
                  }nMt        |t        j                        r|j
                  }n&t        j                  }nt        j                  |      }t        j                  |d| g      5 }t        j                  | dt        j                        } | j                  j                  d       |At        j                  |dt        j                        }|j                  j                  d       |j!                  | |||	      }t#        j$                  dgt'        j(                  |      gd
      }|?t+        j,                  |      }|(|j/                  t1        j2                  |dz   g             |cddd       S # 1 sw Y   yxY w)a)  Generates the RaggedTensor `row_splits` corresponding to a segmentation.

  Returns an integer vector `splits`, where `splits[0] = 0` and
  `splits[i] = splits[i-1] + count(segment_ids==i)`.  Example:

  >>> print(tf.ragged.segment_ids_to_row_splits([0, 0, 0, 2, 2, 3, 4, 4, 4]))
  tf.Tensor([0 3 3 5 6 9], shape=(6,), dtype=int64)

  Args:
    segment_ids: A 1-D integer Tensor.
    num_segments: A scalar integer indicating the number of segments.  Defaults
      to `max(segment_ids) + 1` (or zero if `segment_ids` is empty).
    out_type: The dtype for the return value.  Defaults to `segment_ids.dtype`,
      or `tf.int64` if `segment_ids` does not have a dtype.
    name: A name prefix for the returned tensor (optional).

  Returns:
    A sorted 1-D integer Tensor, with `shape=[num_segments + 1]`.
  r   )bincount_opsNSegmentIdsToRaggedSplitssegment_ids)r   r   num_segments)	minlength	maxlengthr   )r   )tensorflow.python.opsr)   
isinstancer   Tensorr   r   r   r    r   r   r
   convert_to_int_tensorr   r   r   bincountr   concatr	   cumsumr   constant_value	set_shaper   TensorShape)r+   r,   r   r   r)   r#   r   const_num_segmentss           r&   segment_ids_to_row_splitsr:   K   st   0 1+v}}-""h	L&--	0##hhx(H
~~d6F $ 33K:@,,HK%%a( 66|7E=C\\Kl ((+''	 ( K
 sHOOK$@AJF &55lC		'113E3I2JKL3  s   D	F((F1)NN)NNN)__doc__tensorflow.python.frameworkr   r   r   r   r   r/   r   r	   tensorflow.python.ops.raggedr
   tensorflow.python.utilr    tensorflow.python.util.tf_exportr   add_dispatch_supportr'   r:        r&   <module>rC      s    = . + . 4 3 + * 4 + 6
 -.	%D  /%DT -.	8<269  /9rB   