
    BVh                     :    d Z ddlZd	dZd
dZddZddddddZy)z.Functions for NumPy 1.x vs. 2.x compatibility.    Nc                     |Kt        j                  |t         j                        r't        j                  | ||      j	                  |      S t        j                  | |||      S )u  Creates a NumPy array containing input values.

  It will make a copy of the object.

  In NumPy 2.x and later, strict type casting can lead to errors when values
  overflow the specified dtype. This function addresses this by replacing direct
  np.array(..., dtype=...) calls with np.array(...).astype(...). This allows for
  intended overflows, aligning with the behavior of older NumPy versions.

  Args:
    values: Array_like objects. E.g., a python list, tuple, or an object whose
      __array__ method returns an array.
    dtype: The desired numpy data type for the array.
    copy: Bool. If True (default), then the array data is copied. If None, a
      copy will only be made if __array__ returns a copy, if obj is a nested
      sequence, or if a copy is needed to satisfy any of the other requirements
      (dtype, order, etc.). Note that any copy of the data is shallow, i.e., for
      arrays with object dtype, the new array will point to the same objects.
      For False it raises a ValueError if a copy cannot be avoided.
    order: {‘K’, ‘A’, ‘C’, ‘F’}.

  Returns:
    A NumPy array with the specified data type.
  )copyorder)dtyper   r   )np
issubdtypenumberarrayastype)valuesr   r   r   s       S/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/util/numpy_compat.pynp_arrayr      sN    2 2==		:88FU3::5AA88F%d%@@    c                 b   t         j                  j                  t         j                        dk\  rh|Mt        j                  |t         j
                        r)t        j                  | ||      j                  ||      S t        j                  | |||      S t        j                  | ||      S )u  Converts input values to a NumPy array.

  It will not make a copy.

  In NumPy 2.x and later, strict type casting can lead to errors when values
  overflow the specified dtype. This function addresses this by replacing direct
  np.array(..., dtype=...) calls with np.array(...).astype(...). This allows for
  intended overflows, aligning with the behavior of older NumPy versions.

  Args:
    values: Array_like objects. E.g., a python list, tuple, or an object whose
      __array__ method returns an array.
    dtype: The desired numpy data type for the array.
    order: {‘C’, ‘F’, ‘A’, ‘K’}.
    copy: bool. If True, then the object is copied. If None then the object is
      copied only if needed, i.e. if __array__ returns a copy, if obj is a
      nested sequence, or if a copy is needed to satisfy any of the other
      requirements (dtype, order, etc.). For False it raises a ValueError if a
      copy cannot be avoided.

  Returns:
    A NumPy array with the specified data type.
  z
2.0.0.dev0r   r   )r   )r   r   r   )r   r   )r   libNumpyVersion__version__r   r	   asarrayr   )r   r   r   r   s       r   
np_asarrayr   4   s    0 VV(L8R]]5"))<ZZe$7>>u4>PPZZe5tDD::fE77r   c                 .   |}|{t         j                  j                  t         j                        dk\  r6t        j                  t        j
                  |             j                         S t        j                  |       S t        j                  | ||      S )am  Return elements chosen from x or y depending on condition.

  When only condition is provided, np.where(condition) is a shorthand for
  np.asarray(condition).nonzero(). See
  https://numpy.org/doc/stable/reference/generated/numpy.where.html. NumPy
  2.1.0rc0 disallows 0D input arrays in nonzero, so np.atleast_1d is used here
  to remain compatible with NumPy 1.x. See
  https://github.com/numpy/numpy/pull/26268.

  Args:
    condition: Array_like, bool. Where True, yield x, otherwise yield y.
    x: Array_like. Values from which to choose. x, y and condition need to be
    broadcastable to some shape.
    y: Array_like. Values from which to choose. x, y and condition need to be
    broadcastable to some shape.

  Returns:
    An array with elements from x where condition is True, and elements from y
    elsewhere. Or the indices of the elements that are non-zero.
  	2.1.0.rc0)r   r   r   r   
atleast_1dr   nonzerowhere)	conditionxys      r   np_wherer   U   sk    * Y19	vv2>>*k9]]2::i0199;;88I	)Q	""r   C)newshaper   r   c                  ||}t         j                  j                  t         j                        dk\  r5||t        j                  | ||      S t        j
                  | |||      S t        j
                  | ||      S )u  Reshapes an array without changing its data.

  NumPy 2.1.0rc1 added shape and copy arguments to numpy.reshape. See
  https://github.com/numpy/numpy/pull/26292. Both newshape and shape keywords
  are supported, but newshape is going to be deprecated. Use `shape` instead.

  Besides, shape cannot be None now. See
  https://github.com/numpy/numpy/blob/v2.1.0rc1/numpy/_core/fromnumeric.py#L309.
  Previously, np.reshape with newshape=None returned a copy. To maintain this
  behavior, we now use asarray to create an ndarray.

  Args:
    a: Array_like. Array to be reshaped.
    shape: The new shape of the array.
    newshape: The new shape of the array (deprecated).
    order: {‘C’, ‘F’, ‘K’}.
    copy: bool. If True, then the array data is copied. If None, a copy will
    only be made if it’s required by order. For False it raises a ValueError if
    a copy cannot be avoided.

  Returns:
    This will be a new view object if possible; otherwise, it will be a copy.
  r   r   )r   )r   r   r   r   r   reshape)ashaper!   r   r   s        r   
np_reshaper&   q   sn    0 ]EVV(K7})ZZT22::ae$77	AuE	**r   )NTK)NNN)NN)N)__doc__numpyr   r   r   r   r&    r   r   <module>r+      s.     5 A>8B#8+T4 +r   