
    AVh'                         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 Z ed      ej"                  	 	 dd              Zy)zGeneral shape ops for frames.    N)constant_op)ops)tensor_util)	array_ops)math_ops)util_ops)dispatch)	tf_exportc                    t        j                  |      }t        j                  |      }t        j                  |      }| j                  j                  y|dg| j                  j                  dz   z  S | j                  j	                         }d}||   }|d| }||d dd }	|r5|3||rt        d| |z         }n|||rJ t        d||z
  |z   |z        }|||gz   |	z   S )z0Infers the shape of the return value of `frame`.N   r   )r   constant_valueshapendimsas_listmax)
signalframe_length
frame_steppad_endaxissignal_shape
num_frames
frame_axisouter_dimensionsinner_dimensionss
             V/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/signal/shape_ops.py_infer_frame_shaper      s   ++L9,))*5*		#	#D	)$\\	\6V\\''!+,,%%',*D!*!%4(!$%(,j,'qZK:567j		L$<[
j<'*4CEj	Z6	69I	II    zsignal.framec           	      J
   t        j                  |d| |||g      5  t        j                  | d      } t        j                  |d      }t        j                  |d      }t        j                  |d      }| j                  j	                  d       |j                  j                  d       |j                  j                  d       |j                  j                  d       t        | ||||      }d	 } |t        j                  |             \  }	}
 ||      \  }}|
rJ|rHt        t        |	            |   }t        j                  |	||dz   g
      \  }}}|j                         }nft        j                  |       }t        j                  |      |   }t        j                  |	|d|dz
  |z
  g      \  }}}t        j                  |g       }t        j                   |      }t        j                   |      }|rt        j                  || j"                        }|j                  j                  d       | |z   }t        j$                  d|||dz
  z  z   |z
        }t        j&                  t        j(                  |dg|j"                        t        j                  d|gg      t        j(                  |dg|j"                        gd      }t        j*                  | ||      } t        j                  |       }	|	|   }n>t        j$                  t-        j.                  d|j"                        d||z
  |z  z         } |t1        j2                  ||            \  }}||z  }||z  }||z  }t        j&                  |||z  g|gd      }t        j&                  |||g|gd      }t        j                  t        j4                  | t        j6                  |	      |      |      }t        j                  t        j                  ||j"                        |z  |dg      }t        j                  t        j                  ||j"                        d|g      }||z   }t        j                  |      }t        j                  ||j"                        }t        j                  ||g|j"                        } t        j                  t        j8                  |||      t        j&                  || |gd            }!|r|!j;                  |       |!cddd       S # 1 sw Y   yxY w)a/	  Expands `signal`'s `axis` dimension into frames of `frame_length`.

  Slides a window of size `frame_length` over `signal`'s `axis` dimension
  with a stride of `frame_step`, replacing the `axis` dimension with
  `[frames, frame_length]` frames.

  If `pad_end` is True, window positions that are past the end of the `axis`
  dimension are padded with `pad_value` until the window moves fully past the
  end of the dimension. Otherwise, only window positions that fully overlap the
  `axis` dimension are produced.

  For example:

  >>> # A batch size 3 tensor of 9152 audio samples.
  >>> audio = tf.random.normal([3, 9152])
  >>>
  >>> # Compute overlapping frames of length 512 with a step of 180 (frames overlap
  >>> # by 332 samples). By default, only 49 frames are generated since a frame
  >>> # with start position j*180 for j > 48 would overhang the end.
  >>> frames = tf.signal.frame(audio, 512, 180)
  >>> frames.shape.assert_is_compatible_with([3, 49, 512])
  >>>
  >>> # When pad_end is enabled, the final two frames are kept (padded with zeros).
  >>> frames = tf.signal.frame(audio, 512, 180, pad_end=True)
  >>> frames.shape.assert_is_compatible_with([3, 51, 512])

  If the dimension along `axis` is N, and `pad_end=False`, the number of frames
  can be computed by:
   ```python
   num_frames = 1 + (N - frame_size) // frame_step
   ```
   If `pad_end=True`, the number of frames can be computed by:
  ```python
  num_frames = -(-N // frame_step) # ceiling division
  ```

  Args:
    signal: A `[..., samples, ...]` `Tensor`. The rank and dimensions
      may be unknown. Rank must be at least 1.
    frame_length: The frame length in samples. An integer or scalar `Tensor`.
    frame_step: The frame hop size in samples. An integer or scalar `Tensor`.
    pad_end: Whether to pad the end of `signal` with `pad_value`.
    pad_value: An optional scalar `Tensor` to use where the input signal
      does not exist when `pad_end` is True.
    axis: A scalar integer `Tensor` indicating the axis to frame. Defaults to
      the last axis. Supports negative values for indexing from the end.
    name: An optional name for the operation.

  Returns:
    A `Tensor` of frames with shape `[..., num_frames, frame_length, ...]`.

  Raises:
    ValueError: If `frame_length`, `frame_step`, `pad_value`, or `axis` are not
      scalar.
  framer   )namer   r   r   r   r   c                 @    t        j                  |       }||dfS | dfS )NTF)r   r   )val
val_statics     r   maybe_constantzframe.<locals>.maybe_constant   s+    --c2j#-#9j$KU|Kr   )indices_or_sections   )dtype)constant_values)r   N)r   
name_scopeconvert_to_tensorr   with_rank_at_leastassert_has_rankr   r   rangelennpsplititemrankr   reshapesizer(   maximumconcatzerospadr   constantr   gcdstrided_slice
zeros_likegather	set_shape)"r   r   r   r   	pad_valuer   r!   result_shaper%   r   signal_shape_is_staticaxis_is_staticr   length_samplesr   signal_ranknum_outer_dimensionsnum_inner_dimensionsr   pad_samplespaddingssubframe_length_subframes_per_framesubframes_per_hopnum_subframesslice_shapesubframe_shape	subframesframe_selectorsubframe_selectorselectormid_dimensionsframess"                                     r   r    r    7   s   v ~~dGflJ&/&1 2 u""69F((NKL&&zEJ  F3D
LL##A&&&q)$$Q'JJq!%flJ&*,LL ,:,!(L()$/D..3|$%d+d;=88
T4!8,<<>8(8%**,nNN6*k^^K(.d;D??
q+/D"89<;8(8 ((<n$>>*:;$>>*:; ''	6<<@ioo%%a( %_
23j $$
\J*q.99NJLk !!
///3;;L;L
M


![!1 2
3
///3;;L;L
M# 
	h
 }}VXyIf__V,l#D)n##


q(:(:
;
~,;
;=j (\:(NOOQ&/9"o5"o5M""$4%2_%D$E$4$678:K %%'7(5'G'7'9:;=N !!)"9"9	$$\2#$&I &&z););<	&?,N "))*,2D2DE	
 "  11H ,,-=>,, 0 6 68**J+E1A1G1GIN H48*N<LM	F
 |$ku u us   S3TT")Fr   N)__doc__numpyr0   tensorflow.python.frameworkr   r   r   tensorflow.python.opsr   r   tensorflow.python.ops.signalr   tensorflow.python.utilr	    tensorflow.python.util.tf_exportr
   r   add_dispatch_supportr     r   r   <module>ra      sZ    $  3 + 3 + * 1 + 6J4 >	MOn  nr   