3838from tensorflow .python .ops import nn_ops
3939from tensorflow .python .ops import weights_broadcast_ops
4040from tensorflow .python .ops .ragged import ragged_tensor
41- from tensorflow .python .ops .ragged import ragged_util
4241from tensorflow .python .tpu import tpu
4342from tensorflow .python .util import tf_decorator
4443
@@ -513,11 +512,11 @@ def ragged_assert_compatible_and_get_flat_values(values, mask=None):
513512 # tf.TensorShape `assert_is_compatible_with`
514513 # check if both dynamic dimensions are equal and then use the flat_values.
515514 nested_row_split_list = [rt .nested_row_splits for rt in values ]
516- assertion_list = ragged_util . assert_splits_match (nested_row_split_list )
515+ assertion_list = _assert_splits_match (nested_row_split_list )
517516
518517 # if both are ragged sample_weights also should be ragged with same dims.
519518 if isinstance (mask , ragged_tensor .RaggedTensor ):
520- assertion_list_for_mask = ragged_util . assert_splits_match (
519+ assertion_list_for_mask = _assert_splits_match (
521520 [nested_row_split_list [0 ], mask .nested_row_splits ])
522521 tmp = control_flow_ops .with_dependencies (assertion_list_for_mask ,
523522 mask .flat_values )
@@ -539,3 +538,31 @@ def ragged_assert_compatible_and_get_flat_values(values, mask=None):
539538 raise TypeError ('Ragged mask is not allowed with non-ragged inputs.' )
540539
541540 return values , mask
541+
542+
543+ def _assert_splits_match (nested_splits_lists ):
544+ """Checks that the given splits lists are identical.
545+
546+ Performs static tests to ensure that the given splits lists are identical,
547+ and returns a list of control dependency op tensors that check that they are
548+ fully identical.
549+
550+ Args:
551+ nested_splits_lists: A list of nested_splits_lists, where each split_list is
552+ a list of `splits` tensors from a `RaggedTensor`, ordered from outermost
553+ ragged dimension to innermost ragged dimension.
554+
555+ Returns:
556+ A list of control dependency op tensors.
557+ Raises:
558+ ValueError: If the splits are not identical.
559+ """
560+ error_msg = 'Inputs must have identical ragged splits'
561+ for splits_list in nested_splits_lists :
562+ if len (splits_list ) != len (nested_splits_lists [0 ]):
563+ raise ValueError (error_msg )
564+ return [
565+ check_ops .assert_equal (s1 , s2 , message = error_msg ) # pylint: disable=g-complex-comprehension
566+ for splits_list in nested_splits_lists [1 :]
567+ for (s1 , s2 ) in zip (nested_splits_lists [0 ], splits_list )
568+ ]
0 commit comments