
    wg                     :    d Z ddlmZ d Zd Zd Z G d d      Zy)	zx
Provides functionality for multidimensional usage of scalar-functions.

Read the vectorize docstring for more details.
    wrapsc                      t        t              r   }dnt        t              r   }d fdt        t	                    S )z
    Returns a structure with the same dimension as the specified argument,
    where each basic element is replaced by the function f applied on it. All
    other arguments stay the same.
    TFc                 p    t        | d      rt        t        |             S r| <   n| <    i S )N__iter__)hasattrlistmap)xargsf	f_reducedis_argkwargsns    `/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/core/multidimensional.pyr   z#apply_on_element.<locals>.f_reduced   sD    1j!Iq)**Qq	d%f%%    )
isinstanceintstrr	   r
   )r   r   r   r   	structurer   r   s   ```` @@r   apply_on_elementr   
   sS     !SG		As	1I	& & Iy)**r   c                 Z    | D cg c]  }t        |d      rt        |      n| c}S c c}w )zU
    Returns a copy of an iterable object (also copying all embedded iterables).
    r   )r   	iter_copy)r   is     r   r   r   (   s,     DMMaGAz2IaL9MMMs    (c                 P    t        | d      r| j                         S t        |       S )zR
    Returns a copy of the given structure (numpy-array, list, iterable, ..).
    copy)r   r   r   )r   s    r   structure_copyr   /   s&     y&!~~Yr   c                       e Zd ZdZd Zd Zy)	vectorizea  
    Generalizes a function taking scalars to accept multidimensional arguments.

    Examples
    ========

    >>> from sympy import vectorize, diff, sin, symbols, Function
    >>> x, y, z = symbols('x y z')
    >>> f, g, h = list(map(Function, 'fgh'))

    >>> @vectorize(0)
    ... def vsin(x):
    ...     return sin(x)

    >>> vsin([1, x, y])
    [sin(1), sin(x), sin(y)]

    >>> @vectorize(0, 1)
    ... def vdiff(f, y):
    ...     return diff(f, y)

    >>> vdiff([f(x, y, z), g(x, y, z), h(x, y, z)], [x, y, z])
    [[Derivative(f(x, y, z), x), Derivative(f(x, y, z), y), Derivative(f(x, y, z), z)], [Derivative(g(x, y, z), x), Derivative(g(x, y, z), y), Derivative(g(x, y, z), z)], [Derivative(h(x, y, z), x), Derivative(h(x, y, z), y), Derivative(h(x, y, z), z)]]
    c                 b    |D ]#  }t        |t        t        f      rt        d       || _        y)a  
        The given numbers and strings characterize the arguments that will be
        treated as data structures, where the decorated function will be applied
        to every single element.
        If no argument is given, everything is treated multidimensional.
        za is of invalid typeN)r   r   r   	TypeErrormdargs)selfr#   as      r   __init__zvectorize.__init__Q   s6      	8Aa#s, 677	8 r   c                 6     t               fd       S )zx
        Returns a wrapper for the one-dimensional function that can handle
        multidimensional arguments.
        c                     	j                   r	j                   }n%t        t        |             |j                         z   }t        |       }|D ]  }t	        |t
              r||k\  r| |   }d}nt	        |t              r	 ||   }d}t        d      sFrt        |       } t        |      | |<   nt        |      ||<   t        
| ||      }|c S   | i |S # t        $ r Y w xY w)NTFr   )r#   rangelenkeysr   r   r   KeyErrorr   r	   r   r   )r   r   r#   	arglengthr   entryr   resultr   r$   wrappers           r   r0   z#vectorize.__call__.<locals>.wrapperb   s     {{s4y)FKKM9D	I "a%I~  GE!F3'! &q	 #F5*- #Dz"0"7Q$25$9q	-gtVQGF!M+", d%f%% $ ! !s   ?C	C$#C$r   )r$   r   r0   s   ``@r   __call__zvectorize.__call__]   s#    
 
q	& 
	&@ r   N)__name__
__module____qualname____doc__r&   r1    r   r   r    r    8   s    0
&r   r    N)r5   	functoolsr   r   r   r   r    r6   r   r   <module>r8      s+    +<N K Kr   