• File: arraypad.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib64/python3.7/site-packages/numpy/lib/__pycache__/arraypad.cpython-37.pyc
  • Date Modified: 04/24/2023 7:10 PM
  • File size: 40.54 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

<FdD@sdZddlmZmZmZddlZdgZd3ddZdd	Z	d4ddZ
d5d
dZd6ddZd7ddZ
d8ddZd9ddZd:ddZd;ddZd<ddZd=ddZd>dd Zd?d!d"Zd@d#d$ZdAd%d&ZdBd'd(ZdCd)d*ZdDd+d,ZdEd.d/Zd0d1Zd2dZdS)Fzl
The arraypad module contains a group of functions to pad values onto the edges
of an n-dimensional array.

)divisionabsolute_importprint_functionNpadFcstfddt|jD}|s8tdd}ntdd}||}x0tD]$\}}|j||kr^|j||d}q^W|S)a
    Create an ndarray of `shape` with increments along specified `axis`

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    shape : tuple of ints
        Shape of desired array. Should be equivalent to `arr.shape` except
        `shape[axis]` which may have any positive value.
    axis : int
        Axis to increment along.
    reverse : bool
        If False, increment in a positive fashion from 1 to `shape[axis]`,
        inclusive. If True, the bounds are the same but the order reversed.

    Returns
    -------
    padarr : ndarray
        Output array sized to pad `arr` along `axis`, with linear range from
        1 to `shape[axis]` along specified `axis`.

    Notes
    -----
    The range is deliberately 1-indexed for this specific use case. Think of
    this algorithm as broadcasting `np.arange` to a single `axis` of an
    arbitrarily shaped ndarray.

    c3s&|]\}}|krdnVqdS)N).0ix)axisshaperE/opt/alt/python37/lib64/python3.7/site-packages/numpy/lib/arraypad.py	<genexpr>0sz"_arange_ndarray.<locals>.<genexpr>rr)r)tuple	enumeraternpZarangereshaperepeat)arrrrreverseZ	initshapeZpadarrr	Zdimr)rrr
_arange_ndarrays
rcCst|tjr|j|ddS)z
    Rounds arr inplace if destination dtype is integer.

    Parameters
    ----------
    arr : ndarray
        Input array.
    dtype : dtype
        The dtype of the destination array.

    )outN)rZ
issubdtypeZintegerround)rdtyperrr
_round_ifneeded=srrcsxdkr|Stfddt|jD}|dkrPtjtj||jd|fdStjt|||j|fdSdS)a
    Prepend constant `val` along `axis` of `arr`.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : int
        Amount of padding to prepend.
    val : scalar
        Constant value to use. For best results should be of type `arr.dtype`;
        if not `arr.dtype` will be cast to `arr.dtype`.
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, with `pad_amt` constant `val` prepended along `axis`.

    rc3s"|]\}}|kr|nVqdS)Nr)rr	r
)rpad_amtrr
resz!_prepend_const.<locals>.<genexpr>)r)rN)rrrrconcatenatezerosrastype)rrvalrpadshaper)rrr
_prepend_constMsr"csxdkr|Stfddt|jD}|dkrPtj|tj||jdfdStj|t|||jfdSdS)a
    Append constant `val` along `axis` of `arr`.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : int
        Amount of padding to append.
    val : scalar
        Constant value to use. For best results should be of type `arr.dtype`;
        if not `arr.dtype` will be cast to `arr.dtype`.
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, with `pad_amt` constant `val` appended along `axis`.

    rc3s"|]\}}|kr|nVqdS)Nr)rr	r
)rrrr
rsz _append_const.<locals>.<genexpr>)r)rN)rrrrrrrr)rrr rr!r)rrr

_append_constosr#csn|dkr|Stfddt|jD}tfddt|jD}|||}tj|j|d|fdS)a
    Prepend `pad_amt` to `arr` along `axis` by extending edge values.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : int
        Amount of padding to prepend.
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, extended by `pad_amt` edge values appended along `axis`.

    rc3s&|]\}}|krtdndVqdS)Nr)slice)rr	r
)rrr
rsz _prepend_edge.<locals>.<genexpr>c3s"|]\}}|kr|ndVqdS)rNr)rr	r
)rrr
rs)r)rrrrrrr)rrr
edge_slice
pad_singletonedge_arrr)rr

_prepend_edgesr(csp|dkrStfddtjD}tfddtjD}||}tj|j|dfdS)a
    Append `pad_amt` to `arr` along `axis` by extending edge values.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : int
        Amount of padding to append.
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, extended by `pad_amt` edge values prepended along
        `axis`.

    rc3s0|](\}}|krtdnjdVqdS)Nr)r$r)rr	r
)rrrr
rsz_append_edge.<locals>.<genexpr>c3s"|]\}}|kr|ndVqdS)rNr)rr	r
)rrr
rs)r)rrrrrrr)rrrr%r&r'r)rrr
_append_edgesr)c
sdkr|Stfddt|jD}t||ddtj}tfddt|jD}tfddt|jD}|||}||t	}	||	}||7}t
||jtj||j|fdS)	aF
    Prepend linear ramp along `axis`.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : int
        Amount of padding to prepend.
    end : scalar
        Constal value to use. For best results should be of type `arr.dtype`;
        if not `arr.dtype` will be cast to `arr.dtype`.
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, with `pad_amt` values prepended along `axis`. The
        prepended region ramps linearly from the edge value to `end`.

    rc3s"|]\}}|kr|nVqdS)Nr)rr	r
)rrrr
rsz _prepend_ramp.<locals>.<genexpr>T)rc3s&|]\}}|krtdndVqdS)Nr)r$)rr	r
)rrr
rsc3s"|]\}}|kr|ndVqdS)rNr)rr	r
)rrr
rs)r)
rrrrrrfloat64rrfloatrrr)
rrendrr!ramp_arrr%r&edge_padsloper)rrr

_prepend_ramps r0c
sdkr|Stfddt|jD}t||ddtj}tfddt|jD}tfddt|jD}|||}||t	}	||	}||7}t
||jtj|||jfdS)	aB
    Append linear ramp along `axis`.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : int
        Amount of padding to append.
    end : scalar
        Constal value to use. For best results should be of type `arr.dtype`;
        if not `arr.dtype` will be cast to `arr.dtype`.
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, with `pad_amt` values appended along `axis`. The
        appended region ramps linearly from the edge value to `end`.

    rc3s"|]\}}|kr|nVqdS)Nr)rr	r
)rrrr
r&sz_append_ramp.<locals>.<genexpr>F)rc3s&|]\}}|krtdndVqdS)Nr)r$)rr	r
)rrr
r.sc3s"|]\}}|kr|ndVqdS)rNr)rr	r
)rrr
r2s)r)
rrrrrrr*rrr+rrr)
rrr,rr!r-r%r&r.r/r)rrr
_append_ramps r1cs|dkr|Sdkr t||Sdk	r:|jkr:dtfddt|jD}tfddt|jD}||jd|}tj|j|d|fdS)aS
    Prepend `pad_amt` maximum values along `axis`.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : int
        Amount of padding to prepend.
    num : int
        Depth into `arr` along `axis` to calculate maximum.
        Range: [1, `arr.shape[axis]`] or None (entire axis)
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, with `pad_amt` values appended along `axis`. The
        prepended region is the maximum of the first `num` values along
        `axis`.

    rrNc3s*|]"\}}|krtdntVqdS)N)r$)rr	r
)rnumrr
rgsz_prepend_max.<locals>.<genexpr>c3s"|]\}}|kr|ndVqdS)rNr)rr	r
)rrr
rks)r)	r(rrrmaxrrrr)rrr2r	max_slicer&	max_chunkr)rr2r
_prepend_maxBsr6cs|dkr|Sdkr t||Sdk	r:|jkr:d|jddk	rrtfddt|jD}ntdd|jD}tfddt|jD}||jd|}tj||j|dfdS)	a_
    Pad one `axis` of `arr` with the maximum of the last `num` elements.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : int
        Amount of padding to append.
    num : int
        Depth into `arr` along `axis` to calculate maximum.
        Range: [1, `arr.shape[axis]`] or None (entire axis)
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, with `pad_amt` values appended along `axis`. The
        appended region is the maximum of the final `num` values along `axis`.

    rrNc3s2|]*\}}|krtdntdVqdS)Nr)r$)rr	r
)rr,r2rr
rsz_append_max.<locals>.<genexpr>css|]}tdVqdS)N)r$)rr
rrr
rsc3s"|]\}}|kr|ndVqdS)rNr)rr	r
)rrr
rs)r)	r)rrrr3rrrr)rrr2rr4r&r5r)rr,r2r
_append_maxvs$r7cs|dkr|Sdkr t||Sdk	r:|jkr:dtfddt|jD}tfddt|jD}|||}t||jtj	|
||j|fdS)aC
    Prepend `pad_amt` mean values along `axis`.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : int
        Amount of padding to prepend.
    num : int
        Depth into `arr` along `axis` to calculate mean.
        Range: [1, `arr.shape[axis]`] or None (entire axis)
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, with `pad_amt` values prepended along `axis`. The
        prepended region is the mean of the first `num` values along `axis`.

    rrNc3s*|]"\}}|krtdntVqdS)N)r$)rr	r
)rr2rr
rsz _prepend_mean.<locals>.<genexpr>c3s"|]\}}|kr|ndVqdS)rNr)rr	r
)rrr
rs)r)r(rrrmeanrrrrrrr)rrr2r
mean_slicer&
mean_chunkr)rr2r

_prepend_meansr;cs|dkr|Sdkr t||Sdk	r:|jkr:d|jddk	rrtfddt|jD}ntdd|jD}tfddt|jD}||jd|}t||jtj	||
||jfdS)	aB
    Append `pad_amt` mean values along `axis`.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : int
        Amount of padding to append.
    num : int
        Depth into `arr` along `axis` to calculate mean.
        Range: [1, `arr.shape[axis]`] or None (entire axis)
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, with `pad_amt` values appended along `axis`. The
        appended region is the maximum of the final `num` values along `axis`.

    rrNc3s2|]*\}}|krtdntdVqdS)Nr)r$)rr	r
)rr,r2rr
r	sz_append_mean.<locals>.<genexpr>css|]}tdVqdS)N)r$)rr
rrr
rsc3s"|]\}}|kr|ndVqdS)rNr)rr	r
)rrr
rs)r)r)rrrr8rrrrrrr)rrr2rr9r&r:r)rr,r2r
_append_means&r<cs|dkr|Sdkr t||Sdk	r:|jkr:dtfddt|jD}tfddt|jD}tj||d|}t||jtj	|
||j|fdS)aI
    Prepend `pad_amt` median values along `axis`.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : int
        Amount of padding to prepend.
    num : int
        Depth into `arr` along `axis` to calculate median.
        Range: [1, `arr.shape[axis]`] or None (entire axis)
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, with `pad_amt` values prepended along `axis`. The
        prepended region is the median of the first `num` values along `axis`.

    rrNc3s*|]"\}}|krtdntVqdS)N)r$)rr	r
)rr2rr
r?sz_prepend_med.<locals>.<genexpr>c3s"|]\}}|kr|ndVqdS)rNr)rr	r
)rrr
rCs)r)r(rrrrmedianrrrrrr)rrr2r	med_slicer&	med_chunkr)rr2r
_prepend_medsr@cs|dkr|Sdkr t||Sdk	r:|jkr:d|jddk	rrtfddt|jD}ntdd|jD}tfddt|jD}tj||d|}t||jtj	||
||jfdS)	aE
    Append `pad_amt` median values along `axis`.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : int
        Amount of padding to append.
    num : int
        Depth into `arr` along `axis` to calculate median.
        Range: [1, `arr.shape[axis]`] or None (entire axis)
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, with `pad_amt` values appended along `axis`. The
        appended region is the median of the final `num` values along `axis`.

    rrNc3s2|]*\}}|krtdntdVqdS)Nr)r$)rr	r
)rr,r2rr
rvsz_append_med.<locals>.<genexpr>css|]}tdVqdS)N)r$)rr
rrr
rysc3s"|]\}}|kr|ndVqdS)rNr)rr	r
)rrr
r|s)r)r)rrrrr=rrrrrr)rrr2rr>r&r?r)rr,r2r
_append_medOs&rAcs|dkr|Sdkr t||Sdk	r:|jkr:dtfddt|jD}tfddt|jD}||jd|}tj|j|d|fdS)aT
    Prepend `pad_amt` minimum values along `axis`.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : int
        Amount of padding to prepend.
    num : int
        Depth into `arr` along `axis` to calculate minimum.
        Range: [1, `arr.shape[axis]`] or None (entire axis)
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, with `pad_amt` values prepended along `axis`. The
        prepended region is the minimum of the first `num` values along
        `axis`.

    rrNc3s*|]"\}}|krtdntVqdS)N)r$)rr	r
)rr2rr
rsz_prepend_min.<locals>.<genexpr>c3s"|]\}}|kr|ndVqdS)rNr)rr	r
)rrr
rs)r)	r(rrrminrrrr)rrr2r	min_slicer&	min_chunkr)rr2r
_prepend_minsrEcs|dkr|Sdkr t||Sdk	r:|jkr:d|jddk	rrtfddt|jD}ntdd|jD}tfddt|jD}||jd|}tj||j|dfdS)	aG
    Append `pad_amt` median values along `axis`.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : int
        Amount of padding to append.
    num : int
        Depth into `arr` along `axis` to calculate minimum.
        Range: [1, `arr.shape[axis]`] or None (entire axis)
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, with `pad_amt` values appended along `axis`. The
        appended region is the minimum of the final `num` values along `axis`.

    rrNc3s2|]*\}}|krtdntdVqdS)Nr)r$)rr	r
)rr,r2rr
rsz_append_min.<locals>.<genexpr>css|]}tdVqdS)N)r$)rr
rrr
rsc3s"|]\}}|kr|ndVqdS)rNr)rr	r
)rrr
rs)r)	r)rrrrBrrrr)rrr2rrCr&rDr)rr,r2r
_append_mins$rFcsddkrddkr|Stfddt|jD}||}tfddt|jD}ddkrt||}d|krddkrtfddt|jD}|||}d||}~|jdd|jdtfd	dt|jD}tfd
dt|jD}	|||	}
ddkrD|
|}
d|krtfddt|jD}|||}d||
}
~tj|||
fdS)
a
    Pad `axis` of `arr` by reflection.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : tuple of ints, length 2
        Padding to (prepend, append) along `axis`.
    method : str
        Controls method of reflection; options are 'even' or 'odd'.
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, with `pad_amt[0]` values prepended and `pad_amt[1]`
        values appended along `axis`. Both regions are padded with reflected
        values from the original array.

    Notes
    -----
    This algorithm does not pad with repetition, i.e. the edges are not
    repeated in the reflection. For that behavior, use `mode='symmetric'`.

    The modes 'reflect', 'symmetric', and 'wrap' must be padded with a
    single function, lest the indexing tricks in non-integer multiples of the
    original shape would violate repetition in the final iteration.

    rrc3s2|]*\}}|krtdntdddVqdS)Nrr)r$)rr	r
)rrrr
rsz_pad_ref.<locals>.<genexpr>c3s"|]\}}|kr|ndVqdS)rNr)rr	r
)rrr
r"soddc3s&|]\}}|krtdndVqdS)Nr)r$)rr	r
)rrr
r)sc3s,|]$\}}|krtdntVqdS)N)r$)rr	r
)rr,startrr
r5sc3s.|]&\}}|krtdn
tdddVqdS)Nr)r$)rr	r
)rrr
r7sc3s&|]\}}|krtdndVqdS)Nr)r$)rr	r
)rrr
r?s)r)rrrrrr)rrmethodrZ	ref_sliceZ
ref_chunk1r&edge_slice1
edge_chunkrev_idxZ
ref_chunk2edge_slice2r)rr,rrIr
_pad_refs>!


rOcsddkrddkr|Stfddt|jD}tfddt|jD}|||}tfddt|jD}ddkr||}d|krddkrtfddt|jD}|||}	d	|	|}~	|jd|jtfd
dt|jD}|||}
ddkr@|
|}
d|krtfddt|jD}|||}	d	|	|
}
~	tj|||
fdS)
a
    Pad `axis` of `arr` by symmetry.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : tuple of ints, length 2
        Padding to (prepend, append) along `axis`.
    method : str
        Controls method of symmetry; options are 'even' or 'odd'.
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, with `pad_amt[0]` values prepended and `pad_amt[1]`
        values appended along `axis`. Both regions are padded with symmetric
        values from the original array.

    Notes
    -----
    This algorithm DOES pad with repetition, i.e. the edges are repeated.
    For padding without repeated edges, use `mode='reflect'`.

    The modes 'reflect', 'symmetric', and 'wrap' must be padded with a
    single function, lest the indexing tricks in non-integer multiples of the
    original shape would violate repetition in the final iteration.

    rrc3s0|](\}}|krtdntddVqdS)Nr)r$)rr	r
)rrrr
rqsz_pad_sym.<locals>.<genexpr>c3s.|]&\}}|krtdn
tdddVqdS)Nr)r$)rr	r
)rrr
rssc3s"|]\}}|kr|ndVqdS)rNr)rr	r
)rrr
rxsrGc3s&|]\}}|krtdndVqdS)Nr)r$)rr	r
)rrr
rsrHc3s,|]$\}}|krtdntVqdS)N)r$)rr	r
)rr,rIrr
rsc3s&|]\}}|krtdndVqdS)Nr)r$)rr	r
)rrr
rs)r)rrrrrr)rrrJrZ	sym_slicerMZ
sym_chunk1r&rKrLZ
sym_chunk2rNr)rr,rrIr
_pad_symIs>!



rPcsddkrddkr|S|jd|jtfddt|jD}||}tfddt|jD}ddkr||}tfddt|jD}||}ddkr||}tj|||fdS)a1
    Pad `axis` of `arr` via wrapping.

    Parameters
    ----------
    arr : ndarray
        Input array of arbitrary shape.
    pad_amt : tuple of ints, length 2
        Padding to (prepend, append) along `axis`.
    axis : int
        Axis along which to pad `arr`.

    Returns
    -------
    padarr : ndarray
        Output array, with `pad_amt[0]` values prepended and `pad_amt[1]`
        values appended along `axis`. Both regions are padded wrapped values
        from the opposite end of `axis`.

    Notes
    -----
    This method of padding is also known as 'tile' or 'tiling'.

    The modes 'reflect', 'symmetric', and 'wrap' must be padded with a
    single function, lest the indexing tricks in non-integer multiples of the
    original shape would violate repetition in the final iteration.

    rrc3s,|]$\}}|krtdntVqdS)N)r$)rr	r
)rr,rIrr
rsz_pad_wrap.<locals>.<genexpr>c3s"|]\}}|kr|ndVqdS)rNr)rr	r
)rrr
rsc3s0|](\}}|krtdntddVqdS)Nrr)r$)rr	r
)rrrr
rs)r)rrrrrr)rrrZ
wrap_sliceZwrap_chunk1r&Zwrap_chunk2r)rr,rrIr
	_pad_wraps"


rQTcCs|j}|dkrd|St|}yt||df}Wn&tk
rZd}t||fYnX|dkrtt|t}tdd|	DS)aZ
    Private function which does some checks and normalizes the possibly
    much simpler representations of 'pad_width', 'stat_length',
    'constant_values', 'end_values'.

    Parameters
    ----------
    narray : ndarray
        Input ndarray
    shape : {sequence, array_like, float, int}, optional
        The width of padding (pad_width), the number of elements on the
        edge of the narray used for statistics (stat_length), the constant
        value(s) to use when filling padded regions (constant_values), or the
        endpoint target(s) for linear ramps (end_values).
        ((before_1, after_1), ... (before_N, after_N)) unique number of
        elements for each axis where `N` is rank of `narray`.
        ((before, after),) yields same before and after constants for each
        axis.
        (constant,) or val is a shortcut for before = after = constant for
        all axes.
    cast_to_int : bool, optional
        Controls if values in ``shape`` will be rounded and cast to int
        before being returned.

    Returns
    -------
    normalized_shape : tuple of tuples
        val                               => ((val, val), (val, val), ...)
        [[val1, val2], [val3, val4], ...] => ((val1, val2), (val3, val4), ...)
        ((val1, val2), (val3, val4), ...) => no change
        [[val1, val2], ]                  => ((val1, val2), (val1, val2), ...)
        ((val1, val2), )                  => ((val1, val2), (val1, val2), ...)
        [[val ,     ], ]                  => ((val, val), (val, val), ...)
        ((val ,     ), )                  => ((val, val), (val, val), ...)

    N))NNrHz/Unable to create correctly shaped tuple from %sTcss|]}t|VqdS)N)r)rrrrr
rsz#_normalize_shape.<locals>.<genexpr>)
ndimrasarrayZbroadcast_to
ValueErrorrrintrtolist)Zndarrayrcast_to_intZndimsZ	shape_arrfmtrrr
_normalize_shapes%
rYcCsbt||}xR|D]J}dd|D}dd|D}|ddksH|ddkrd}t||fqW|S)a
    Private function which does some checks and reformats pad_width and
    stat_length using _normalize_shape.

    Parameters
    ----------
    narray : ndarray
        Input ndarray
    number_elements : {sequence, int}, optional
        The width of padding (pad_width) or the number of elements on the edge
        of the narray used for statistics (stat_length).
        ((before_1, after_1), ... (before_N, after_N)) unique number of
        elements for each axis.
        ((before, after),) yields same before and after constants for each
        axis.
        (constant,) or int is a shortcut for before = after = constant for all
        axes.

    Returns
    -------
    _validate_lengths : tuple of tuples
        int                               => ((int, int), (int, int), ...)
        [[int1, int2], [int3, int4], ...] => ((int1, int2), (int3, int4), ...)
        ((int1, int2), (int3, int4), ...) => no change
        [[int1, int2], ]                  => ((int1, int2), (int1, int2), ...)
        ((int1, int2), )                  => ((int1, int2), (int1, int2), ...)
        [[int ,     ], ]                  => ((int, int), (int, int), ...)
        ((int ,     ), )                  => ((int, int), (int, int), ...)

    cSsg|]}|dkrdn|qS)Nrr)rr
rrr

<listcomp>:sz%_validate_lengths.<locals>.<listcomp>cSsg|]}|dkrdndqS)rrrr)rr
rrr
rZ;srrz"%s cannot contain negative values.)rYrT)narrayZnumber_elementsZnormshpr	ZchkrXrrr
_validate_lengthss

r\cstjjdkstdt|tdggdgdgdgdgdgdgdggd
}dd	d	d
d}t|tjj	rx,|D]$}|||kr|t
d|||fq|Wx ||D]}||||qWx|D]<}|dkrt||||<|d
krt||dd||<qWn|}	t
tj}
fdd|
D}fdd|
D}tj|}
t|
j}||<x&|
D]}t|	|||||qrW|S}|dkrxHtt|dD]2\}\\}}\}}t||||}t||||}qWn|dkr:x2tD]&\}\}}t|||}t|||}qWnX|dkrxHtt|dD]2\}\\}}\}}t||||}t||||}qXWn|dkrxHtt|dD]2\}\\}}\}}t||||}t||||}qWn|dkrBxHtt|dD]2\}\\}}\}}t||||}t||||}qWnP|dkrxHtt|dD]2\}\\}}\}}t ||||}t!||||}q`Wn|dkrxHtt|dD]2\}\\}}\}}t"||||}t#||||}qWn|dkr,xtD]\}\}}j|d	krL|d	ks:|d	krt
d$|q|d	ks`|d	kr|j|dkrt|||}t|||}q|d}|j|d}xl||ks||krt%||||}t%||||}t&|||f||}||8}||8}|||7}qWt&|||f||}qWnf|dkrxtD]\}\}}|d}|j|}xl||kst||krt%||||}t%||||}t'|||f||}||8}||8}|||7}q`Wt'|||f||}q@Wn|dkrxtD]\}\}}|j|}xj||ks&||krzt%||||}t%||||}t(|||f|}||8}||8}|||7}qWt(|||f|}qW|S)a
    Pads an array.

    Parameters
    ----------
    array : array_like of rank N
        Input array
    pad_width : {sequence, array_like, int}
        Number of values padded to the edges of each axis.
        ((before_1, after_1), ... (before_N, after_N)) unique pad widths
        for each axis.
        ((before, after),) yields same before and after pad for each axis.
        (pad,) or int is a shortcut for before = after = pad width for all
        axes.
    mode : str or function
        One of the following string values or a user supplied function.

        'constant'
            Pads with a constant value.
        'edge'
            Pads with the edge values of array.
        'linear_ramp'
            Pads with the linear ramp between end_value and the
            array edge value.
        'maximum'
            Pads with the maximum value of all or part of the
            vector along each axis.
        'mean'
            Pads with the mean value of all or part of the
            vector along each axis.
        'median'
            Pads with the median value of all or part of the
            vector along each axis.
        'minimum'
            Pads with the minimum value of all or part of the
            vector along each axis.
        'reflect'
            Pads with the reflection of the vector mirrored on
            the first and last values of the vector along each
            axis.
        'symmetric'
            Pads with the reflection of the vector mirrored
            along the edge of the array.
        'wrap'
            Pads with the wrap of the vector along the axis.
            The first values are used to pad the end and the
            end values are used to pad the beginning.
        <function>
            Padding function, see Notes.
    stat_length : sequence or int, optional
        Used in 'maximum', 'mean', 'median', and 'minimum'.  Number of
        values at edge of each axis used to calculate the statistic value.

        ((before_1, after_1), ... (before_N, after_N)) unique statistic
        lengths for each axis.

        ((before, after),) yields same before and after statistic lengths
        for each axis.

        (stat_length,) or int is a shortcut for before = after = statistic
        length for all axes.

        Default is ``None``, to use the entire axis.
    constant_values : sequence or int, optional
        Used in 'constant'.  The values to set the padded values for each
        axis.

        ((before_1, after_1), ... (before_N, after_N)) unique pad constants
        for each axis.

        ((before, after),) yields same before and after constants for each
        axis.

        (constant,) or int is a shortcut for before = after = constant for
        all axes.

        Default is 0.
    end_values : sequence or int, optional
        Used in 'linear_ramp'.  The values used for the ending value of the
        linear_ramp and that will form the edge of the padded array.

        ((before_1, after_1), ... (before_N, after_N)) unique end values
        for each axis.

        ((before, after),) yields same before and after end values for each
        axis.

        (constant,) or int is a shortcut for before = after = end value for
        all axes.

        Default is 0.
    reflect_type : {'even', 'odd'}, optional
        Used in 'reflect', and 'symmetric'.  The 'even' style is the
        default with an unaltered reflection around the edge value.  For
        the 'odd' style, the extented part of the array is created by
        subtracting the reflected values from two times the edge value.

    Returns
    -------
    pad : ndarray
        Padded array of rank equal to `array` with shape increased
        according to `pad_width`.

    Notes
    -----
    .. versionadded:: 1.7.0

    For an array with rank greater than 1, some of the padding of later
    axes is calculated from padding of previous axes.  This is easiest to
    think about with a rank 2 array where the corners of the padded array
    are calculated by using padded values from the first axis.

    The padding function, if used, should return a rank 1 array equal in
    length to the vector argument with padded values replaced. It has the
    following signature::

        padding_func(vector, iaxis_pad_width, iaxis, **kwargs)

    where

        vector : ndarray
            A rank 1 array already padded with zeros.  Padded values are
            vector[:pad_tuple[0]] and vector[-pad_tuple[1]:].
        iaxis_pad_width : tuple
            A 2-tuple of ints, iaxis_pad_width[0] represents the number of
            values padded at the beginning of vector where
            iaxis_pad_width[1] represents the number of values padded at
            the end of vector.
        iaxis : int
            The axis currently being calculated.
        kwargs : misc
            Any keyword arguments the function requires.

    Examples
    --------
    >>> a = [1, 2, 3, 4, 5]
    >>> np.lib.pad(a, (2,3), 'constant', constant_values=(4, 6))
    array([4, 4, 1, 2, 3, 4, 5, 6, 6, 6])

    >>> np.lib.pad(a, (2, 3), 'edge')
    array([1, 1, 1, 2, 3, 4, 5, 5, 5, 5])

    >>> np.lib.pad(a, (2, 3), 'linear_ramp', end_values=(5, -4))
    array([ 5,  3,  1,  2,  3,  4,  5,  2, -1, -4])

    >>> np.lib.pad(a, (2,), 'maximum')
    array([5, 5, 1, 2, 3, 4, 5, 5, 5])

    >>> np.lib.pad(a, (2,), 'mean')
    array([3, 3, 1, 2, 3, 4, 5, 3, 3])

    >>> np.lib.pad(a, (2,), 'median')
    array([3, 3, 1, 2, 3, 4, 5, 3, 3])

    >>> a = [[1, 2], [3, 4]]
    >>> np.lib.pad(a, ((3, 2), (2, 3)), 'minimum')
    array([[1, 1, 1, 2, 1, 1, 1],
           [1, 1, 1, 2, 1, 1, 1],
           [1, 1, 1, 2, 1, 1, 1],
           [1, 1, 1, 2, 1, 1, 1],
           [3, 3, 3, 4, 3, 3, 3],
           [1, 1, 1, 2, 1, 1, 1],
           [1, 1, 1, 2, 1, 1, 1]])

    >>> a = [1, 2, 3, 4, 5]
    >>> np.lib.pad(a, (2, 3), 'reflect')
    array([3, 2, 1, 2, 3, 4, 5, 4, 3, 2])

    >>> np.lib.pad(a, (2, 3), 'reflect', reflect_type='odd')
    array([-1,  0,  1,  2,  3,  4,  5,  6,  7,  8])

    >>> np.lib.pad(a, (2, 3), 'symmetric')
    array([2, 1, 1, 2, 3, 4, 5, 5, 4, 3])

    >>> np.lib.pad(a, (2, 3), 'symmetric', reflect_type='odd')
    array([0, 1, 1, 2, 3, 4, 5, 5, 6, 7])

    >>> np.lib.pad(a, (2, 3), 'wrap')
    array([4, 5, 1, 2, 3, 4, 5, 1, 2, 3])

    >>> def padwithtens(vector, pad_width, iaxis, kwargs):
    ...     vector[:pad_width[0]] = 10
    ...     vector[-pad_width[1]:] = 10
    ...     return vector

    >>> a = np.arange(6)
    >>> a = a.reshape((2, 3))

    >>> np.lib.pad(a, 2, padwithtens)
    array([[10, 10, 10, 10, 10, 10, 10],
           [10, 10, 10, 10, 10, 10, 10],
           [10, 10,  0,  1,  2, 10, 10],
           [10, 10,  3,  4,  5, 10, 10],
           [10, 10, 10, 10, 10, 10, 10],
           [10, 10, 10, 10, 10, 10, 10]])
    r	z%`pad_width` must be of integral type.constant_values
end_valuesstat_lengthreflect_type)
constantedgelinear_rampmaximumr8r=minimumreflect	symmetricwrapNrZeven)r_r]r^r`z%%s keyword not in allowed keywords %s)r^r]F)rWcsg|]}t|qSr)rsum)rr	)	pad_widthrr
rZ>szpad.<locals>.<listcomp>cs0g|](}t|d|dj|qS)r)r$r)rr	)r[rjrr
rZ?srarbrcrdr8r=rerfz:There aren't any elements to reflect in axis {} of `array`rrgrh))rrSrZkind	TypeErrorarrayr\
isinstancecompatZ
basestringrT
setdefaultrYlistrangerRrrZapply_along_axiscopyrzipr"r#r(r)r0r1r6r7r;r<r@rArErFformatrBrOrPrQ)rlrjmodekwargsZ
allowedkwargsZ
kwdefaultskeykwr	ZfunctionZrankZtotal_dim_increaseZ
offset_slicesZ	new_shapeZnewmatZiaxisrZ
pad_beforeZ	pad_afterZ
before_valZ	after_valZchunk_beforeZchunk_afterrJZsafe_padZ
pad_iter_bZ
pad_iter_ar)r[rjr
rFsF






&

&
&
&
&
&







)F)r)r)r)r)r)r)r)r)r)r)r)r)r)r)r)r)r)T)__doc__Z
__future__rrrZnumpyr__all__rrr"r#r(r)r0r1r6r7r;r<r@rArErFrOrPrQrYr\rrrrr
<module>s2
+
"
"
!
"
7
7
4
8
4
9
4
9
4
8
U
T
@
<-