
    O=d:?                        d Z ddlZddlZddlZddlmZmZmZm	Z	 dZ
 ed          Zd Zd Zd"d	Zd
 Zd"dZd#dZd"dZd Zd#dZefdZdefdZd"dZefdZdefdZd Zd Zd Zd#dZd$dZd Z d Z!d Z"d Z#d Z$d"dZ%d  Z&d! Z'dS )%zD
Numerical/mathematical related functions.

.. versionadded:: 2.1.0
    N   )UNSETiteratoriterator_with_defaultiteriteratee)addceilclampdividefloormax_max_bymeanmean_bymedianmin_min_bymoving_meanmultiplypowerround_scaleslopestd_deviationsum_sum_bysubtract	transposevariancezscoreinfc                     | |z   S )a  
    Adds two numbers.

    Args:
        a (number): First number to add.
        b (number): Second number to add.

    Returns:
        number

    Example:

        >>> add(10, 5)
        15

    .. versionadded:: 2.1.0

    .. versionchanged:: 3.3.0
        Support adding two numbers when passed as positional arguments.

    .. versionchanged:: 4.0.0
        Only support two argument addition.
     )abs     :D:\Sites\api_v1\venv\Lib\site-packages\pydash/numerical.pyr   r   /   s    0 q5L    c                      t          |           S )a  
    Sum each element in `collection`.

    Args:
        collection (list|dict|number): Collection to process or first number to add.

    Returns:
        number: Result of summation.

    Example:

        >>> sum_([1, 2, 3, 4])
        10

    .. versionadded:: 2.1.0

    .. versionchanged:: 3.3.0
        Support adding two numbers when passed as positional arguments.

    .. versionchanged:: 4.0.0
        Move iteratee support to :func:`sum_by`. Move two argument addition to
        :func:`add`.
    )r   
collections    r&   r   r   J   s    0 *r'   c                 P    t          d t          | |          D                       S )a  
    Sum each element in `collection`. If iteratee is passed, each element of `collection` is passed
    through a iteratee before the summation is computed.

    Args:
        collection (list|dict|number): Collection to process or first number to add.
        iteratee (mixed|number, optional): Iteratee applied per iteration or second number to add.

    Returns:
        number: Result of summation.

    Example:

        >>> sum_by([1, 2, 3, 4], lambda x: x ** 2)
        30

    .. versionadded:: 4.0.0
    c              3   &   K   | ]}|d          V  dS r   Nr#   ).0results     r&   	<genexpr>zsum_by.<locals>.<genexpr>x   s&      JJVvayJJJJJJr'   )sumr   r*   iteratees     r&   r   r   e   s+    & JJ|J'I'IJJJJJJr'   c                      t          |           S )a  
    Calculate arithmetic mean of each element in `collection`.

    Args:
        collection (list|dict): Collection to process.

    Returns:
        float: Result of mean.

    Example:

        >>> mean([1, 2, 3, 4])
        2.5

    .. versionadded:: 2.1.0

    .. versionchanged:: 4.0.0

        - Removed ``average`` and ``avg`` aliases.
        - Moved iteratee functionality to :func:`mean_by`.
    )r   r)   s    r&   r   r   {   s    , :r'   c                 B    t          | |          t          |           z  S )a  
    Calculate arithmetic mean of each element in `collection`. If iteratee is passed, each element
    of `collection` is passed through a iteratee before the mean is computed.

    Args:
        collection (list|dict): Collection to process.
        iteratee (mixed, optional): Iteratee applied per iteration.

    Returns:
        float: Result of mean.

    Example:

        >>> mean_by([1, 2, 3, 4], lambda x: x ** 2)
        7.5

    .. versionadded:: 4.0.0
    )r   lenr2   s     r&   r   r      s    & *h''#j//99r'   c                 8    t          t          j        | |          S )a  
    Round number up to precision.

    Args:
        x (number): Number to round up.
        precision (int, optional): Rounding precision. Defaults to ``0``.

    Returns:
        int: Number rounded up.

    Example:

        >>> ceil(3.275) == 4.0
        True
        >>> ceil(3.215, 1) == 3.3
        True
        >>> ceil(6.004, 2) == 6.01
        True

    .. versionadded:: 3.3.0
    )roundermathr	   x	precisions     r&   r	   r	      s    , 49a+++r'   c                 4    ||}| }| |k     r|} n| |k    r|} | S )a  
    Clamps number within the inclusive lower and upper bounds.

    Args:
        x (number): Number to clamp.
        lower (number, optional): Lower bound.
        upper (number): Upper bound

    Returns:
        number

    Example:

        >>> clamp(-10, -5, 5)
        -5
        >>> clamp(10, -5, 5)
        5
        >>> clamp(10, 5)
        5
        >>> clamp(-10, 5)
        -10

    .. versionadded:: 4.0.0
    r#   )r;   loweruppers      r&   r
   r
      s6    2 }5yy	
UHr'   c                 :    t          | |t          j        d          S )a  
    Divide two numbers.

    Args:
        dividend (int/float): The first number in a division.
        divisor (int/float): The second number in a division.

    Returns:
        int/float: Returns the quotient.

    Example:

        >>> divide(20, 5)
        4.0
        >>> divide(1.5, 3)
        0.5
        >>> divide(None, None)
        1.0
        >>> divide(5, None)
        5.0

    .. versionadded:: 4.0.0
    r   )call_math_operatoroperatortruediv)dividenddivisors     r&   r   r      s    0 h1A1EEEr'   c                 8    t          t          j        | |          S )a  
    Round number down to precision.

    Args:
        x (number): Number to round down.
        precision (int, optional): Rounding precision. Defaults to ``0``.

    Returns:
        int: Number rounded down.

    Example:

        >>> floor(3.75) == 3.0
        True
        >>> floor(3.215, 1) == 3.2
        True
        >>> floor(0.046, 2) == 0.04
        True

    .. versionadded:: 3.3.0
    )r8   r9   r   r:   s     r&   r   r     s    , 4:q),,,r'   c                 $    t          | |          S )a  
    Retrieves the maximum value of a `collection`.

    Args:
        collection (list|dict): Collection to iterate over.
        default (mixed, optional): Value to return if `collection` is empty.

    Returns:
        mixed: Maximum value.

    Example:

        >>> max_([1, 2, 3, 4])
        4
        >>> max_([], default=-1)
        -1

    .. versionadded:: 1.0.0

    .. versionchanged:: 4.0.0
        Moved iteratee iteratee support to :func:`max_by`.
    default)r   r*   rI   s     r&   r   r         . *g....r'   c                     t          | t                    r|                                 } t          t	          | |          t          j        |                    S )a  
    Retrieves the maximum value of a `collection`.

    Args:
        collection (list|dict): Collection to iterate over.
        iteratee (mixed, optional): Iteratee applied per iteration.
        default (mixed, optional): Value to return if `collection` is empty.

    Returns:
        mixed: Maximum value.

    Example:

        >>> max_by([1.0, 1.5, 1.8], math.floor)
        1.0
        >>> max_by([{'a': 1}, {'a': 2}, {'a': 3}], 'a')
        {'a': 3}
        >>> max_by([], default=-1)
        -1

    .. versionadded:: 4.0.0
    key)
isinstancedictvaluesmaxr   pydr3   r*   r3   rI   s      r&   r   r   6  sO    . *d## )&&((
$Z99s|H?U?UVVVVr'   c                 L   t          |           }|dz   dz  }t          d t          | |          D                       } t          j        |          r| t          |dz
                     }n8t          |dz
            }t          |dz
            }| |         | |         z   dz  }|S )a  
    Calculate median of each element in `collection`. If iteratee is passed, each element of
    `collection` is passed through a iteratee before the median is computed.

    Args:
        collection (list|dict): Collection to process.
        iteratee (mixed, optional): Iteratee applied per iteration.

    Returns:
        float: Result of median.

    Example:

        >>> median([1, 2, 3, 4, 5])
        3
        >>> median([1, 2, 3, 4])
        2.5

    .. versionadded:: 2.1.0
    r      c              3   &   K   | ]}|d          V  dS r-   r#   )r.   rets     r&   r0   zmedian.<locals>.<genexpr>j  s&      MM3AMMMMMMr'   g      ?g      ?)r6   sortedr   rS   is_oddint)r*   r3   lengthmiddler/   leftrights          r&   r   r   S  s    * __FqjAFMM,z8*L*LMMMMMJ
z& <C
OO,6C<  FSL!!T"Z%66!;Mr'   c                 $    t          | |          S )a  
    Retrieves the minimum value of a `collection`.

    Args:
        collection (list|dict): Collection to iterate over.
        default (mixed, optional): Value to return if `collection` is empty.

    Returns:
        mixed: Minimum value.

    Example:

        >>> min_([1, 2, 3, 4])
        1
        >>> min_([], default=100)
        100

    .. versionadded:: 1.0.0

    .. versionchanged:: 4.0.0
        Moved iteratee iteratee support to :func:`min_by`.
    rH   )r   rJ   s     r&   r   r   v  rK   r'   c                     t          | t                    r|                                 } t          t	          | |          t          j        |                    S )a  
    Retrieves the minimum value of a `collection`.

    Args:
        collection (list|dict): Collection to iterate over.
        iteratee (mixed, optional): Iteratee applied per iteration.
        default (mixed, optional): Value to return if `collection` is empty.

    Returns:
        mixed: Minimum value.

    Example:

        >>> min_by([1.8, 1.5, 1.0], math.floor)
        1.8
        >>> min_by([{'a': 1}, {'a': 2}, {'a': 3}], 'a')
        {'a': 1}
        >>> min_by([], default=100)
        100

    .. versionadded:: 4.0.0
    rM   )rO   rP   rQ   minr   rS   r3   rT   s      r&   r   r     sO    . *d## )&&((
$Z99s|H?U?UVVVVr'   c                     g }t          |          }t          |dz
  t          |           dz             D ]D}| ||z
  |         }t          |          |k    r"|                    t	          |                     E|S )aN  
    Calculate moving mean of each element of `array`.

    Args:
        array (list): List to process.
        size (int): Window size.

    Returns:
        list: Result of moving average.

    Example:

        >>> moving_mean(range(10), 1)
        [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
        >>> moving_mean(range(10), 5)
        [2.0, 3.0, 4.0, 5.0, 6.0, 7.0]
        >>> moving_mean(range(10), 10)
        [4.5]

    .. versionadded:: 2.1.0

    .. versionchanged:: 4.0.0
        Rename to ``moving_mean`` and remove ``moving_average`` and ``moving_avg`` aliases.
    r   )r[   ranger6   appendr   )arraysizer/   iwindows        r&   r   r     s|    2 Ft99D4!8SZZ!^,, ( (q4x!|$v;;$MM$v,,'''Mr'   c                 :    t          | |t          j        d          S )a  
    Multiply two numbers.

    Args:
        multiplier (int/float): The first number in a multiplication.
        multiplicand (int/float): The second number in a multiplication.

    Returns:
        int/float: Returns the product.

    Example:

        >>> multiply(4, 5)
        20
        >>> multiply(10, 4)
        40
        >>> multiply(None, 10)
        10
        >>> multiply(None, None)
        1

    .. versionadded:: 4.0.0
    r   )rA   rB   mul)
multipliermultiplicands     r&   r   r     s    0 j,aHHHr'   c                     t          j        |           rt          |           }n%t          j        |           rfd| D             }nd}|S )a{  
    Calculate exponentiation of `x` raised to the `n` power.

    Args:
        x (number): Base number.
        n (number): Exponent.

    Returns:
        number: Result of calculation.

    Example:

        >>> power(5, 2)
        25
        >>> power(12.5, 3)
        1953.125

    .. versionadded:: 2.1.0

    .. versionchanged:: 4.0.0
        Removed alias ``pow_``.
    c                 0    g | ]}t          |          S r#   )pow)r.   itemns     r&   
<listcomp>zpower.<locals>.<listcomp>  s!    ---4#dA,,---r'   N)rS   	is_numberrp   is_list)r;   rr   r/   s    ` r&   r   r     s[    . }Q Q	Q ----1---Mr'   c                 .    t          t          | |          S )a  
    Round number to precision.

    Args:
        x (number): Number to round.
        precision (int, optional): Rounding precision. Defaults to ``0``.

    Returns:
        int: Rounded number.

    Example:

        >>> round_(3.275) == 3.0
        True
        >>> round_(3.275, 1) == 3.3
        True

    .. versionadded:: 2.1.0

    .. versionchanged:: 4.0.0
        Remove alias ``curve``.
    )r8   roundr:   s     r&   r   r     s    . 5!Y'''r'   c                 H    t          |           }||z  fd| D             S )a  
    Scale list of value to a maximum number.

    Args:
        array (list): Numbers to scale.
        maximum (number): Maximum scale value.

    Returns:
        list: Scaled numbers.

    Example:

        >>> scale([1, 2, 3, 4])
        [0.25, 0.5, 0.75, 1.0]
        >>> scale([1, 2, 3, 4], 1)
        [0.25, 0.5, 0.75, 1.0]
        >>> scale([1, 2, 3, 4], 4)
        [1.0, 2.0, 3.0, 4.0]
        >>> scale([1, 2, 3, 4], 2)
        [0.5, 1.0, 1.5, 2.0]

    .. versionadded:: 2.1.0
    c                     g | ]}|z  S r#   r#   )r.   rq   factors     r&   rs   zscale.<locals>.<listcomp>A  s    ,,,dD6M,,,r'   )rR   )rf   maximum	array_maxrz   s      @r&   r   r   '  s4    0 E

Iy F,,,,e,,,,r'   c                 x    | d         | d         }}|d         |d         }}||k    rt           }n||z
  ||z
  z  }|S )aI  
    Calculate the slope between two points.

    Args:
        point1 (list|tuple): X and Y coordinates of first point.
        point2 (list|tuple): X and Y cooredinates of second point.

    Returns:
        float: Calculated slope.

    Example:

        >>> slope((1, 2), (4, 8))
        2.0

    .. versionadded:: 2.1.0
    r   r   )INFINITY)point1point2x1y1x2y2r/   s          r&   r   r   D  sM    $ AYq	BAYq	B	Rxxr'b2g&Mr'   c                 D    t          j        t          |                     S )a\  
    Calculate standard deviation of list of numbers.

    Args:
        array (list): List to process.

    Returns:
        float: Calculated standard deviation.

    Example:

        >>> round(std_deviation([1, 18, 20, 4]), 2) == 8.35
        True

    .. versionadded:: 2.1.0

    .. versionchanged:: 4.0.0
        Remove alias ``sigma``.
    )r9   sqrtr   )rf   s    r&   r   r   a  s    ( 9Xe__%%%r'   c                 :    t          | |t          j        d          S )a  
    Subtracts two numbers.

    Args:
        minuend (int/float): Value passed in by the user.
        subtrahend (int/float): Value passed in by the user.

    Returns:
        int/float: Result of the difference from the given values.

    Example:

        >>> subtract(10, 5)
        5
        >>> subtract(-10, 4)
        -14
        >>> subtract(2, 0.5)
        1.5

    .. versionadded:: 4.0.0
    r   )rA   rB   sub)minuend
subtrahends     r&   r   r   x  s    , gz8<CCCr'   c                     g }t          |           D ]2\  }}t          |          D ]\  }}t          j        |||g|          }3|S )a  
    Transpose the elements of `array`.

    Args:
        array (list): List to process.

    Returns:
        list: Transposed list.

    Example:

        >>> transpose([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
        [[1, 4, 7], [2, 5, 8], [3, 6, 9]]

    .. versionadded:: 2.1.0
    )r   rS   set_)rf   transyrowr;   cols         r&   r   r     s`    " E5// 1 13smm 	1 	1FAsHUQFC00EE	1 Lr'   c                     t          |           fd}t          j        |                               |                                                                           S )a  
    Calculate the variance of the elements in `array`.

    Args:
        array (list): List to process.

    Returns:
        float: Calculated variance.

    Example:

        >>> variance([1, 18, 20, 4])
        69.6875

    .. versionadded:: 2.1.0
    c                 *    t          | z
  d          S )NrV   )r   )r;   avgs    r&   varzvariance.<locals>.var  s    QWa   r'   )r   rS   _map_value)rf   r   r   s     @r&   r   r     s_    " u++C! ! ! ! ! 5<<S!!&&((..000r'   c                     t          j        | |          }t          |          t          |          fd|D             S )a
  
    Calculate the standard score assuming normal distribution. If iteratee is passed, each element
    of `collection` is passed through a iteratee before the standard score is computed.

    Args:
        collection (list|dict): Collection to process.
        iteratee (mixed, optional): Iteratee applied per iteration.

    Returns:
        float: Calculated standard score.

    Example:

        >>> results = zscore([1, 2, 3])

        # [-1.224744871391589, 0.0, 1.224744871391589]

    .. versionadded:: 2.1.0
    c                      g | ]
}|z
  z  S r#   r#   )r.   rq   r   sigs     r&   rs   zzscore.<locals>.<listcomp>  s"    1114TCZ3111r'   )rS   r   r   r   )r*   r3   rf   r   r   s      @@r&   r    r      sL    ( HZ**E
u++C


C1111151111r'   c                     | s|} |s|}t          j        |           s!	 t          |           } n# t          $ r Y nw xY wt          j        |          s!	 t          |          }n# t          $ r Y nw xY w || |          S )z<Return the result of the math operation on the given values.)rS   rt   float	Exception)value1value2oprI   s       r&   rA   rA     s      =   	6]]FF 	 	 	D	 =   	6]]FF 	 	 	D	 2ffs   . 
;;A# #
A0/A0c                      t          d           fdd }t          j        |          r |          }n4t          j        |          r 	 fd|D             }n# t          $ r Y nw xY w|S )N
   c                 &     | z            z  S Nr#   )rq   funcr<   s    r&   rounder_funczrounder.<locals>.rounder_func  s    tD9$%%	11r'   c                 &    g | ]} |          S r#   r#   )r.   rq   r   s     r&   rs   zrounder.<locals>.<listcomp>  s#    777Tll4((777r'   )rp   rS   rt   is_iterable	TypeError)r   r;   r<   r/   r   s   ` ` @r&   r8   r8     s    B	""I2 2 2 2 2 2 F
}Q a			 	7777Q777FF 	 	 	D	 Ms   A   
A-,A-r   )r   )r   )(__doc__r9   rB   pydashrS   helpersr   r   r   r   __all__r   r~   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    rA   r8   r#   r'   r&   <module>r      s{          I I I I I I I I I I I I: 5<<  6  6K K K K,  2: : : :,, , , ,2" " " "JF F F6- - - -2 # / / / /4 !%e W W W W:       F # / / / /4 !%e W W W W8" " "JI I I6  B( ( ( (4- - - -:  :& & &.D D D2  41 1 122 2 2 2@  .    r'   