
    voi                        S SK r S SKrS SKrS SKrS SKJr  S SKrSSKJ	r	J
r
  / SQrS rS rS r " S	 S
5      r " S S\5      r " S S\S9r " S S5      rS r " S S\5      r " S S5      r\S 5       r " S S5      r " S S5      rS/S jrS rS rS rS0S  jrS! r S" r!S# r"S1S$ jr#S% r$S& r%S' r&S( r'S) r(\RR                  " 5       RT                  RV                  \RR                  \RX                  " 5       RT                  RV                  \RX                  \RZ                  " 5       RT                  RV                  \RZ                  \R\                  " 5       RT                  RV                  \R\                  \R^                  " 5       RT                  RV                  \RR                  S*\RX                  S+\R\                  0r0S2S, jr1S- r2S. r3g)3    N)contextmanager   )all_warningswarn)deprecate_funcget_bound_method_classr   safe_as_intcheck_shape_equalitycheck_nDr   
reshape_ndidentityslice_at_axisdeprecate_parameter
DEPRECATEDc                 x    U nSn[        US5      (       a$  UR                  nUS-  n[        US5      (       a  M$  U$ )a  Count the number of inner wrappers by unpacking ``__wrapped__``.

If a wrapped function wraps another wrapped function, then we refer to the
wrapping of the second function as an *inner wrapper*.

For example, consider this code fragment:

.. code-block:: python
    @wrap_outer
    @wrap_inner
    def foo():
        pass

Here ``@wrap_inner`` applies a wrapper to ``foo``, and ``@wrap_outer``
applies a wrapper to the result.

Parameters
----------
func : callable
    The callable of which to determine the number of inner wrappers.

Returns
-------
count : int
    The number of times `func` has been wrapped.

See Also
--------
count_global_wrappers
r   __wrapped__r   )hasattrr   )func	unwrappedcounts      Q/var/www/html/land-ocr/venv/lib/python3.13/site-packages/skimage/_shared/utils.pycount_inner_wrappersr      sE    > IE
)]
+
+))	
 )]
+
+ L    c                 T    [        U 5      n[        U 5      nX!-
  S-   n[        US5      $ )af  Find stacklevel of `func` relative to its global representation.

Determine automatically with which stacklevel a warning should be raised.

Parameters
----------
func : Callable
    Tries to find the global version of `func` and counts the number of
    additional wrappers around `func`.

Returns
-------
stacklevel : int
    The stacklevel. Minimum of 2.
r      )r   count_global_wrappersmax)r   inner_wrapped_countglobal_wrapped_count
stacklevels       r   _warning_stacklevelr!   B   s4    " /t406%;a?Jz1r   c                     SU R                   ;   a  Sn[        U5      eU R                   R                  S5      tp#U R                  R	                  X 5      nU H  n[        XEU5      nM     [        U5      nUS:  d   eU$ )a  Count the total number of times a function as been wrapped globally.

Similar to :func:`count_inner_wrappers`, this counts the number of times
`func` has been wrapped. However, this function doesn't start counting
from `func` but instead tries to access the "global representation" of
`func`. This means that you could use this function from inside a wrapper
that was applied first, and still count wrappers that were applied on
top of it afterwards.

E.g., `func` might be wrapped by multiple decorators that emit
warnings. In that case, calling this function in the inner-most decorator
will still return the total count of wrappers.

Parameters
----------
func : callable
    The callable of which to determine the number of wrappers. Can be a
    function or method of a class.

Returns
-------
count : int
    The number of times `func` has been wrapped.

See Also
--------
count_inner_wrappers
z<locals>zuCannot determine stacklevel of a function defined in another function's local namespace. Set the stacklevel manually..r   )__qualname__
ValueErrorsplit__globals__getgetattrr   )r   msg
first_nameotherglobal_funcpartr   s          r   r   r   Z   s    : T&&&G 	 o**005J""&&z8K k=  !-EA::Lr   c                   .    \ rS rSrSrSSS.S jrS rSrg)change_default_value   a  Decorator for changing the default value of an argument.

Parameters
----------
arg_name : str
    The name of the argument to be updated.
new_value : any
    The argument new value.
changed_version : str
    The package version in which the change will be introduced.
warning_msg : str
    Optional warning message. If None, a generic warning message
    is used.
stacklevel : {None, int}, optional
    If None, the decorator attempts to detect the appropriate stacklevel for the
    deprecation warning automatically. This can fail, e.g., due to
    decorating a closure, in which case you can set the stacklevel manually
    here. The outermost decorator should have stacklevel 2, the next inner
    one stacklevel 3, etc.
N)warning_msgr    c                @    Xl         X l        X@l        X0l        XPl        g N)arg_name	new_valuer2   changed_versionr    )selfr5   r6   r7   r2   r    s         r   __init__change_default_value.__init__   s     !"&.$r   c                 $  ^ ^^ [         R                  " T5      R                  n[        UR	                  5       5      R                  T R                  5      mUT R                     R                  nT R                  cs  ST R                   ST R                   ST R                   ST R                   SU ST R                   ST R                   ST R                   S	T R                   S
3T l        [        R                  " T5      UUU 4S j5       nU$ )NzThe new recommended value for z is z. Until version z, the default z
 value is z. From version z, the z default value will be z/. To avoid this warning, please explicitly set z value.c                    > [        U 5      TS-   :  af  TR                  UR                  5       ;  aH  TR                  b  TR                  O
[	        T5      n[
        R                  " TR                  [        US9  T" U 0 UD6$ )Nr   )r    )	lenr5   keysr    r!   warningsr   r2   FutureWarning)argskwargsr    arg_idxr   r8   s      r   
fixed_func1change_default_value.__call__.<locals>.fixed_func   sn    4y7Q;&4==+M 2 OO,T2  d..*U(((r   )inspect	signature
parameterslistr>   indexr5   defaultr2   r6   r7   	functoolswraps)r8   r   rH   	old_valuerD   rC   s   ``   @r   __call__change_default_value.__call__   s   &&t,77
z()//>t}}-55	#0t>>""243G3G2H I#}}oZ	{ C  $ 4 45VDMM? K))-(8 977;}}oWN  
			) 
		) r   )r5   r7   r6   r    r2   __name__
__module__r$   __firstlineno____doc__r9   rO   __static_attributes__ r   r   r0   r0      s    , DHTX%r   r0   c                       \ rS rSrSrS rSrg)PatchClassRepr   z5Control class representations in rendered signatures.c                 "    SU R                    S3$ )N<>)rR   )clss    r   __repr__PatchClassRepr.__repr__   s    3<<.""r   rW   N)rR   rS   r$   rT   rU   r_   rV   rW   r   r   rY   rY      s
    ?#r   rY   c                       \ rS rSrSrSrg)r      a  Signal value to help with deprecating parameters that use None.

This is a proxy object, used to signal that a parameter has not been set.
This is useful if ``None`` is already used for a different purpose or just
to highlight a deprecated parameter in the signature.
rW   NrR   rS   r$   rT   rU   rV   rW   r   r   r   r      s    r   r   )	metaclassc                   >    \ rS rSrSr\rSrSrSSSSS.S jrS	 r	S
r
g)r      ak  Deprecate a parameter of a function.

Parameters
----------
deprecated_name : str
    The name of the deprecated parameter.
start_version : str
    The package version in which the warning was introduced.
stop_version : str
    The package version in which the warning will be replaced by
    an error / the deprecation is completed.
template : str, optional
    If given, this message template is used instead of the default one.
new_name : str, optional
    If given, the default message will recommend the new parameter name and an
    error will be raised if the user uses both old and new names for the
    same parameter.
modify_docstring : bool, optional
    If the wrapped function has a docstring, add the deprecated parameters
    to the "Other Parameters" section.
stacklevel : {None, int}, optional
    If None, the decorator attempts to detect the appropriate stacklevel for the
    deprecation warning automatically. This can fail, e.g., due to
    decorating a closure, in which case you can set the stacklevel manually
    here. The outermost decorator should have stacklevel 2, the next inner
    one stacklevel 3, etc.

Notes
-----
Assign `DEPRECATED` as the new default value for the deprecated parameter.
This marks the status of the parameter also in the signature and rendered
HTML docs.

This decorator can be stacked to deprecate more than one parameter.

Examples
--------
>>> from skimage._shared.utils import deprecate_parameter, DEPRECATED
>>> @deprecate_parameter(
...     "b", new_name="c", start_version="0.1", stop_version="0.3"
... )
... def foo(a, b=DEPRECATED, *, c=None):
...     return a, c

Calling ``foo(1, b=2)``  will warn with::

    FutureWarning: Parameter `b` is deprecated since version 0.1 and will
    be removed in 0.3 (or later). To avoid this warning, please use the
    parameter `c` instead. For more details, see the documentation of
    `foo`.
a	  Parameter `{deprecated_name}` is deprecated since version {deprecated_version} and will be removed in {changed_version} (or later). To avoid this warning, please do not use the parameter `{deprecated_name}`. For more details, see the documentation of `{func_name}`.a  Parameter `{deprecated_name}` is deprecated since version {deprecated_version} and will be removed in {changed_version} (or later). To avoid this warning, please use the parameter `{new_name}` instead. For more details, see the documentation of `{func_name}`.NT)templatenew_namemodify_docstringr    c                X    Xl         XPl        X@l        X l        X0l        X`l        Xpl        g r4   )deprecated_namerh   rg   start_versionstop_versionri   r    )r8   rk   rl   rm   rg   rh   ri   r    s           r   r9   deprecate_parameter.__init__  s+      /  *( 0$r   c                 f  ^ ^^^^	 [         R                  " T5      R                  n [        UR	                  5       5      R                  T R                  5      mSmT R                  (       a3   [        UR	                  5       5      R                  T R                  5      mUT R                     R                  [        La!  [        ST R                   S[        < S35      eT R                  b  T R                  nO&T R                  b  T R                  nOT R                  nUR                  T R                  T R                   T R"                  TR$                  T R                  S9m	[&        R(                  " T5      UUUU U	4S j5       nT R*                  (       a@  TR,                  b3  [/        TT R                  T R                  0T R                   5      nXel        U$ ! [         a  n[        T R                  < S35      UeS nAff = f! [         a  n[        T R                  < S35      UeS nAff = f)Nz not in parametersFz
Expected `z` to have the value z2 to indicate its status in the rendered signature.)rk   deprecated_versionr7   	func_namerh   c                    > [         n[         n[        U 5      T:  a(  U T   nTR                  b  U S T [         4-   U TS-   S  -   n TR                  UR	                  5       ;   a/  UTR                     nTR                  b  [         UTR                  '   TSLa  [        U 5      T:  a  U T   nTR                  (       a-  TR                  UR	                  5       ;   a  UTR                     nU[         La  TR
                  b  TR
                  O
[        T5      n[        R                  " T	[        US9  U[         La&  [        STR                   STR                   S35      eTR                  b  X!TR                  '   T" U 0 UD6$ )Nr   Fcategoryr    zBoth deprecated parameter `z` and new parameter `z<` are used. Use only the latter to avoid conflicting values.)r   r=   rh   rk   r>   r    r!   r?   r   r@   r%   )
rA   rB   deprecated_valuer6   r    deprecated_idxr   new_idxr8   warning_messages
        r   rD   0deprecate_parameter.__call__.<locals>.fixed_funcS  s   )"I 4y>)#'#7 ==,_n-%-(~1345 
 ##v{{}4#)$*>*>#? ==,3=F4//0 e#D	G(; M	}}&++-!?"4==1	z1 2 OO,T2 
 #m
 J.$5d6J6J5K L..2mm_ =GH 
 ]].,<4==)(((r   )rF   rG   rH   rI   r>   rJ   rk   r%   rh   rK   r   RuntimeErrorrg   replace_parameter_templateremove_parameter_templateformatrl   rm   r$   rL   rM   ri   rU   _docstring_add_deprecated)
r8   r   rH   erg   rD   newdocrv   rw   rx   s
   ``     @@@r   rO   deprecate_parameter.__call__1  s   &&t,77
	S!*//"34::4;O;OPN ==Pz0177F d**+33:ET1122Fzn UD E 
 ==$}}H]]&66H55H"// 00#11 --'']] * 
 
	.	) .	) 
.	)`   T\\%=.t++T]];T=O=OF "(k  	S 4 477IJKQRR	S  P DMM#44F!GHaOPs/   2G -2H 
H%G??H
H0H++H0)rk   ri   rh   r    rl   rm   rg   )rR   rS   r$   rT   rU   r   r|   r{   r9   rO   rV   rW   r   r   r   r      s=    2h J	 	M  %&Yr   r   c           	         U R                   c  g SSKJnJn  U" U 5      nUR                  5        HY  u  pg/ nUc  UR                  SU S35        OUR                  SU S35        USS	U 3/-  nUS
   R                  U" USUS95        M[     [        U5      n	U	R                  S5      n
U
SS nUS   R                  5       (       d+  UR                  S5        US   R                  5       (       d  M+  UR                  S5      nUS   R                  5       (       a1  USUR                  S5      -   -  nUS   R                  5       (       a  M1  US-  nUSR                  U5      -   nSR                  UR                  S5       Vs/ s H  oR                  5       PM     sn5      nU$ ! [         a    U R                   s $ f = fs  snf )a  Add deprecated kwarg(s) to the "Other Params" section of a docstring.

Parameters
----------
func : function
    The function whose docstring we wish to update.
kwarg_mapping : dict
    A dict containing {old_arg: new_arg} key/value pairs, see
    `deprecate_parameter`.
deprecated_version : str
    A major.minor version string specifying when old_arg was
    deprecated.

Returns
-------
new_doc : str
    The updated docstring. Returns the original docstring if numpydoc is
    not available.
Nr   )FunctionDoc	Parameter`z` is deprecated.zDeprecated in favor of `z`. z.. deprecated:: zOther Parametersr   )nametypedesc
r   z
    z

)rU   numpydoc.docscraper   r   ImportErroritemsappendstrr&   strippopjoinrstrip)r   kwarg_mappingrp   r   r   Docold_argnew_argr   new_docstringr&   	no_headerdescrfinal_docstringlines                  r   r~   r~     s   ( ||=
 d
C)//1?KK!G9$456KK27)2>?'(:';<==&&7DA	
 2 HM %Eab	Il  ""a l  "" MM!E
A,



IMM!,,, A,



	VOEhmmI66Oii?;P;PQU;V W;V4;V WXOO  ||L !Xs   F$ G $F=<F=c                       \ rS rSrSrSrg)FailedEstimationAccessErrori  zError from use of failed estimation instance

This error arises from attempts to use an instance of
:class:`FailedEstimation`.
rW   Nrc   rW   r   r   r   r     s    r   r   c                   D    \ rS rSrSr\rSrS rS r	S r
S rS rS	 rS
rg)FailedEstimationi  a  Class to indicate a failed transform estimation.

The ``from_estimate`` class method of each transform type may return an
instance of this class to indicate some failure in the estimation process.

Parameters
----------
message : str
    Message indicating reason for failed estimation.

Attributes
----------
message : str
    Message above.

Raises
------
FailedEstimationAccessError
    Exception raised for missing attributes or if the instance is used as a
    callable.
zYou can check for a failed estimation by truth testing the returned object. For failed estimations, `bool(estimation_result)` will be `False`. E.g.

    if not estimation_result:
        raise RuntimeError(f'Failed estimation: {estimation_result}')c                     Xl         g r4   message)r8   r   s     r   r9   FailedEstimation.__init__  s    r   c                     g)NFrW   r8   s    r   __bool__FailedEstimation.__bool__  s    r   c                 N    [        U 5      R                   SU R                  < S3$ )N())r   rR   r   r   s    r   r_   FailedEstimation.__repr__  s%    t*%%&a'7q99r   c                     U R                   $ r4   r   r   s    r   __str__FailedEstimation.__str__  s    ||r   c                     [        U 5      R                   SU R                   SU R                   3nU R	                  U5      e)Nz is not callable. 

Hint: r   rR   r   hint	error_cls)r8   rA   rB   r*   s       r   rO   FailedEstimation.__call__  sG    Dz""##5dll^ DYYK! 	 nnS!!r   c                     [        U 5      R                   SU< SU R                   SU R                   3nU R	                  U5      e)Nz has no attribute z. r   r   )r8   r   r*   s      r   __getattr__FailedEstimation.__getattr__  sM    Dz""##5dXR~ NYYK! 	 nnS!!r   r   N)rR   rS   r$   rT   rU   r   r   r   r9   r   r_   r   rO   r   rV   rW   r   r   r   r     s7    , ,I	P 	:""r   r   c               #      #    [         R                  " 5          [         R                  " S[        SSS9  Sv   SSS5        g! , (       d  f       g= f7f)zeFilter warnings about the deprecated `estimate` method.

Use either as decorator or context manager.
ignorez`estimate` is deprecatedskimage)actionrt   r   moduleN)r?   catch_warningsfilterwarningsr@   rW   r   r   #_ignore_deprecated_estimate_warningr     s=      
	 	 	"".		
 	 
#	"	"s   A A	A
AAc                   .    \ rS rSrSr   SS jrS rSrg)channel_as_last_axisi#  a  Decorator for automatically making channels axis last for all arrays.

This decorator reorders axes for compatibility with functions that only
support channels along the last axis. After the function call is complete
the channels axis is restored back to its original position.

Parameters
----------
channel_arg_positions : tuple of int, optional
    Positional arguments at the positions specified in this tuple are
    assumed to be multichannel arrays. The default is to assume only the
    first argument to the function is a multichannel array.
channel_kwarg_names : tuple of str, optional
    A tuple containing the names of any keyword arguments corresponding to
    multichannel arrays.
multichannel_output : bool, optional
    A boolean that should be True if the output of the function is not a
    multichannel array and False otherwise. This decorator does not
    currently support the general case of functions with multiple outputs
    where some or all are multichannel.

c                 P    [        U5      U l        [        U5      U l        X0l        g r4   )setarg_positionskwarg_namesmultichannel_output)r8   channel_arg_positionschannel_kwarg_namesr   s       r   r9   channel_as_last_axis.__init__;  s&     !!6723#6 r   c                 J   ^ ^ [         R                  " T5      UU 4S j5       nU$ )Nc                    > UR                  SS 5      nUc  T" U 0 UD6$ [        R                  " U5      (       a  U4n[        U5      S:  a  [	        S5      eUS:X  d  US:X  a  T" U 0 UD6$ T	R
                  (       an  / n[        U 5       HQ  u  pEUT	R
                  ;   a+  UR                  [        R                  " XRS   S5      5        M@  UR                  U5        MS     [        U5      nOU nT	R                   H"  n[        R                  " X   US   S5      X'   M$     SUS'   T" U0 UD6nT	R                  (       a  [        R                  " USUS   5      nU$ )Nchannel_axisr   z1only a single channel axis is currently supported)r   r   )r(   npisscalarr=   r%   r   	enumerater   moveaxistupler   r   )
rA   rB   r   new_argsposargr   outr   r8   s
           r   rD   1channel_as_last_axis.__call__.<locals>.fixed_funcF  sG   !::nd;L#T,V,,
 {{<(( ,< 1$ !TUUu$(:T,V,,!! )$HCd000 Ca"(MN ,	 !0
 !?((!{{6<a"M )
 &(F>" +F+C''kk#r<?;Jr   )rL   rM   )r8   r   rD   s   `` r   rO   channel_as_last_axis.__call__E  s'    		'	 
'	R r   )r   r   r   N))r   rW   TrQ   rW   r   r   r   r   #  s    2 # 	7+r   r   c                   0    \ rS rSrSrSSSS.S jrS rSrg)r   is  a  Decorate a deprecated function and warn when it is called.

Adapted from <http://wiki.python.org/moin/PythonDecoratorLibrary>.

Parameters
----------
deprecated_version : str
    The package version when the deprecation was introduced.
removed_version : str
    The package version in which the deprecated function will be removed.
hint : str, optional
    A hint on how to address this deprecation,
    e.g., "Use `skimage.submodule.alternative_func` instead."
stacklevel :  {None, int}, optional
    If None, the decorator attempts to detect the appropriate stacklevel for the
    deprecation warning automatically. This can fail, e.g., due to
    decorating a closure, in which case you can set the stacklevel manually
    here. The outermost decorator should have stacklevel 2, the next inner
    one stacklevel 3, etc.

Examples
--------
>>> @deprecate_func(
...     deprecated_version="1.0.0",
...     removed_version="1.2.0",
...     hint="Use `bar` instead."
... )
... def foo():
...     pass

Calling ``foo`` will warn with::

    FutureWarning: `foo` is deprecated since version 1.0.0
    and will be removed in version 1.2.0. Use `bar` instead.
N)removed_versionr   r    c                4    Xl         X l        X0l        X@l        g r4   rp   r   r   r    )r8   rp   r   r   r    s        r   r9   deprecate_func.__init__  s     #5.	$r   c                   ^ ^^ STR                    ST R                   3mT R                  (       a  TST R                   S3-  mT R                  (       a"  TST R                  R	                  S5       S3-  m[
        R                  " T5      UUU 4S j5       nST 3nUR                  c  X2l        U$ US-   UR                  -   Ul        U$ )	Nr   z` is deprecated since version z  and will be removed in version r#    c                     > TR                   b  TR                   O
[        T5      n[        R                  " T[        US9  T" U 0 UD6$ )Nrs   )r    r!   r?   r   r@   )rA   rB   r    r   r   r8   s      r   wrapped(deprecate_func.__call__.<locals>.wrapped  sG     ??. (. 
 MM'MjQ(((r   z**Deprecated:** z

    )rR   rp   r   r   r   rL   rM   rU   )r8   r   r   docr   s   ``  @r   rO   deprecate_func.__call__  s    <T=T=T<UV 	 9$:N:N9OqQQG99499++C0133G			) 
	) !	*??"!O  "J.@GOr   )rp   r   r   r    rQ   rW   r   r   r   r   s  s    "J 6:QU%r   r   c                 t    Uc  U R                   R                  S5      S   OUn[        SSSU S3SS9" U 5      $ )	zDeprecate ``estimate`` method.r#   r   z0.26z2.2zPlease use `z*.from_estimate` class constructor instead.r   r   )r$   r&   r   )r   
class_names     r   _deprecate_estimater     sQ    4>4F""((-a0JJ!J<'QR	
  r   c                     S n[        U S5      R                  nUR                  Ul        [        R                  " U5      Ul        [        XR                  5      U l        U $ )zDeprecate inherited ``estimate`` instance method.

This needs a class decorator so we can correctly specify the class of the
`from_estimate` class method in the deprecation message.
c                 *    U R                   " U0 UD6S L $ r4   )	_estimate)r8   rA   rB   s      r   estimate/_deprecate_inherited_estimate.<locals>.estimate  s    ~~t.v.$66r   r   )	r)   r   rU   rF   rG   __signature__r   rR   r   )r^   r   inherited_meths      r   _deprecate_inherited_estimater     sQ    7 S*-99N%--H$..~>H&x>CLJr   c                   ^ [        U S5      mU4S jnTR                  R                  S5      S   nTR                  R	                  X R
                  5      Ul        [        R                  " T5      Ul        [        U5      U l
        U $ )a  Fix docstring for inherited ``from_estimate`` class method.

Even for classes that inherit the `from_estimate` method, and do not
override it, we nevertheless need to change the *docstring* of the
`from_estimate` method to point the user to the current (inheriting) class,
rather than the class in which the method is defined (the inherited class).

This needs a class decorator so we can modify the docstring of the new
class method.  CPython currently does not allow us to modify class method
docstrings by updating ``__doc__``.
from_estimatec                    > T" U0 UD6$ r4   rW   )r^   rA   rB   inherited_cmeths      r   r   6_update_from_estimate_docstring.<locals>.from_estimate  s    ///r   r#   )r)   r$   r&   rU   replacerR   rF   rG   r   classmethodr   )r^   r   inherited_class_namer   s      @r   _update_from_estimate_docstringr     s{     c?3O0 +77==cB2F+33;;llM #*"3"3O"DM#M2CJr   c                 n    [         R                  S:  a  U R                  $ U R                  R                  $ )z$Return the class for a bound method.3)sysversionim_class__self__	__class__)ms    r   r   r     s&    s*1::D

0D0DDr   c                 D   [         R                  " U 5      S-  nUR                  S:X  a  US:  a  SU-
  nOSX"S:     -
  X"S:  '   [         R                  " USUS9(       d  [	        SU  S35      e[         R
                  " U 5      R                  [         R                  5      $ )a/  
Attempt to safely cast values to integer format.

Parameters
----------
val : scalar or iterable of scalars
    Number or container of numbers which are intended to be interpreted as
    integers, e.g., for indexing purposes, but which may not carry integer
    type.
atol : float
    Absolute tolerance away from nearest integer to consider values in
    ``val`` functionally integers.

Returns
-------
val_int : NumPy scalar or ndarray of dtype `np.int64`
    Returns the input value(s) coerced to dtype `np.int64` assuming all
    were within ``atol`` of the nearest integer.

Notes
-----
This operation calculates ``val`` modulo 1, which returns the mantissa of
all values. Then all mantissas greater than 0.5 are subtracted from one.
Finally, the absolute tolerance from zero is calculated. If it is less
than ``atol`` for all value(s) in ``val``, they are rounded and returned
in an integer array. Or, if ``val`` was a scalar, a NumPy scalar type is
returned.

If any value(s) are outside the specified tolerance, an informative error
is raised.

Examples
--------
>>> safe_as_int(7.0)
7

>>> safe_as_int([9, 4, 2.9999999999])
array([9, 4, 3])

>>> safe_as_int(53.1)
Traceback (most recent call last):
    ...
ValueError: Integer argument required but received 53.1, check inputs.

>>> safe_as_int(53.01, atol=0.01)
53

r   r   g      ?)atolz'Integer argument required but received z, check inputs.)r   asarrayndimallcloser%   roundastypeint64)valr  mods      r   r	   r	     s    b **S/A
C xx1}9c'CSs^+#I;;sAD)B3%WXX88C=))r   c                  `   ^ U S   m[        U4S jU SS  5       5      (       d  [        S5      eg)z)Check that all images have the same shaper   c              3   V   >#    U  H  nTR                   UR                   :H  v   M      g 7fr4   )shape).0imageimage0s     r   	<genexpr>'check_shape_equality.<locals>.<genexpr>A  s     C
uv||u{{*
s   &)r   Nz+Input images must have the same dimensions.)allr%   )imagesr  s    @r   r
   r
   >  s2    AYFCqr
CCCFGG
r   c                 .    [        S5      4U-  U 4-   S-   $ )a  
Construct tuple of slices to slice an array in the given dimension.

Parameters
----------
sl : slice
    The slice for the given dimension.
axis : int
    The axis to which `sl` is applied. All other dimensions are left
    "unsliced".

Returns
-------
sl : tuple of slices
    A tuple with slices matching `shape` in length.

Examples
--------
>>> slice_at_axis(slice(None, 3, -1), 1)
(slice(None, None, None), slice(None, 3, -1), Ellipsis)
N).)slice)slaxiss     r   r   r   F  s!    , $K>D B5(611r   c                 x    U R                   S:w  a  [        S5      eS/U-  nSX2'   [        R                  " X5      $ )a@  Reshape a 1D array to have n dimensions, all singletons but one.

Parameters
----------
arr : array, shape (N,)
    Input array
ndim : int
    Number of desired dimensions of reshaped array.
dim : int
    Which dimension/axis will not be singleton-sized.

Returns
-------
arr_reshaped : array, shape ([1, ...], N, [1,...])
    View of `arr` reshaped to the desired shape.

Examples
--------
>>> rng = np.random.default_rng()
>>> arr = rng.random(7)
>>> reshape_nd(arr, 2, 0).shape
(7, 1)
>>> reshape_nd(arr, 3, 1).shape
(1, 7, 1)
>>> reshape_nd(arr, 4, -1).shape
(1, 1, 1, 7)
r   zarr must be a 1D arrayr   )r  r%   r   reshape)arrr  dim	new_shapes       r   r   r   _  s<    8 xx1}122d
IIN::c%%r   c                 <   [         R                  " U 5      n SnSn[        U[        5      (       a  U/nU R                  S:X  a  [        XB-  5      eU R                  U;  a8  [        X2SR                  U Vs/ s H  n[        U5      PM     sn5      4-  5      egs  snf )a"  
Verify an array meets the desired ndims and array isn't empty.

Parameters
----------
array : array-like
    Input array to be validated
ndim : int or iterable of ints
    Allowable ndim or ndims for the array.
arg_name : str, optional
    The name of the array in the original function.

z1The parameter `%s` must be a %s-dimensional arrayz+The parameter `%s` cannot be an empty arrayr   z-or-N)	r   
asanyarray
isinstanceintsizer%   r  r   r   )arrayr  r5   msg_incorrect_dimmsg_empty_arrayns         r   r   r     s     MM% EKCO$vzzQ566zz6;;7M1A7M+N OO
 	
 7Ms   5Bc                    U R                   [        R                  :X  a  U R                  [        R                  5      $ U(       a1  U R                   R
                  S;  a  U R                  [        5      n U $ SSKJn  U" U 5      n U $ )a  Convert input image to float image with the appropriate range.

Parameters
----------
image : ndarray
    Input image.
preserve_range : bool
    Determines if the range of the image should be kept or transformed
    using img_as_float. Also see
    https://scikit-image.org/docs/dev/user_guide/data_types.html

Notes
-----
* Input images with `float32` data type are not upcast.

Returns
-------
image : ndarray
    Transformed version of the input.

dfr   )img_as_float)	dtyper   float16r	  float32charfloat
util.dtyper+  )r  preserve_ranger+  s      r   convert_to_floatr3    sg    , {{bjj ||BJJ'' ;;4'LL'E
 L 	.U#Lr   c                     Uc  U [         :X  a  S$ S$ US:  d  US:  a  [        S5      eU [         :X  a  US:w  a  [        S5      eU$ )a?  Validate and return spline interpolation's order.

Parameters
----------
image_dtype : dtype
    Image dtype.
order : {None, int}, optional
    The order of the spline interpolation. The order has to be in the range
    0-5. If ``None`` assume order 0 for Boolean images, otherwise 1. See
    `skimage.transform.warp` for detail.

Returns
-------
order : int
    if input order is None, returns 0 if image_dtype is bool and 1
    otherwise. Otherwise, image_dtype is checked and input order
    is validated accordingly (order > 0 is not supported for bool
    image dtype)

r   r      z6Spline interpolation order has to be in the range 0-5.zInput image dtype is bool. Interpolation is not defined with bool data type. Please set order to 0 or explicitly cast input image to another data type.)boolr%   )image_dtypeorders     r   _validate_interpolation_orderr9    s[    , }4'q.Q.qyEAIQRRduz5
 	
 Lr   c                 .    [        SSSS9nX;   a  X   n U $ )z7Convert padding modes from `ndi.correlate` to `np.pad`.edge	symmetricreflect)nearestr=  mirror)dictmodemode_translation_dicts     r   _to_np_moderD    s$     YW$$*Kr   c                 ^    [        SSSSSS9nX;  a  [        SU  S35      e[        X   5      $ )	zEConvert from `numpy.pad` mode name to the corresponding ndimage mode.constantr>  r=  r?  wrap)rF  r;  r<  r=  rG  zUnknown mode: 'z', or cannot translate mode. The mode should be one of 'constant', 'edge', 'symmetric', 'reflect', or 'wrap'. See the documentation of numpy.pad for more info.)r@  r%   _fix_ndimage_moderA  s     r   _to_ndimage_moderI    sS      (dV $ 
 	
 2899r   c                 .    SSS.nUR                  X 5      $ )Nzgrid-constantz	grid-wrap)rF  rG  )r(   )rB  
grid_modess     r   rH  rH    s     .{CJ>>$%%r   gGc                 ,   [        U [        5      (       a  [        R                  " S U  5       6 $ [        R                  " U 5      n U(       d  U R
                  S:X  a  [        S5      e[        R                  U R                  [        R                  5      $ )a  Return an appropriate floating-point dtype for a given dtype.

float32, float64, complex64, complex128 are preserved.
float16 is promoted to float32.
complex256 is demoted to complex128.
Other types are cast to float64.

Parameters
----------
input_dtype : np.dtype or tuple of np.dtype
    The input dtype. If a tuple of multiple dtypes is provided, each
    dtype is first converted to a supported floating point type and the
    final dtype is then determined by applying `np.result_type` on the
    sequence of supported floating point types.
allow_complex : bool, optional
    If False, raise a ValueError on complex-valued inputs.

Returns
-------
float_type : dtype
    Floating-point dtype for the image.
c              3   8   #    U  H  n[        U5      v   M     g 7fr4   )_supported_float_type)r  ds     r   r  (_supported_float_type.<locals>.<genexpr>.  s     N+Q 5a 8 8+s   cz%complex valued input is not supported)r"  r   r   result_typer,  kindr%   new_float_typer(   r/  float64)input_dtypeallow_complexs     r   rP  rP    sm    . +u%%~~N+NOO((;'K[--4@AAk..

;;r   c                     U $ )z&Returns the first argument unmodified.rW   )r  rA   rB   s      r   r   r   5  s    Lr   c                    [         R                  " U 5      n U R                  [        :w  a2  [         R                  " U S:g  U S:g  -  5      (       a  [        U S35      e[         R                  " U [        S9$ )zReturn `array` as a numpy.ndarray of dtype bool.

Raises
------
ValueError:
    An error including the given `variable_name` if `array` can not be
    safely cast to a boolean array.
r   r   zo array is not of dtype boolean or contains values other than 0 and 1 so cannot be safely cast to boolean array.)r,  )r   r  r,  r6  anyr%   )r%  variable_names     r   as_binary_ndarrayr^  :  si     JJuE{{d665A:%1*-.. / "0 1 
 ::e4((r   r4   )gMbP?)r  )F)4rL   rF   r   r?   
contextlibr   numpyr   	_warningsr   r   __all__r   r!   r   r0   r   rY   r   r   r~   AttributeErrorr   r   r   r   r   r   r   r   r   r	   r
   r   r   r   r3  r9  rD  rI  rH  r.  r,  r/  rW  	complex64
complex128r-  rV  rP  r   r^  rW   r   r   <module>rf     s     
  %  ) $N0.b: :z#T #> r rj?D. 9" 9"x  M M`H HV&:E
=*@22 &F
6!H#L:&& JJLRZZJJLRZZLLNr||MMOJJLRZZ
<>
)r   