summaryrefslogtreecommitdiff
path: root/numpy/lib/twodim_base.py
Commit message (Collapse)AuthorAgeFilesLines
* DOC: Fix matpltolib error in documentation (#23212)Sebastian Berg2023-02-141-1/+1
| | | | | | | | As noted by Kyle Sunden, this was deprecated and has been removed, using the method is the correct way of doing it in newer matplotlib. Closes gh-23209 Co-authored-by: Kyle Sunden <ksunden@users.noreply.github.com>
* ENH: Improve array function overhead by using vectorcallSebastian Berg2023-01-171-16/+4
| | | | | | | | | | | | | | | | | | | | | | | | This moves dispatching for `__array_function__` into a C-wrapper. This helps speed for multiple reasons: * Avoids one additional dispatching function call to C * Avoids the use of `*args, **kwargs` which is slower. * For simple NumPy calls we can stay in the faster "vectorcall" world This speeds up things generally a little, but can speed things up a lot when keyword arguments are used on lightweight functions, for example:: np.can_cast(arr, dtype, casting="same_kind") is more than twice as fast with this. There is one alternative in principle to get best speed: We could inline the "relevant argument"/dispatcher extraction. That changes behavior in an acceptable but larger way (passes default arguments). Unless the C-entry point seems unwanted, this should be a decent step in the right direction even if we want to do that eventually, though. Closes gh-20790 Closes gh-18547 (although not quite sure why)
* DOC: #22266 Add examples for tril_indices_from(), triu_indices_from() (#22562)Richie Cotton2023-01-161-2/+69
| | | | | | | | | | | * DOC: #22266 Add examples for tri[lu]_indices_from() * DOC: see also for tri[lu]_indices_from() * DOC: Fix triu_indices_from example and minor updates. * incides -> indices * Update wording surrounding . Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* DEP: Remove `normed=` keyword argument from histogromsSebastian Berg2022-06-021-11/+6
| | | | | | The normed keyword argument has been deprecated for a long time. This removes it, replacing its position with the new density argument.
* BUG: lib: Allow type uint64 for eye() arguments.warren2022-05-111-3/+9
| | | | | | Closes gh-9982. (Plus a few small PEP 8 fixes.)
* ENH: Check that the lengths of the inputs to histogram2d are the same. (#20228)Jérome Eertmans2021-11-021-0/+3
| | | | | | | Improves exception message when inputs have different shapes. Closes gh-20050 Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* DOC: Typos found by codespellDimitri Papadopoulos2021-09-211-2/+2
|
* DOC: added explanation about tril/triu n-dimensional functionality. (#19131)Melissa Weber Mendonça2021-06-141-3/+34
| | | | | * DOC: added explanation about tril/triu n-dimensional functionality. Additional examples are also provided. Closes gh-10310
* DOC: Add example to histogram2d docstringmelissawm2021-05-241-0/+34
|
* DOC: improve numpy.histogram2d() documentationMarysia Winkels2021-05-091-1/+3
| | | | | | Clarify necessity of H.T in code example. Resolves issue #18929 Co-authored-by: Laura Kopf <60775505+lkopf@users.noreply.github.com>>
* DOC: Clarify docs for fliplr() / flipud()Tim Hoffmann2021-03-091-9/+13
|
* BUG: Fixed an issue where `diagflat` could overflow on windows and 32-bit ↵Bas van Beek2021-02-211-4/+4
| | | | platforms
* import indices, broadcast_toIllviljan2021-01-151-7/+8
|
* use same tri formatIllviljan2021-01-151-1/+1
|
* faster tril_indicesIllviljan2021-01-111-2/+8
| | | nonzero is slow. Use np.indices and np.broadcast_to to speed it up.
* ENH: implement NEP-35's `like=` argument (gh-16935)Peter Andreas Entschev2020-08-281-3/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR adds the implementation of NEP-35's like= argument, allowing dispatch of array creation functions with __array_function__ based on a reference array. * ENH: Add like= kwarg via __array_function__ dispatcher to asarray * ENH: Add new function for __array_function__ dispatching from C This new function allows dispatching from C directly, while also implementing the new `like=` argument, requiring only minimal changes to existing array creation functions that need to add support for that argument. * ENH: Add like= support to numpy.array The implementation uses array_implement_c_array_function, thus introducing minimal complexity to the original _array_fromobject code. * BUG: Fix like= dispatcher for np.full * ENH: Remove np.asarray like= dispatcher via Python np.asarray can rely on np.array's C dispatcher instead. * TST: Add some tests for like= argument Tests comprise some of the functions that have been implemented already: * np.array (C dispatcher) * np.asarray (indirect C dispatcher via np.array) * np.full (Python dispatcher) * np.ones (Python dispatcher) * ENH: Remove like= argument during array_implement_array_function * ENH: Add like= kwarg to ones and full * BUG: prevent duplicate removal of `like=` argument * ENH: Make `like=` a keyword-only argument * ENH: Use PyUnicode_InternFromString in arrayfunction_override Replace PyUnicode_FromString by PyUnicode_InternFromString to cache "like" string. * ENH: Check for arrayfunction_override import errors Check and handle errors on importing NumPy's Python functions * BUG: Fix array_implement_c_array_function error handling * ENH: Handle exceptions with C implementation of `like=` * ENH: Add `like=` dispatch for all asarray functions Using Python dispatcher for all of them. Using the C dispatcher directly on the `np.array` call can result in incorrect behavior. Incorrect behavior may happen if the downstream library's implementation is different or if not all keyword arguments are supported. * ENH: Simplify handling of exceptions with `like=` * TST: Add test for exception handling with `like=` * ENH: Add support for `like=` to `np.empty` and `np.zeros` * TST: Add `like=` tests for `np.empty` and `np.zeros` * ENH: Add `like=` to remaining multiarraymodule.c functions Functions are: * np.arange * np.frombuffer * np.fromfile * np.fromiter * np.fromstring * TST: Add tests for multiarraymodule.c functions with like= Functions are: * np.arange * np.frombuffer * np.fromfile * np.fromiter * np.fromstring * ENH: Add `like=` support to more creation functions Support for the following functions is added: * np.eye * np.fromfunction * np.genfromtxt * np.identity * np.loadtxt * np.tri * TST: Add `like=` tests for multiple functions Tests for the following functions are added: * np.eye * np.fromfunction * np.genfromtxt * np.identity * np.loadtxt * np.tri * TST: Reduce code duplication in `like=` tests * DOC: Document `like=` in functions that support it Add documentations for the following functions: * np.array * np.arange * np.asarray * np.asanyarray * np.ascontiguousarray * np.asfortranarray * np.require * np.empty * np.full * np.ones * np.zeros * np.identity * np.eye * np.tri * np.frombuffer * np.fromfile * np.fromiter * np.fromstring * np.loadtxt * np.genfromtxt * ENH: Add `like=` to numpy/__init__.pyi stubs * BUG: Remove duplicate `like=` dispatching in as*array Functions `np.asanyarray`, `np.contiguousarray` and `np.fortranarray` were dispatching both via their definitions and `np.array` calls, the latter should be avoided. * BUG: Fix missing check in array_implement_array_function * BUG: Add missing keyword-only markers in stubs * BUG: Fix duplicate keyword-only marker in array stub * BUG: Fix syntax error in numpy/__init__.pyi * BUG: Fix more syntax errors in numpy/__init__.pyi * ENH: Intern arrayfunction_override strings in multiarraymodule * STY: Add missing brackets to arrayfunction_override.c * MAINT: Remove arrayfunction_override dict check for kwarg * TST: Assert that 'like' is not in TestArrayLike kwargs * MAINT: Rename array_implement_c_array_function(_creation) This is done to be more explicit as to its usage being intended for array creation functions only. * MAINT: Use NotImplemented to indicate fallback to default * TST: Test that results with `like=np.array` are correct * TST: Avoid duplicating MyArray code in TestArrayLike * TST: Don't delete temp file, it may cause issues with Windows * TST: Don't rely on eval in TestArrayLike * TST: Use lambda with StringIO in TestArrayLike * ENH: Avoid unnecessary Py_XDECREF in arrayfunction_override * TST: Make TestArrayLike more readable * ENH: Cleaner error handling in arrayfunction_override * ENH: Simplify array_implement_c_array_function_creation * STY: Add missing spaces to multiarraymodule.c * STY: C99 declaration style in arrayfunction_override.c * ENH: Simplify arrayfunction_override.c further Remove cleanup label from array_implementation_c_array_function, simplifying the code. Fix unitialized variable warning in array_implementation_array_function_internal. * DOC: Use string replacement for `like=` documentation Avoid repeating the full text for the `like=` argument by storing it as a variable and using `replace` on each docstring. * DOC: Update `like=` docstring * TST: Test like= with array not implementing __array_function__ * TST: Add missing asanyarray to TestArrayLike * ENH: Use helper function for like= dispatching Avoid dispatching like= from Python implementation functions to improve their performance. This is achieved by only calling a dispatcher function when like is passed by the users. * ENH: Rename array_function_dispatch kwarg to public_api * BUG: Add accidentally removed decorator for np.eye back * DOC: Add set_array_function_like_doc function The function keeps Python files cleaner and resolve errors when __doc__ is not defined due to PYTHONOPTIMIZE or -OO . * DOC: Add mention to like= kwarg being experimental * TST: Test like= with not implemented downstream function * DOC: Fix like= docstring reference to NEP 35. * ENH: Prevent silent errors if public_api is not callable * ENH: Make set_array_function_like_doc a decorator * ENH: Simplify `_*_with_like` functions * BUG: Fix multiple `like=` dispatching in `require` * MAINT: Remove now unused public_api from array_function_dispatch Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
* BUG,DOC: Fix bad MPL kwarg.Ross Barnowski2020-07-161-1/+1
| | | | | Invalide kwarg to imshow causes failures in the plot directive for docs builds using MPL > v3.3
* DOC: rm matrix from triu docstring.Ross Barnowski2020-06-251-1/+1
| | | | | Replace "matrix" with "array" to avoid confusion re: np.matrix. Consistent with other np.tri\* functions.
* MAINT: Remove unnecessary 'from __future__ import ...' statementsJon Dufresne2020-01-031-2/+0
| | | | | As numpy is Python 3 only, these import statements are now unnecessary and don't alter runtime behavior.
* MAINT: lib: Clean up in twodim_base.py.Warren Weckesser2020-01-011-2/+2
| | | | * Remove unused imports.
* DOC: fix documentation of i and j for tri.hvy2019-07-241-1/+1
|
* BUG: further fixup to histogram2d dispatcher.Marten van Kerkwijk2019-06-201-1/+1
| | | | Now with tests....
* MAINT: check bins length in histogram2d_dispatcherStephan Hoyer2019-06-111-4/+11
|
* MAINT: fix histogram*d dispatchersStephan Hoyer2019-06-111-1/+7
| | | | fixes GH-13728
* DOC, TST: clean up matplotlib importsTyler Reddy2019-01-021-4/+2
| | | | | | * as requested by review in gh-12634, the vast majority of docstring matplotlib imports can be simplified to a single line
* DOC, TST: remove agg setting from docsTyler Reddy2019-01-021-1/+0
| | | | | | | * there is no longer any usage of "agg" backend switching in our docstrings because this backend is already activated in the refguide_check machinery
* TST, DOC: enable refguide_checkTyler Reddy2018-12-141-21/+26
| | | | | | | | * ported the refguide_check module from SciPy for usage in NumPy docstring execution/ verification; added the refguide_check run to Azure Mac OS CI * adjusted NumPy docstrings such that refguide_check passes
* ENH: set correct __module__ for objects in numpy's public APIStephan Hoyer2018-11-131-0/+6
| | | | | | | | | | | | | Fixes GH-12271 Tests verify that everything in ``dir(numpy)`` either has ``__module__`` set to ``'numpy'``, or appears in an explicit whitelist of undocumented functions and exported bulitins. These should eventually be documented or removed. I also identified a handful of functions for which I had accidentally not setup dispatch for with ``__array_function__`` before, because they were listed under "ndarray methods" in ``_add_newdocs.py``. I guess that should be a lesson in trusting code comments :).
* MAINT: set preferred __module__ for numpy functionsStephan Hoyer2018-10-231-1/+7
|
* ENH: __array_function__ support for np.lib, part 2/2 (#12119)Stephan Hoyer2018-10-221-0/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * ENH: __array_function__ support for np.lib, part 2 xref GH12028 np.lib.npyio through np.lib.ufunclike * Fix failures in numpy/core/tests/test_overrides.py * CLN: handle depreaction in dispatchers for np.lib.ufunclike * CLN: fewer dispatchers in lib.twodim_base * CLN: fewer dispatchers in lib.shape_base * CLN: more dispatcher consolidation * BUG: fix test failure * Use all method instead of function in assert_equal * DOC: indicate n is array_like in scimath.logn * MAINT: updates per review * MAINT: more conservative changes in assert_array_equal * MAINT: add back in comment * MAINT: casting tweaks in assert_array_equal * MAINT: fixes and tests for assert_array_equal on subclasses
* MAINT: Rename histogramdd's normed argument to density, to match histogramEric Wieser2018-07-081-4/+10
| | | | Fixes gh-4371
* ENH: Disable fuzzing on histogram boundariesEric Wieser2018-04-301-1/+1
| | | | | | | | | | Previously a fuzzy rounded comparison was used for the rightmost bin of histogramdd. It's not clear why this was done, and it resulted in surprising behavior. This also removes the restriction that bin edges must be floats, and allows integer arrays to be passed (and returned) Fixes gh-10864
* ENH: Add `order=` keyword to `np.eye()` (#9996)Danny Hermes2017-11-121-2/+7
| | | Fixes #9995
* MAINT: Don't internally use the one-argument whereEric Wieser2017-06-031-3/+4
| | | | nonzero is a clearer spelling
* DOC: Correct shape of edges in np.histogram2d (#8980)Importance of Being Ernest2017-04-231-2/+2
| | | | | If nx and ny are the bin counts (as stated in the bins argument's text), then the return H has indeed shape (nx, ny). However, the returned xedges and yedges will then have shape (nx+1,) and (ny+1,) respectively. Fixes #8979
* DOC: Improve histogram2d() example.wrwrwr2016-10-081-29/+17
| | | | Closes #8115.
* ENH: generalize rot90 with axes kwarg, move to function_base.py, and add testsDenis Alevi2016-03-201-57/+4
|
* ENH: Add generalized flip function and its testsEren Sezener2016-03-121-4/+4
|
* DOC: fix a number of reST formatting issues in docstrings.Ralf Gommers2016-02-131-2/+2
|
* DOC: Use print only as function when print_function is imported from __future__gfyoung2015-12-191-1/+1
| | | | Closes gh-6863.
* DOC: Updated docstring for histogram2d as suggested in issue #5538Åsmund Hjulstad2015-02-131-3/+5
| | | | Also, added unittest for [int, array] combination arguments
* BUG: Make diag, diagonal return 1-D arrays for matrix arguments.Charles Harris2015-01-041-2/+2
| | | | | | | | This is an ugly hack to preserve backwards compatibility for code that uses matrices. It is needed since both diag and diagonal have been changed to preserve subtypes otherwise. Note that a.diagonal() still returns matrices when a is a matrix.
* Improved PEP-8 complianceGarrett-R2014-12-081-0/+2
|
* BUG: Closes #2015: diag returns ndarrayGarrett-R2014-12-081-1/+1
| | | | | | | If x is a matrix, np.diag(x) and np.diagonal(x) now return matrices instead of arrays. Both of these cause x.diagonal() to be called. That means they return row vectors (just like x.flatten(), x.ravel(), x.cumprod(), etc.)
* Merge pull request #4929 from juliantaylor/charris-pep8-numpy-libCharles Harris2014-07-311-8/+8
|\ | | | | Charris pep8 numpy lib
| * MAINT: Fixes for problems in numpy/lib revealed by pyflakes.Charles Harris2014-07-311-8/+8
| | | | | | | | | | | | Some of those problems look like potential coding errors. In those cases a Fixme comment was made and the offending code, usually an unused variable, was commented out.
* | BUG: Avoid type promotion in tril and triu.Yotam Doron2014-07-291-2/+2
| |
* | BUG: Use `np.where` in np.triu/np.tril, fixes #4859jaimefrio2014-07-101-3/+6
|/ | | | | Replaces the current method to zero items, from multiplication to using `np.where`.
* STY: Use `.astype`'s `copy` kwarg in `np.tri`jaimefrio2014-05-271-4/+2
| | | | Replace an explicit type check with setting `copy=False` in call to `astype`.
* ENH: Replace exponentiation with cumulative product in np.vanderjaimefrio2014-03-311-25/+27
| | | | | Speeds calculation up by ~3x for 100x100 matrices, and by ~45x for 1000x1000