
    AVh                     x    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Z
d	 Zd
 Zd Zd Zd Zd Zy)z:Defines functions common to multiple feature column files.    N)dtypes)ops)	array_ops)math_ops)nestc                 P   t        j                  dd      5 }| j                  dddf   }| j                  dddf   }|t        j                  |      z  }t        j                  ||      }t        j                  t        j                  ||z        t        j                        }t        j                  |       dd t        j                  |      dd z
  }t        j                  ||j                        }t        j                  ||gd|      cddd       S # 1 sw Y   yxY w)z?Returns a [batch_size] Tensor with per-example sequence length.Nsequence_lengthr      )segment_ids)dtype)axisname)r   
name_scopeindicesr   	ones_liker   segment_maxcastceilr   int64shapezerosr   concat)	sp_tensornum_elementsr   row_ids
column_ids
seq_lengthn_padpaddings           V/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/feature_column/utils.py"sequence_length_from_sparse_tensorr!      s    
~~d-. L*1%G""1a4(J)%%j11J%%jgFJ j</0&,,@J
 OOI&r*Y__Z-H!-LLEooe:+;+;<GZ1
K)L L Ls   C;DD%c                 z    | t         j                  k7  r(| j                  st        dj	                  ||             y y )Nz.{} dtype must be string or integer. dtype: {}.)r   string
is_integer
ValueErrorformat)r   prefixs     r    assert_string_or_intr(   3   s=    v}}u'7'7
8??NP P (8    c                     t        | t        j                        s$t        dj	                  t        |       |             y )Nz2key must be a string. Got: type {}. Given key: {}.)
isinstancesixstring_typesr%   r&   type)keys    r    assert_key_is_stringr0   9   s;    	C))	*
<CCIs	  
+r)   c                 n   |yt        |t              rt        | |      S t        |t              r|j                  rt        | |      S t        t        |dd            r|j                         }t        j                  |      rt        ||       st        dj                  || |            t        d t        j                  |      D              }t        d t        j                  |      D              }|rt!        |      S |r|j                  rt!        |      S t#        dj                  |||            )ac  Returns default value as tuple if it's valid, otherwise raises errors.

  This function verifies that `default_value` is compatible with both `shape`
  and `dtype`. If it is not compatible, it raises an error. If it is compatible,
  it casts default_value to a tuple and returns it. `key` is used only
  for error message.

  Args:
    shape: An iterable of integers specifies the shape of the `Tensor`.
    default_value: If a single value is provided, the same value will be applied
      as the default value for every item. If an iterable of values is
      provided, the shape of the `default_value` should be equal to the given
      `shape`.
    dtype: defines the type of values. Default value is `tf.float32`. Must be a
      non-quantized, real integer or floating point type.
    key: Column name, used only for error messages.

  Returns:
    A tuple which will be used as default value.

  Raises:
    TypeError: if `default_value` is an iterable but not compatible with `shape`
    TypeError: if `default_value` is not compatible with `dtype`.
    ValueError: if `dtype` is not convertible to `tf.float32`.
  Ntolistz^The shape of default_value must be equal to given shape. default_value: {}, shape: {}, key: {}c              3   <   K   | ]  }t        |t                y wN)r+   int.0vs     r    	<genexpr>z&check_default_value.<locals>.<genexpr>n   s      A 
1cA   c              3   <   K   | ]  }t        |t                y wr4   )r+   floatr6   s     r    r9   z&check_default_value.<locals>.<genexpr>p   s      C!"
1eCr:   zRdefault_value must be compatible with dtype. default_value: {}, dtype: {}, key: {})r+   r5   _create_tupler<   is_floatingcallablegetattrr2   r   	is_nested&_is_shape_and_default_value_compatibler%   r&   allflattenany	_as_tuple	TypeError)r   default_valuer   r/   is_list_all_intis_list_has_floats         r    check_default_valuerK   @   s+   4 s#..u%%*;*;..gmXt45!((*M	^^M"1-G228&UC3)* *  A$(LL$?A AO C&*ll=&AC C}%%U..}%% ::@&#UC;1	2 2r)   c           
      x    | r2t        t        | d         D cg c]  }t        | dd |       c}      S |S c c}w )z7Returns a tuple with given shape and filled with value.r   r
   N)tupleranger=   )r   value_s      r    r=   r=   {   s;    
5q?Ka-ab	51KLL	, Ls   7c                 ~    t        j                  |       s| S t        | D cg c]  }t        |       c}      S c c}w r4   )r   rA   rM   rF   )rO   r8   s     r    rF   rF      s0    		L	e,	!,	--,s   :c                     t        j                  |       t        |      k7  ry|syt        |       |d   k7  ryt	        |d         D ]  }t        | |   |dd       r y y)z2Verifies compatibility of shape and default_value.FTr   r
   N)r   rA   boollenrN   rB   )rH   r   is      r    rB   rB      sj    
 
^^M"d5k1	58#q? a1-2BE!"IN 
r)   )r
   )__doc__r,   tensorflow.python.frameworkr   r   tensorflow.python.opsr   r   tensorflow.python.utilr   r!   r(   r0   rK   r=   rF   rB    r)   r    <module>r[      sC    A 
 . + + * 'L2P82v.r)   