
    AVh                     6   d Z ddl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 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       G d dej:                               Z ej>                  d       G d dej@                               Z! ejD                   ejF                  e!ejH                  jJ                               d#dZ&d#dZ'd Z(d Z) e*       Z+d  Z,d$d!Z-d$d"Z.y)%zLA class used to partition a sequence into contiguous subsequences ("rows").
    N)
struct_pb2)composite_tensor)constant_op)dtypes)ops)tensor)tensor_conversion)tensor_shape)tensor_util)	type_spec)type_spec_registry)	array_ops)	check_ops)control_flow_ops)gen_ragged_math_ops)math_ops)segment_id_ops)nested_structure_coder)	tf_exportzexperimental.RowPartitionc                      e Zd ZdZ	 	 	 	 	 	 d*dZe	 	 	 	 d+d       Ze	 	 	 d,d       Ze	 	 	 d,d       Ze	 	 	 d,d       Z	e	 	 	 d,d       Z
e	 	 	 	 	 d-d	       Zed.d
       Zd Zed        Zd Zd Zd Zd Zd Zd Zd Zd Zed        Zed        Zed        Zd Zd Zd Zd Zd Zd Z d Z!d Z"d  Z#d! Z$d" Z%d# Z&d$ Z'd% Z(d& Z)d' Z*d/d(Z+ed)        Z,y)0RowPartitiona2  Partitioning of a sequence of values into contiguous subsequences ("rows").

  A `RowPartition` describes how a sequence with `nvals` items should be
  divided into `nrows` contiguous subsequences ("rows").  For example, a
  `RowPartition` could be used to partition the vector `[1, 2, 3, 4, 5]` into
  subsequences `[[1, 2], [3], [], [4, 5]]`.  Note that `RowPartition` stores
  information about how values are partitioned, but does not include the
  partitioned values themselves.  `tf.RaggedTensor` is used to pair a `values`
  tensor with one or more `RowPartition`s, providing a complete encoding for a
  ragged tensor (i.e. a tensor with variable-length dimensions).

  `RowPartition`s may be defined using several different schemes:

    * `row_lengths`: an integer vector with shape `[nrows]`, which specifies
      the length of each row.

    * `row_splits`: an integer vector with shape `[nrows+1]`, specifying the
      "split points" between each row.

    * `row_starts`: an integer vector with shape `[nrows]`, which specifies
      the start offset for each row.  Equivalent to `row_splits[:-1]`.

    * `row_limits`: an integer vector with shape `[nrows]`, which specifies
      the stop offset for each row.  Equivalent to `row_splits[1:]`.

    * `value_rowids` is an integer vector with shape `[nvals]`, corresponding
      one-to-one with sequence values, which specifies the row that each value
      belongs to.  If the partition has empty trailing rows, then `nrows`
      must also be specified.

    * `uniform_row_length` is an integer scalar, specifying the length of every
      row.  This scheme may only be used if all rows have the same length.

  For example, the following `RowPartition`s all represent the partitioning of
  8 values into 5 sublists as follows: `[[*, *, *, *], [], [*, *, *], [*], []]`.

  >>> p1 = RowPartition.from_row_lengths([4, 0, 3, 1, 0])
  >>> p2 = RowPartition.from_row_splits([0, 4, 4, 7, 8, 8])
  >>> p3 = RowPartition.from_row_starts([0, 4, 4, 7, 8], nvals=8)
  >>> p4 = RowPartition.from_row_limits([4, 4, 7, 8, 8])
  >>> p5 = RowPartition.from_value_rowids([0, 0, 0, 0, 2, 2, 2, 3], nrows=5)

  For more information about each scheme, see the documentation for the
  its factory method.  For additional examples, see the documentation on
  `tf.RaggedTensor`.

  ### Precomputed Encodings

  `RowPartition` always stores at least one encoding of the partitioning, but
  it can be configured to cache additional encodings as well.  This can
  avoid unnecessary recomputation in eager mode.  (In graph mode, optimizations
  such as common subexpression elimination will typically prevent these
  unnecessary recomputations.)  To check which encodings are precomputed, use
  `RowPartition.has_precomputed_<encoding>`.  To cache an additional
  encoding, use `RowPartition.with_precomputed_<encoding>`.
  Nc                 R   |t         urt        d      t        |t        j                        st        d|z        |j                  t        j                  t        j                  fvrt        d      |j                  j                  d       |j                  dg       || _        |||||fD ]T  }|t        |t        j                        st        d      |j                  |j                  k7  sEt        d| d|        || _        || _        || _        || _        || _        y)	a@  Creates a `RowPartition` from the specified encoding tensor(s).

    This constructor is private -- please use one of the following ops to
    build `RowPartition`s:

      * `RowPartition.from_row_lengths`
      * `RowPartition.from_value_rowids`
      * `RowPartition.from_row_splits`
      * `RowPartition.from_row_starts`
      * `RowPartition.from_row_limits`
      * `RowPartition.from_uniform_row_length`

    If row_splits is has a constant value, then all other arguments should
    have a constant value.

    Args:
      row_splits: A 1-D integer tensor with shape `[nrows+1]`.
      row_lengths: A 1-D integer tensor with shape `[nrows]`
      value_rowids: A 1-D integer tensor with shape `[nvals]`.
      nrows: A 1-D integer scalar tensor.
      uniform_row_length: A scalar tensor.
      nvals: A scalar tensor.
      internal: Private key value, required to ensure that this private
        constructor is *only* called from the factory methods.

    Raises:
      TypeError: If a row partitioning tensor has an inappropriate dtype.
      TypeError: If exactly one row partitioning argument was not specified.
      ValueError: If a row partitioning tensor has an inappropriate shape.
      ValueError: If multiple partitioning arguments are specified.
      ValueError: If nrows is specified but value_rowids is not None.
    zzRowPartition constructor is private; please use one of the factory methods instead (e.g., RowPartition.from_row_lengths())z2Row-partitioning argument must be a Tensor, got %rz0Row-partitioning argument must be int32 or int64   Nz&Cached value must be a Tensor or None.z)Inconsistent dtype for encoding tensors: z vs )_row_partition_factory_key
ValueError
isinstance
tensor_libTensor	TypeErrordtyper   int32int64shapeassert_has_rank	set_shape_row_splits_row_lengths_value_rowids_nrows_uniform_row_length_nvals)	self
row_splitsrow_lengthsvalue_rowidsnrowsuniform_row_lengthnvalsinternalr   s	            Z/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/ragged/row_partition.py__init__zRowPartition.__init__v   s8   P 11 : ; ;
 j*"3"34J ! " "fll;;IJJ $$Q'$ !D
 e5GO 8		&*"3"34BC
C\\Z---F$XT*7 8 88 $D%DDK1DDK    c           
         ddl m} t        |t              st	        d      t        j                  dd||g      5  | j                  |d||      }|yt        j                  |      }|&t        j                  |dd dggd	      d   d
z   }d}n|j                  dkD  r|d   d
z   nd}t        j                  ||j                  d      }nt        j                  ||j                  d      }t        j                  |      }|W|dk  rt        d|z        t        j                  |      }|-|j                  dkD  r||d   d
z   k\  st        d||d   fz        |j                   j#                  d
       |j                   j#                  d       |rd}	t%        j&                  |d
|	      t%        j&                  |d|	      t%        j(                  |dd
 |	      t+        ||	      t%        j,                  |dd ||	      g}
t/        j0                  |
|      }t3        j4                  |t6        j8                        }t3        j4                  |t6        j8                        }|j;                  ||||j                        }t        j                  dgt3        j<                  |      gd	      }|'|j?                  |g       |j?                  |d
z   g        | ||||t@              cddd       S # 1 sw Y   yxY w)a  Creates a `RowPartition` with rows partitioned by `value_rowids`.

    This `RowPartition` divides a sequence `values` into rows by specifying
    which row each value should be added to:

    ```python
    partitioned_rows = [[] for _ in nrows]
    for (value, rowid) in zip(values, value_rowids):
      partitioned_rows[rowid].append(value)
    ```

    Args:
      value_rowids: A 1-D integer tensor with shape `[nvals]`, which corresponds
        one-to-one with `values`, and specifies each value's row index.  Must be
        nonnegative, and must be sorted in ascending order.
      nrows: An integer scalar specifying the number of rows.  This should be
        specified if the `RowPartition` may containing empty training rows. Must
        be greater than `value_rowids[-1]` (or greater than or equal to zero if
        `value_rowids` is empty). Defaults to `value_rowids[-1] + 1` (or zero if
        `value_rowids` is empty).
      validate: If true, then use assertions to check that the arguments form a
        valid `RowPartition`.
      dtype: Optional dtype for the RowPartition. If missing, the type
        is inferred from the type of `value_rowids`, dtype_hint, or tf.int64.
      dtype_hint: Optional dtype for the RowPartition, used when dtype
        is None. In some cases, a caller may not have a dtype in mind when
        converting to a tensor, so dtype_hint can be used as a soft preference.
        If the conversion to `dtype_hint` is not possible, this argument has no
        effect.

    Returns:
      A `RowPartition`.

    Raises:
      ValueError: If `nrows` is incompatible with `value_rowids`.

    #### Example:

    >>> print(RowPartition.from_value_rowids(
    ...     value_rowids=[0, 0, 0, 0, 2, 2, 2, 3],
    ...     nrows=4))
    tf.RowPartition(row_splits=[0 4 4 7 8])
    r   )bincount_opsvalidate must have type boolNRowPartitionFromValueRowIdsr/   
dtype_hintr    axisr   r0   namezExpected nrows >= 0; got %dzIExpected nrows >= value_rowids[-1] + 1; got nrows=%d, value_rowids[-1]=%dz?Arguments to from_value_rowids do not form a valid RowPartitionmessage)	minlength	maxlengthr    )r-   r.   r/   r0   r3   )!tensorflow.python.opsr8   r   boolr   r   
name_scope_convert_row_partitionr   constant_valuer   concatsizeconvert_to_tensorr    r   r#   r$   r   assert_rankassert_non_negative_assert_monotonic_increasingassert_lessr   with_dependenciesr   castr   r!   bincountcumsumr%   r   )clsr/   r0   validater    r<   r8   const_rowidsconst_nrowsmsgchecksvalue_rowids_int32nrows_int32r.   r-   s                  r4   from_value_rowidszRowPartition.from_value_rowids   s   h 3h%455	;%u-
/ ?///
:U 0 Ll	"11,?""L$5t#<1EaH1L%+0<0A0AA0ER(1,1+''<--G=% %%e\-?-?I!007"1_:[HII$33LA,%,*;*;a*?,r"2Q"66(+6R8H*IJK K ((+kk!!!$	 !!,3?!!%C8)),r*:CH(sC!!,rs"3UCH
 (99&,O $==v||DMM%6k ))
""	 * $k
 ##aS(//+*F$GaPj		 {m,kAo./!#-/u?/ ?/ ?/s   J,K11K:c                 T   t        |t              st        d      t        |t        t        f      r|st        d      t        |t        j                        r | |t              S t        j                  dd|g      5  | j                  |d||      }|j                  j                  d       |rUd	}t        j                  |d|d
z         t!        |d   |dz         t#        ||dz         g}t%        j&                  ||      } | |t              cddd       S # 1 sw Y   yxY w)a  Creates a `RowPartition` with rows partitioned by `row_splits`.

    This `RowPartition` divides a sequence `values` into rows by indicating
    where each row begins and ends:

    ```python
    partitioned_rows = []
    for i in range(len(row_splits) - 1):
      row_start = row_splits[i]
      row_end = row_splits[i + 1]
      partitioned_rows.append(values[row_start:row_end])
    ```

    Args:
      row_splits: A 1-D integer tensor with shape `[nrows+1]`.  Must not be
        empty, and must be sorted in ascending order.  `row_splits[0]` must be
        zero.
      validate: If true, then use assertions to check that the arguments form a
        valid `RowPartition`.
      dtype: Optional dtype for the RowPartition. If missing, the type
        is inferred from the type of `row_splits`, dtype_hint, or tf.int64.
      dtype_hint: Optional dtype for the RowPartition, used when dtype
        is None. In some cases, a caller may not have a dtype in mind when
        converting to a tensor, so dtype_hint can be used as a soft preference.
        If the conversion to `dtype_hint` is not possible, this argument has no
        effect.

    Returns:
      A `RowPartition`.

    Raises:
      ValueError: If `row_splits` is an empty list.
    r9   z#row_splits tensor may not be empty.r-   r3   NRowPartitionFromRowSplitsr-   r;   r   z>Arguments to from_row_splits do not form a valid RaggedTensor:rankrB   r   zero	monotonic)r   rG   r   listtupler   r   
TensorSpecr   r   rH   rI   r#   r$   r   rN   _assert_zerorP   r   rR   )rV   r-   rW   r    r<   rZ   r[   s          r4   from_row_splitszRowPartition.from_row_splits;  s   N h%455*tUm,Z<==*j334J1KLL	9J<	H M--
lz . Hj&&q)	N!!*a#,HAv?(S;%69
 &77
K
J1KLM M Ms   ?BDD'c                    t        |t              st        d      t        j                  dd|g      5  | j                  |d||      }|j                  j                  d       |rGd}t        j                  |d|      t        j                  ||      g}t        j                  ||      }t        j                  |      }t        j                   d	g|gd	
      } | ||t"              cddd       S # 1 sw Y   yxY w)a	  Creates a `RowPartition` with rows partitioned by `row_lengths`.

    This `RowPartition` divides a sequence `values` into rows by indicating
    the length of each row:

    ```python
    partitioned_rows = [[values.pop(0) for _ in range(length)]
                        for length in row_lengths]
    ```

    Args:
      row_lengths: A 1-D integer tensor with shape `[nrows]`.  Must be
        nonnegative.
      validate: If true, then use assertions to check that the arguments form a
        valid `RowPartition`.

      dtype: Optional dtype for the RowPartition. If missing, the type
        is inferred from the type of `row_lengths`, dtype_hint, or tf.int64.
      dtype_hint: Optional dtype for the RowPartition, used when dtype
        is None. In some cases, a caller may not have a dtype in mind when
        converting to a tensor, so dtype_hint can be used as a soft preference.
        If the conversion to `dtype_hint` is not possible, this argument has no
        effect.

    Returns:
      A `RowPartition`.
    r9   NRowPartitionFromRowLengthsr.   r;   r   z>Arguments to from_row_lengths do not form a valid RowPartitionrB   r   r>   )r-   r.   r3   )r   rG   r   r   rH   rI   r#   r$   r   rN   rO   r   rR   r   rU   r   rK   r   )	rV   r.   rW   r    r<   rZ   r[   
row_limitsr-   s	            r4   from_row_lengthszRowPartition.from_row_lengthsz  s    B h%455	:[M	J /..
}5 / Jk''*	N!!+q#>))+sC
 '88M??;/j##aS*$5A>j!-// / /s   B7C55C>c           	      V   t        |t              st        d      t        j                  dd|g      5  | j                  |d||      }|j                  j                  d       t        j                  ||j                        }|rfd}t        j                  |d|      t        |dd |      t        ||      t        j                  |d	d ||      g}t!        j"                  ||      }t%        j&                  ||ggd
      } | ||t(              cddd       S # 1 sw Y   yxY w)a  Creates a `RowPartition` with rows partitioned by `row_starts`.

    Equivalent to: `from_row_splits(concat([row_starts, nvals], axis=0))`.

    Args:
      row_starts: A 1-D integer tensor with shape `[nrows]`.  Must be
        nonnegative and sorted in ascending order.  If `nrows>0`, then
        `row_starts[0]` must be zero.
      nvals: A scalar tensor indicating the number of values.
      validate: If true, then use assertions to check that the arguments form a
        valid `RowPartition`.
      dtype: Optional dtype for the RowPartition. If missing, the type
        is inferred from the type of `row_starts`, dtype_hint, or tf.int64.
      dtype_hint: Optional dtype for the RowPartition, used when dtype
        is None. In some cases, a caller may not have a dtype in mind when
        converting to a tensor, so dtype_hint can be used as a soft preference.
        If the conversion to `dtype_hint` is not possible, this argument has no
        effect.

    Returns:
      A `RowPartition`.
    r9   NRowPartitionFromRowStarts
row_startsr;   r   z=Arguments to from_row_starts do not form a valid RaggedTensorrB   r=   r   r>   )r-   r2   r3   )r   rG   r   r   rH   rI   r#   r$   r   rS   r    r   rN   rh   rP   assert_less_equalr   rR   r   rK   r   )	rV   rp   r2   rW   r    r<   rZ   r[   r-   s	            r4   from_row_startszRowPartition.from_row_starts  s   : h%455	9J<	H 6--
lz . Hj&&q) mmE:#3#34e	M!!*a=BQ5(SA''
23L	
 &77
K
##Z%$9BjJe46%6 6 6s   C!DD(c                 4   t        |t              st        d      t        j                  dd|g      5  | j                  |d||      }|j                  j                  d       |rVd}t        j                  |d|      t        j                  |dd |      t        ||      g}t        j                  ||      }t        j                  dg|j                         }t        j"                  ||gd	
      } | |t$              cddd       S # 1 sw Y   yxY w)aq  Creates a `RowPartition` with rows partitioned by `row_limits`.

    Equivalent to: `from_row_splits(values, concat([0, row_limits], axis=0))`.

    Args:
      row_limits: A 1-D integer tensor with shape `[nrows]`.  Must be sorted in
        ascending order.
      validate: If true, then use assertions to check that the arguments form a
        valid `RowPartition`.
      dtype: Optional dtype for the RowPartition. If missing, the type
        is inferred from the type of `row_limits`, dtype_hint, or tf.int64.
      dtype_hint: Optional dtype for the RowPartition, used when dtype
        is None. In some cases, a caller may not have a dtype in mind when
        converting to a tensor, so dtype_hint can be used as a soft preference.
        If the conversion to `dtype_hint` is not possible, this argument has no
        effect.

    Returns:
      A `RowPartition`.
    r9   NRowPartitionFromRowLimitsrl   r;   r   z=Arguments to from_row_limits do not form a valid RaggedTensorrB   r   r>   r`   )r   rG   r   r   rH   rI   r#   r$   r   rN   rO   rP   r   rR   r   zerosr    rK   r   )	rV   rl   rW   r    r<   rZ   r[   rc   r-   s	            r4   from_row_limitszRowPartition.from_row_limits  s   4 h%455	9J<	H M--
lz . Hj&&q)	M!!*a=))*Ra.#F(SA

 &77
K
__aS*"2"23d##T:$6Q?jJ1KL!M M Ms   CDDc                    t        |t              st        d      ||t        d      t	        j
                  dd||g      5  t        |df|df|dfg||      \  }}}|j                  j                  d	       t        j                  |      }|h|:t        j                  |t        j                  d
|j                              }||z  }n,|d	k(  r"t        j                  d	|j                        }n||z  }|dnt        j                  |      }	|dnt        j                  |      }
t        j                  |      }g }|
R|	P|N|	|z  }
|'|r%|j!                  t#        j$                  ||
             t        j                  |
|j                        }|||z  }|	A|?t'        |	d
z         D cg c]  }||z  	 }}t        j                  ||j                        }n't        j&                  |d
z   |j                        |z  }|r|	||
0|j!                  t#        j$                  ||z  |d|d|d|f             n|	|z  |
k7  rt        d||	|
fz        |j                  j(                  '|j!                  t#        j*                  |d	d             t        j                  |      }|F|j!                  t#        j,                  |t        j                  d	|j                        d             n|d	k  rt        d      t/        j0                  ||      } | ||||t2              cddd       S c c}w # 1 sw Y   yxY w)a  Creates a `RowPartition` with rows partitioned by `uniform_row_length`.

    This `RowPartition` divides a sequence `values` into rows that all have
    the same length:

    ```python
    partitioned_rows = [[values.pop(0) for _ in range(uniform_row_length)]
             for _ in range(nrows)]
    ```

    Note that either or both of nvals and nrows must be specified.

    Args:
      uniform_row_length: A scalar integer tensor.  Must be nonnegative. The
        size of the outer axis of `values` must be evenly divisible by
        `uniform_row_length`.
      nvals: a non-negative scalar integer tensor for the number of values.
        Must be specified if nrows is not specified. If not specified,
        defaults to uniform_row_length*nrows
      nrows: The number of rows in the constructed RowPartition.  If not
        specified, then it defaults to `nvals/uniform_row_length` (or `0` if
        `uniform_row_length==0`).  `nrows` only needs to be specified if
        `uniform_row_length` might be zero.  `uniform_row_length*nrows` must be
        `nvals`.
      validate: If true, then use assertions to check that the arguments form a
        valid `RowPartition`.
      dtype: Optional dtype for the RowPartition. If missing, the type
        is inferred from the type of `uniform_row_length`, dtype_hint,
        or tf.int64.
      dtype_hint: Optional dtype for the RowPartition, used when dtype
        is None. In some cases, a caller may not have a dtype in mind when
        converting to a tensor, so dtype_hint can be used as a soft preference.
        If the conversion to `dtype_hint` is not possible, this argument has no
        effect.

    Returns:
      A `RowPartition`.
    r9   Nz5Either (or both) of nvals and nrows must be specified RowPartitionFromUniformRowLengthr1   r2   r0   )r    r<   r   r   r    ztimes nrowszmust equal nvalsz8uniform_row_length=%d times nrows=%d must equal nvals=%dz$uniform_row_length must be a scalar.rB   z uniform_row_length must be >= 0.)r-   r1   r0   r2   r3   )r   rG   r   r   r   rH   _convert_all_to_tensorsr#   r$   r   rJ   r   maximumr   constantr    appendr   assert_equalrangerb   rN   assert_greater_equalr   rR   r   )rV   r1   r2   r0   rW   r    r<   const_row_lengthrowlen_or_1rY   const_nvalsconst_uniform_row_lengthr[   vr-   s                  r4   from_uniform_row_lengthz$RowPartition.from_uniform_row_length  s   \ h%455}NOO	@+U3
5 V/ "$68L#M$)7#3eW5E#G(--795% ..q1 %334FG	# (( ""1&8&>&>?A+ ;&%"&&q0B0H0HI%++%!MD{/I/I%/Pk!MD{/I/I%/Pk!,!;!;<N!Of		!8=U=a!$<<
--	..ukB
C$$[2D2J2JK	** 
	 %5%A49+/4JKqa**K
K ))*6H6N6NO
^^AI/5579KL
 
#3#;
--$$,,e');],e567 ++{:J!;<=> > ##((0
--##$@BC '556HI#
--,,$&&q*<*B*BC<>? !?@@%77
K
/-/cV/ V/P LQV/ V/s    E.L92L4>E,L94L99Mc                 r   |t         j                  }t        |t        j                        r7|j
                  t        j                  k(  r|t        j                  ||      }nt        j                  ||||      }|j
                  t         j                  t         j                  fvrt        d|z        |S )a  Converts `partition` to Tensors.

    Args:
      partition: A row-partitioning tensor for the `RowPartition` being
        constructed.  I.e., one of: row_splits, row_lengths, row_starts,
        row_limits, value_rowids, uniform_row_length.
      name: The name of the row-partitioning tensor.
      dtype: Optional dtype for the RowPartition. If missing, the type
        is inferred from the type of `uniform_row_length`, dtype_hint,
        or tf.int64.
      dtype_hint: Optional dtype for the RowPartition, used when dtype
        is None. In some cases, a caller may not have a dtype in mind when
        converting to a tensor, so dtype_hint can be used as a soft preference.
        If the conversion to `dtype_hint` is not possible, this argument has no
        effect.

    Returns:
      A tensor equivalent to partition.

    Raises:
      ValueError: if dtype is not int32 or int64.
    r@   )r<   r    rA   z!%s must have dtype int32 or int64)r   r"   r   npndarrayr    r!   r   rM   r	   convert_to_tensor_v2r   )rV   	partitionrA   r    r<   s        r4   rI   z#RowPartition._convert_row_partition  s    0 <<j9bjj)288#''	=i#88

%di v||V\\:::TABBr6   c                     t        j                  || j                        }t        || j                  | j
                  | j                  | j                  t              S )aC  Returns a new RowPartition equal to self with control dependencies.

    Specifically, self._row_splits is gated by the given control dependencies.
    Used to add sanity checks to the constructors.

    Args:
      dependencies: a list of tensors to use as dependencies.

    Returns:
      A new RowPartition object.
    r-   r.   r/   r0   r1   r3   )	r   rR   r&   r   r'   r(   r)   r*   r   )r,   dependenciesnew_row_splitss      r4   _with_dependencieszRowPartition._with_dependencies  sU     &778<8H8HJN!%%''kk33+- -r6   c                 .    | j                   j                  S )zEThe `DType` used to encode the row partition (either int32 or int64).)r&   r    r,   s    r4   r    zRowPartition.dtype  s     !!!r6   c                     | j                   S )a  Returns the row-split indices for this row partition.

    `row_splits` specifies where the values for each row begin and end.
    In particular, the values for row `i` are stored in the slice
    `values[row_splits[i]:row_splits[i+1]]`.

    Returns:
      A 1-D integer `Tensor` with shape `[self.nrows+1]`.
      The returned tensor is non-empty, and is sorted in ascending order.
      `self.row_splits()[0] == 0`.
      `self.row_splits()[-1] == self.nvals()`.
    r&   r   s    r4   r-   zRowPartition.row_splits  s     r6   c                 p    | j                   | j                   S t        j                  | j                        S )aL  Returns the row indices for this row partition.

    `value_rowids` specifies the row index fo reach value.  In particular,
    `value_rowids[i]` is the row index for `values[i]`.

    Returns:
      A 1-D integer `Tensor` with shape `[self.nvals()]`.
      The returned tensor is nonnegative, and is sorted in ascending order.
    )r(   r   row_splits_to_segment_idsr&   r   s    r4   r/   zRowPartition.value_rowids  s3     %33D4D4DEEr6   c                      | j                   d   S )a  Returns the number of values partitioned by this `RowPartition`.

    If the sequence partitioned by this `RowPartition` is a tensor, then
    `nvals` is the size of that tensor's outermost dimension -- i.e.,
    `nvals == values.shape[0]`.

    Returns:
      scalar integer Tensor
    r=   r   r   s    r4   r2   zRowPartition.nvals  s     Br6   c                 \   | j                   | j                   S t        j                  | j                  j                  d      }|j
                  1t        j                  | j                  | j                        d   dz
  S t        j                  |j
                  dz
  | j                        S )ziReturns the number of rows created by this `RowPartition`.

    Returns:
      scalar integer Tensor
    r   )out_typer   ry   )
r)   r
   dimension_at_indexr&   r#   valuer   r    r   r|   )r,   nsplitss     r4   r0   zRowPartition.nrows  s     {{[[--d.>.>.D.DaHG}}__T--

CAFJJ!!'--!"34::FFr6   c                     | j                   S )a-  Returns the length of each row in this partition, if rows are uniform.

    If all rows in this `RowPartition` have the same length, then this returns
    that length as a scalar integer `Tensor`.  Otherwise, it returns `None`.

    Returns:
      scalar Tensor with `type=self.dtype`, or `None`.
    r*   r   s    r4   r1   zRowPartition.uniform_row_length  s     ###r6   c                      | j                   dd S )a  Returns the start indices for rows in this row partition.

    These indices specify where the values for each row begin.
    `partition.row_starts()` is equal to `partition.row_splits()[:-1]`.

    Returns:
      A 1-D integer Tensor with shape `[self.nrows()]`.
      The returned tensor is nonnegative, and is sorted in ascending order.
      `self.row_starts()[0] == 0`.
      `self.row_starts()[-1] <= self.nvals()`.
    Nr=   r   r   s    r4   rp   zRowPartition.row_starts'  s     CR  r6   c                      | j                   dd S )a  Returns the limit indices for rows in this row partition.

    These indices specify where the values for each row end.
    `partition.row_limits()` is equal to `partition.row_splits()[:-1]`.

    Returns:
      A 1-D integer Tensor with shape `[self.nrows]`.
      The returned tensor is nonnegative, and is sorted in ascending order.
      `self.row_limits()[-1] == self.nvals()`.
    r   Nr   r   s    r4   rl   zRowPartition.row_limits5  s     ABr6   c                 `    | j                   | j                   S | j                  }|dd |dd z
  S )zReturns the lengths of rows in this `RowPartition`.

    Returns:
      A 1-D integer Tensor with shape `[self.nrows]`.
      The returned tensor is nonnegative.
      `tf.reduce_sum(self.row_lengths) == self.nvals()`.
    Nr   r=   )r'   r&   )r,   splitss     r4   r.   zRowPartition.row_lengthsB  s>     $F!":s##r6   c                 P   | j                   3t        j                  | j                   j                  d         }||dz
  S | j                  0t        j                  | j                  j                  d         }||S | j
                  t        j                  | j
                        S y)a  The number of rows in this partition, if statically known.

    ```python
    self.row_lengths().shape == [self.static_nrows]
    self.row_starts().shape == [self.static_nrows]
    self.row_limits().shape == [self.static_nrows]
    self.row_splits().shape == [self.static_nrows + 1]
    ```

    Returns:
      The number of rows in this partition as an `int` (if statically known);
      or `None` (otherwise).
    Nr   r   )r&   r
   dimension_valuer#   r'   r)   r   rJ   )r,   nrows_plus_oner0   s      r4   static_nrowszRowPartition.static_nrowsO  s     ##33D4D4D4J4J14MNn		#!!$**4+<+<+B+B1+EFe		{{''44r6   c                     | j                   #t        j                  | j                         }||S | j                  Bt	        j
                  | j                  j                  d      }|j                  |j                  S y)a  The number of values in this partition, if statically known.

    ```python
    self.value_rowids().shape == [self.static_vals]
    ```

    Returns:
      The number of values in this partition as an `int` (if statically known);
      or `None` (otherwise).
    Nr   )r+   r   rJ   r(   r
   r   r#   r   )r,   r2   s     r4   static_nvalszRowPartition.static_nvalsj  sn     {{((5e		%--d.@.@.F.FJe		 {{r6   c                 Z    | j                   t        j                  | j                         S y)zThe number of values in each row of this partition, if statically known.

    Returns:
      The number of values in each row of this partition as an `int` (if
      statically known); or `None` (otherwise).
    N)r*   r   rJ   r   s    r4   static_uniform_row_lengthz&RowPartition.static_uniform_row_length  s*     +''(@(@AAr6   c                     t        j                  t        j                  d| j                        | j                         t        j                  d| j                              j                  S )a%  Return the offset of each value.

    RowPartition takes an array x and converts it into sublists.
    offsets[i] is the index of x[i] in its sublist.
    Given a shape, such as:
    [*,*,*],[*,*],[],[*,*]
    This returns:
    0,1,2,0,1,0,1

    Returns:
      an offset for every value.
    r   r   )startslimitsdeltas)r   ragged_ranger   r|   r    r.   rt_dense_valuesr   s    r4   offsets_in_rowszRowPartition.offsets_in_rows  sT     ++##Atzz2!##Atzz24 5DODr6   c                     | j                   duS )a  Returns true if the partition is known to be uniform statically.

    This is based upon the existence of self._uniform_row_length. For example:
    RowPartition.from_row_lengths([3,3,3]).is_uniform()==false
    RowPartition.from_uniform_row_length(5, nvals=20).is_uniform()==true
    RowPartition.from_row_lengths([2,0,2]).is_uniform()==false

    Returns:
      Whether a RowPartition is known to be uniform statically.
    Nr   r   s    r4   
is_uniformzRowPartition.is_uniform  s     ##4//r6   c                    | j                   }| j                  S| j                  j                   |k7  r:t        dt        | j                  j                         z   dz   t        |      z         | j                  S| j                  j                   |k7  r:t        dt        | j                  j                         z   dz   t        |      z         | j
                  S| j
                  j                   |k7  r:t        dt        | j
                  j                         z   dz   t        |      z         | j                  T| j                  j                   |k7  r:t        dt        | j                  j                         z   dz   t        |      z         yy)zbChecks if the object is internally consistent.

    Raises:
      ValueError if inconsistent.
    Nz_uniform_row_length.dtype=z, not z_row_lengths.dtype=z_value_rowids.dtype=z_nrows.dtype=)r    r*   r   strr'   r(   r)   )r,   my_dtypes     r4   _static_checkzRowPartition._static_check  s{    zzH+		!	!	'	'8	35T55;;<=?GHX' ( 	( $):):)@)@H)L,s43D3D3J3J/KK "%h-0 1 1 %$*<*<*B*Bh*N-D4F4F4L4L0MM "%h-0 1 1 {{4;;#4#4#@T[[->->)??(J8}% & & $Ar6   c           
         t        j                  |      }|t         j                  t         j                  fvrt	        d      | j
                  |k(  r| S t        t        | j                  |      t        | j                  |      t        | j                  |      t        | j                  |      t        | j                  |      t              S )a1  Returns a copy of this RowPartition with the given encoding dtype.

    Args:
      dtype: The dtype for encoding tensors, such as `row_splits` and `nrows`.
      One of `tf.int32` or `tf.int64`.

    Returns:
      A copy of this RowPartition, with the encoding tensors cast to the given
      type.
    zdtype must be int32 or int64r   )r   as_dtyper!   r"   r   r    r   _cast_if_not_noner&   r'   r(   r)   r*   r   )r,   r    s     r4   
with_dtypezRowPartition.with_dtype  s     OOE"EV\\6<<00566zzUk$T%5%5u=%d&7&7?&t'9'95AU3,T-E-EuM+- -r6   c                 t    | j                   d| j                   d| j                    dS d| j                   dS )Nztf.RowPartition(nrows=, uniform_row_length=)ztf.RowPartition(row_splits=)r*   r)   r&   r   s    r4   __repr__zRowPartition.__repr__  sP    +&t{{m 4$$($<$<#=Q@ A +4+;+;*<A>>r6   c                     | j                   duS )zReturns true if `row_splits` has already been computed.

    If true, then `self.row_splits()` will return its value without calling
    any TensorFlow ops.
    Nr   r   s    r4   _has_precomputed_row_splitsz(RowPartition._has_precomputed_row_splits  s     4''r6   c                     | j                   duS )zReturns true if `row_lengths` has already been computed.

    If true, then `self.row_lengths()` will return its value without calling
    any TensorFlow ops.
    N)r'   r   s    r4   _has_precomputed_row_lengthsz)RowPartition._has_precomputed_row_lengths  s     D((r6   c                     | j                   duS )zReturns true if `value_rowids` has already been computed.

    If true, then `self.value_rowids()` will return its value without calling
    any TensorFlow ops.
    N)r(   r   s    r4   _has_precomputed_value_rowidsz*RowPartition._has_precomputed_value_rowids   s     T))r6   c                     | j                   duS )zReturns true if `nrows` has already been computed.

    If true, then `self.nrows()` will return its value without calling
    any TensorFlow ops.
    N)r)   r   s    r4   _has_precomputed_nrowsz#RowPartition._has_precomputed_nrows       ;;d""r6   c                     | j                   duS )zReturns true if `nvals` has already been computed.

    If true, then `self.nvals()` will return its value without calling
    any TensorFlow ops.
    N)r+   r   s    r4   _has_precomputed_nvalsz#RowPartition._has_precomputed_nvals  r   r6   c           	          t        | j                         | j                  | j                  | j                  | j
                  | j                  t              S )7Returns a copy of `self` with `row_splits` precomputed.r-   r.   r/   r0   r1   r2   r3   )r   r-   r'   r(   r)   r*   r+   r   r   s    r4   _with_precomputed_row_splitsz)RowPartition._with_precomputed_row_splits  sE    ??$%%''kk33kk+- -r6   c           	          t        | j                  | j                         | j                  | j                  | j
                  | j                  t              S )z8Returns a copy of `self` with `row_lengths` precomputed.r-   r.   r/   r0   r2   r1   r3   )r   r&   r.   r(   r)   r+   r*   r   r   s    r4   _with_precomputed_row_lengthsz*RowPartition._with_precomputed_row_lengths#  sG    ##$$&''kkkk33+- -r6   c           	          t        | j                  | j                  | j                         | j                  | j
                  | j                  t              S )z9Returns a copy of `self` with `value_rowids` precomputed.r   )r   r&   r'   r/   r)   r+   r*   r   r   s    r4   _with_precomputed_value_rowidsz+RowPartition._with_precomputed_value_rowids.  sG    ##%%&&(kkkk33+- -r6   c           	          t        | j                  | j                  | j                  | j	                         | j
                  | j                  t              S )z2Returns a copy of `self` with `nrows` precomputed.r   )r   r&   r'   r(   r0   r+   r*   r   r   s    r4   _with_precomputed_nrowsz$RowPartition._with_precomputed_nrows9  sF    ##%%''jjlkk33+- -r6   c           	          t        | j                         | j                  | j                  | j                  | j                         | j                  t              S )r   r   )r   r-   r'   r(   r)   r2   r*   r   r   s    r4   _with_precomputed_nvalsz$RowPartition._with_precomputed_nvalsD  sG    ??$%%''kkjjl33+- -r6   c           	      F   | j                   }|j                  |      st        d      |j                  *t	        j
                  |j                  | j                        n| j                  }|j                  *t	        j
                  |j                  | j                        n| j                  }|j                  *t	        j
                  |j                  | j                        n| j                  }t        | j                  | j                  | j                  |||t               S )z3Merge with a TypeSpec to create a new RowPartition.z4RowPartition and RowPartitionSpec are not compatible)r-   r.   r/   r2   r1   r0   r3   )
_type_specis_compatible_withr   r0   r   r|   r    r)   r2   r+   r1   r*   r   r&   r'   r(   r   )r,   ba_specr0   r2   r1   s         r4   _merge_with_speczRowPartition._merge_with_specO  s    __F$$Q'MNN ! 3   	9= 
 !" 3   	9= 
 
			) %--	djj/3/G/G  ##%%''-+- -r6   c           	      ^   | |u s| j                   |j                   u rz| j                  |j                  u rb| j                  |j                  u rJ| j                  |j                  u r2| j                  |j                  u r| j
                  |j
                  u r| S t        | j                  |j                  d|      \  }}t        | j                  |j                  d|      \  }}t        | j
                  |j
                  d|      \  }}|r|rd}t        | j                   |j                   d|      \  }	}
|
rd}t        | j                  |j                  d|      \  }}|rd}t        | j                  |j                  d|      \  }}|r|rd}|	| j                   u r:|| j                  u r,|| j                  u r|| j                  u r|| j
                  u r| S |	|j                   u r:||j                  u r,||j                  u r||j                  u r||j
                  u r|S t        |	|||||t              S )	a  Returns a RowPartition that merges encodings from `self` and `other`.

    Requires that `self` and `other` describe the same partition.

    Args:
      other: A `RowPartition` that encodes the same partition as `self`.
      validate: If true, then add runtime checks to verify that `self` and
        `other` encode the same row partition.

    Returns:
      A `RowPartition`.
    r0   r2   r1   Fr-   r.   r/   r   )	r&   r'   r(   r)   r+   r*   _merge_tensorsr   r   )r,   otherrW   r0   nrows_validatedr2   _r1   uniform_row_length_validatedr-   row_splits_validatedr.   row_lengths_validatedr/   value_rowids_validateds                  r4   _merge_precomputed_encodingsz)RowPartition._merge_precomputed_encodingse  s6    				U..	.			e00	0			u22	2		$		$		!	!U%>%>	>k ,DKKw,46E?dkk5<<(KHE17E  %";";h8(44 $h'5d6F6F6;6G6G6BH(N$J$ h)78I8I8=8J8J8Ex*Q&K& h+9E//,K(L(/h 	d&&&;$:K:K+K***u/Cd666ke'''u)))+++0Ee777l!-+- -r6   c                 ,    t         j                  |       S N)RowPartitionSpec
from_valuer   s    r4   r   zRowPartition._type_spec  s    &&t,,r6   )NNNNNF)NTNN)TNN)NNTNNNN)T)-__name__
__module____qualname____doc__r5   classmethodr^   ri   rm   rr   rv   r   rI   r   propertyr    r-   r/   r2   r0   r1   rp   rl   r.   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r6   r4   r   r   8   s   7|   "&GZ  #!%"#'u/ u/n   $ !%	<M <M|  !%!"&	4/ 4/l   $ !%16 16f   $ !%	+M +MZ  %)$('+$()-G/ G/R # #J-4 " "F G	$! $  4  * 	 	D$0&:-:?()*##	-	-	-	-	--,F-X - -r6   r   ztf.RowPartitionSpecc                   
    e Zd ZdZg dZ ed       Zdddej                  fdZ	 fdZ
d Zed        Zed	        Zed
        Zed        Zed        Zed        Zd Zd Zed        Zd Zed        Zd Zd Zd Z xZS )r   z+Type specification for a `tf.RowPartition`.r)   r+   r*   _dtypec                     t         S r   )r   r   s    r4   <lambda>zRowPartitionSpec.<lambda>  s    \ r6   Nc                 :   t        j                  |g      }t        j                  |g      }t        |t         j                        st        j                  |g      }n|j                  d      }|| _        || _        || _        t        j                  |      | _	        | j                  t        j                  t        j                  fvrt        d      t        j                  |d         }t        j                  |d         }t        j                  |d         }|dk(  r4|t        j                  dg      | _        n|dk7  rt        d|d|      |dk(  r4|t        j                  dg      | _        n|dk7  rt        d|d|      |d|b|dk7  r||z  dk7  rt        d|d|d      ||||z  k7  rt        d|d|d	|      |#|dk7  rt        j                  ||z  g      | _        |%|"|t        j                  ||z  g      | _        yyyy)
a  Constructs a new RowPartitionSpec.

    Args:
      nrows: The number of rows in the RowPartition, or `None` if unspecified.
      nvals: The number of values partitioned by the RowPartition, or `None` if
        unspecified.
      uniform_row_length: The number of values in each row for this
        RowPartition, or `None` if rows are ragged or row length is unspecified.
      dtype: The data type used to encode the partition.  One of `tf.int64` or
        `tf.int32`.
    r   z"dtype must be tf.int32 or tf.int64r   Nznvals=z is not compatible with nrows=z+ is not compatible with uniform_row_length=z (doesn't divide evenly)z and uniform_row_length=)r
   TensorShaper   	with_rankr)   r+   r*   r   r   r   r!   r"   r   r   )r,   r0   r2   r1   r    ncolss         r4   r5   zRowPartitionSpec.__init__  s"   $ $$eW-E$$eW-E(,*B*BC'335G4HI-77:DKDK1D//%(DK{{6<<66;<< ((q2E((q2E(();A)>?Ez	"..s3A:( ) 	)z	"..s3A:"');= > 	>U.	!*:?H I 	I		u5495%I J 	J	5A:"../?@U.5= ,,eem_=dk 4A.r6   c                 0   t         t        |   |      sy| j                  j	                  |j
                        }| j                  j	                  |j                        }| j                  j	                  |j                        }| j                  |||      S )NF)superr   r   r)   
merge_withr0   r+   r2   r*   r1   _dimensions_compatible)r,   r   r0   r2   r   	__class__s        r4   r   z#RowPartitionSpec.is_compatible_with  sw    !4;EBKK""5;;/EKK""5;;/E$$//0H0HIE&&ueU;;r6   c                 ^    | j                   | j                  | j                  | j                  fS r   r   r   s    r4   
_serializezRowPartitionSpec._serialize	  s#    KKd&>&>LLr6   c                     |\  }}}}t        j                  |d         }t        j                  |d         } | ||||      S Nr   r
   r   )rV   serializationr0   r2   r1   r    s         r4   _deserializezRowPartitionSpec._deserialize  sM     1>-UE%u((q2E((q2Eue/77r6   c                 F    t        j                  | j                  d         S r  )r
   r   r)   r   s    r4   r0   zRowPartitionSpec.nrows      ''A77r6   c                 F    t        j                  | j                  d         S r  )r
   r   r+   r   s    r4   r2   zRowPartitionSpec.nvals  r
  r6   c                 F    t        j                  | j                  d         S r  )r
   r   r*   r   s    r4   r1   z#RowPartitionSpec.uniform_row_length  s    ''(@(@(CDDr6   c                     | j                   S r   )r   r   s    r4   r    zRowPartitionSpec.dtype   s    ;;r6   c                     t        j                  t        j                  | j                  d      dz   g      }t	        j
                  || j                        S )Nr   r   )r
   r   r   r)   r   rg   r   )r,   row_splits_shapes     r4   _component_specsz!RowPartitionSpec._component_specs$  sG    #//		(	(a	81	<=?  !14;;??r6   c                 "    |j                         S r   )r-   )r,   r   s     r4   _to_componentszRowPartitionSpec._to_components*  s    r6   c                 0    t         j                  |d      S )NF)rW   )r   ri   )r,   r   s     r4   _from_componentsz!RowPartitionSpec._from_components-  s    '''??r6   c                     t        |t              st        d       | |j                  |j                  |j
                  |j                        S )Nz'Expected `value` to be a `RowPartition`)r   r   r   r   r   r   r    )rV   r   s     r4   r   zRowPartitionSpec.from_value0  sD    e\*?@@u!!5#5#5..= =r6   c           	      p    d| j                   d| j                  d| j                  d| j                  d	S )NzRowPartitionSpec(nrows=z, nvals=r   z, dtype=r   r0   r2   r1   r    r   s    r4   r   zRowPartitionSpec.__repr__7  s(    ::tzz43J3J::' (r6   c                     t        j                  | d         } t        j                  |d         }t        j                  |d         }| dk(  r|dvry|dk(  r|dvry|||dk7  r	||z  dk7  ry| 	||| z  k7  ryy)z4Returns true if the given dimensions are compatible.r   )r   NFTr  )r0   r2   r1   r   s       r4   r   z'RowPartitionSpec._dimensions_compatible<  s     ((q2E((q2E(();A)>?Eze9,ze9,U.	!*		u5r6   c                    | j                   j                  |j                        }| j                  j                  |j                        }| j
                  j                  |j                        }t        j                  |||      st        d      | j                  |j                  k7  rt        d      t        |d   |d   |d   | j                        S )zMerge two RowPartitionSpecs.z&Merging incompatible RowPartitionSpecsz2Merging RowPartitionSpecs with incompatible dtypesr   r  )r)   r   r0   r+   r2   r*   r1   r   r   r   r    )r,   r   r0   r2   r   s        r4   _merge_withzRowPartitionSpec._merge_withM  s    KK""5;;/EKK""5;;/E$$//0H0HIE225%G?@@ zzU[[ KLL%("'(/4Qx"&**. .r6   c                     t        j                  | j                  d         }t        j                  | j                  d         }t	        ||| j
                  |      S r  )r
   r   r)   r+   r   r*   )r,   r    r0   r2   s       r4   r   zRowPartitionSpec.with_dtype_  sI    ((Q8E((Q8EE5$*B*BEJJr6   c                     ~| j                   }t        j                  | j                  d         }t        j                  | j                  d         }| j
                  d n!t        j                  | j
                  d         }t        ||||      S r  )r    r
   r   r)   r+   r*   r   )r,   memor    r0   r2   r1   s         r4   __deepcopy__zRowPartitionSpec.__deepcopy__d  s    JJE((Q8E((Q8E"&":":"B$&66"66q9;  E5*<eDDr6   )r   r   r   r   	__slots__r   
value_typer   r"   r5   r   r  r   r  r0   r2   r1   r    r  r  r  r   r   staticmethodr   r  r   r  __classcell__)r  s   @r4   r   r     s    3C)12* "&\\	:>x<M 8 8 8 8 8 8 E E   @ @
@ = =(
   .$K
Er6   r   c                 B    t        j                  | dd  | d d z
  |      S )Nr   r=   rB   )r   rO   r   rC   s     r4   rP   rP   {  s+    		&	&QRj6#2;
1 1r6   c                 p    t        j                  | t        j                  d| j                        |      S )Nr   ry   rB   )r   r~   r   r|   r    r$  s     r4   rh   rh     s/    			k""1FLL97
L Lr6   c                 6    | d S t        j                  | |      S r   )r   rS   )r   r    s     r4   r   r     s    AX]]65%AAr6   c                    | |dfS || dfS | |u r| dfS d|z  }| j                   j                  |j                         st        |      |r1t        j                  | ||      g}t        j                  ||       dfS | dfS )a  Merge two optional Tensors with equal values into a single Tensor.

  Args:
    t1: tf.Tensor or None
    t2: tf.Tensor or None
    name: A name for the tensors (for error messages)
    validate: If true, then check that `t1` is compatible with `t2` (if both are
      non-None).

  Returns:
    A pair `(merged_value, validated)`:
      * `merged_value` is `t1` if it is not None; or `t2` otherwise.
      * `validated` is true if we validated that t1 and t2 are equal (either
        by adding a check, or because t1 is t2).
  FTzJRowPartition._merge_precomputed_encodings: partitions have incompatible %srB   )r#   r   r   r   r~   r   rR   )t1t2rA   rW   err_msgr[   s         r4   r   r     s      Zu9	zu9	Rxt8O&(,-G88&&rxx0w&&r2w?@f//;TAAYr6   c                 P    t        | t        j                        r| j                  S y r   )r   r   r   r    )r   s    r4   _get_dtype_or_noner,    s    z(();;	r6   c                    ||S | D ]*  }t        |t        j                        s|j                  c S  | D ]=  }t        |t        j
                        st        j                  |j                        c S  ||S t        j                  S )z,Gets the target dtype of a family of values.)	r   r   r   r    r   r   r   r   r"   )valuesr    r<   r   s       r4   _get_target_dtyper/    s    
L e%**+[[  *e%$__U[[))* 	r6   c           	      .   t        | D cg c]  \  }}|	 c}}||      }|du }|r/| D cg c]!  \  }}|dnt        j                  |||      # c}}S | D cg c]!  \  }}|dnt        j                  |||      # c}}S c c}}w c c}}w c c}}w )z7Convert a list of objects to tensors of the same dtype.N)r    rA   )r/  r   rM   r   rS   )r.  r    r<   xr   target_dtypeconvert_behaviorrA   s           r4   rz   rz     s    "F#;&1aA#;UJO, d] @F2;1d 	s44\ . 	.   Q 	x}}QlNN  $<
s   B
&B&Br   r   )/r   numpyr   tensorflow.core.protobufr   tensorflow.python.frameworkr   r   r   r   r   r   r	   r
   r   r   r   rF   r   r   r   r   r   tensorflow.python.ops.raggedr   tensorflow.python.saved_modelr    tensorflow.python.util.tf_exportr   CompositeTensorr   registerTypeSpecr   register_codecBuiltInTypeSpecCodecTypeSpecProtoROW_PARTITION_SPECrP   rh   r   r   objectr   r,  r/  rz   r   r6   r4   <module>rB     s    / 8 3 . + < 9 4 3 1 : + + 2 5 * 7 @ 6 &'z-#33 z- (z-H$ 23nEy)) nE 4nEb &  % %///*22EE1
L
BB $X &r6   