summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSayantika Banik <sayantikabanik122@gmail.com>2021-09-08 06:21:36 +0000
committerSayantika Banik <sayantikabanik122@gmail.com>2021-09-08 06:21:36 +0000
commit879b3b4798975c7c0c49cef6ece3563c5f2daaeb (patch)
treee102f2222f1557d9b4f8b1a3e9484ca59b8ad954
parent9680d760cdb08cc54c18657c77269853670f17e9 (diff)
parent17c3a6b414a3e642abeb116ff71e97f9b6f2aab5 (diff)
downloadnumpy-879b3b4798975c7c0c49cef6ece3563c5f2daaeb.tar.gz
Merge branch 'main' of https://github.com/sayantikabanik/numpy
-rw-r--r--.circleci/config.yml15
-rw-r--r--.clang-format37
-rw-r--r--doc/Makefile9
-rwxr-xr-xdoc/preprocess.py51
-rw-r--r--doc/release/upcoming_changes/18884.new_feature.rst7
-rw-r--r--doc/release/upcoming_changes/19754.new_feature.rst7
-rw-r--r--doc/source/conf.py19
-rw-r--r--doc/source/dev/examples/.doxyfile2
-rw-r--r--doc/source/dev/examples/doxy_class.hpp21
-rw-r--r--doc/source/dev/examples/doxy_func.h11
-rw-r--r--doc/source/dev/examples/doxy_rst.h15
-rw-r--r--doc/source/dev/howto-docs.rst217
-rw-r--r--doc/source/dev/howto_build_docs.rst21
-rw-r--r--doc/source/doxyfile340
-rw-r--r--doc/source/user/c-info.ufunc-tutorial.rst21
-rw-r--r--doc_requirements.txt1
-rw-r--r--numpy/array_api/_typing.py2
-rw-r--r--numpy/core/include/numpy/.doxyfile2
-rw-r--r--numpy/core/include/numpy/random/distributions.h2
-rw-r--r--numpy/core/src/common/.doxyfile1
-rw-r--r--numpy/core/src/common/array_assign.c4
-rw-r--r--numpy/core/src/common/cblasfuncs.c8
-rw-r--r--numpy/core/src/common/lowlevel_strided_loops.h4
-rw-r--r--numpy/core/src/common/mem_overlap.c4
-rw-r--r--numpy/core/src/common/npy_argparse.c5
-rw-r--r--numpy/core/src/common/npy_argparse.h2
-rw-r--r--numpy/core/src/common/npy_longdouble.c5
-rw-r--r--numpy/core/src/common/numpyos.c17
-rw-r--r--numpy/core/src/common/python_xerbla.c4
-rw-r--r--numpy/core/src/common/ucsnarrow.c5
-rw-r--r--numpy/core/src/dummymodule.c5
-rw-r--r--numpy/core/src/multiarray/_multiarray_tests.c.src2
-rw-r--r--numpy/core/src/multiarray/abstractdtypes.c8
-rw-r--r--numpy/core/src/multiarray/alloc.c14
-rw-r--r--numpy/core/src/multiarray/array_assign_array.c6
-rw-r--r--numpy/core/src/multiarray/array_assign_scalar.c4
-rw-r--r--numpy/core/src/multiarray/array_coercion.c5
-rw-r--r--numpy/core/src/multiarray/array_method.c3
-rw-r--r--numpy/core/src/multiarray/arrayobject.c8
-rw-r--r--numpy/core/src/multiarray/arraytypes.c.src4
-rw-r--r--numpy/core/src/multiarray/buffer.c7
-rw-r--r--numpy/core/src/multiarray/calculation.c7
-rw-r--r--numpy/core/src/multiarray/common.c5
-rw-r--r--numpy/core/src/multiarray/common.h2
-rw-r--r--numpy/core/src/multiarray/common_dtype.c7
-rw-r--r--numpy/core/src/multiarray/compiled_base.c7
-rw-r--r--numpy/core/src/multiarray/conversion_utils.c7
-rw-r--r--numpy/core/src/multiarray/convert.c9
-rw-r--r--numpy/core/src/multiarray/convert_datatype.c7
-rw-r--r--numpy/core/src/multiarray/convert_datatype.h12
-rw-r--r--numpy/core/src/multiarray/ctors.c7
-rw-r--r--numpy/core/src/multiarray/datetime.c15
-rw-r--r--numpy/core/src/multiarray/datetime_busday.c4
-rw-r--r--numpy/core/src/multiarray/datetime_busdaycal.c8
-rw-r--r--numpy/core/src/multiarray/datetime_strings.c9
-rw-r--r--numpy/core/src/multiarray/descriptor.c6
-rw-r--r--numpy/core/src/multiarray/dragon4.h4
-rw-r--r--numpy/core/src/multiarray/dtype_transfer.c12
-rw-r--r--numpy/core/src/multiarray/dtypemeta.c8
-rw-r--r--numpy/core/src/multiarray/einsum.c.src4
-rw-r--r--numpy/core/src/multiarray/flagsobject.c6
-rw-r--r--numpy/core/src/multiarray/getset.c6
-rw-r--r--numpy/core/src/multiarray/hashdescr.c6
-rw-r--r--numpy/core/src/multiarray/item_selection.c8
-rw-r--r--numpy/core/src/multiarray/iterators.c7
-rw-r--r--numpy/core/src/multiarray/legacy_dtype_implementation.c2
-rw-r--r--numpy/core/src/multiarray/lowlevel_strided_loops.c.src2
-rw-r--r--numpy/core/src/multiarray/mapping.c8
-rw-r--r--numpy/core/src/multiarray/methods.c12
-rw-r--r--numpy/core/src/multiarray/multiarraymodule.c12
-rw-r--r--numpy/core/src/multiarray/nditer_api.c3
-rw-r--r--numpy/core/src/multiarray/nditer_constr.c4
-rw-r--r--numpy/core/src/multiarray/nditer_impl.h4
-rw-r--r--numpy/core/src/multiarray/nditer_pywrap.c11
-rw-r--r--numpy/core/src/multiarray/number.c8
-rw-r--r--numpy/core/src/multiarray/refcount.c6
-rw-r--r--numpy/core/src/multiarray/scalarapi.c7
-rw-r--r--numpy/core/src/multiarray/scalartypes.c.src4
-rw-r--r--numpy/core/src/multiarray/sequence.c7
-rw-r--r--numpy/core/src/multiarray/shape.c7
-rw-r--r--numpy/core/src/multiarray/strfuncs.c4
-rw-r--r--numpy/core/src/multiarray/temp_elide.c5
-rw-r--r--numpy/core/src/multiarray/typeinfo.c7
-rw-r--r--numpy/core/src/multiarray/usertypes.c8
-rw-r--r--numpy/core/src/multiarray/vdot.c2
-rw-r--r--numpy/core/src/npymath/halffloat.c1
-rw-r--r--numpy/core/src/umath/_operand_flag_tests.c.src5
-rw-r--r--numpy/core/src/umath/_rational_tests.c.src14
-rw-r--r--numpy/core/src/umath/_scaled_float_dtype.c6
-rw-r--r--numpy/core/src/umath/_struct_ufunc_tests.c.src8
-rw-r--r--numpy/core/src/umath/_umath_tests.c.src5
-rw-r--r--numpy/core/src/umath/_umath_tests.dispatch.c2
-rw-r--r--numpy/core/src/umath/clip.c.src5
-rw-r--r--numpy/core/src/umath/dispatching.c9
-rw-r--r--numpy/core/src/umath/extobj.c5
-rw-r--r--numpy/core/src/umath/legacy_array_method.c7
-rw-r--r--numpy/core/src/umath/loops.c.src4
-rw-r--r--numpy/core/src/umath/matmul.c.src4
-rw-r--r--numpy/core/src/umath/reduction.c6
-rw-r--r--numpy/core/src/umath/scalarmath.c.src3
-rw-r--r--numpy/core/src/umath/ufunc_object.c10
-rw-r--r--numpy/core/src/umath/ufunc_type_resolution.c13
-rw-r--r--numpy/core/src/umath/umathmodule.c18
-rw-r--r--numpy/f2py/cfuncs.py2
-rw-r--r--numpy/f2py/src/fortranobject.h2
-rw-r--r--numpy/f2py/src/test/foomodule.c4
-rw-r--r--numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c4
-rw-r--r--numpy/fft/_pocketfft.c8
-rw-r--r--numpy/lib/nanfunctions.py24
-rw-r--r--numpy/lib/tests/test_nanfunctions.py138
-rw-r--r--numpy/linalg/lapack_lite/clapack_scrub.py5
-rw-r--r--numpy/linalg/lapack_lite/python_xerbla.c4
-rw-r--r--numpy/linalg/lapack_litemodule.c5
-rw-r--r--numpy/linalg/umath_linalg.c.src5
-rw-r--r--numpy/random/include/aligned_malloc.h2
-rw-r--r--test_requirements.txt4
116 files changed, 1182 insertions, 371 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml
index fdb85be98..c343e9168 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -8,7 +8,11 @@ jobs:
docker:
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
- - image: cimg/python:3.8
+ # circleci/python3.8 images come with old versions of Doxygen(1.6.x),
+ # therefore a new base image chose instead to guarantee to
+ # have a newer version >= 1.8.10 to avoid warnings
+ # that related to the default behaviors or non-exist config options
+ - image: cimg/base:2021.05
working_directory: ~/repo
@@ -23,7 +27,8 @@ jobs:
name: create virtual environment, install dependencies
command: |
sudo apt-get update
- sudo apt-get install -y graphviz texlive-fonts-recommended texlive-latex-recommended texlive-latex-extra latexmk texlive-xetex
+ sudo apt-get install -y python3.8 python3.8-dev python3-venv graphviz texlive-fonts-recommended texlive-latex-recommended \
+ texlive-latex-extra latexmk texlive-xetex doxygen
python3.8 -m venv venv
. venv/bin/activate
@@ -58,7 +63,7 @@ jobs:
. venv/bin/activate
cd doc
# Don't use -q, show warning summary"
- SPHINXOPTS="-n" make -e html || echo "ignoring errors for now, see gh-13114"
+ SPHINXOPTS="-j4 -n" make -e html || echo "ignoring errors for now, see gh-13114"
- run:
name: build devdocs
@@ -67,14 +72,14 @@ jobs:
. venv/bin/activate
cd doc
make clean
- SPHINXOPTS=-q make -e html
+ SPHINXOPTS="-j4 -q" make -e html
- run:
name: build neps
command: |
. venv/bin/activate
cd doc/neps
- SPHINXOPTS=-q make -e html
+ SPHINXOPTS="-j4 -q" make -e html
- store_artifacts:
path: doc/build/html/
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 000000000..c78fb5f77
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,37 @@
+# A clang-format style that approximates Python's PEP 7
+# Useful for IDE integration
+#
+# Based on Paul Ganssle's version at
+# https://gist.github.com/pganssle/0e3a5f828b4d07d79447f6ced8e7e4db
+# and modified for NumPy
+BasedOnStyle: Google
+AlignAfterOpenBracket: Align
+AllowShortEnumsOnASingleLine: false
+AllowShortIfStatementsOnASingleLine: false
+AlwaysBreakAfterReturnType: TopLevel
+BreakBeforeBraces: Stroustrup
+ColumnLimit: 79
+ContinuationIndentWidth: 8
+DerivePointerAlignment: false
+IndentWidth: 4
+IncludeBlocks: Regroup
+IncludeCategories:
+ - Regex: '^[<"](Python|structmember|pymem)'
+ Priority: -3
+ CaseSensitive: true
+ - Regex: '^"numpy/'
+ Priority: -2
+ - Regex: '^"(npy_pycompat|npy_config)'
+ Priority: -1
+ - Regex: '^"[[:alnum:]_.]+"'
+ Priority: 1
+ - Regex: '^<[[:alnum:]_.]+"'
+ Priority: 2
+Language: Cpp
+PointerAlignment: Right
+ReflowComments: true
+SpaceBeforeParens: ControlStatements
+SpacesInParentheses: false
+StatementMacros: [PyObject_HEAD, PyObject_VAR_HEAD, PyObject_HEAD_EXTRA]
+TabWidth: 4
+UseTab: Never
diff --git a/doc/Makefile b/doc/Makefile
index 68d496389..16fc3229d 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -14,6 +14,7 @@ PYTHON = python$(PYVER)
SPHINXOPTS ?=
SPHINXBUILD ?= LANG=C sphinx-build
PAPER ?=
+DOXYGEN ?= doxygen
# For merging a documentation archive into a git checkout of numpy/doc
# Turn a tag like v1.18.0 into 1.18
# Use sed -n -e 's/patttern/match/p' to return a blank value if no match
@@ -77,7 +78,7 @@ INSTALL_DIR = $(CURDIR)/build/inst-dist
INSTALL_PPH = $(INSTALL_DIR)/lib/python$(PYVER)/site-packages:$(INSTALL_DIR)/local/lib/python$(PYVER)/site-packages:$(INSTALL_DIR)/lib/python$(PYVER)/dist-packages:$(INSTALL_DIR)/local/lib/python$(PYVER)/dist-packages
UPLOAD_DIR=/srv/docs_scipy_org/doc/numpy-$(RELEASE)
-DIST_VARS=SPHINXBUILD="LANG=C PYTHONPATH=$(INSTALL_PPH) python$(PYVER) `which sphinx-build`" PYTHON="PYTHONPATH=$(INSTALL_PPH) python$(PYVER)"
+DIST_VARS=SPHINXBUILD="LANG=C PYTHONPATH=$(INSTALL_PPH) python$(PYVER) `which sphinx-build`" PYTHON="PYTHONPATH=$(INSTALL_PPH) python$(PYVER)"
NUMPYVER:=$(shell $(PYTHON) -c "import numpy; print(numpy.version.git_revision[:10])" 2>/dev/null)
GITVER ?= $(shell cd ..; $(PYTHON) -c "import versioneer as v; print(v.get_versions()['full-revisionid'][:10])")
@@ -176,6 +177,12 @@ build/generate-stamp: $(wildcard source/reference/*.rst)
html: version-check html-build
html-build: generate
mkdir -p build/html build/doctrees
+ $(PYTHON) preprocess.py
+ifeq (, $(shell which $(DOXYGEN)))
+ @echo "Unable to find 'Doxygen:$(DOXYGEN)', skip generating C/C++ API from comment blocks."
+else
+ $(DOXYGEN) build/doxygen/Doxyfile
+endif
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) build/html $(FILES)
$(PYTHON) postprocess.py html build/html/*.html
@echo
diff --git a/doc/preprocess.py b/doc/preprocess.py
new file mode 100755
index 000000000..e88d9608e
--- /dev/null
+++ b/doc/preprocess.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python3
+import subprocess
+import os
+import sys
+from string import Template
+
+def main():
+ doxy_gen(os.path.abspath(os.path.join('..')))
+
+def doxy_gen(root_path):
+ """
+ Generate Doxygen configration file.
+ """
+ confs = doxy_config(root_path)
+ build_path = os.path.join(root_path, "doc", "build", "doxygen")
+ gen_path = os.path.join(build_path, "Doxyfile")
+ if not os.path.exists(build_path):
+ os.makedirs(build_path)
+ with open(gen_path, 'w') as fd:
+ fd.write("#Please Don't Edit! This config file was autogenerated by ")
+ fd.write(f"doxy_gen({root_path}) in doc/preprocess.py.\n")
+ for c in confs:
+ fd.write(c)
+
+class DoxyTpl(Template):
+ delimiter = '@'
+
+def doxy_config(root_path):
+ """
+ Fetch all Doxygen sub-config files and gather it with the main config file.
+ """
+ confs = []
+ dsrc_path = os.path.join(root_path, "doc", "source")
+ sub = dict(ROOT_DIR=root_path)
+ with open(os.path.join(dsrc_path, "doxyfile"), "r") as fd:
+ conf = DoxyTpl(fd.read())
+ confs.append(conf.substitute(CUR_DIR=dsrc_path, **sub))
+
+ for dpath, _, files in os.walk(root_path):
+ if ".doxyfile" not in files:
+ continue
+ conf_path = os.path.join(dpath, ".doxyfile")
+ with open(conf_path, "r") as fd:
+ conf = DoxyTpl(fd.read())
+ confs.append(conf.substitute(CUR_DIR=dpath, **sub))
+ return confs
+
+
+if __name__ == "__main__":
+ main()
+
diff --git a/doc/release/upcoming_changes/18884.new_feature.rst b/doc/release/upcoming_changes/18884.new_feature.rst
new file mode 100644
index 000000000..41503b00e
--- /dev/null
+++ b/doc/release/upcoming_changes/18884.new_feature.rst
@@ -0,0 +1,7 @@
+Generate C/C++ API reference documentation from comments blocks is now possible
+-------------------------------------------------------------------------------
+This feature depends on Doxygen_ in the generation process and on Breathe_
+to integrate it with Sphinx.
+
+.. _`Doxygen`: https://www.doxygen.nl/index.html
+.. _`Breathe`: https://breathe.readthedocs.io/en/latest/
diff --git a/doc/release/upcoming_changes/19754.new_feature.rst b/doc/release/upcoming_changes/19754.new_feature.rst
new file mode 100644
index 000000000..4e91e4cb3
--- /dev/null
+++ b/doc/release/upcoming_changes/19754.new_feature.rst
@@ -0,0 +1,7 @@
+A ``.clang-format`` file has been added
+---------------------------------------
+Clang-format is a C/C++ code formatter, together with the added
+``.clang-format`` file, it produces code close enough to the NumPy
+C_STYLE_GUIDE for general use. Clang-format version 12+ is required
+due to the use of several new features, it is available in
+Fedora 34 and Ubuntu Focal among other distributions.
diff --git a/doc/source/conf.py b/doc/source/conf.py
index 41b5cee25..d08f29e59 100644
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -2,6 +2,7 @@
import os
import re
import sys
+import importlib
# Minimum version, enforced by sphinx
needs_sphinx = '3.2.0'
@@ -86,6 +87,16 @@ extensions = [
'sphinx.ext.mathjax',
]
+skippable_extensions = [
+ ('breathe', 'skip generating C/C++ API from comment blocks.'),
+]
+for ext, warn in skippable_extensions:
+ ext_exist = importlib.util.find_spec(ext) is not None
+ if ext_exist:
+ extensions.append(ext)
+ else:
+ print(f"Unable to find Sphinx extension '{ext}', {warn}.")
+
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
@@ -477,3 +488,11 @@ class NumPyLexer(CLexer):
inherit,
],
}
+
+
+# -----------------------------------------------------------------------------
+# Breathe & Doxygen
+# -----------------------------------------------------------------------------
+breathe_projects = dict(numpy=os.path.join("..", "build", "doxygen", "xml"))
+breathe_default_project = "numpy"
+breathe_default_members = ("members", "undoc-members", "protected-members")
diff --git a/doc/source/dev/examples/.doxyfile b/doc/source/dev/examples/.doxyfile
new file mode 100644
index 000000000..966c1b636
--- /dev/null
+++ b/doc/source/dev/examples/.doxyfile
@@ -0,0 +1,2 @@
+INPUT += @CUR_DIR
+INCLUDE_PATH += @CUR_DIR
diff --git a/doc/source/dev/examples/doxy_class.hpp b/doc/source/dev/examples/doxy_class.hpp
new file mode 100644
index 000000000..ceba63487
--- /dev/null
+++ b/doc/source/dev/examples/doxy_class.hpp
@@ -0,0 +1,21 @@
+/**
+ * Template to represent limbo numbers.
+ *
+ * Specializations for integer types that are part of nowhere.
+ * It doesn't support with any real types.
+ *
+ * @param Tp Type of the integer. Required to be an integer type.
+ * @param N Number of elements.
+*/
+template<typename Tp, std::size_t N>
+class DoxyLimbo {
+ public:
+ /// Default constructor. Initialize nothing.
+ DoxyLimbo();
+ /// Set Default behavior for copy the limbo.
+ DoxyLimbo(const DoxyLimbo<Tp, N> &l);
+ /// Returns the raw data for the limbo.
+ const Tp *data();
+ protected:
+ Tp p_data[N]; ///< Example for inline comment.
+};
diff --git a/doc/source/dev/examples/doxy_func.h b/doc/source/dev/examples/doxy_func.h
new file mode 100644
index 000000000..792a9d1b7
--- /dev/null
+++ b/doc/source/dev/examples/doxy_func.h
@@ -0,0 +1,11 @@
+/**
+ * This a simple brief.
+ *
+ * And the details goes here.
+ * Multi lines are welcome.
+ *
+ * @param num leave a comment for parameter num.
+ * @param str leave a comment for the second parameter.
+ * @return leave a comment for the returned value.
+ */
+int doxy_javadoc_example(int num, const char *str);
diff --git a/doc/source/dev/examples/doxy_rst.h b/doc/source/dev/examples/doxy_rst.h
new file mode 100644
index 000000000..6ab4a0775
--- /dev/null
+++ b/doc/source/dev/examples/doxy_rst.h
@@ -0,0 +1,15 @@
+/**
+ * A comment block contains reST markup.
+ * @rst
+ * .. note::
+ *
+ * Thanks to Breathe_, we were able to bring it to Doxygen_
+ *
+ * Some code example::
+ *
+ * int example(int x) {
+ * return x * 2;
+ * }
+ * @endrst
+ */
+void doxy_reST_example(void);
diff --git a/doc/source/dev/howto-docs.rst b/doc/source/dev/howto-docs.rst
index 3156d3452..cc17a1feb 100644
--- a/doc/source/dev/howto-docs.rst
+++ b/doc/source/dev/howto-docs.rst
@@ -59,8 +59,8 @@ Obvious **wording** mistakes (like leaving out a "not") fall into the typo
category, but other rewordings -- even for grammar -- require a judgment call,
which raises the bar. Test the waters by first presenting the fix as an issue.
-Some functions/objects like numpy.ndarray.transpose, numpy.array etc. defined in
-C-extension modules have their docstrings defined seperately in `_add_newdocs.py
+Some functions/objects like numpy.ndarray.transpose, numpy.array etc. defined in
+C-extension modules have their docstrings defined seperately in `_add_newdocs.py
<https://github.com/numpy/numpy/blob/main/numpy/core/_add_newdocs.py>`__
**********************
@@ -215,6 +215,219 @@ Note that for documentation within NumPy, it is not necessary to do
Please use the ``numpydoc`` :ref:`formatting standard <numpydoc:format>` as
shown in their :ref:`example <numpydoc:example>`.
+.. _doc_c_code:
+
+Documenting C/C++ Code
+======================
+
+NumPy uses Doxygen_ to parse specially-formatted C/C++ comment blocks. This generates
+XML files, which are converted by Breathe_ into RST, which is used by Sphinx.
+
+**It takes three steps to complete the documentation process**:
+
+1. Writing the comment blocks
+-----------------------------
+
+Although there is still no commenting style set to follow, the Javadoc
+is more preferable than the others due to the similarities with the current
+existing non-indexed comment blocks.
+
+.. note::
+ Please see `"Documenting the code" <https://www.doxygen.nl/manual/docblocks.html>`__.
+
+**This is what Javadoc style looks like**:
+
+.. literalinclude:: examples/doxy_func.h
+
+**And here is how it is rendered**:
+
+.. doxygenfunction:: doxy_javadoc_example
+
+**For line comment, you can use a triple forward slash. For example**:
+
+.. literalinclude:: examples/doxy_class.hpp
+
+**And here is how it is rendered**:
+
+.. doxygenclass:: DoxyLimbo
+
+Common Doxygen Tags:
+++++++++++++++++++++
+
+.. note::
+ For more tags/commands, please take a look at https://www.doxygen.nl/manual/commands.html
+
+``@brief``
+
+Starts a paragraph that serves as a brief description. By default the first sentence
+of the documentation block is automatically treated as a brief description, since
+option `JAVADOC_AUTOBRIEF <https://www.doxygen.nl/manual/config.html#cfg_javadoc_autobrief>`__
+is enabled within doxygen configurations.
+
+``@details``
+
+Just like ``@brief`` starts a brief description, ``@details`` starts the detailed description.
+You can also start a new paragraph (blank line) then the ``@details`` command is not needed.
+
+``@param``
+
+Starts a parameter description for a function parameter with name <parameter-name>,
+followed by a description of the parameter. The existence of the parameter is checked
+and a warning is given if the documentation of this (or any other) parameter is missing
+or not present in the function declaration or definition.
+
+``@return``
+
+Starts a return value description for a function.
+Multiple adjacent ``@return`` commands will be joined into a single paragraph.
+The ``@return`` description ends when a blank line or some other sectioning command is encountered.
+
+``@code/@endcode``
+
+Starts/Ends a block of code. A code block is treated differently from ordinary text.
+It is interpreted as source code.
+
+``@rst/@endrst``
+
+Starts/Ends a block of reST markup.
+
+Example
+~~~~~~~
+**Take a look at the following example**:
+
+.. literalinclude:: examples/doxy_rst.h
+
+**And here is how it is rendered**:
+
+.. doxygenfunction:: doxy_reST_example
+
+2. Feeding Doxygen
+------------------
+
+Not all headers files are collected automatically. You have to add the desired
+C/C++ header paths within the sub-config files of Doxygen.
+
+Sub-config files have the unique name ``.doxyfile``, which you can usually find near
+directories that contain documented headers. You need to create a new config file if
+there's not one located in a path close(2-depth) to the headers you want to add.
+
+Sub-config files can accept any of Doxygen_ `configuration options <https://www.doxygen.nl/manual/config.html>`__,
+but do not override or re-initialize any configuration option,
+rather only use the concatenation operator "+=". For example::
+
+ # to specfiy certain headers
+ INPUT += @CUR_DIR/header1.h \
+ @CUR_DIR/header2.h
+ # to add all headers in certain path
+ INPUT += @CUR_DIR/to/headers
+ # to define certain macros
+ PREDEFINED += C_MACRO(X)=X
+ # to enable certain branches
+ PREDEFINED += NPY_HAVE_FEATURE \
+ NPY_HAVE_FEATURE2
+
+.. note::
+ @CUR_DIR is a template constant returns the current
+ dir path of the sub-config file.
+
+3. Inclusion directives
+-----------------------
+
+Breathe_ provides a wide range of custom directives to allow
+converting the documents generated by Doxygen_ into reST files.
+
+.. note::
+ For more information, please check out "`Directives & Config Variables <https://breathe.readthedocs.io/en/latest/directives.html>`__"
+
+Common directives:
+++++++++++++++++++
+
+``doxygenfunction``
+
+This directive generates the appropriate output for a single function.
+The function name is required to be unique in the project.
+
+.. code::
+
+ .. doxygenfunction:: <function name>
+ :outline:
+ :no-link:
+
+Checkout the `example <https://breathe.readthedocs.io/en/latest/function.html#function-example>`__
+to see it in action.
+
+
+``doxygenclass``
+
+This directive generates the appropriate output for a single class.
+It takes the standard project, path, outline and no-link options and
+additionally the members, protected-members, private-members, undoc-members,
+membergroups and members-only options:
+
+.. code::
+
+ .. doxygenclass:: <class name>
+ :members: [...]
+ :protected-members:
+ :private-members:
+ :undoc-members:
+ :membergroups: ...
+ :members-only:
+ :outline:
+ :no-link:
+
+Checkout the `doxygenclass documentation <https://breathe.readthedocs.io/en/latest/class.html#class-example>_`
+for more details and to see it in action.
+
+``doxygennamespace``
+
+This directive generates the appropriate output for the contents of a namespace.
+It takes the standard project, path, outline and no-link options and additionally the content-only,
+members, protected-members, private-members and undoc-members options.
+To reference a nested namespace, the full namespaced path must be provided,
+e.g. foo::bar for the bar namespace inside the foo namespace.
+
+.. code::
+
+ .. doxygennamespace:: <namespace>
+ :content-only:
+ :outline:
+ :members:
+ :protected-members:
+ :private-members:
+ :undoc-members:
+ :no-link:
+
+Checkout the `doxygennamespace documentation <https://breathe.readthedocs.io/en/latest/namespace.html#namespace-example>`__
+for more details and to see it in action.
+
+``doxygengroup``
+
+This directive generates the appropriate output for the contents of a doxygen group.
+A doxygen group can be declared with specific doxygen markup in the source comments
+as covered in the doxygen `grouping documentation <https://www.doxygen.nl/manual/grouping.html>`__.
+
+It takes the standard project, path, outline and no-link options and additionally the
+content-only, members, protected-members, private-members and undoc-members options.
+
+.. code::
+
+ .. doxygengroup:: <group name>
+ :content-only:
+ :outline:
+ :members:
+ :protected-members:
+ :private-members:
+ :undoc-members:
+ :no-link:
+ :inner:
+
+Checkout the `doxygengroup documentation <https://breathe.readthedocs.io/en/latest/group.html#group-example>`__
+for more details and to see it in action.
+
+.. _`Doxygen`: https://www.doxygen.nl/index.html
+.. _`Breathe`: https://breathe.readthedocs.io/en/latest/
+
*********************
Documentation reading
diff --git a/doc/source/dev/howto_build_docs.rst b/doc/source/dev/howto_build_docs.rst
index 884cf7935..b175926da 100644
--- a/doc/source/dev/howto_build_docs.rst
+++ b/doc/source/dev/howto_build_docs.rst
@@ -58,18 +58,28 @@ new virtual environment is recommended.
Dependencies
^^^^^^^^^^^^
-All of the necessary dependencies for building the NumPy docs can be installed
-with::
+All of the necessary dependencies for building the NumPy docs except for
+Doxygen_ can be installed with::
pip install -r doc_requirements.txt
-We currently use Sphinx_ for generating the API and reference
-documentation for NumPy. In addition, building the documentation requires
-the Sphinx extension `plot_directive`, which is shipped with
+We currently use Sphinx_ along with Doxygen_ for generating the API and
+reference documentation for NumPy. In addition, building the documentation
+requires the Sphinx extension `plot_directive`, which is shipped with
:doc:`Matplotlib <matplotlib:index>`. We also use numpydoc_ to render docstrings in
the generated API documentation. :doc:`SciPy <scipy:index>`
is installed since some parts of the documentation require SciPy functions.
+For installing Doxygen_, please check the official
+`download <https://www.doxygen.nl/download.html#srcbin>`_ and
+`installation <https://www.doxygen.nl/manual/install.html>`_ pages, or if you
+are using Linux then you can install it through your distribution package manager.
+
+.. note::
+
+ Try to install a newer version of Doxygen_ > 1.8.10 otherwise you may get some
+ warnings during the build.
+
Submodules
^^^^^^^^^^
@@ -80,6 +90,7 @@ additional parts required for building the documentation::
.. _Sphinx: http://www.sphinx-doc.org/
.. _numpydoc: https://numpydoc.readthedocs.io/en/latest/index.html
+.. _Doxygen: https://www.doxygen.nl/index.html
Instructions
------------
diff --git a/doc/source/doxyfile b/doc/source/doxyfile
new file mode 100644
index 000000000..ea45b9578
--- /dev/null
+++ b/doc/source/doxyfile
@@ -0,0 +1,340 @@
+# Doxyfile 1.8.18
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+DOXYFILE_ENCODING = UTF-8
+PROJECT_NAME = NumPy
+PROJECT_NUMBER =
+PROJECT_BRIEF = "NumPy is the fundamental package for scientific computing in Python"
+PROJECT_LOGO =
+OUTPUT_DIRECTORY = @ROOT_DIR/doc/build/doxygen
+CREATE_SUBDIRS = NO
+ALLOW_UNICODE_NAMES = NO
+OUTPUT_LANGUAGE = English
+OUTPUT_TEXT_DIRECTION = None
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ABBREVIATE_BRIEF = "The $name class" \
+ "The $name widget" \
+ "The $name file" \
+ is \
+ provides \
+ specifies \
+ contains \
+ represents \
+ a \
+ an \
+ the
+ALWAYS_DETAILED_SEC = NO
+INLINE_INHERITED_MEMB = NO
+FULL_PATH_NAMES = YES
+STRIP_FROM_PATH = @ROOT_DIR
+STRIP_FROM_INC_PATH =
+SHORT_NAMES = NO
+JAVADOC_AUTOBRIEF = YES
+JAVADOC_BANNER = NO
+QT_AUTOBRIEF = NO
+MULTILINE_CPP_IS_BRIEF = NO
+INHERIT_DOCS = YES
+SEPARATE_MEMBER_PAGES = NO
+TAB_SIZE = 4
+ALIASES =
+ALIASES += "rst=\verbatim embed:rst:leading-asterisk"
+ALIASES += "endrst=\endverbatim"
+OPTIMIZE_OUTPUT_FOR_C = NO
+OPTIMIZE_OUTPUT_JAVA = NO
+OPTIMIZE_FOR_FORTRAN = NO
+OPTIMIZE_OUTPUT_VHDL = NO
+OPTIMIZE_OUTPUT_SLICE = NO
+EXTENSION_MAPPING =
+MARKDOWN_SUPPORT = YES
+TOC_INCLUDE_HEADINGS = 5
+AUTOLINK_SUPPORT = YES
+BUILTIN_STL_SUPPORT = NO
+CPP_CLI_SUPPORT = NO
+SIP_SUPPORT = NO
+IDL_PROPERTY_SUPPORT = YES
+DISTRIBUTE_GROUP_DOC = NO
+GROUP_NESTED_COMPOUNDS = NO
+SUBGROUPING = YES
+INLINE_GROUPED_CLASSES = NO
+INLINE_SIMPLE_STRUCTS = NO
+TYPEDEF_HIDES_STRUCT = NO
+LOOKUP_CACHE_SIZE = 0
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+EXTRACT_ALL = NO
+EXTRACT_PRIVATE = NO
+EXTRACT_PRIV_VIRTUAL = NO
+EXTRACT_PACKAGE = NO
+EXTRACT_STATIC = NO
+EXTRACT_LOCAL_CLASSES = YES
+EXTRACT_LOCAL_METHODS = NO
+EXTRACT_ANON_NSPACES = NO
+HIDE_UNDOC_MEMBERS = NO
+HIDE_UNDOC_CLASSES = NO
+HIDE_FRIEND_COMPOUNDS = NO
+HIDE_IN_BODY_DOCS = NO
+INTERNAL_DOCS = NO
+CASE_SENSE_NAMES = YES
+HIDE_SCOPE_NAMES = NO
+HIDE_COMPOUND_REFERENCE= NO
+SHOW_INCLUDE_FILES = YES
+SHOW_GROUPED_MEMB_INC = NO
+FORCE_LOCAL_INCLUDES = NO
+INLINE_INFO = YES
+SORT_MEMBER_DOCS = YES
+SORT_BRIEF_DOCS = NO
+SORT_MEMBERS_CTORS_1ST = NO
+SORT_GROUP_NAMES = NO
+SORT_BY_SCOPE_NAME = NO
+STRICT_PROTO_MATCHING = NO
+GENERATE_TODOLIST = YES
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = YES
+GENERATE_DEPRECATEDLIST= YES
+ENABLED_SECTIONS =
+MAX_INITIALIZER_LINES = 30
+SHOW_USED_FILES = YES
+SHOW_FILES = YES
+SHOW_NAMESPACES = YES
+FILE_VERSION_FILTER =
+LAYOUT_FILE =
+CITE_BIB_FILES =
+#---------------------------------------------------------------------------
+# Configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET = no
+WARNINGS = YES
+WARN_IF_UNDOCUMENTED = YES
+WARN_IF_DOC_ERROR = YES
+WARN_NO_PARAMDOC = NO
+WARN_AS_ERROR = NO
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+#---------------------------------------------------------------------------
+# Configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT =
+INPUT_ENCODING = UTF-8
+FILE_PATTERNS = *.h, *.hpp
+RECURSIVE = YES
+EXCLUDE =
+EXCLUDE_SYMLINKS = NO
+EXCLUDE_PATTERNS =
+EXCLUDE_SYMBOLS =
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS =
+EXAMPLE_RECURSIVE = NO
+IMAGE_PATH =
+INPUT_FILTER =
+FILTER_PATTERNS =
+FILTER_SOURCE_FILES = NO
+FILTER_SOURCE_PATTERNS =
+USE_MDFILE_AS_MAINPAGE =
+#---------------------------------------------------------------------------
+# Configuration options related to source browsing
+#---------------------------------------------------------------------------
+SOURCE_BROWSER = NO
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = YES
+REFERENCED_BY_RELATION = NO
+REFERENCES_RELATION = NO
+REFERENCES_LINK_SOURCE = YES
+SOURCE_TOOLTIPS = YES
+USE_HTAGS = NO
+VERBATIM_HEADERS = YES
+CLANG_ASSISTED_PARSING = NO
+CLANG_OPTIONS =
+CLANG_DATABASE_PATH =
+#---------------------------------------------------------------------------
+# Configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX = YES
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML = NO
+HTML_OUTPUT = html
+HTML_FILE_EXTENSION = .html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_EXTRA_STYLESHEET =
+HTML_EXTRA_FILES =
+HTML_COLORSTYLE_HUE = 220
+HTML_COLORSTYLE_SAT = 100
+HTML_COLORSTYLE_GAMMA = 80
+HTML_TIMESTAMP = NO
+HTML_DYNAMIC_MENUS = YES
+HTML_DYNAMIC_SECTIONS = NO
+HTML_INDEX_NUM_ENTRIES = 100
+GENERATE_DOCSET = NO
+DOCSET_FEEDNAME = "Doxygen generated docs"
+DOCSET_BUNDLE_ID = org.doxygen.Project
+DOCSET_PUBLISHER_ID = org.doxygen.Publisher
+DOCSET_PUBLISHER_NAME = Publisher
+GENERATE_HTMLHELP = NO
+CHM_FILE =
+HHC_LOCATION =
+GENERATE_CHI = NO
+CHM_INDEX_ENCODING =
+BINARY_TOC = NO
+TOC_EXPAND = NO
+GENERATE_QHP = NO
+QCH_FILE =
+QHP_NAMESPACE = org.doxygen.Project
+QHP_VIRTUAL_FOLDER = doc
+QHP_CUST_FILTER_NAME =
+QHP_CUST_FILTER_ATTRS =
+QHP_SECT_FILTER_ATTRS =
+QHG_LOCATION =
+GENERATE_ECLIPSEHELP = NO
+ECLIPSE_DOC_ID = org.doxygen.Project
+DISABLE_INDEX = NO
+GENERATE_TREEVIEW = NO
+ENUM_VALUES_PER_LINE = 4
+TREEVIEW_WIDTH = 250
+EXT_LINKS_IN_WINDOW = NO
+HTML_FORMULA_FORMAT = png
+FORMULA_FONTSIZE = 10
+FORMULA_TRANSPARENT = YES
+FORMULA_MACROFILE =
+USE_MATHJAX = NO
+MATHJAX_FORMAT = HTML-CSS
+MATHJAX_RELPATH = https://cdn.jsdelivr.net/npm/mathjax@@2
+MATHJAX_EXTENSIONS =
+MATHJAX_CODEFILE =
+SEARCHENGINE = YES
+SERVER_BASED_SEARCH = NO
+EXTERNAL_SEARCH = NO
+SEARCHENGINE_URL =
+SEARCHDATA_FILE = searchdata.xml
+EXTERNAL_SEARCH_ID =
+EXTRA_SEARCH_MAPPINGS =
+#---------------------------------------------------------------------------
+# Configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX = NO
+LATEX_OUTPUT = latex
+LATEX_CMD_NAME =
+MAKEINDEX_CMD_NAME = makeindex
+LATEX_MAKEINDEX_CMD = makeindex
+COMPACT_LATEX = NO
+PAPER_TYPE = a4
+EXTRA_PACKAGES =
+LATEX_HEADER =
+LATEX_FOOTER =
+LATEX_EXTRA_STYLESHEET =
+LATEX_EXTRA_FILES =
+PDF_HYPERLINKS = YES
+USE_PDFLATEX = YES
+LATEX_BATCHMODE = NO
+LATEX_HIDE_INDICES = NO
+LATEX_SOURCE_CODE = NO
+LATEX_BIB_STYLE = plain
+LATEX_TIMESTAMP = NO
+LATEX_EMOJI_DIRECTORY =
+#---------------------------------------------------------------------------
+# Configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF = NO
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+RTF_EXTENSIONS_FILE =
+RTF_SOURCE_CODE = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN = NO
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+MAN_SUBDIR =
+MAN_LINKS = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the XML output
+#---------------------------------------------------------------------------
+GENERATE_XML = YES
+XML_OUTPUT = xml
+XML_PROGRAMLISTING = YES
+XML_NS_MEMB_FILE_SCOPE = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the DOCBOOK output
+#---------------------------------------------------------------------------
+GENERATE_DOCBOOK = NO
+DOCBOOK_OUTPUT = docbook
+DOCBOOK_PROGRAMLISTING = NO
+#---------------------------------------------------------------------------
+# Configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+GENERATE_AUTOGEN_DEF = NO
+#---------------------------------------------------------------------------
+# Configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+GENERATE_PERLMOD = NO
+PERLMOD_LATEX = NO
+PERLMOD_PRETTY = YES
+PERLMOD_MAKEVAR_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = YES
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+INCLUDE_FILE_PATTERNS =
+PREDEFINED =
+EXPAND_AS_DEFINED =
+SKIP_FUNCTION_MACROS = YES
+#---------------------------------------------------------------------------
+# Configuration options related to external references
+#---------------------------------------------------------------------------
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = NO
+EXTERNAL_GROUPS = YES
+EXTERNAL_PAGES = YES
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+CLASS_DIAGRAMS = YES
+DIA_PATH =
+HIDE_UNDOC_RELATIONS = YES
+HAVE_DOT = NO
+DOT_NUM_THREADS = 0
+DOT_FONTNAME = Helvetica
+DOT_FONTSIZE = 10
+DOT_FONTPATH =
+CLASS_GRAPH = YES
+COLLABORATION_GRAPH = YES
+GROUP_GRAPHS = YES
+UML_LOOK = NO
+UML_LIMIT_NUM_FIELDS = 10
+TEMPLATE_RELATIONS = NO
+INCLUDE_GRAPH = YES
+INCLUDED_BY_GRAPH = YES
+CALL_GRAPH = NO
+CALLER_GRAPH = NO
+GRAPHICAL_HIERARCHY = YES
+DIRECTORY_GRAPH = YES
+DOT_IMAGE_FORMAT = png
+INTERACTIVE_SVG = NO
+DOT_PATH =
+DOTFILE_DIRS =
+MSCFILE_DIRS =
+DIAFILE_DIRS =
+PLANTUML_JAR_PATH =
+PLANTUML_CFG_FILE =
+PLANTUML_INCLUDE_PATH =
+DOT_GRAPH_MAX_NODES = 50
+MAX_DOT_GRAPH_DEPTH = 0
+DOT_TRANSPARENT = NO
+DOT_MULTI_TARGETS = NO
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
diff --git a/doc/source/user/c-info.ufunc-tutorial.rst b/doc/source/user/c-info.ufunc-tutorial.rst
index 8ff45a934..9bd01b963 100644
--- a/doc/source/user/c-info.ufunc-tutorial.rst
+++ b/doc/source/user/c-info.ufunc-tutorial.rst
@@ -80,6 +80,7 @@ the module.
.. code-block:: c
+ #define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <math.h>
@@ -252,11 +253,12 @@ the primary thing that must be changed to create your own ufunc.
.. code-block:: c
- #include "Python.h"
- #include "math.h"
+ #define PY_SSIZE_T_CLEAN
+ #include <Python.h>
#include "numpy/ndarraytypes.h"
#include "numpy/ufuncobject.h"
#include "numpy/npy_3kcompat.h"
+ #include <math.h>
/*
* single_type_logit.c
@@ -427,11 +429,12 @@ the primary thing that must be changed to create your own ufunc.
.. code-block:: c
- #include "Python.h"
- #include "math.h"
+ #define PY_SSIZE_T_CLEAN
+ #include <Python.h>
#include "numpy/ndarraytypes.h"
#include "numpy/ufuncobject.h"
#include "numpy/halffloat.h"
+ #include <math.h>
/*
* multi_type_logit.c
@@ -696,11 +699,12 @@ as well as all other properties of a ufunc.
.. code-block:: c
- #include "Python.h"
- #include "math.h"
+ #define PY_SSIZE_T_CLEAN
+ #include <Python.h>
#include "numpy/ndarraytypes.h"
#include "numpy/ufuncobject.h"
#include "numpy/halffloat.h"
+ #include <math.h>
/*
* multi_arg_logit.c
@@ -828,11 +832,12 @@ The C file is given below.
.. code-block:: c
- #include "Python.h"
- #include "math.h"
+ #define PY_SSIZE_T_CLEAN
+ #include <Python.h>
#include "numpy/ndarraytypes.h"
#include "numpy/ufuncobject.h"
#include "numpy/npy_3kcompat.h"
+ #include <math.h>
/*
diff --git a/doc_requirements.txt b/doc_requirements.txt
index 61ce7549b..4eebb5519 100644
--- a/doc_requirements.txt
+++ b/doc_requirements.txt
@@ -5,3 +5,4 @@ scipy
matplotlib
pandas
pydata-sphinx-theme
+breathe
diff --git a/numpy/array_api/_typing.py b/numpy/array_api/_typing.py
index d530a91ae..831a108bc 100644
--- a/numpy/array_api/_typing.py
+++ b/numpy/array_api/_typing.py
@@ -37,7 +37,7 @@ NestedSequence = Sequence[Sequence[Any]]
Device = Any
Dtype = Type[
- Union[[int8, int16, int32, int64, uint8, uint16, uint32, uint64, float32, float64]]
+ Union[int8, int16, int32, int64, uint8, uint16, uint32, uint64, float32, float64]
]
SupportsDLPack = Any
SupportsBufferProtocol = Any
diff --git a/numpy/core/include/numpy/.doxyfile b/numpy/core/include/numpy/.doxyfile
new file mode 100644
index 000000000..ed2aefff7
--- /dev/null
+++ b/numpy/core/include/numpy/.doxyfile
@@ -0,0 +1,2 @@
+INCLUDE_PATH += @CUR_DIR
+PREDEFINED += NPY_INTERNAL_BUILD
diff --git a/numpy/core/include/numpy/random/distributions.h b/numpy/core/include/numpy/random/distributions.h
index 554198174..434e052f5 100644
--- a/numpy/core/include/numpy/random/distributions.h
+++ b/numpy/core/include/numpy/random/distributions.h
@@ -5,7 +5,7 @@
extern "C" {
#endif
-#include "Python.h"
+#include <Python.h>
#include "numpy/npy_common.h"
#include <stddef.h>
#include <stdbool.h>
diff --git a/numpy/core/src/common/.doxyfile b/numpy/core/src/common/.doxyfile
new file mode 100644
index 000000000..462cbbcfa
--- /dev/null
+++ b/numpy/core/src/common/.doxyfile
@@ -0,0 +1 @@
+INCLUDE_PATH += @CUR_DIR
diff --git a/numpy/core/src/common/array_assign.c b/numpy/core/src/common/array_assign.c
index c55f6bdb4..b7495fc09 100644
--- a/numpy/core/src/common/array_assign.c
+++ b/numpy/core/src/common/array_assign.c
@@ -7,12 +7,12 @@
*
* See LICENSE.txt for the license.
*/
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include <numpy/ndarraytypes.h>
#include "npy_config.h"
#include "npy_pycompat.h"
diff --git a/numpy/core/src/common/cblasfuncs.c b/numpy/core/src/common/cblasfuncs.c
index e78587de0..714636782 100644
--- a/numpy/core/src/common/cblasfuncs.c
+++ b/numpy/core/src/common/cblasfuncs.c
@@ -2,17 +2,19 @@
* This module provides a BLAS optimized matrix multiply,
* inner product and dot for numpy arrays
*/
-
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include <assert.h>
-#include <numpy/arrayobject.h>
+
+#include "numpy/arrayobject.h"
#include "npy_cblas.h"
#include "arraytypes.h"
#include "common.h"
+#include <assert.h>
+
static const double oneD[2] = {1.0, 0.0}, zeroD[2] = {0.0, 0.0};
static const float oneF[2] = {1.0, 0.0}, zeroF[2] = {0.0, 0.0};
diff --git a/numpy/core/src/common/lowlevel_strided_loops.h b/numpy/core/src/common/lowlevel_strided_loops.h
index 3df054b40..2bbe4d100 100644
--- a/numpy/core/src/common/lowlevel_strided_loops.h
+++ b/numpy/core/src/common/lowlevel_strided_loops.h
@@ -1,8 +1,8 @@
#ifndef __LOWLEVEL_STRIDED_LOOPS_H
#define __LOWLEVEL_STRIDED_LOOPS_H
#include "common.h"
-#include <npy_config.h>
-#include <array_method.h>
+#include "npy_config.h"
+#include "array_method.h"
#include "dtype_transfer.h"
#include "mem_overlap.h"
diff --git a/numpy/core/src/common/mem_overlap.c b/numpy/core/src/common/mem_overlap.c
index 9da33bfc1..2632e1413 100644
--- a/numpy/core/src/common/mem_overlap.c
+++ b/numpy/core/src/common/mem_overlap.c
@@ -181,9 +181,11 @@
All rights reserved.
Licensed under 3-clause BSD license, see LICENSE.txt.
*/
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#include "numpy/ndarraytypes.h"
#include "mem_overlap.h"
#include "npy_extint128.h"
diff --git a/numpy/core/src/common/npy_argparse.c b/numpy/core/src/common/npy_argparse.c
index 8460a38e6..76123c1ed 100644
--- a/numpy/core/src/common/npy_argparse.c
+++ b/numpy/core/src/common/npy_argparse.c
@@ -1,8 +1,9 @@
-#include "Python.h"
-
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+
#include "numpy/ndarraytypes.h"
#include "npy_argparse.h"
#include "npy_pycompat.h"
diff --git a/numpy/core/src/common/npy_argparse.h b/numpy/core/src/common/npy_argparse.h
index 5da535c91..487619d6d 100644
--- a/numpy/core/src/common/npy_argparse.h
+++ b/numpy/core/src/common/npy_argparse.h
@@ -1,7 +1,7 @@
#ifndef _NPY_ARGPARSE_H
#define _NPY_ARGPARSE_H
-#include "Python.h"
+#include <Python.h>
#include "numpy/ndarraytypes.h"
/*
diff --git a/numpy/core/src/common/npy_longdouble.c b/numpy/core/src/common/npy_longdouble.c
index 260e02a64..38dfd325c 100644
--- a/numpy/core/src/common/npy_longdouble.c
+++ b/numpy/core/src/common/npy_longdouble.c
@@ -1,8 +1,9 @@
-#include <Python.h>
-
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+
#include "numpy/ndarraytypes.h"
#include "numpy/npy_math.h"
#include "npy_pycompat.h"
diff --git a/numpy/core/src/common/numpyos.c b/numpy/core/src/common/numpyos.c
index 42a71777b..4551a06a2 100644
--- a/numpy/core/src/common/numpyos.c
+++ b/numpy/core/src/common/numpyos.c
@@ -1,11 +1,9 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include <locale.h>
-#include <stdio.h>
-
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/npy_math.h"
@@ -13,14 +11,13 @@
#include "npy_pycompat.h"
+#include <locale.h>
+#include <stdio.h>
+
#ifdef HAVE_STRTOLD_L
#include <stdlib.h>
#ifdef HAVE_XLOCALE_H
- /*
- * the defines from xlocale.h are included in locale.h on some systems;
- * see gh-8367
- */
- #include <xlocale.h>
+#include <xlocale.h> // xlocale was removed in glibc 2.26, see gh-8367
#endif
#endif
diff --git a/numpy/core/src/common/python_xerbla.c b/numpy/core/src/common/python_xerbla.c
index fe2f718b2..37a41408b 100644
--- a/numpy/core/src/common/python_xerbla.c
+++ b/numpy/core/src/common/python_xerbla.c
@@ -1,4 +1,6 @@
-#include "Python.h"
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+
#include "numpy/npy_common.h"
#include "npy_cblas.h"
diff --git a/numpy/core/src/common/ucsnarrow.c b/numpy/core/src/common/ucsnarrow.c
index 3ef5d6878..4bea4beee 100644
--- a/numpy/core/src/common/ucsnarrow.c
+++ b/numpy/core/src/common/ucsnarrow.c
@@ -1,12 +1,9 @@
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include <locale.h>
-#include <stdio.h>
-
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/npy_math.h"
diff --git a/numpy/core/src/dummymodule.c b/numpy/core/src/dummymodule.c
index e26875736..7284ffd68 100644
--- a/numpy/core/src/dummymodule.c
+++ b/numpy/core/src/dummymodule.c
@@ -4,12 +4,13 @@
* This is a dummy module whose purpose is to get distutils to generate the
* configuration files before the libraries are made.
*/
-
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define NO_IMPORT_ARRAY
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include <npy_pycompat.h>
+
+#include "npy_pycompat.h"
static struct PyMethodDef methods[] = {
{NULL, NULL, 0, NULL}
diff --git a/numpy/core/src/multiarray/_multiarray_tests.c.src b/numpy/core/src/multiarray/_multiarray_tests.c.src
index f4764b371..e945d0771 100644
--- a/numpy/core/src/multiarray/_multiarray_tests.c.src
+++ b/numpy/core/src/multiarray/_multiarray_tests.c.src
@@ -1,8 +1,8 @@
/* -*-c-*- */
#define PY_SSIZE_T_CLEAN
+#include <Python.h>
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#include <Python.h>
#define _NPY_NO_DEPRECATIONS /* for NPY_CHAR */
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
diff --git a/numpy/core/src/multiarray/abstractdtypes.c b/numpy/core/src/multiarray/abstractdtypes.c
index 3fa354ddc..99573f089 100644
--- a/numpy/core/src/multiarray/abstractdtypes.c
+++ b/numpy/core/src/multiarray/abstractdtypes.c
@@ -1,10 +1,10 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/ndarraytypes.h"
#include "numpy/arrayobject.h"
diff --git a/numpy/core/src/multiarray/alloc.c b/numpy/core/src/multiarray/alloc.c
index e74056736..adb4ae128 100644
--- a/numpy/core/src/multiarray/alloc.c
+++ b/numpy/core/src/multiarray/alloc.c
@@ -1,20 +1,18 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
-
+#include <structmember.h>
#include <pymem.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
-#include <numpy/ndarraytypes.h>
+#include "numpy/ndarraytypes.h"
#include "numpy/arrayobject.h"
-#include <numpy/npy_common.h>
+#include "numpy/npy_common.h"
#include "npy_config.h"
#include "alloc.h"
-
#include <assert.h>
-
#ifdef NPY_OS_LINUX
#include <sys/mman.h>
#ifndef MADV_HUGEPAGE
diff --git a/numpy/core/src/multiarray/array_assign_array.c b/numpy/core/src/multiarray/array_assign_array.c
index 665dadfbf..020a7f29a 100644
--- a/numpy/core/src/multiarray/array_assign_array.c
+++ b/numpy/core/src/multiarray/array_assign_array.c
@@ -6,13 +6,13 @@
*
* See LICENSE.txt for the license.
*/
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
-#include <numpy/ndarraytypes.h>
+#include "numpy/ndarraytypes.h"
#include "npy_config.h"
#include "npy_pycompat.h"
diff --git a/numpy/core/src/multiarray/array_assign_scalar.c b/numpy/core/src/multiarray/array_assign_scalar.c
index 6cd5f4ad9..4ffef7ecc 100644
--- a/numpy/core/src/multiarray/array_assign_scalar.c
+++ b/numpy/core/src/multiarray/array_assign_scalar.c
@@ -6,12 +6,12 @@
*
* See LICENSE.txt for the license.
*/
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include <numpy/ndarraytypes.h>
#include "npy_config.h"
diff --git a/numpy/core/src/multiarray/array_coercion.c b/numpy/core/src/multiarray/array_coercion.c
index 89719f129..90b50097a 100644
--- a/numpy/core/src/multiarray/array_coercion.c
+++ b/numpy/core/src/multiarray/array_coercion.c
@@ -1,8 +1,9 @@
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _UMATHMODULE
#define _MULTIARRAYMODULE
+#define _UMATHMODULE
-#include "Python.h"
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
#include "numpy/npy_3kcompat.h"
diff --git a/numpy/core/src/multiarray/array_method.c b/numpy/core/src/multiarray/array_method.c
index 44ba8c733..816c9e271 100644
--- a/numpy/core/src/multiarray/array_method.c
+++ b/numpy/core/src/multiarray/array_method.c
@@ -26,10 +26,9 @@
* It is then sufficient for a ufunc (or other owner) to only hold a
* weak reference to the input DTypes.
*/
-
-
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
+
#include <npy_pycompat.h>
#include "arrayobject.h"
#include "array_method.h"
diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c
index 55ba5601b..d653bfc22 100644
--- a/numpy/core/src/multiarray/arrayobject.c
+++ b/numpy/core/src/multiarray/arrayobject.c
@@ -20,13 +20,13 @@ maintainer email: oliphant.travis@ieee.org
Space Science Telescope Institute
(J. Todd Miller, Perry Greenfield, Rick White)
*/
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-/*#include <stdio.h>*/
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src
index b3ea7544d..c0c087056 100644
--- a/numpy/core/src/multiarray/arraytypes.c.src
+++ b/numpy/core/src/multiarray/arraytypes.c.src
@@ -1,7 +1,7 @@
/* -*- c -*- */
#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "structmember.h"
+#include <Python.h>
+#include <structmember.h>
#include <limits.h>
#include <assert.h>
diff --git a/numpy/core/src/multiarray/buffer.c b/numpy/core/src/multiarray/buffer.c
index 5458c81cc..d10122c4f 100644
--- a/numpy/core/src/multiarray/buffer.c
+++ b/numpy/core/src/multiarray/buffer.c
@@ -1,9 +1,10 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
diff --git a/numpy/core/src/multiarray/calculation.c b/numpy/core/src/multiarray/calculation.c
index 21e52c32b..327f685d4 100644
--- a/numpy/core/src/multiarray/calculation.c
+++ b/numpy/core/src/multiarray/calculation.c
@@ -1,9 +1,10 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "lowlevel_strided_loops.h"
diff --git a/numpy/core/src/multiarray/common.c b/numpy/core/src/multiarray/common.c
index 1fd9ab1a3..82d34193d 100644
--- a/numpy/core/src/multiarray/common.c
+++ b/numpy/core/src/multiarray/common.c
@@ -1,8 +1,9 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "npy_config.h"
diff --git a/numpy/core/src/multiarray/common.h b/numpy/core/src/multiarray/common.h
index 203decaa0..3251da480 100644
--- a/numpy/core/src/multiarray/common.h
+++ b/numpy/core/src/multiarray/common.h
@@ -1,6 +1,6 @@
#ifndef _NPY_PRIVATE_COMMON_H_
#define _NPY_PRIVATE_COMMON_H_
-#include "structmember.h"
+#include <structmember.h>
#include <numpy/npy_common.h>
#include <numpy/ndarraytypes.h>
#include <limits.h>
diff --git a/numpy/core/src/multiarray/common_dtype.c b/numpy/core/src/multiarray/common_dtype.c
index 659580c98..ca80b1ed7 100644
--- a/numpy/core/src/multiarray/common_dtype.c
+++ b/numpy/core/src/multiarray/common_dtype.c
@@ -1,9 +1,10 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
-#include <numpy/npy_common.h>
+#include "numpy/npy_common.h"
#include "numpy/arrayobject.h"
#include "common_dtype.h"
diff --git a/numpy/core/src/multiarray/compiled_base.c b/numpy/core/src/multiarray/compiled_base.c
index de793f87c..efe120b80 100644
--- a/numpy/core/src/multiarray/compiled_base.c
+++ b/numpy/core/src/multiarray/compiled_base.c
@@ -1,9 +1,10 @@
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <structmember.h>
-#include <string.h>
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/npy_3kcompat.h"
#include "numpy/npy_math.h"
@@ -15,6 +16,8 @@
#include "common.h"
#include "simd/simd.h"
+#include <string.h>
+
typedef enum {
PACK_ORDER_LITTLE = 0,
PACK_ORDER_BIG
diff --git a/numpy/core/src/multiarray/conversion_utils.c b/numpy/core/src/multiarray/conversion_utils.c
index adfff1129..6de764fb1 100644
--- a/numpy/core/src/multiarray/conversion_utils.c
+++ b/numpy/core/src/multiarray/conversion_utils.c
@@ -1,9 +1,10 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
diff --git a/numpy/core/src/multiarray/convert.c b/numpy/core/src/multiarray/convert.c
index 2ad8d6d0e..2f68db07c 100644
--- a/numpy/core/src/multiarray/convert.c
+++ b/numpy/core/src/multiarray/convert.c
@@ -1,11 +1,12 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-#include <npy_config.h>
+#include "npy_config.h"
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
#include "npy_pycompat.h"
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c
index 45b03a6f3..b6755e91d 100644
--- a/numpy/core/src/multiarray/convert_datatype.c
+++ b/numpy/core/src/multiarray/convert_datatype.c
@@ -1,9 +1,10 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
diff --git a/numpy/core/src/multiarray/convert_datatype.h b/numpy/core/src/multiarray/convert_datatype.h
index 22b3859d2..e5fc23972 100644
--- a/numpy/core/src/multiarray/convert_datatype.h
+++ b/numpy/core/src/multiarray/convert_datatype.h
@@ -78,9 +78,9 @@ PyArray_CheckCastSafety(NPY_CASTING casting,
NPY_NO_EXPORT NPY_CASTING
legacy_same_dtype_resolve_descriptors(
PyArrayMethodObject *self,
- PyArray_DTypeMeta **dtypes,
- PyArray_Descr **given_descrs,
- PyArray_Descr **loop_descrs);
+ PyArray_DTypeMeta *dtypes[2],
+ PyArray_Descr *given_descrs[2],
+ PyArray_Descr *loop_descrs[2]);
NPY_NO_EXPORT int
legacy_cast_get_strided_loop(
@@ -92,9 +92,9 @@ legacy_cast_get_strided_loop(
NPY_NO_EXPORT NPY_CASTING
simple_cast_resolve_descriptors(
PyArrayMethodObject *self,
- PyArray_DTypeMeta **dtypes,
- PyArray_Descr **input_descrs,
- PyArray_Descr **loop_descrs);
+ PyArray_DTypeMeta *dtypes[2],
+ PyArray_Descr *input_descrs[2],
+ PyArray_Descr *loop_descrs[2]);
NPY_NO_EXPORT int
PyArray_InitializeCasts(void);
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index ee8f27ebb..73d864a4d 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -1,9 +1,10 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
diff --git a/numpy/core/src/multiarray/datetime.c b/numpy/core/src/multiarray/datetime.c
index 182eb12f9..093090b4c 100644
--- a/numpy/core/src/multiarray/datetime.c
+++ b/numpy/core/src/multiarray/datetime.c
@@ -6,16 +6,13 @@
*
* See LICENSE.txt for the license.
*/
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include <datetime.h>
-#include <time.h>
-
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
-#include <numpy/arrayobject.h>
+#include "numpy/arrayobject.h"
#include "npy_config.h"
#include "npy_pycompat.h"
@@ -30,7 +27,11 @@
#include "usertypes.h"
#include "dtype_transfer.h"
-#include <lowlevel_strided_loops.h>
+#include "lowlevel_strided_loops.h"
+
+#include <datetime.h>
+#include <time.h>
+
/*
* Computes the python `ret, d = divmod(d, unit)`.
diff --git a/numpy/core/src/multiarray/datetime_busday.c b/numpy/core/src/multiarray/datetime_busday.c
index f0564146d..d3e9e1451 100644
--- a/numpy/core/src/multiarray/datetime_busday.c
+++ b/numpy/core/src/multiarray/datetime_busday.c
@@ -6,12 +6,12 @@
*
* See LICENSE.txt for the license.
*/
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include <numpy/arrayobject.h>
#include "npy_config.h"
diff --git a/numpy/core/src/multiarray/datetime_busdaycal.c b/numpy/core/src/multiarray/datetime_busdaycal.c
index e3e729d3c..880efe934 100644
--- a/numpy/core/src/multiarray/datetime_busdaycal.c
+++ b/numpy/core/src/multiarray/datetime_busdaycal.c
@@ -7,19 +7,19 @@
*
* See LICENSE.txt for the license.
*/
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
-#include <numpy/arrayobject.h>
+#include "numpy/arrayobject.h"
+#include "numpy/arrayscalars.h"
#include "npy_config.h"
#include "npy_pycompat.h"
#include "common.h"
-#include "numpy/arrayscalars.h"
#include "lowlevel_strided_loops.h"
#include "_datetime.h"
#include "datetime_busday.h"
diff --git a/numpy/core/src/multiarray/datetime_strings.c b/numpy/core/src/multiarray/datetime_strings.c
index 360868568..5080647cb 100644
--- a/numpy/core/src/multiarray/datetime_strings.c
+++ b/numpy/core/src/multiarray/datetime_strings.c
@@ -6,15 +6,14 @@
*
* See LICENSE.txt for the license.
*/
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include <time.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
-#include <numpy/arrayobject.h>
+#include "numpy/arrayobject.h"
#include "npy_config.h"
#include "npy_pycompat.h"
@@ -24,6 +23,8 @@
#include "_datetime.h"
#include "datetime_strings.h"
+#include <time.h>
+
/*
* Platform-specific time_t typedef. Some platforms use 32 bit, some use 64 bit
* and we just use the default with the exception of mingw, where we must use
diff --git a/numpy/core/src/multiarray/descriptor.c b/numpy/core/src/multiarray/descriptor.c
index 90453e38f..397768f19 100644
--- a/numpy/core/src/multiarray/descriptor.c
+++ b/numpy/core/src/multiarray/descriptor.c
@@ -1,11 +1,11 @@
/* Array Descr Object */
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
diff --git a/numpy/core/src/multiarray/dragon4.h b/numpy/core/src/multiarray/dragon4.h
index 4b76bf9e5..d1b799f68 100644
--- a/numpy/core/src/multiarray/dragon4.h
+++ b/numpy/core/src/multiarray/dragon4.h
@@ -33,8 +33,8 @@
#ifndef _NPY_DRAGON4_H_
#define _NPY_DRAGON4_H_
-#include "Python.h"
-#include "structmember.h"
+#include <Python.h>
+#include <structmember.h>
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
diff --git a/numpy/core/src/multiarray/dtype_transfer.c b/numpy/core/src/multiarray/dtype_transfer.c
index 50db627ea..8fb44c4f6 100644
--- a/numpy/core/src/multiarray/dtype_transfer.c
+++ b/numpy/core/src/multiarray/dtype_transfer.c
@@ -7,16 +7,16 @@
* The University of British Columbia
*
* See LICENSE.txt for the license.
-
+ *
*/
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "structmember.h"
+#include <Python.h>
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
-#include <numpy/arrayobject.h>
+#include "numpy/arrayobject.h"
#include "lowlevel_strided_loops.h"
#include "npy_pycompat.h"
diff --git a/numpy/core/src/multiarray/dtypemeta.c b/numpy/core/src/multiarray/dtypemeta.c
index 597468c50..059ec201e 100644
--- a/numpy/core/src/multiarray/dtypemeta.c
+++ b/numpy/core/src/multiarray/dtypemeta.c
@@ -1,12 +1,11 @@
/* Array Descr Object */
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
-#include "assert.h"
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include <numpy/ndarraytypes.h>
#include <numpy/arrayscalars.h>
#include "npy_pycompat.h"
@@ -19,6 +18,7 @@
#include "convert_datatype.h"
#include "usertypes.h"
+#include <assert.h>
static void
dtypemeta_dealloc(PyArray_DTypeMeta *self) {
diff --git a/numpy/core/src/multiarray/einsum.c.src b/numpy/core/src/multiarray/einsum.c.src
index 85806fab3..cd1a58982 100644
--- a/numpy/core/src/multiarray/einsum.c.src
+++ b/numpy/core/src/multiarray/einsum.c.src
@@ -9,8 +9,8 @@
*/
#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "structmember.h"
+#include <Python.h>
+#include <structmember.h>
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
diff --git a/numpy/core/src/multiarray/flagsobject.c b/numpy/core/src/multiarray/flagsobject.c
index fe73c18ee..3b1b4f406 100644
--- a/numpy/core/src/multiarray/flagsobject.c
+++ b/numpy/core/src/multiarray/flagsobject.c
@@ -1,11 +1,11 @@
/* Array Flags Object */
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "arrayobject.h"
#include "numpy/arrayscalars.h"
diff --git a/numpy/core/src/multiarray/getset.c b/numpy/core/src/multiarray/getset.c
index de2a8c14e..2c8d1b3b4 100644
--- a/numpy/core/src/multiarray/getset.c
+++ b/numpy/core/src/multiarray/getset.c
@@ -1,11 +1,11 @@
/* Array Descr Object */
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "npy_config.h"
diff --git a/numpy/core/src/multiarray/hashdescr.c b/numpy/core/src/multiarray/hashdescr.c
index e9a99cc8f..a3c9e986b 100644
--- a/numpy/core/src/multiarray/hashdescr.c
+++ b/numpy/core/src/multiarray/hashdescr.c
@@ -1,7 +1,9 @@
-#define PY_SSIZE_T_CLEAN
-#include <Python.h>
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
+
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+
#include <numpy/arrayobject.h>
#include "npy_config.h"
diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c
index 2b8ea9e79..ad5478bbf 100644
--- a/numpy/core/src/multiarray/item_selection.c
+++ b/numpy/core/src/multiarray/item_selection.c
@@ -1,10 +1,10 @@
-#define PY_SSIZE_T_CLEAN
-#include <Python.h>
-#include "structmember.h"
-
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+#include <structmember.h>
+
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
diff --git a/numpy/core/src/multiarray/iterators.c b/numpy/core/src/multiarray/iterators.c
index f724837ce..36bfaa7cf 100644
--- a/numpy/core/src/multiarray/iterators.c
+++ b/numpy/core/src/multiarray/iterators.c
@@ -1,9 +1,10 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
diff --git a/numpy/core/src/multiarray/legacy_dtype_implementation.c b/numpy/core/src/multiarray/legacy_dtype_implementation.c
index 9b4946da3..72a52d7a8 100644
--- a/numpy/core/src/multiarray/legacy_dtype_implementation.c
+++ b/numpy/core/src/multiarray/legacy_dtype_implementation.c
@@ -6,9 +6,9 @@
* until such a time where legay user dtypes are deprecated and removed
* entirely.
*/
-
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
+
#include "numpy/arrayobject.h"
#include "scalartypes.h"
#include "_datetime.h"
diff --git a/numpy/core/src/multiarray/lowlevel_strided_loops.c.src b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
index e38873746..b32664cc9 100644
--- a/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
+++ b/numpy/core/src/multiarray/lowlevel_strided_loops.c.src
@@ -9,7 +9,7 @@
*/
#define PY_SSIZE_T_CLEAN
-#include "Python.h"
+#include <Python.h>
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c
index 41311b03f..014a863d5 100644
--- a/numpy/core/src/multiarray/mapping.c
+++ b/numpy/core/src/multiarray/mapping.c
@@ -1,10 +1,10 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-/*#include <stdio.h>*/
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "arrayobject.h"
diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c
index dc23b3471..2c10817fa 100644
--- a/numpy/core/src/multiarray/methods.c
+++ b/numpy/core/src/multiarray/methods.c
@@ -1,14 +1,14 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
-#include <stdarg.h>
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
-#include "arrayobject.h"
#include "numpy/arrayscalars.h"
+#include "arrayobject.h"
#include "arrayfunction_override.h"
#include "npy_argparse.h"
#include "npy_config.h"
@@ -30,6 +30,8 @@
#include "methods.h"
#include "alloc.h"
+#include <stdarg.h>
+
/* NpyArg_ParseKeywords
*
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c
index 232b29b5e..3b70424a5 100644
--- a/numpy/core/src/multiarray/multiarraymodule.c
+++ b/numpy/core/src/multiarray/multiarraymodule.c
@@ -11,16 +11,14 @@
oliphant@ee.byu.edu
Brigham Young University
*/
-
-/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */
-
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "structmember.h"
-
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _UMATHMODULE
#define _MULTIARRAYMODULE
+
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+#include <structmember.h>
+
#include <numpy/npy_common.h>
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
diff --git a/numpy/core/src/multiarray/nditer_api.c b/numpy/core/src/multiarray/nditer_api.c
index a1ca5bff5..811eece7d 100644
--- a/numpy/core/src/multiarray/nditer_api.c
+++ b/numpy/core/src/multiarray/nditer_api.c
@@ -11,8 +11,9 @@
*/
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-/* Indicate that this .c file is allowed to include the header */
+/* Allow this .c file to include nditer_impl.h */
#define NPY_ITERATOR_IMPLEMENTATION_CODE
+
#include "nditer_impl.h"
#include "templ_common.h"
#include "ctors.h"
diff --git a/numpy/core/src/multiarray/nditer_constr.c b/numpy/core/src/multiarray/nditer_constr.c
index 98d4f5a75..57dbb3a94 100644
--- a/numpy/core/src/multiarray/nditer_constr.c
+++ b/numpy/core/src/multiarray/nditer_constr.c
@@ -11,10 +11,10 @@
*/
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-/* Indicate that this .c file is allowed to include the header */
+/* Allow this .c file to include nditer_impl.h */
#define NPY_ITERATOR_IMPLEMENTATION_CODE
-#include "nditer_impl.h"
+#include "nditer_impl.h"
#include "arrayobject.h"
#include "array_coercion.h"
#include "templ_common.h"
diff --git a/numpy/core/src/multiarray/nditer_impl.h b/numpy/core/src/multiarray/nditer_impl.h
index a5a9177e5..6499e4895 100644
--- a/numpy/core/src/multiarray/nditer_impl.h
+++ b/numpy/core/src/multiarray/nditer_impl.h
@@ -11,8 +11,8 @@
#define _NPY_PRIVATE__NDITER_IMPL_H_
#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "structmember.h"
+#include <Python.h>
+#include <structmember.h>
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
diff --git a/numpy/core/src/multiarray/nditer_pywrap.c b/numpy/core/src/multiarray/nditer_pywrap.c
index 8acc7f87f..8e072d5f4 100644
--- a/numpy/core/src/multiarray/nditer_pywrap.c
+++ b/numpy/core/src/multiarray/nditer_pywrap.c
@@ -6,13 +6,14 @@
*
* See LICENSE.txt for the license.
*/
-#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "structmember.h"
-
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
-#include <numpy/arrayobject.h>
+
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+#include <structmember.h>
+
+#include "numpy/arrayobject.h"
#include "npy_config.h"
#include "npy_pycompat.h"
#include "alloc.h"
diff --git a/numpy/core/src/multiarray/number.c b/numpy/core/src/multiarray/number.c
index 9ed7cde47..292ef55a6 100644
--- a/numpy/core/src/multiarray/number.c
+++ b/numpy/core/src/multiarray/number.c
@@ -1,10 +1,10 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-/*#include <stdio.h>*/
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "npy_config.h"
diff --git a/numpy/core/src/multiarray/refcount.c b/numpy/core/src/multiarray/refcount.c
index 41dd059b0..a1c310700 100644
--- a/numpy/core/src/multiarray/refcount.c
+++ b/numpy/core/src/multiarray/refcount.c
@@ -2,13 +2,13 @@
* This module corresponds to the `Special functions for NPY_OBJECT`
* section in the numpy reference for C-API.
*/
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
#include "iterators.h"
diff --git a/numpy/core/src/multiarray/scalarapi.c b/numpy/core/src/multiarray/scalarapi.c
index 0e93cbbe9..e409e9874 100644
--- a/numpy/core/src/multiarray/scalarapi.c
+++ b/numpy/core/src/multiarray/scalarapi.c
@@ -1,9 +1,10 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src
index 740ec8cc2..4faa647ec 100644
--- a/numpy/core/src/multiarray/scalartypes.c.src
+++ b/numpy/core/src/multiarray/scalartypes.c.src
@@ -1,7 +1,7 @@
/* -*- c -*- */
#define PY_SSIZE_T_CLEAN
-#include "Python.h"
-#include "structmember.h"
+#include <Python.h>
+#include <structmember.h>
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#ifndef _MULTIARRAYMODULE
diff --git a/numpy/core/src/multiarray/sequence.c b/numpy/core/src/multiarray/sequence.c
index 1c74f1719..8db0690a1 100644
--- a/numpy/core/src/multiarray/sequence.c
+++ b/numpy/core/src/multiarray/sequence.c
@@ -1,9 +1,10 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
diff --git a/numpy/core/src/multiarray/shape.c b/numpy/core/src/multiarray/shape.c
index 02c349759..5a4e8c0f3 100644
--- a/numpy/core/src/multiarray/shape.c
+++ b/numpy/core/src/multiarray/shape.c
@@ -1,9 +1,10 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
diff --git a/numpy/core/src/multiarray/strfuncs.c b/numpy/core/src/multiarray/strfuncs.c
index d9d9b7c0a..ba457f4f4 100644
--- a/numpy/core/src/multiarray/strfuncs.c
+++ b/numpy/core/src/multiarray/strfuncs.c
@@ -1,8 +1,10 @@
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include <numpy/arrayobject.h>
+
+#include "numpy/arrayobject.h"
#include "npy_pycompat.h"
#include "npy_import.h"
#include "strfuncs.h"
diff --git a/numpy/core/src/multiarray/temp_elide.c b/numpy/core/src/multiarray/temp_elide.c
index 2b4621744..f615aa336 100644
--- a/numpy/core/src/multiarray/temp_elide.c
+++ b/numpy/core/src/multiarray/temp_elide.c
@@ -1,8 +1,9 @@
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "npy_config.h"
#include "numpy/arrayobject.h"
diff --git a/numpy/core/src/multiarray/typeinfo.c b/numpy/core/src/multiarray/typeinfo.c
index b0563b3c0..8cf6bc1e0 100644
--- a/numpy/core/src/multiarray/typeinfo.c
+++ b/numpy/core/src/multiarray/typeinfo.c
@@ -3,6 +3,10 @@
* Unfortunately, we need two different types to cover the cases where min/max
* do and do not appear in the tuple.
*/
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
+#include "npy_pycompat.h"
#include "typeinfo.h"
#if (defined(PYPY_VERSION_NUM) && (PYPY_VERSION_NUM <= 0x07030000))
@@ -10,9 +14,6 @@
#include <structseq.h>
#endif
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
-#include "npy_pycompat.h"
static PyTypeObject PyArray_typeinfoType;
diff --git a/numpy/core/src/multiarray/usertypes.c b/numpy/core/src/multiarray/usertypes.c
index 5602304e9..d0cf53576 100644
--- a/numpy/core/src/multiarray/usertypes.c
+++ b/numpy/core/src/multiarray/usertypes.c
@@ -20,13 +20,13 @@ maintainer email: oliphant.travis@ieee.org
Space Science Telescope Institute
(J. Todd Miller, Perry Greenfield, Rick White)
*/
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "structmember.h"
+#include <structmember.h>
-/*#include <stdio.h>*/
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#define _MULTIARRAYMODULE
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
diff --git a/numpy/core/src/multiarray/vdot.c b/numpy/core/src/multiarray/vdot.c
index 9b5d19522..ff08ed2d4 100644
--- a/numpy/core/src/multiarray/vdot.c
+++ b/numpy/core/src/multiarray/vdot.c
@@ -1,7 +1,9 @@
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#define _MULTIARRAYMODULE
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
+
#include "common.h"
#include "vdot.h"
#include "npy_cblas.h"
diff --git a/numpy/core/src/npymath/halffloat.c b/numpy/core/src/npymath/halffloat.c
index cbaa11e43..51948c736 100644
--- a/numpy/core/src/npymath/halffloat.c
+++ b/numpy/core/src/npymath/halffloat.c
@@ -1,4 +1,5 @@
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+
#include "numpy/halffloat.h"
/*
diff --git a/numpy/core/src/umath/_operand_flag_tests.c.src b/numpy/core/src/umath/_operand_flag_tests.c.src
index d22a5c507..c59e13baf 100644
--- a/numpy/core/src/umath/_operand_flag_tests.c.src
+++ b/numpy/core/src/umath/_operand_flag_tests.c.src
@@ -1,6 +1,7 @@
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
+
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#include <numpy/arrayobject.h>
#include <numpy/ufuncobject.h>
#include "numpy/npy_3kcompat.h"
diff --git a/numpy/core/src/umath/_rational_tests.c.src b/numpy/core/src/umath/_rational_tests.c.src
index 7b1e5627a..bf50a2226 100644
--- a/numpy/core/src/umath/_rational_tests.c.src
+++ b/numpy/core/src/umath/_rational_tests.c.src
@@ -1,16 +1,16 @@
/* Fixed size rational numbers exposed to Python */
-
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <structmember.h>
-#include <numpy/arrayobject.h>
-#include <numpy/ufuncobject.h>
-#include <numpy/npy_3kcompat.h>
-#include <math.h>
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#include "numpy/arrayobject.h"
+#include "numpy/ufuncobject.h"
+#include "numpy/npy_3kcompat.h"
#include "common.h" /* for error_converting */
+#include <math.h>
+
/* Relevant arithmetic exceptions */
diff --git a/numpy/core/src/umath/_scaled_float_dtype.c b/numpy/core/src/umath/_scaled_float_dtype.c
index cbea378f0..866f636a0 100644
--- a/numpy/core/src/umath/_scaled_float_dtype.c
+++ b/numpy/core/src/umath/_scaled_float_dtype.c
@@ -11,10 +11,10 @@
* NOTE: The tests were initially written using private API and ABI, ideally
* they should be replaced/modified with versions using public API.
*/
-
-#define _UMATHMODULE
-#define _MULTIARRAYMODULE
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+#define _UMATHMODULE
+
#include "numpy/ndarrayobject.h"
#include "numpy/ufuncobject.h"
diff --git a/numpy/core/src/umath/_struct_ufunc_tests.c.src b/numpy/core/src/umath/_struct_ufunc_tests.c.src
index d602656c8..ee71c4698 100644
--- a/numpy/core/src/umath/_struct_ufunc_tests.c.src
+++ b/numpy/core/src/umath/_struct_ufunc_tests.c.src
@@ -1,11 +1,13 @@
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
-#include "Python.h"
-#include "math.h"
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#include "numpy/ndarraytypes.h"
#include "numpy/ufuncobject.h"
#include "numpy/npy_3kcompat.h"
+#include <math.h>
+
/*
* struct_ufunc_test.c
diff --git a/numpy/core/src/umath/_umath_tests.c.src b/numpy/core/src/umath/_umath_tests.c.src
index 2e79d377e..0cd673831 100644
--- a/numpy/core/src/umath/_umath_tests.c.src
+++ b/numpy/core/src/umath/_umath_tests.c.src
@@ -5,9 +5,10 @@
** INCLUDES **
*****************************************************************************
*/
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
-#include "Python.h"
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.h"
#include "numpy/npy_math.h"
diff --git a/numpy/core/src/umath/_umath_tests.dispatch.c b/numpy/core/src/umath/_umath_tests.dispatch.c
index 85f365010..66058550e 100644
--- a/numpy/core/src/umath/_umath_tests.dispatch.c
+++ b/numpy/core/src/umath/_umath_tests.dispatch.c
@@ -6,7 +6,9 @@
* VSX VSX2 VSX3
* NEON ASIMD ASIMDHP
*/
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
+
#include "npy_cpu_dispatch.h"
#ifndef NPY_DISABLE_OPTIMIZATION
diff --git a/numpy/core/src/umath/clip.c.src b/numpy/core/src/umath/clip.c.src
index 9c4bac2d1..bc966b7ac 100644
--- a/numpy/core/src/umath/clip.c.src
+++ b/numpy/core/src/umath/clip.c.src
@@ -1,12 +1,13 @@
/**
* This module provides the inner loops for the clip ufunc
*/
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+
#define _UMATHMODULE
#define _MULTIARRAYMODULE
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#include "Python.h"
-
#include "numpy/halffloat.h"
#include "numpy/npy_math.h"
#include "numpy/ndarraytypes.h"
diff --git a/numpy/core/src/umath/dispatching.c b/numpy/core/src/umath/dispatching.c
index b97441b13..40de28754 100644
--- a/numpy/core/src/umath/dispatching.c
+++ b/numpy/core/src/umath/dispatching.c
@@ -34,11 +34,12 @@
* into the `signature` so that it is available to the ufunc loop.
*
*/
-#include <Python.h>
-
-#define _UMATHMODULE
-#define _MULTIARRAYMODULE
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+#define _UMATHMODULE
+
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
#include "numpy/ndarraytypes.h"
#include "common.h"
diff --git a/numpy/core/src/umath/extobj.c b/numpy/core/src/umath/extobj.c
index cd81f7734..6b9a27e26 100644
--- a/numpy/core/src/umath/extobj.c
+++ b/numpy/core/src/umath/extobj.c
@@ -1,7 +1,8 @@
-#define _UMATHMODULE
-#define _MULTIARRAYMODULE
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+#define _UMATHMODULE
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "npy_config.h"
diff --git a/numpy/core/src/umath/legacy_array_method.c b/numpy/core/src/umath/legacy_array_method.c
index 4351f1d25..77b1b9013 100644
--- a/numpy/core/src/umath/legacy_array_method.c
+++ b/numpy/core/src/umath/legacy_array_method.c
@@ -2,12 +2,13 @@
* This file defines most of the machinery in order to wrap legacy style
* ufunc loops into new style arraymethods.
*/
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+#define _UMATHMODULE
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#define _UMATHMODULE
-#define _MULTIARRAYMODULE
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#include "numpy/ndarraytypes.h"
#include "convert_datatype.h"
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src
index 8df439aca..7c0710819 100644
--- a/numpy/core/src/umath/loops.c.src
+++ b/numpy/core/src/umath/loops.c.src
@@ -1,11 +1,11 @@
/* -*- c -*- */
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
#define _UMATHMODULE
#define _MULTIARRAYMODULE
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#include "Python.h"
-
#include "npy_config.h"
#include "numpy/npy_common.h"
#include "numpy/arrayobject.h"
diff --git a/numpy/core/src/umath/matmul.c.src b/numpy/core/src/umath/matmul.c.src
index 0e47d1ab5..4dd0c4759 100644
--- a/numpy/core/src/umath/matmul.c.src
+++ b/numpy/core/src/umath/matmul.c.src
@@ -1,11 +1,11 @@
/* -*- c -*- */
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
#define _UMATHMODULE
#define _MULTIARRAYMODULE
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#include "Python.h"
-
#include "npy_config.h"
#include "numpy/npy_common.h"
#include "numpy/arrayobject.h"
diff --git a/numpy/core/src/umath/reduction.c b/numpy/core/src/umath/reduction.c
index 86cc20eb1..d5a251368 100644
--- a/numpy/core/src/umath/reduction.c
+++ b/numpy/core/src/umath/reduction.c
@@ -6,15 +6,15 @@
*
* See LICENSE.txt for the license.
*/
-#define _UMATHMODULE
-#define _MULTIARRAYMODULE
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+#define _UMATHMODULE
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "npy_config.h"
-#include <numpy/arrayobject.h>
+#include "numpy/arrayobject.h"
#include "npy_pycompat.h"
#include "ctors.h"
diff --git a/numpy/core/src/umath/scalarmath.c.src b/numpy/core/src/umath/scalarmath.c.src
index 5836545f8..402e6b561 100644
--- a/numpy/core/src/umath/scalarmath.c.src
+++ b/numpy/core/src/umath/scalarmath.c.src
@@ -5,12 +5,13 @@
but still supports error-modes.
*/
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
#define _UMATHMODULE
#define _MULTIARRAYMODULE
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#include "Python.h"
#include "npy_config.h"
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.h"
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index ebc6bf02a..7abcb9513 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -23,12 +23,14 @@
* Rick White
*
*/
-#define _UMATHMODULE
-#define _MULTIARRAYMODULE
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+#define _UMATHMODULE
+
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
-#include "Python.h"
-#include "stddef.h"
+#include <stddef.h>
#include "npy_config.h"
#include "npy_pycompat.h"
diff --git a/numpy/core/src/umath/ufunc_type_resolution.c b/numpy/core/src/umath/ufunc_type_resolution.c
index a7d536656..7e24bc493 100644
--- a/numpy/core/src/umath/ufunc_type_resolution.c
+++ b/numpy/core/src/umath/ufunc_type_resolution.c
@@ -20,19 +20,18 @@
*
* See LICENSE.txt for the license.
*/
-#define _UMATHMODULE
-#define _MULTIARRAYMODULE
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+#define _UMATHMODULE
+
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
// printif debug tracing
#ifndef NPY_UF_DBG_TRACING
#define NPY_UF_DBG_TRACING 0
#endif
-#include <stdbool.h>
-
-#include "Python.h"
-
#include "npy_config.h"
#include "npy_pycompat.h"
#include "npy_import.h"
@@ -48,6 +47,8 @@
#include "cblasfuncs.h"
#endif
+#include <stdbool.h>
+
static PyObject *
npy_casting_to_py_object(NPY_CASTING casting)
{
diff --git a/numpy/core/src/umath/umathmodule.c b/numpy/core/src/umath/umathmodule.c
index 6a718889b..a9954dfc1 100644
--- a/numpy/core/src/umath/umathmodule.c
+++ b/numpy/core/src/umath/umathmodule.c
@@ -1,25 +1,17 @@
/* -*- c -*- */
-
-/*
- * vim:syntax=c
- */
-
-/*
- *****************************************************************************
- ** INCLUDES **
- *****************************************************************************
- */
+/* vim:syntax=c */
/*
* _UMATHMODULE IS needed in __ufunc_api.h, included from numpy/ufuncobject.h.
* This is a mess and it would be nice to fix it. It has nothing to do with
* __ufunc_api.c
*/
-#define _UMATHMODULE
-#define _MULTIARRAYMODULE
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define _MULTIARRAYMODULE
+#define _UMATHMODULE
-#include "Python.h"
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
#include "npy_config.h"
diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py
index 714f9a932..8f42b4029 100644
--- a/numpy/f2py/cfuncs.py
+++ b/numpy/f2py/cfuncs.py
@@ -51,7 +51,7 @@ includes0['math.h'] = '#include <math.h>'
includes0['string.h'] = '#include <string.h>'
includes0['setjmp.h'] = '#include <setjmp.h>'
-includes['Python.h'] = '#include "Python.h"'
+includes['Python.h'] = '#include <Python.h>'
needs['arrayobject.h'] = ['Python.h']
includes['arrayobject.h'] = '''#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API
#include "arrayobject.h"'''
diff --git a/numpy/f2py/src/fortranobject.h b/numpy/f2py/src/fortranobject.h
index d4cc10243..278c236a7 100644
--- a/numpy/f2py/src/fortranobject.h
+++ b/numpy/f2py/src/fortranobject.h
@@ -4,7 +4,7 @@
extern "C" {
#endif
-#include "Python.h"
+#include <Python.h>
#ifdef FORTRANOBJECT_C
#define NO_IMPORT_ARRAY
diff --git a/numpy/f2py/src/test/foomodule.c b/numpy/f2py/src/test/foomodule.c
index 88ec62440..00a48f4c0 100644
--- a/numpy/f2py/src/test/foomodule.c
+++ b/numpy/f2py/src/test/foomodule.c
@@ -9,7 +9,9 @@
extern "C" {
#endif
-#include "Python.h"
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+
#include "fortranobject.h"
static PyObject *foo_error;
diff --git a/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c b/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c
index fe21d4b9b..ea47e0555 100644
--- a/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c
+++ b/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c
@@ -9,7 +9,9 @@ extern "C" {
#endif
/*********************** See f2py2e/cfuncs.py: includes ***********************/
-#include "Python.h"
+
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
#include "fortranobject.h"
#include <math.h>
diff --git a/numpy/fft/_pocketfft.c b/numpy/fft/_pocketfft.c
index ba9995f97..1eb2eba18 100644
--- a/numpy/fft/_pocketfft.c
+++ b/numpy/fft/_pocketfft.c
@@ -9,17 +9,19 @@
* Copyright (C) 2004-2018 Max-Planck-Society
* \author Martin Reinecke
*/
-
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#include "Python.h"
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+
#include "numpy/arrayobject.h"
+#include "npy_config.h"
+
#include <math.h>
#include <string.h>
#include <stdlib.h>
-#include "npy_config.h"
#define restrict NPY_RESTRICT
#define RALLOC(type,num) \
diff --git a/numpy/lib/nanfunctions.py b/numpy/lib/nanfunctions.py
index 2c2c3435b..766bf3c82 100644
--- a/numpy/lib/nanfunctions.py
+++ b/numpy/lib/nanfunctions.py
@@ -160,8 +160,12 @@ def _remove_nan_1d(arr1d, overwrite_input=False):
True if `res` can be modified in place, given the constraint on the
input
"""
+ if arr1d.dtype == object:
+ # object arrays do not support `isnan` (gh-9009), so make a guess
+ c = np.not_equal(arr1d, arr1d, dtype=bool)
+ else:
+ c = np.isnan(arr1d)
- c = np.isnan(arr1d)
s = np.nonzero(c)[0]
if s.size == arr1d.size:
warnings.warn("All-NaN slice encountered", RuntimeWarning,
@@ -214,7 +218,11 @@ def _divide_by_count(a, b, out=None):
return np.divide(a, b, out=out, casting='unsafe')
else:
if out is None:
- return a.dtype.type(a / b)
+ # Precaution against reduced object arrays
+ try:
+ return a.dtype.type(a / b)
+ except AttributeError:
+ return a / b
else:
# This is questionable, but currently a numpy scalar can
# be output to a zero dimensional array.
@@ -1551,7 +1559,13 @@ def nanvar(a, axis=None, dtype=None, out=None, ddof=0, keepdims=np._NoValue):
# Compute variance.
var = np.sum(sqr, axis=axis, dtype=dtype, out=out, keepdims=keepdims)
- if var.ndim < cnt.ndim:
+
+ # Precaution against reduced object arrays
+ try:
+ var_ndim = var.ndim
+ except AttributeError:
+ var_ndim = np.ndim(var)
+ if var_ndim < cnt.ndim:
# Subclasses of ndarray may ignore keepdims, so check here.
cnt = cnt.squeeze(axis)
dof = cnt - ddof
@@ -1671,6 +1685,8 @@ def nanstd(a, axis=None, dtype=None, out=None, ddof=0, keepdims=np._NoValue):
keepdims=keepdims)
if isinstance(var, np.ndarray):
std = np.sqrt(var, out=var)
- else:
+ elif hasattr(var, 'dtype'):
std = var.dtype.type(np.sqrt(var))
+ else:
+ std = np.sqrt(var)
return std
diff --git a/numpy/lib/tests/test_nanfunctions.py b/numpy/lib/tests/test_nanfunctions.py
index 1f1f5601b..7756f2d79 100644
--- a/numpy/lib/tests/test_nanfunctions.py
+++ b/numpy/lib/tests/test_nanfunctions.py
@@ -231,79 +231,75 @@ class TestNanFunctions_ArgminArgmax:
assert_(res.shape == ())
-class TestNanFunctions_IntTypes:
-
- int_types = (np.int8, np.int16, np.int32, np.int64, np.uint8,
- np.uint16, np.uint32, np.uint64)
+@pytest.mark.parametrize(
+ "dtype",
+ np.typecodes["AllInteger"] + np.typecodes["AllFloat"] + "O",
+)
+class TestNanFunctions_NumberTypes:
mat = np.array([127, 39, 93, 87, 46])
-
- def integer_arrays(self):
- for dtype in self.int_types:
- yield self.mat.astype(dtype)
-
- def test_nanmin(self):
- tgt = np.min(self.mat)
- for mat in self.integer_arrays():
- assert_equal(np.nanmin(mat), tgt)
-
- def test_nanmax(self):
- tgt = np.max(self.mat)
- for mat in self.integer_arrays():
- assert_equal(np.nanmax(mat), tgt)
-
- def test_nanargmin(self):
- tgt = np.argmin(self.mat)
- for mat in self.integer_arrays():
- assert_equal(np.nanargmin(mat), tgt)
-
- def test_nanargmax(self):
- tgt = np.argmax(self.mat)
- for mat in self.integer_arrays():
- assert_equal(np.nanargmax(mat), tgt)
-
- def test_nansum(self):
- tgt = np.sum(self.mat)
- for mat in self.integer_arrays():
- assert_equal(np.nansum(mat), tgt)
-
- def test_nanprod(self):
- tgt = np.prod(self.mat)
- for mat in self.integer_arrays():
- assert_equal(np.nanprod(mat), tgt)
-
- def test_nancumsum(self):
- tgt = np.cumsum(self.mat)
- for mat in self.integer_arrays():
- assert_equal(np.nancumsum(mat), tgt)
-
- def test_nancumprod(self):
- tgt = np.cumprod(self.mat)
- for mat in self.integer_arrays():
- assert_equal(np.nancumprod(mat), tgt)
-
- def test_nanmean(self):
- tgt = np.mean(self.mat)
- for mat in self.integer_arrays():
- assert_equal(np.nanmean(mat), tgt)
-
- def test_nanvar(self):
- tgt = np.var(self.mat)
- for mat in self.integer_arrays():
- assert_equal(np.nanvar(mat), tgt)
-
- tgt = np.var(mat, ddof=1)
- for mat in self.integer_arrays():
- assert_equal(np.nanvar(mat, ddof=1), tgt)
-
- def test_nanstd(self):
- tgt = np.std(self.mat)
- for mat in self.integer_arrays():
- assert_equal(np.nanstd(mat), tgt)
-
- tgt = np.std(self.mat, ddof=1)
- for mat in self.integer_arrays():
- assert_equal(np.nanstd(mat, ddof=1), tgt)
+ mat.setflags(write=False)
+
+ nanfuncs = {
+ np.nanmin: np.min,
+ np.nanmax: np.max,
+ np.nanargmin: np.argmin,
+ np.nanargmax: np.argmax,
+ np.nansum: np.sum,
+ np.nanprod: np.prod,
+ np.nancumsum: np.cumsum,
+ np.nancumprod: np.cumprod,
+ np.nanmean: np.mean,
+ np.nanmedian: np.median,
+ np.nanvar: np.var,
+ np.nanstd: np.std,
+ }
+ nanfunc_ids = [i.__name__ for i in nanfuncs]
+
+ @pytest.mark.parametrize("nanfunc,func", nanfuncs.items(), ids=nanfunc_ids)
+ @np.errstate(over="ignore")
+ def test_nanfunc(self, dtype, nanfunc, func):
+ mat = self.mat.astype(dtype)
+ tgt = func(mat)
+ out = nanfunc(mat)
+
+ assert_almost_equal(out, tgt)
+ if dtype == "O":
+ assert type(out) is type(tgt)
+ else:
+ assert out.dtype == tgt.dtype
+
+ @pytest.mark.parametrize(
+ "nanfunc,func",
+ [(np.nanquantile, np.quantile), (np.nanpercentile, np.percentile)],
+ ids=["nanquantile", "nanpercentile"],
+ )
+ def test_nanfunc_q(self, dtype, nanfunc, func):
+ mat = self.mat.astype(dtype)
+ tgt = func(mat, q=1)
+ out = nanfunc(mat, q=1)
+
+ assert_almost_equal(out, tgt)
+ if dtype == "O":
+ assert type(out) is type(tgt)
+ else:
+ assert out.dtype == tgt.dtype
+
+ @pytest.mark.parametrize(
+ "nanfunc,func",
+ [(np.nanvar, np.var), (np.nanstd, np.std)],
+ ids=["nanvar", "nanstd"],
+ )
+ def test_nanfunc_ddof(self, dtype, nanfunc, func):
+ mat = self.mat.astype(dtype)
+ tgt = func(mat, ddof=1)
+ out = nanfunc(mat, ddof=1)
+
+ assert_almost_equal(out, tgt)
+ if dtype == "O":
+ assert type(out) is type(tgt)
+ else:
+ assert out.dtype == tgt.dtype
class SharedNanFunctionsTestsMixin:
diff --git a/numpy/linalg/lapack_lite/clapack_scrub.py b/numpy/linalg/lapack_lite/clapack_scrub.py
index 738fad7fe..44c0d92d9 100644
--- a/numpy/linalg/lapack_lite/clapack_scrub.py
+++ b/numpy/linalg/lapack_lite/clapack_scrub.py
@@ -299,6 +299,5 @@ if __name__ == '__main__':
source = scrub_source(source, nsteps, verbose=True)
- writefo = open(outfilename, 'w')
- writefo.write(source)
- writefo.close()
+ with open(outfilename, 'w') as writefo:
+ writefo.write(source)
diff --git a/numpy/linalg/lapack_lite/python_xerbla.c b/numpy/linalg/lapack_lite/python_xerbla.c
index fe2f718b2..37a41408b 100644
--- a/numpy/linalg/lapack_lite/python_xerbla.c
+++ b/numpy/linalg/lapack_lite/python_xerbla.c
@@ -1,4 +1,6 @@
-#include "Python.h"
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+
#include "numpy/npy_common.h"
#include "npy_cblas.h"
diff --git a/numpy/linalg/lapack_litemodule.c b/numpy/linalg/lapack_litemodule.c
index 362a593a6..2fed0f2b0 100644
--- a/numpy/linalg/lapack_litemodule.c
+++ b/numpy/linalg/lapack_litemodule.c
@@ -4,11 +4,12 @@ More modifications by Jeff Whitaker
*/
#define NPY_NO_DEPRECATED_API NPY_API_VERSION
-#include "Python.h"
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
+
#include "numpy/arrayobject.h"
#include "npy_cblas.h"
-
#define FNAME(name) BLAS_FUNC(name)
typedef CBLAS_INT fortran_int;
diff --git a/numpy/linalg/umath_linalg.c.src b/numpy/linalg/umath_linalg.c.src
index a486e9e5b..ff63ea218 100644
--- a/numpy/linalg/umath_linalg.c.src
+++ b/numpy/linalg/umath_linalg.c.src
@@ -5,9 +5,10 @@
** INCLUDES **
*****************************************************************************
*/
-#define NPY_NO_DEPRECATED_API NPY_API_VERSION
+#define PY_SSIZE_T_CLEAN
+#include <Python.h>
-#include "Python.h"
+#define NPY_NO_DEPRECATED_API NPY_API_VERSION
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.h"
diff --git a/numpy/random/include/aligned_malloc.h b/numpy/random/include/aligned_malloc.h
index ea24f6d23..43f68253d 100644
--- a/numpy/random/include/aligned_malloc.h
+++ b/numpy/random/include/aligned_malloc.h
@@ -1,7 +1,7 @@
#ifndef _RANDOMDGEN__ALIGNED_MALLOC_H_
#define _RANDOMDGEN__ALIGNED_MALLOC_H_
-#include "Python.h"
+#include <Python.h>
#include "numpy/npy_common.h"
#define NPY_MEMALIGN 16 /* 16 for SSE2, 32 for AVX, 64 for Xeon Phi */
diff --git a/test_requirements.txt b/test_requirements.txt
index ee9bc9a84..961e98580 100644
--- a/test_requirements.txt
+++ b/test_requirements.txt
@@ -1,8 +1,8 @@
cython==0.29.24
wheel<0.37.1
setuptools<49.2.0
-hypothesis==6.17.3
-pytest==6.2.4
+hypothesis==6.18.0
+pytest==6.2.5
pytz==2021.1
pytest-cov==2.12.1
pickle5; python_version == '3.7' and platform_python_implementation != 'PyPy'