o
    ?e                     @   sn   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 ZejZej	Z	ej
Zd	d
 Zdd ZdS )zrPrivate convenience functions for RaggedTensors.

None of these methods are exposed in the main "ragged" package.
    )	array_ops)	check_ops)control_flow_ops)gen_ragged_math_ops)math_opsc                    sF   d D ]}t |t d krt q fdddd D S )a7  Checks that the given splits lists are identical.

  Performs static tests to ensure that the given splits lists are identical,
  and returns a list of control dependency op tensors that check that they are
  fully identical.

  Args:
    nested_splits_lists: A list of nested_splits_lists, where each split_list is
      a list of `splits` tensors from a `RaggedTensor`, ordered from outermost
      ragged dimension to innermost ragged dimension.

  Returns:
    A list of control dependency op tensors.
  Raises:
    ValueError: If the splits are not identical.
  z(Inputs must have identical ragged splitsr   c                    s4   g | ]}t d  |D ]\}}tj|| dqqS )r   message)zipr   Zassert_equal).0splits_lists1s2	error_msgnested_splits_lists i/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/ops/ragged/ragged_util.py
<listcomp>0   s    z'assert_splits_match.<locals>.<listcomp>   N)len
ValueError)r   r   r   r   r   assert_splits_match   s   
r   c                 C   s   t jdgt| gddS )z2Returns splits corresponding to the given lengths.r   Zaxis)r   concatr   Zcumsum)lengthsr   r   r   lengths_to_splits=   s   r   c                 C   s  t j|ddt j|d|j ddg}t j|ddt j|d|j ddg}t||}t||}|jjdkrOt|dd	 |dd
}t|dd |dd
}nt||dd
}t	j||jdd }|d||  }||d }t	
d|j}	t|||	}
t	| |
jS )a  Repeats each range of `params` (as specified by `splits`) `repeats` times.

  Let the `i`th range of `params` be defined as
  `params[splits[i]:splits[i + 1]]`.  Then this function returns a tensor
  containing range 0 repeated `repeats[0]` times, followed by range 1 repeated
  `repeats[1]`, ..., followed by the last range repeated `repeats[-1]` times.

  Args:
    params: The `Tensor` whose values should be repeated.
    splits: A splits tensor indicating the ranges of `params` that should be
      repeated. Elements should be non-negative integers.
    repeats: The number of times each range should be repeated. Supports
      broadcasting from a scalar value. Elements should be non-negative
      integers.

  Returns:
    A `Tensor` with the same rank and type as `params`.

  #### Example:

  >>> print(repeat_ranges(
  ...     params=tf.constant(['a', 'b', 'c']),
  ...     splits=tf.constant([0, 2, 3]),
  ...     repeats=tf.constant(3)))
  tf.Tensor([b'a' b'b' b'a' b'b' b'a' b'b' b'c' b'c' b'c'],
      shape=(9,), dtype=string)
  z,Input argument 'splits' must be non-negativer   z1Input argument 'splits' must be integer, but got z insteadz-Input argument 'repeats' must be non-negativez2Input argument 'repeats' must be integer, but got r   Nr   r   r   )Zout_typer   )r   Zassert_non_negativeZassert_integerZdtyper   Zwith_dependenciesshapeZndimsrepeatr   Zonesr   Zragged_rangegatherZrt_dense_values)paramsZsplitsZrepeatsZsplits_checksZrepeats_checksZrepeated_startsZrepeated_limitsZrepeated_splitsZn_splitsoneoffsetsr   r   r   repeat_rangesB   sD   r#   N)__doc__Ztensorflow.python.opsr   r   r   r   r   r   Zget_positive_axisZconvert_to_int_tensorZrepeat_with_axisr   r   r#   r   r   r   r   <module>   s   