| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
| |
np.pad with mode="wrap" returns unexpected result that original data is not strictly looped in padding. This may happen in some occassions when padding widths in the same dimension are unbalanced (see added testcase in test_arraypad.py and the related issue). The reason is the function pad makes iterative calls of _set_wrap_both() in the above situation, yet period for padding is not correctly computed in each iteration.
The bug is fixed by guaranteeing that period is always a multiple of original data size, and also be the possible maximum for computation efficiency.
Closes #22464
Co-authored-by: Lars Grüter <lagru+github@mailbox.org>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
This makes the scalar operations warnings read e.g.:
overflow encountered in scalar multiply
rather than:
overflow encountered in float_scalars
It also fixes one case where "assignment" rather than "cast" was
used when I added the FPEs for casts.
Otherwise, uses the helper that I intrudced for for the floating
point casts in all places to simplify the code, the only
"complicated" thing is that I try to give "scalar divide" rather
than "scalar true_divide" as warnings, since "true_divide" should
not really be something that end-users need be aware of.
|
| |
|
|
|
|
| |
This implements NEP 34.
|
|
|
|
|
|
|
| |
Inheriting from object was necessary for Python 2 compatibility to use
new-style classes. In Python 3, this is unnecessary as there are no
old-style classes.
Dropping the object is more idiomatic Python.
|
|
|
|
|
| |
As numpy is Python 3 only, these import statements are now unnecessary
and don't alter runtime behavior.
|
| |
|
| |
|
|\
| |
| | |
BUG: Fix uint-overflow if padding with linear_ramp and negative gain
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
linspace supports non-scalar values since version 1.16. This can replace
the former _linear_ramp method.
This removes a bug in the old implementation where certain edge and
end values resulted in an integer underflow for unsigned dtypes (see
gh-14191). Protect against this regression with a new test for all
numeric dtypes.
|
|/
|
|
|
|
|
|
|
| |
Provides a clearer error message if stat_length=0 is the cause of an
exception (mean and median return nan with warnings) as well as tests
covering this behavior.
Note: This shouldn't change the behavior/API except for the content of
the raised ValueError.
|
|
|
| |
* DOC: fix mistatement in numpy.pad docstring
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* ENH: Add support for constant, edge, linear_ramp to new numpy.pad
Passes unit tests:
- TestConstant
- TestEdge
- TestZeroPadWidth
- TestLegacyVectorFunction
- TestNdarrayPadWidth
- TestUnicodeInput
- TestLinearRamp
* MAINT: Simplify diff / change order of functions
* MAINT: Revert to old handling of keyword-only arguments
* ENH: Add support for stat modes
* ENH: Add support for "reflect" mode
* MAINT: Remove _slice_column
* ENH: Add support for "symmetric" mode
* MAINT: Simplify mode "linear_ramp"
Creating the linear ramp as an array with 1-sized dimensions except
for the one given by `axis` allows implicit broadcasting to the needed
shape. This seems to be even a little bit faster that doing this by hand
and allows the simplicifaction of the algorithm.
Note: Profiling and optimization will be done again at a later stage.
* MAINT: Reorder arguments of a sum and fix typo
Addresses feedback raised in PR.
* ENH: Add support for "wrap" mode
This completes the first draft of the complete rewrite meaning all unit
tests should pass from this commit onwards.
* MAINT: Merge functions for "reflect" and "symmetric" mode
The set functions were nearly the same, apart from some index offsets.
Merging them reduces code duplication.
* TST: Add regression test for gh-11216
The rewrite in past commits fixed this bug.
* BUG: Fix edge case for _set_wrap_both when pad_amt contains 0.
And include test to protect against regression.
* MAINT: Simplify and optimize pad modes
Major changes & goals:
Don't deal with pad area in the front and back separately. This
modularity isn't needed and makes handling of the right edge more
awkward. All modes now deal with the left and right side at the same
time.
Move the creation of the linear ramps fully to its own function which
behaves like a vectorized version of linspace.
Separate calculation and application of the pad area where possible.
This means that _get_edges can be reused for _get_linear_ramps.
Combine _normalize_shape and _validate_lengths in a single function
which should handles common cases faster.
Add new mode "empty" which leaves the padded areas undefined.
Add documentation where it was missing.
* TST: Don't use np.empty in unit tests
* MAINT: Reorder workflow in numpy.pad and deal with empty dimensions
Only modes "constant" and "empty" can extend dimensions of size 0. Deal
with this edge case gracefully for all other modes either fail or
return empty array with padded non-zero dimensions.
Handle default values closer to their actual usage. And validate
keyword arguments that must be numbers.
* MAINT: Add small tweaks to control flow and documentation
* BUG: Ensure wrap mode works if right_pad is 0
* ENH: Use reduced region of interest for iterative padding
When padding multiple dimensions iteratively corner values are
unnecessarily overwritten multiple times. This function reduces the
working area for the first dimensions so that corners are excluded.
* MAINT: Restore original argument order in _slice_at_axis
* MAINT: Keep original error message of broadcast_to
* MAINT: Restore old behavior for non-number end_values.
* BENCH: Make the pad benchmark pagefault in setup
* ENH/TST: Preserve memory layout (order) of the input array
and add appropriate unit test.
* STY: Revert cosmetical changes to reduce diff
* MAINT: Pin dtype to float64 for np.pad's benchmarks
* MAINT: Remove redundant code path in _view_roi
* MAINT/TST: Provide proper error message for unsupported modes
and add appropriate unit test.
* STY: Keep docstrings consistent and fix typo.
* MAINT: Simplify logical workflow in pad
* MAINT: Remove dtype argument from _linear_ramp
The responsibility of rounding (but without type conversion) is not
really need in _linear_ramp and only makes it a little bit harder to
reason about.
* DOC: Add version tag to new argument "empty"
* MAINT: Default to C-order for padded arrays
unless the input is F-contiguous.
* MAINT: Name slice of original area consistently
for all arguments describing the same thing.
* STY: Reduce vertical space
* MAINT: Remove shape argument from _slice_at_axis
Simplifies calls to this function and the function itself.
Using `(...,)` instead should keep this unambiguous. This change is not
compatible with Python 2.7 which doesn't support this syntax outside
sequence slicing. If that is wanted one could use `(Ellipsis,)` instead.
* TST: Test if end_values of linear_ramp are exact
which was not given in the old implementation `_arange_ndarray`.
* DOC: Improve comments and wrap long line
* MAINT: Refactor index_pair to width_pair
Calling the right value an index is just plain wrong as it can't be used
as such.
* MAINT: Make _linear_ramp compatible with size=0
* MAINT: Don't rely on negative indices for slicing
Calculating the proper positive index of the start of the right pad area
makes it possible to omit the extra code paths for a width of 0. This
should make the code easier to reason about.
* MAINT: Skip calculation of right_stat if identical
If the input area for both sides is the same we don't need to calculate
it twice.
* TST: Adapt tests from gh-12789 to rewrite of pad
* TST: Add tests for mode "empty"
* TST: Test dtype persistence for all modes
* TST: Test exception for unsupported modes
* TST: Test repeated wrapping for each side
individually. Reaches some only partially covered if-statments in
_set_wrap_both.
* TST: Test padding of empty dimension with constant
* TST: Test if end_values of linear_ramp are exact
which was not given in the old implementation `_arange_ndarray`. (Was
accidentally overwritten during the last merge).
* TST: Test persistence of memory layout
Adapted from an older commit 3ac4d2a1b9b258d65f8d2b5f8f25f88e3a0e8f58
which was accidentally overwritten during the last merge.
* MAINT: Simplify branching in _set_reflect_both
Reduce branching and try to make the calculation of the various indices
easier to understand.
* TST: Parametrize TestConditionalShortcuts class
* TST: Test empty dimension padding for all modes
* TST: Keep test parametrization ordered
Keep parametrization ordered, otherwise pytest-xdist might believe that
different tests were collected during parallelization causing test
failures.
* DOC: Describe performance improvement of np.pad
as well as the new mode "empty" in release notes (see gh-11358).
* DOC: Remove outdated / misleading notes
These notes are badly worded or actually misleading. For a better
explanation on how these functions work have a look at the context and
comments just above the lines calling these functions.
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* TST: Move test for negative stat_length
and extend coverage to all modes and more variations of a negative
stat_length.
* TST: Merge tests for pad_width in single class
* TST: Test behavior of pad's kwargs for all modes
* TST: Move test to TestReflect
Can be grouped with already existing test class checking the behavior
for the reflect mode.
* TST: Simplify regression test for object input
* TST: Move testing pad_width as ndarray
Can be grouped in class TestPadWidth as this test checks if an ndarray
is accepted as the value to pad_width
* TST: Remove faulty tests for pad_width's type
These test were ineffective. The TypeError raised in these test was not
actually due to pad_width receiving the wrong type but due to the
missing parameter mode.
Added missing type complex to the appropriate existing test checking for
pad_widths type behavior.
* TST: Move test for pad_width of zero
* TST: Move test for simple stat_length
* TST: Simplify classes with only one test
* TST: Add naive test for non-contiguous arrays
* MAINT: Don't import pad directly
Using np.pad instead of directly importing the function seems to be more
inline with other test modules.
* STY: Make class layout consistent in module
* TST: Fix match-string for missing pad mode error
The CLI fails due to error message containing a reference to
_pad_dispatcher() being returned instead of pad(). For some reason this
test passes when run locally.
|
| |
|
|\
| |
| | |
TST: Add more tests for np.pad
|
| |
| |
| |
| | |
rounds to `float`
|
| |
| |
| |
| | |
The test is marked xfail right now as it is not fixed in master
|
| | |
|
| | |
|
| | |
|
| | |
|
|/ |
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
The old way of creating the padded array padded with wrong values for
large integers because the new prepended / appended array was implicitly
created with dtype float64:
>>> (np.zeros(1) + (2 ** 64 - 1)).astype(np.uint64)
array([0], np.uint64)
>>> (np.zeros(1) + (2 ** 63 - 1)).astype(np.int64)
array([-9223372036854775808])
|
|
|
|
|
| |
That function is nose specific and has not worked since `__init__` files
were added to the tests directories.
|
|
|
|
| |
Check that axes with non-zero padding are non-empty.
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
| |
Simplify the expansion of the pad_width argument by using `broadcast_to()`.
This fixes the problem reported in gh-7808, where, for example,
`pad_width=((1, 2),)` resulted in an error.
Closes gh-7808.
|
|
|
|
| |
This test exposes padding bug described in the issue #7353
|
|
|
|
|
| |
isinstance(mode, str) is False in python2.7 when mode is of unicode
type, and mode is then mistakenly assumed to be a callable. See #7112
|
|
|
|
|
| |
`mode` is a required argument so just declare it as such. This does not
prevent it from being passed as a keyword argument.
|
| |
|
|
|
|
|
|
|
| |
The possibly controversial part of this is making the nested array
value lists PEP8 compliant, as there is something to be said aligning
the values for clarity. In the end, it seemed like the easiest thing
to do was to make them PEP8 compliant. The eye can get used to that.
|
|
|
|
|
|
|
| |
Run autopep8 over the test files in numpy/lib/test and make fixes
to the result.
Also remove Python5 workaround.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
New padding method which scales much better with dimensionality.
This new implementation is fully vectorized, builds each abstracted
n-dimensional padding block in a single step, and takes advantage
of separability. The API is completely preserved, and the old
algorithm is used if a vector function is input for `mode`.
The new algorithm is faster for all tested combinations of inputs,
and scales much better with dimensionality. Execution time reductions
from ~25% for small rank 1 arrays to >99% for rank 4+ arrays observed.
|
|
|
|
|
|
|
| |
Add `print_function` to all `from __future__ import ...` statements
and use the python3 print function syntax everywhere.
Closes #3078.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The new import `absolute_import` is added the `from __future__ import`
statement and The 2to3 `import` fixer is run to make the imports
compatible. There are several things that need to be dealt with to make
this work.
1) Files meant to be run as scripts run in a different environment than
files imported as part of a package, and so changes to those files need
to be skipped. The affected script files are:
* all setup.py files
* numpy/core/code_generators/generate_umath.py
* numpy/core/code_generators/generate_numpy_api.py
* numpy/core/code_generators/generate_ufunc_api.py
2) Some imported modules are not available as they are created during
the build process and consequently 2to3 is unable to handle them
correctly. Files that import those modules need a bit of extra work.
The affected files are:
* core/__init__.py,
* core/numeric.py,
* core/_internal.py,
* core/arrayprint.py,
* core/fromnumeric.py,
* numpy/__init__.py,
* lib/npyio.py,
* lib/function_base.py,
* fft/fftpack.py,
* random/__init__.py
Closes #3172
|
|
|
|
|
|
|
|
| |
This should be harmless, as we already are division clean. However,
placement of this import takes some care. In the future a script
can be used to append new features without worry, at least until
such time as it exceeds a single line. Having that ability will
make it easier to deal with absolute imports and printing updates.
|
|
The various padding functions are exposed as options to a public 'pad'
function. Example:
pad(a, 5, mode='mean')
Current modes are 'constant', 'edge', 'linear_ramp', 'maximum', 'mean',
'median', 'minimum', 'reflect', 'symmetric', 'wrap', and <function>
This commit includes unit tests and doctests and is based on feature
request ticket #655.
|