├── numpy ├── tests │ ├── __init__.py │ ├── test_numpy_version.py │ └── test_reloading.py ├── core │ ├── tests │ │ ├── __init__.py │ │ ├── data │ │ │ ├── astype_copy.pkl │ │ │ └── recarray_from_file.fits │ │ └── test_machar.py │ ├── code_generators │ │ └── __init__.py │ ├── src │ │ ├── private │ │ │ ├── npy_pycompat.h │ │ │ ├── npy_longdouble.h │ │ │ ├── ufunc_override.h │ │ │ ├── npy_fpmath.h │ │ │ └── npy_import.h │ │ ├── multiarray │ │ │ ├── getset.h │ │ │ ├── hashdescr.h │ │ │ ├── sequence.h │ │ │ ├── cblasfuncs.h │ │ │ ├── convert.h │ │ │ ├── nditer_pywrap.h │ │ │ ├── methods.h │ │ │ ├── buffer.h │ │ │ ├── ucsnarrow.h │ │ │ ├── refcount.h │ │ │ ├── temp_elide.h │ │ │ ├── strfuncs.h │ │ │ ├── vdot.h │ │ │ ├── typeinfo.h │ │ │ ├── usertypes.h │ │ │ ├── iterators.h │ │ │ ├── datetime_busday.h │ │ │ ├── multiarraymodule.h │ │ │ ├── alloc.h │ │ │ ├── arraytypes.h │ │ │ ├── compiled_base.h │ │ │ ├── numpyos.h │ │ │ ├── arrayobject.h │ │ │ ├── item_selection.h │ │ │ ├── scalartypes.h │ │ │ ├── shape.h │ │ │ └── convert_datatype.h │ │ ├── npymath │ │ │ ├── npy_math_common.h │ │ │ ├── npy_math.c │ │ │ └── _signbit.c │ │ ├── umath │ │ │ ├── cpuid.h │ │ │ ├── override.h │ │ │ ├── ufunc_object.h │ │ │ └── extobj.h │ │ └── dummymodule.c │ ├── mlib.ini.in │ ├── include │ │ └── numpy │ │ │ ├── arrayobject.h │ │ │ ├── npy_no_deprecated_api.h │ │ │ ├── utils.h │ │ │ ├── oldnumeric.h │ │ │ ├── npy_os.h │ │ │ └── numpyconfig.h │ ├── npymath.ini.in │ ├── cversions.py │ └── umath_tests.py ├── f2py │ ├── tests │ │ ├── __init__.py │ │ ├── src │ │ │ ├── assumed_shape │ │ │ │ ├── .f2py_f2cmap │ │ │ │ ├── precision.f90 │ │ │ │ ├── foo_use.f90 │ │ │ │ ├── foo_free.f90 │ │ │ │ └── foo_mod.f90 │ │ │ ├── mixed │ │ │ │ ├── foo.f │ │ │ │ ├── foo_free.f90 │ │ │ │ └── foo_fixed.f90 │ │ │ ├── common │ │ │ │ └── block.f │ │ │ ├── regression │ │ │ │ └── inout.f90 │ │ │ ├── kind │ │ │ │ └── foo.f90 │ │ │ ├── parameter │ │ │ │ ├── constant_compound.f90 │ │ │ │ ├── constant_integer.f90 │ │ │ │ ├── constant_real.f90 │ │ │ │ └── constant_non_compound.f90 │ │ │ ├── string │ │ │ │ └── char.f90 │ │ │ └── size │ │ │ │ └── foo.f90 │ │ ├── test_block_docstring.py │ │ ├── test_string.py │ │ ├── test_regression.py │ │ ├── test_common.py │ │ ├── test_assumed_shape.py │ │ ├── test_mixed.py │ │ └── test_kind.py │ ├── setup.cfg │ ├── info.py │ ├── src │ │ └── test │ │ │ ├── foo90.f90 │ │ │ ├── bar.f │ │ │ └── foo.f │ ├── __version__.py │ └── __main__.py ├── fft │ ├── tests │ │ └── __init__.py │ ├── __init__.py │ ├── setup.py │ └── fftpack.h ├── lib │ ├── tests │ │ ├── __init__.py │ │ └── data │ │ │ ├── python3.npy │ │ │ ├── py2-objarr.npy │ │ │ ├── py2-objarr.npz │ │ │ ├── py3-objarr.npy │ │ │ ├── py3-objarr.npz │ │ │ └── win64python2.npy │ └── setup.py ├── ma │ ├── tests │ │ └── __init__.py │ ├── version.py │ └── setup.py ├── compat │ ├── tests │ │ ├── __init__.py │ │ └── test_compat.py │ ├── setup.py │ └── __init__.py ├── distutils │ ├── tests │ │ ├── __init__.py │ │ ├── test_fcompiler_nagfor.py │ │ ├── test_fcompiler_intel.py │ │ └── test_from_template.py │ ├── mingw │ │ └── gfortran_vs2003_hack.c │ ├── __version__.py │ ├── info.py │ ├── compat.py │ ├── setup.py │ ├── command │ │ ├── develop.py │ │ ├── bdist_rpm.py │ │ ├── sdist.py │ │ ├── install_data.py │ │ ├── egg_info.py │ │ ├── install_headers.py │ │ ├── __init__.py │ │ └── build_py.py │ ├── numpy_distribution.py │ ├── pathccompiler.py │ ├── fcompiler │ │ ├── none.py │ │ └── pathf95.py │ └── __init__.py ├── linalg │ ├── tests │ │ ├── __init__.py │ │ └── test_deprecations.py │ ├── lapack_lite │ │ ├── f2c_config.c.patch │ │ └── wrapped_routines │ └── info.py ├── matrixlib │ ├── tests │ │ ├── __init__.py │ │ ├── test_numeric.py │ │ ├── test_multiarray.py │ │ └── test_regression.py │ ├── __init__.py │ └── setup.py ├── random │ ├── tests │ │ └── __init__.py │ └── mtrand │ │ ├── initarray.h │ │ ├── mtrand_py_helper.h │ │ └── Python.pxi ├── testing │ ├── tests │ │ └── __init__.py │ ├── _private │ │ └── __init__.py │ ├── decorators.py │ ├── noseclasses.py │ ├── nosetester.py │ ├── __init__.py │ ├── setup.py │ └── utils.py ├── polynomial │ ├── tests │ │ └── __init__.py │ ├── setup.py │ └── __init__.py ├── _build_utils │ ├── __init__.py │ ├── README │ └── apple_accelerate.py ├── _distributor_init.py ├── doc │ └── __init__.py └── setup.py ├── doc ├── neps │ ├── .gitignore │ ├── _static │ │ └── nep-0000.png │ ├── nep-0009-structured_array_extensions.rst │ └── Makefile ├── source │ ├── f2py │ │ ├── var_session.dat │ │ ├── spam_session.dat │ │ ├── var.pyf │ │ ├── calculate_session.dat │ │ ├── ftype.f │ │ ├── callback.f │ │ ├── fib2.pyf │ │ ├── compile_session.dat │ │ ├── scalar.f │ │ ├── calculate.f │ │ ├── common.f │ │ ├── extcallback.f │ │ ├── allocarr.f90 │ │ ├── fib1.f │ │ ├── fib1.pyf │ │ ├── array.f │ │ ├── extcallback_session.dat │ │ ├── fib3.f │ │ ├── moddata.f90 │ │ ├── string.f │ │ ├── callback2.pyf │ │ ├── spam.pyf │ │ ├── callback_session.dat │ │ ├── scalar_session.dat │ │ ├── run_main_session.dat │ │ ├── common_session.dat │ │ ├── ftype_session.dat │ │ ├── setup_example.py │ │ ├── string_session.dat │ │ ├── moddata_session.dat │ │ ├── allocarr_session.dat │ │ ├── index.rst │ │ └── advanced.rst │ ├── reference │ │ ├── routines.fft.rst │ │ ├── constants.rst │ │ ├── routines.polynomials.polyutils.rst │ │ ├── figures │ │ │ ├── dtype-hierarchy.dia │ │ │ ├── dtype-hierarchy.pdf │ │ │ ├── dtype-hierarchy.png │ │ │ ├── threefundamental.pdf │ │ │ └── threefundamental.png │ │ ├── testing.rst │ │ ├── routines.numarray.rst │ │ ├── routines.padding.rst │ │ ├── internals.rst │ │ ├── routines.oldnumeric.rst │ │ ├── swig.rst │ │ ├── routines.functional.rst │ │ ├── routines.window.rst │ │ ├── routines.financial.rst │ │ ├── routines.emath.rst │ │ ├── routines.help.rst │ │ ├── routines.set.rst │ │ ├── routines.ctypeslib.rst │ │ ├── maskedarray.rst │ │ ├── routines.err.rst │ │ ├── routines.datetime.rst │ │ ├── routines.polynomials.package.rst │ │ ├── routines.bitwise.rst │ │ ├── routines.polynomials.poly1d.rst │ │ ├── routines.sort.rst │ │ ├── routines.dual.rst │ │ ├── routines.matlib.rst │ │ ├── routines.other.rst │ │ ├── index.rst │ │ ├── routines.statistics.rst │ │ ├── routines.dtype.rst │ │ ├── routines.logic.rst │ │ ├── routines.polynomials.rst │ │ ├── routines.rst │ │ └── routines.indexing.rst │ ├── user │ │ ├── misc.rst │ │ ├── basics.byteswapping.rst │ │ ├── basics.io.rst │ │ ├── setting-up.rst │ │ ├── basics.types.rst │ │ ├── basics.broadcasting.rst │ │ ├── basics.subclassing.rst │ │ ├── basics.indexing.rst │ │ ├── c-info.rst │ │ ├── basics.creation.rst │ │ ├── basics.rst │ │ ├── basics.rec.rst │ │ ├── install.rst │ │ └── index.rst │ ├── dev │ │ ├── gitwash │ │ │ ├── pull_button.png │ │ │ ├── forking_button.png │ │ │ ├── git_development.rst │ │ │ ├── index.rst │ │ │ ├── dot2_dot3.rst │ │ │ ├── git_intro.rst │ │ │ └── following_latest.rst │ │ ├── gitwash_links.txt │ │ ├── governance │ │ │ ├── index.rst │ │ │ └── people.rst │ │ └── index.rst │ ├── glossary.rst │ ├── _static │ │ └── .gitignore │ ├── _templates │ │ ├── autosummary │ │ │ ├── minimal_module.rst │ │ │ └── class.rst │ │ ├── indexsidebar.html │ │ ├── layout.html │ │ └── searchbox.html │ ├── docs │ │ └── index.rst │ ├── contents.rst │ └── bugs.rst ├── cdoc │ ├── Makefile │ └── README ├── HOWTO_DOCUMENT.rst.txt ├── newdtype_example │ ├── floatint │ │ └── __init__.py │ ├── setup.py │ └── example.py ├── release │ ├── 1.10.3-notes.rst │ ├── 1.6.1-notes.rst │ ├── 1.8.2-notes.rst │ ├── 1.11.3-notes.rst │ ├── 1.14.5-notes.rst │ ├── 1.7.1-notes.rst │ └── 1.12.1-notes.rst └── changelog │ ├── 1.14.5-changelog.rst │ ├── 1.14.2-changelog.rst │ └── 1.14.3-changelog.rst ├── .coveragerc ├── tools ├── allocation_tracking │ ├── sorttable.js │ ├── setup.py │ └── README.md ├── ci │ └── appveyor │ │ └── requirements.txt ├── c_coverage │ └── c_coverage_collect.sh ├── travis-upload-wheel.sh ├── swig │ ├── test │ │ ├── Fortran.h │ │ ├── Fortran.cxx │ │ ├── Flat.i │ │ ├── Makefile │ │ ├── Fortran.i │ │ ├── Array1.h │ │ ├── Farray.h │ │ ├── ArrayZ.h │ │ ├── Array2.h │ │ ├── Flat.h │ │ └── Flat.cxx │ └── Makefile ├── travis-before-install.sh ├── commitstats.py └── npy_tempita │ ├── license.txt │ └── compat3.py ├── benchmarks └── benchmarks │ ├── __init__.py │ └── bench_lib.py ├── .gitattributes ├── .gitmodules ├── pytest.ini ├── README.md └── MANIFEST.in /numpy/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /numpy/core/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /numpy/f2py/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /numpy/fft/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /numpy/lib/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /numpy/ma/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/neps/.gitignore: -------------------------------------------------------------------------------- 1 | index.rst 2 | -------------------------------------------------------------------------------- /numpy/compat/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /numpy/distutils/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /numpy/linalg/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /numpy/matrixlib/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /numpy/random/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /numpy/testing/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /numpy/polynomial/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /numpy/testing/_private/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | branch = True 3 | include = */numpy/* 4 | -------------------------------------------------------------------------------- /doc/source/f2py/var_session.dat: -------------------------------------------------------------------------------- 1 | >>> import var 2 | >>> var.BAR 3 | 5 -------------------------------------------------------------------------------- /numpy/f2py/setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_rpm] 2 | doc_files = docs/ 3 | tests/ -------------------------------------------------------------------------------- /numpy/f2py/tests/src/assumed_shape/.f2py_f2cmap: -------------------------------------------------------------------------------- 1 | dict(real=dict(rk="double")) 2 | -------------------------------------------------------------------------------- /doc/cdoc/Makefile: -------------------------------------------------------------------------------- 1 | all: build 2 | 3 | build: 4 | doxygen 5 | 6 | .PHONY: all build 7 | 8 | -------------------------------------------------------------------------------- /doc/source/reference/routines.fft.rst: -------------------------------------------------------------------------------- 1 | .. _routines.fft: 2 | .. automodule:: numpy.fft 3 | -------------------------------------------------------------------------------- /numpy/_build_utils/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | -------------------------------------------------------------------------------- /numpy/core/code_generators/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | -------------------------------------------------------------------------------- /doc/HOWTO_DOCUMENT.rst.txt: -------------------------------------------------------------------------------- 1 | This document has been replaced, see https://numpydoc.readthedocs.io/en/latest/ 2 | -------------------------------------------------------------------------------- /doc/neps/_static/nep-0000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/doc/neps/_static/nep-0000.png -------------------------------------------------------------------------------- /doc/newdtype_example/floatint/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | -------------------------------------------------------------------------------- /doc/source/user/misc.rst: -------------------------------------------------------------------------------- 1 | ************* 2 | Miscellaneous 3 | ************* 4 | 5 | .. automodule:: numpy.doc.misc 6 | -------------------------------------------------------------------------------- /numpy/lib/tests/data/python3.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/numpy/lib/tests/data/python3.npy -------------------------------------------------------------------------------- /doc/source/reference/constants.rst: -------------------------------------------------------------------------------- 1 | ********* 2 | Constants 3 | ********* 4 | 5 | .. automodule:: numpy.doc.constants 6 | -------------------------------------------------------------------------------- /numpy/lib/tests/data/py2-objarr.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/numpy/lib/tests/data/py2-objarr.npy -------------------------------------------------------------------------------- /numpy/lib/tests/data/py2-objarr.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/numpy/lib/tests/data/py2-objarr.npz -------------------------------------------------------------------------------- /numpy/lib/tests/data/py3-objarr.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/numpy/lib/tests/data/py3-objarr.npy -------------------------------------------------------------------------------- /numpy/lib/tests/data/py3-objarr.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/numpy/lib/tests/data/py3-objarr.npz -------------------------------------------------------------------------------- /doc/source/dev/gitwash/pull_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/doc/source/dev/gitwash/pull_button.png -------------------------------------------------------------------------------- /doc/source/glossary.rst: -------------------------------------------------------------------------------- 1 | ******** 2 | Glossary 3 | ******** 4 | 5 | .. toctree:: 6 | 7 | .. automodule:: numpy.doc.glossary 8 | -------------------------------------------------------------------------------- /numpy/core/tests/data/astype_copy.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/numpy/core/tests/data/astype_copy.pkl -------------------------------------------------------------------------------- /numpy/lib/tests/data/win64python2.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/numpy/lib/tests/data/win64python2.npy -------------------------------------------------------------------------------- /tools/allocation_tracking/sorttable.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/tools/allocation_tracking/sorttable.js -------------------------------------------------------------------------------- /benchmarks/benchmarks/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import, division, print_function 2 | 3 | from . import common 4 | -------------------------------------------------------------------------------- /tools/ci/appveyor/requirements.txt: -------------------------------------------------------------------------------- 1 | cython 2 | nose 3 | pytest-timeout 4 | pytest-xdist 5 | pytest-env 6 | pytest-faulthandler 7 | -------------------------------------------------------------------------------- /doc/source/dev/gitwash/forking_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/doc/source/dev/gitwash/forking_button.png -------------------------------------------------------------------------------- /doc/source/reference/routines.polynomials.polyutils.rst: -------------------------------------------------------------------------------- 1 | Polyutils 2 | ========= 3 | 4 | .. automodule:: numpy.polynomial.polyutils 5 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/mixed/foo.f: -------------------------------------------------------------------------------- 1 | subroutine bar11(a) 2 | cf2py intent(out) a 3 | integer a 4 | a = 11 5 | end 6 | -------------------------------------------------------------------------------- /doc/source/user/basics.byteswapping.rst: -------------------------------------------------------------------------------- 1 | ************* 2 | Byte-swapping 3 | ************* 4 | 5 | .. automodule:: numpy.doc.byteswapping 6 | -------------------------------------------------------------------------------- /numpy/core/tests/data/recarray_from_file.fits: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/numpy/core/tests/data/recarray_from_file.fits -------------------------------------------------------------------------------- /doc/source/reference/figures/dtype-hierarchy.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/doc/source/reference/figures/dtype-hierarchy.dia -------------------------------------------------------------------------------- /doc/source/reference/figures/dtype-hierarchy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/doc/source/reference/figures/dtype-hierarchy.pdf -------------------------------------------------------------------------------- /doc/source/reference/figures/dtype-hierarchy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/doc/source/reference/figures/dtype-hierarchy.png -------------------------------------------------------------------------------- /numpy/distutils/mingw/gfortran_vs2003_hack.c: -------------------------------------------------------------------------------- 1 | int _get_output_format(void) 2 | { 3 | return 0; 4 | } 5 | 6 | int _imp____lc_codepage = 0; 7 | -------------------------------------------------------------------------------- /doc/source/reference/figures/threefundamental.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/doc/source/reference/figures/threefundamental.pdf -------------------------------------------------------------------------------- /doc/source/reference/figures/threefundamental.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xman/numpy-posit/HEAD/doc/source/reference/figures/threefundamental.png -------------------------------------------------------------------------------- /doc/source/_static/.gitignore: -------------------------------------------------------------------------------- 1 | # This file is here to avoid a sphinx warning about a missing _static folder. 2 | # Empty folders are not allowed into git. 3 | -------------------------------------------------------------------------------- /tools/c_coverage/c_coverage_collect.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | valgrind --tool=callgrind --compress-strings=no --compress-pos=no --collect-jumps=yes "$@" 3 | -------------------------------------------------------------------------------- /doc/source/user/basics.io.rst: -------------------------------------------------------------------------------- 1 | ************** 2 | I/O with NumPy 3 | ************** 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | 8 | basics.io.genfromtxt 9 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Numerical data files 2 | numpy/lib/tests/data/*.npy binary 3 | 4 | # Release notes, reduce number of conflicts. 5 | doc/release/*.rst merge=union 6 | -------------------------------------------------------------------------------- /doc/source/user/setting-up.rst: -------------------------------------------------------------------------------- 1 | ********** 2 | Setting up 3 | ********** 4 | 5 | .. toctree:: 6 | :maxdepth: 1 7 | 8 | whatisnumpy 9 | install 10 | -------------------------------------------------------------------------------- /doc/source/f2py/spam_session.dat: -------------------------------------------------------------------------------- 1 | >>> import spam 2 | >>> status = spam.system('whoami') 3 | pearu 4 | >> status = spam.system('blah') 5 | sh: line 1: blah: command not found -------------------------------------------------------------------------------- /numpy/core/src/private/npy_pycompat.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_PYCOMPAT_H_ 2 | #define _NPY_PYCOMPAT_H_ 3 | 4 | #include "numpy/npy_3kcompat.h" 5 | 6 | #endif /* _NPY_COMPAT_H_ */ 7 | -------------------------------------------------------------------------------- /doc/source/reference/testing.rst: -------------------------------------------------------------------------------- 1 | .. _testing-guidelines: 2 | 3 | Testing Guidelines 4 | ================== 5 | 6 | .. include:: ../../TESTS.rst.txt 7 | :start-line: 6 8 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/getset.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_ARRAY_GETSET_H_ 2 | #define _NPY_ARRAY_GETSET_H_ 3 | 4 | extern NPY_NO_EXPORT PyGetSetDef array_getsetlist[]; 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /numpy/f2py/info.py: -------------------------------------------------------------------------------- 1 | """Fortran to Python Interface Generator. 2 | 3 | """ 4 | from __future__ import division, absolute_import, print_function 5 | 6 | postpone_import = True 7 | -------------------------------------------------------------------------------- /doc/source/dev/gitwash_links.txt: -------------------------------------------------------------------------------- 1 | .. _NumPy: http://www.numpy.org 2 | .. _`NumPy github`: http://github.com/numpy/numpy 3 | .. _`NumPy mailing list`: http://scipy.org/Mailing_Lists 4 | -------------------------------------------------------------------------------- /doc/source/reference/routines.numarray.rst: -------------------------------------------------------------------------------- 1 | ********************** 2 | Numarray compatibility 3 | ********************** 4 | 5 | The numarray module was removed in NumPy 1.9.0. 6 | -------------------------------------------------------------------------------- /doc/source/user/basics.types.rst: -------------------------------------------------------------------------------- 1 | ********** 2 | Data types 3 | ********** 4 | 5 | .. seealso:: :ref:`Data type objects ` 6 | 7 | .. automodule:: numpy.doc.basics 8 | -------------------------------------------------------------------------------- /doc/source/user/basics.broadcasting.rst: -------------------------------------------------------------------------------- 1 | ************ 2 | Broadcasting 3 | ************ 4 | 5 | .. seealso:: :class:`numpy.broadcast` 6 | 7 | .. automodule:: numpy.doc.broadcasting 8 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/hashdescr.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_HASHDESCR_H_ 2 | #define _NPY_HASHDESCR_H_ 3 | 4 | NPY_NO_EXPORT npy_hash_t 5 | PyArray_DescrHash(PyObject* odescr); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /doc/source/reference/routines.padding.rst: -------------------------------------------------------------------------------- 1 | Padding Arrays 2 | ============== 3 | 4 | .. currentmodule:: numpy 5 | 6 | .. autosummary:: 7 | :toctree: generated/ 8 | 9 | pad 10 | -------------------------------------------------------------------------------- /doc/source/user/basics.subclassing.rst: -------------------------------------------------------------------------------- 1 | .. _basics.subclassing: 2 | 3 | ******************* 4 | Subclassing ndarray 5 | ******************* 6 | 7 | .. automodule:: numpy.doc.subclassing 8 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/sequence.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_ARRAY_SEQUENCE_H_ 2 | #define _NPY_ARRAY_SEQUENCE_H_ 3 | 4 | extern NPY_NO_EXPORT PySequenceMethods array_as_sequence; 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /doc/source/_templates/autosummary/minimal_module.rst: -------------------------------------------------------------------------------- 1 | {{ fullname | escape | underline}} 2 | 3 | .. automodule:: {{ fullname }} 4 | 5 | {% block docstring %} 6 | {% endblock %} 7 | 8 | 9 | -------------------------------------------------------------------------------- /doc/source/_templates/indexsidebar.html: -------------------------------------------------------------------------------- 1 |

Resources

2 | 5 | -------------------------------------------------------------------------------- /doc/source/dev/governance/index.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | NumPy governance 3 | ##################### 4 | 5 | .. toctree:: 6 | :maxdepth: 3 7 | 8 | governance 9 | people 10 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/assumed_shape/precision.f90: -------------------------------------------------------------------------------- 1 | module precision 2 | integer, parameter :: rk = selected_real_kind(8) 3 | integer, parameter :: ik = selected_real_kind(4) 4 | end module 5 | -------------------------------------------------------------------------------- /doc/release/1.10.3-notes.rst: -------------------------------------------------------------------------------- 1 | ========================== 2 | NumPy 1.10.3 Release Notes 3 | ========================== 4 | 5 | N/A this release did not happen due to various screwups involving PyPi. 6 | -------------------------------------------------------------------------------- /numpy/distutils/__version__.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | major = 0 4 | minor = 4 5 | micro = 0 6 | version = '%(major)d.%(minor)d.%(micro)d' % (locals()) 7 | -------------------------------------------------------------------------------- /numpy/distutils/info.py: -------------------------------------------------------------------------------- 1 | """ 2 | Enhanced distutils with Fortran compilers support and more. 3 | """ 4 | from __future__ import division, absolute_import, print_function 5 | 6 | postpone_import = True 7 | -------------------------------------------------------------------------------- /doc/source/reference/internals.rst: -------------------------------------------------------------------------------- 1 | *************** 2 | NumPy internals 3 | *************** 4 | 5 | .. toctree:: 6 | 7 | internals.code-explanations 8 | 9 | .. automodule:: numpy.doc.internals 10 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/mixed/foo_free.f90: -------------------------------------------------------------------------------- 1 | module foo_free 2 | contains 3 | subroutine bar13(a) 4 | !f2py intent(out) a 5 | integer a 6 | a = 13 7 | end subroutine bar13 8 | end module foo_free 9 | -------------------------------------------------------------------------------- /doc/source/docs/index.rst: -------------------------------------------------------------------------------- 1 | .. _documentation: 2 | 3 | NumPy's Documentation 4 | ===================== 5 | 6 | .. toctree:: 7 | :maxdepth: 2 8 | 9 | howto_document 10 | howto_build_docs 11 | 12 | -------------------------------------------------------------------------------- /doc/source/reference/routines.oldnumeric.rst: -------------------------------------------------------------------------------- 1 | ************************* 2 | Old Numeric compatibility 3 | ************************* 4 | 5 | .. currentmodule:: numpy 6 | 7 | The oldnumeric module was removed in NumPy 1.9.0. 8 | -------------------------------------------------------------------------------- /doc/source/user/basics.indexing.rst: -------------------------------------------------------------------------------- 1 | .. _basics.indexing: 2 | 3 | ******** 4 | Indexing 5 | ******** 6 | 7 | .. seealso:: :ref:`Indexing routines ` 8 | 9 | .. automodule:: numpy.doc.indexing 10 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/cblasfuncs.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_CBLASFUNCS_H_ 2 | #define _NPY_CBLASFUNCS_H_ 3 | 4 | NPY_NO_EXPORT PyObject * 5 | cblas_matrixproduct(int, PyArrayObject *, PyArrayObject *, PyArrayObject *); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /doc/source/reference/swig.rst: -------------------------------------------------------------------------------- 1 | ************** 2 | NumPy and SWIG 3 | ************** 4 | 5 | .. sectionauthor:: Bill Spotz 6 | 7 | 8 | .. toctree:: 9 | :maxdepth: 2 10 | 11 | swig.interface-file 12 | swig.testing 13 | -------------------------------------------------------------------------------- /doc/source/user/c-info.rst: -------------------------------------------------------------------------------- 1 | ################# 2 | Using NumPy C-API 3 | ################# 4 | 5 | .. toctree:: 6 | 7 | c-info.how-to-extend 8 | c-info.python-as-glue 9 | c-info.ufunc-tutorial 10 | c-info.beyond-basics 11 | -------------------------------------------------------------------------------- /numpy/f2py/src/test/foo90.f90: -------------------------------------------------------------------------------- 1 | subroutine foo() 2 | integer a 3 | real*8 b,c(3) 4 | common /foodata/ a,b,c 5 | print*, " F: in foo" 6 | a = 5 7 | b = 6.3 8 | c(2) = 9.1 9 | end subroutine foo 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /numpy/core/mlib.ini.in: -------------------------------------------------------------------------------- 1 | [meta] 2 | Name = mlib 3 | Description = Math library used with this version of numpy 4 | Version = 1.0 5 | 6 | [default] 7 | Libs=@posix_mathlib@ 8 | Cflags= 9 | 10 | [msvc] 11 | Libs=@msvc_mathlib@ 12 | Cflags= 13 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/convert.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_ARRAYOBJECT_CONVERT_H_ 2 | #define _NPY_ARRAYOBJECT_CONVERT_H_ 3 | 4 | NPY_NO_EXPORT int 5 | PyArray_AssignZero(PyArrayObject *dst, 6 | PyArrayObject *wheremask); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/mixed/foo_fixed.f90: -------------------------------------------------------------------------------- 1 | module foo_fixed 2 | contains 3 | subroutine bar12(a) 4 | !f2py intent(out) a 5 | integer a 6 | a = 12 7 | end subroutine bar12 8 | end module foo_fixed 9 | -------------------------------------------------------------------------------- /doc/source/user/basics.creation.rst: -------------------------------------------------------------------------------- 1 | .. _arrays.creation: 2 | 3 | ************** 4 | Array creation 5 | ************** 6 | 7 | .. seealso:: :ref:`Array creation routines ` 8 | 9 | .. automodule:: numpy.doc.creation 10 | -------------------------------------------------------------------------------- /numpy/core/include/numpy/arrayobject.h: -------------------------------------------------------------------------------- 1 | #ifndef Py_ARRAYOBJECT_H 2 | #define Py_ARRAYOBJECT_H 3 | 4 | #include "ndarrayobject.h" 5 | #include "npy_interrupt.h" 6 | 7 | #ifdef NPY_NO_PREFIX 8 | #include "noprefix.h" 9 | #endif 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/nditer_pywrap.h: -------------------------------------------------------------------------------- 1 | #ifndef __NDITER_PYWRAP_H 2 | #define __NDITER_PYWRAP_H 3 | 4 | NPY_NO_EXPORT PyObject * 5 | NpyIter_NestedIters(PyObject *NPY_UNUSED(self), 6 | PyObject *args, PyObject *kwds); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /numpy/core/src/npymath/npy_math_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Common headers needed by every npy math compilation unit 3 | */ 4 | #include 5 | #include 6 | #include 7 | 8 | #include "npy_config.h" 9 | #include "numpy/npy_math.h" 10 | -------------------------------------------------------------------------------- /numpy/core/src/umath/cpuid.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_PRIVATE__CPUID_H_ 2 | #define _NPY_PRIVATE__CPUID_H_ 3 | 4 | #include /* for NPY_NO_EXPORT */ 5 | 6 | NPY_NO_EXPORT int 7 | npy_cpu_supports(const char * feature); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /numpy/random/mtrand/initarray.h: -------------------------------------------------------------------------------- 1 | #include "Python.h" 2 | #define NO_IMPORT_ARRAY 3 | #include "numpy/arrayobject.h" 4 | #include "randomkit.h" 5 | 6 | extern void 7 | init_by_array(rk_state *self, unsigned long init_key[], 8 | npy_intp key_length); 9 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/methods.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_ARRAY_METHODS_H_ 2 | #define _NPY_ARRAY_METHODS_H_ 3 | 4 | extern NPY_NO_EXPORT PyMethodDef array_methods[]; 5 | 6 | NPY_NO_EXPORT const char * 7 | npy_casting_to_string(NPY_CASTING casting); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /doc/source/f2py/var.pyf: -------------------------------------------------------------------------------- 1 | ! -*- f90 -*- 2 | python module var 3 | usercode ''' 4 | int BAR = 5; 5 | ''' 6 | interface 7 | usercode ''' 8 | PyDict_SetItemString(d,"BAR",PyInt_FromLong(BAR)); 9 | ''' 10 | end interface 11 | end python module 12 | -------------------------------------------------------------------------------- /doc/source/contents.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | NumPy manual contents 3 | ##################### 4 | 5 | .. toctree:: 6 | 7 | user/index 8 | reference/index 9 | f2py/index 10 | dev/index 11 | release 12 | about 13 | bugs 14 | license 15 | glossary 16 | -------------------------------------------------------------------------------- /doc/source/dev/gitwash/git_development.rst: -------------------------------------------------------------------------------- 1 | .. _git-development: 2 | 3 | ===================== 4 | Git for development 5 | ===================== 6 | 7 | Contents: 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | 12 | development_setup 13 | configure_git 14 | dot2_dot3 15 | -------------------------------------------------------------------------------- /doc/source/f2py/calculate_session.dat: -------------------------------------------------------------------------------- 1 | >>> import foo 2 | >>> foo.calculate(range(5), lambda x: x*x) 3 | array([ 0., 1., 4., 9., 16.]) 4 | >>> import math 5 | >>> foo.calculate(range(5), math.exp) 6 | array([ 1. , 2.71828175, 7.38905621, 20.08553696, 54.59814835]) 7 | -------------------------------------------------------------------------------- /numpy/distutils/compat.py: -------------------------------------------------------------------------------- 1 | """Small modules to cope with python 2 vs 3 incompatibilities inside 2 | numpy.distutils 3 | 4 | """ 5 | from __future__ import division, absolute_import, print_function 6 | 7 | import sys 8 | 9 | def get_exception(): 10 | return sys.exc_info()[1] 11 | -------------------------------------------------------------------------------- /doc/source/dev/index.rst: -------------------------------------------------------------------------------- 1 | ##################### 2 | Contributing to NumPy 3 | ##################### 4 | 5 | .. toctree:: 6 | :maxdepth: 3 7 | 8 | gitwash/index 9 | development_environment 10 | governance/index 11 | 12 | For core developers: see :ref:`development-workflow`. 13 | -------------------------------------------------------------------------------- /doc/source/f2py/ftype.f: -------------------------------------------------------------------------------- 1 | C FILE: FTYPE.F 2 | SUBROUTINE FOO(N) 3 | INTEGER N 4 | Cf2py integer optional,intent(in) :: n = 13 5 | REAL A,X 6 | COMMON /DATA/ A,X(3) 7 | PRINT*, "IN FOO: N=",N," A=",A," X=[",X(1),X(2),X(3),"]" 8 | END 9 | C END OF FTYPE.F 10 | -------------------------------------------------------------------------------- /doc/source/f2py/callback.f: -------------------------------------------------------------------------------- 1 | C FILE: CALLBACK.F 2 | SUBROUTINE FOO(FUN,R) 3 | EXTERNAL FUN 4 | INTEGER I 5 | REAL*8 R 6 | Cf2py intent(out) r 7 | R = 0D0 8 | DO I=-5,5 9 | R = R + FUN(I) 10 | ENDDO 11 | END 12 | C END OF FILE CALLBACK.F 13 | -------------------------------------------------------------------------------- /doc/source/reference/routines.functional.rst: -------------------------------------------------------------------------------- 1 | Functional programming 2 | ********************** 3 | 4 | .. currentmodule:: numpy 5 | 6 | .. autosummary:: 7 | :toctree: generated/ 8 | 9 | apply_along_axis 10 | apply_over_axes 11 | vectorize 12 | frompyfunc 13 | piecewise 14 | -------------------------------------------------------------------------------- /numpy/f2py/src/test/bar.f: -------------------------------------------------------------------------------- 1 | subroutine bar() 2 | integer a 3 | real*8 b,c(3) 4 | common /foodata/ a,b,c 5 | a = 4 6 | b = 6.7 7 | c(2) = 3.0 8 | write(*,*) "bar:a=",a 9 | write(*,*) "bar:b=",b 10 | write(*,*) "bar:c=",c 11 | end 12 | -------------------------------------------------------------------------------- /numpy/f2py/src/test/foo.f: -------------------------------------------------------------------------------- 1 | subroutine bar() 2 | integer a 3 | real*8 b,c(3) 4 | common /foodata/ a,b,c 5 | a = 4 6 | b = 6.7 7 | c(2) = 3.0 8 | write(*,*) "bar:a=",a 9 | write(*,*) "bar:b=",b 10 | write(*,*) "bar:c=",c 11 | end 12 | -------------------------------------------------------------------------------- /doc/source/f2py/fib2.pyf: -------------------------------------------------------------------------------- 1 | ! -*- f90 -*- 2 | python module fib2 3 | interface 4 | subroutine fib(a,n) 5 | real*8 dimension(n),intent(out),depend(n) :: a 6 | integer intent(in) :: n 7 | end subroutine fib 8 | end interface 9 | end python module fib2 10 | -------------------------------------------------------------------------------- /doc/source/reference/routines.window.rst: -------------------------------------------------------------------------------- 1 | Window functions 2 | ================ 3 | 4 | .. currentmodule:: numpy 5 | 6 | Various windows 7 | --------------- 8 | 9 | .. autosummary:: 10 | :toctree: generated/ 11 | 12 | bartlett 13 | blackman 14 | hamming 15 | hanning 16 | kaiser 17 | -------------------------------------------------------------------------------- /doc/source/f2py/compile_session.dat: -------------------------------------------------------------------------------- 1 | >>> import f2py2e 2 | >>> fsource = ''' 3 | ... subroutine foo 4 | ... print*, "Hello world!" 5 | ... end 6 | ... ''' 7 | >>> f2py2e.compile(fsource,modulename='hello',verbose=0) 8 | 0 9 | >>> import hello 10 | >>> hello.foo() 11 | Hello world! 12 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/common/block.f: -------------------------------------------------------------------------------- 1 | SUBROUTINE INITCB 2 | DOUBLE PRECISION LONG 3 | CHARACTER STRING 4 | INTEGER OK 5 | 6 | COMMON /BLOCK/ LONG, STRING, OK 7 | LONG = 1.0 8 | STRING = '2' 9 | OK = 3 10 | RETURN 11 | END 12 | -------------------------------------------------------------------------------- /doc/source/user/basics.rst: -------------------------------------------------------------------------------- 1 | ************ 2 | NumPy basics 3 | ************ 4 | 5 | .. toctree:: 6 | :maxdepth: 1 7 | 8 | basics.types 9 | basics.creation 10 | basics.io 11 | basics.indexing 12 | basics.broadcasting 13 | basics.byteswapping 14 | basics.rec 15 | basics.subclassing 16 | -------------------------------------------------------------------------------- /numpy/_build_utils/README: -------------------------------------------------------------------------------- 1 | ======= 2 | WARNING 3 | ======= 4 | 5 | This directory (numpy/_build_utils) is *not* part of the public numpy API, 6 | - it is internal build support for numpy. 7 | - it is only present in source distributions or during an in place build 8 | - it is *not* installed with the rest of numpy 9 | -------------------------------------------------------------------------------- /doc/source/dev/gitwash/index.rst: -------------------------------------------------------------------------------- 1 | .. _using-git: 2 | 3 | Working with *NumPy* source code 4 | ================================ 5 | 6 | Contents: 7 | 8 | .. toctree:: 9 | :maxdepth: 2 10 | 11 | git_intro 12 | following_latest 13 | git_development 14 | development_workflow 15 | git_resources 16 | -------------------------------------------------------------------------------- /doc/source/user/basics.rec.rst: -------------------------------------------------------------------------------- 1 | .. _structured_arrays: 2 | 3 | ***************** 4 | Structured arrays 5 | ***************** 6 | 7 | .. automodule:: numpy.doc.structured_arrays 8 | 9 | Recarray Helper Functions 10 | ************************* 11 | 12 | .. automodule:: numpy.lib.recfunctions 13 | :members: 14 | -------------------------------------------------------------------------------- /numpy/f2py/__version__.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | major = 2 4 | 5 | try: 6 | from __svn_version__ import version 7 | version_info = (major, version) 8 | version = '%s_%s' % version_info 9 | except (ImportError, ValueError): 10 | version = str(major) 11 | -------------------------------------------------------------------------------- /numpy/fft/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | # To get sub-modules 4 | from .info import __doc__ 5 | 6 | from .fftpack import * 7 | from .helper import * 8 | 9 | from numpy.testing._private.pytesttester import PytestTester 10 | test = PytestTester(__name__) 11 | del PytestTester 12 | -------------------------------------------------------------------------------- /numpy/core/src/npymath/npy_math.c: -------------------------------------------------------------------------------- 1 | /* 2 | * vim:syntax=c 3 | * This file is compiled into the npy_math library with externally visible 4 | * symbols, and the static and inline specifiers utilized in the npy_math 5 | * function definitions are switched off. 6 | */ 7 | 8 | #define NPY_INLINE_MATH 0 9 | #include "npy_math_internal.h" 10 | -------------------------------------------------------------------------------- /doc/source/f2py/scalar.f: -------------------------------------------------------------------------------- 1 | C FILE: SCALAR.F 2 | SUBROUTINE FOO(A,B) 3 | REAL*8 A, B 4 | Cf2py intent(in) a 5 | Cf2py intent(inout) b 6 | PRINT*, " A=",A," B=",B 7 | PRINT*, "INCREMENT A AND B" 8 | A = A + 1D0 9 | B = B + 1D0 10 | PRINT*, "NEW A=",A," B=",B 11 | END 12 | C END OF FILE SCALAR.F 13 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/regression/inout.f90: -------------------------------------------------------------------------------- 1 | ! Check that intent(in out) translates as intent(inout). 2 | ! The separation seems to be a common usage. 3 | subroutine foo(x) 4 | implicit none 5 | real(4), intent(in out) :: x 6 | dimension x(3) 7 | x(1) = x(1) + x(2) + x(3) 8 | return 9 | end 10 | -------------------------------------------------------------------------------- /numpy/core/src/umath/override.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_UMATH_OVERRIDE_H 2 | #define _NPY_UMATH_OVERRIDE_H 3 | 4 | #include "npy_config.h" 5 | #include "numpy/ufuncobject.h" 6 | 7 | NPY_NO_EXPORT int 8 | PyUFunc_CheckOverride(PyUFuncObject *ufunc, char *method, 9 | PyObject *args, PyObject *kwds, 10 | PyObject **result); 11 | #endif 12 | -------------------------------------------------------------------------------- /doc/source/reference/routines.financial.rst: -------------------------------------------------------------------------------- 1 | Financial functions 2 | ******************* 3 | 4 | .. currentmodule:: numpy 5 | 6 | Simple financial functions 7 | -------------------------- 8 | 9 | .. autosummary:: 10 | :toctree: generated/ 11 | 12 | fv 13 | pv 14 | npv 15 | pmt 16 | ppmt 17 | ipmt 18 | irr 19 | mirr 20 | nper 21 | rate 22 | -------------------------------------------------------------------------------- /numpy/matrixlib/__init__.py: -------------------------------------------------------------------------------- 1 | """Sub-package containing the matrix class and related functions. 2 | 3 | """ 4 | from __future__ import division, absolute_import, print_function 5 | 6 | from .defmatrix import * 7 | 8 | __all__ = defmatrix.__all__ 9 | 10 | from numpy.testing._private.pytesttester import PytestTester 11 | test = PytestTester(__name__) 12 | del PytestTester 13 | -------------------------------------------------------------------------------- /doc/source/f2py/calculate.f: -------------------------------------------------------------------------------- 1 | subroutine calculate(x,n) 2 | cf2py intent(callback) func 3 | external func 4 | c The following lines define the signature of func for F2PY: 5 | cf2py real*8 y 6 | cf2py y = func(y) 7 | c 8 | cf2py intent(in,out,copy) x 9 | integer n,i 10 | real*8 x(n) 11 | do i=1,n 12 | x(i) = func(x(i)) 13 | end do 14 | end 15 | -------------------------------------------------------------------------------- /doc/source/f2py/common.f: -------------------------------------------------------------------------------- 1 | C FILE: COMMON.F 2 | SUBROUTINE FOO 3 | INTEGER I,X 4 | REAL A 5 | COMMON /DATA/ I,X(4),A(2,3) 6 | PRINT*, "I=",I 7 | PRINT*, "X=[",X,"]" 8 | PRINT*, "A=[" 9 | PRINT*, "[",A(1,1),",",A(1,2),",",A(1,3),"]" 10 | PRINT*, "[",A(2,1),",",A(2,2),",",A(2,3),"]" 11 | PRINT*, "]" 12 | END 13 | C END OF COMMON.F 14 | -------------------------------------------------------------------------------- /doc/source/f2py/extcallback.f: -------------------------------------------------------------------------------- 1 | subroutine f1() 2 | print *, "in f1, calling f2 twice.." 3 | call f2() 4 | call f2() 5 | return 6 | end 7 | 8 | subroutine f2() 9 | cf2py intent(callback, hide) fpy 10 | external fpy 11 | print *, "in f2, calling f2py.." 12 | call fpy() 13 | return 14 | end 15 | -------------------------------------------------------------------------------- /numpy/_distributor_init.py: -------------------------------------------------------------------------------- 1 | """ Distributor init file 2 | 3 | Distributors: you can add custom code here to support particular distributions 4 | of numpy. 5 | 6 | For example, this is a good place to put any checks for hardware requirements. 7 | 8 | The numpy standard source distribution will not put code in this file, so you 9 | can safely replace this file with your own version. 10 | """ 11 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "doc/scipy-sphinx-theme"] 2 | path = doc/scipy-sphinx-theme 3 | url = https://github.com/scipy/scipy-sphinx-theme.git 4 | [submodule "doc/sphinxext"] 5 | path = doc/sphinxext 6 | url = https://github.com/numpy/numpydoc.git 7 | [submodule "numpy/core/src/npymath/softposit"] 8 | path = numpy/core/src/npymath/softposit 9 | url = https://gitlab.com/xman16/SoftPosit.git 10 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/assumed_shape/foo_use.f90: -------------------------------------------------------------------------------- 1 | subroutine sum_with_use(x, res) 2 | use precision 3 | 4 | implicit none 5 | 6 | real(kind=rk), intent(in) :: x(:) 7 | real(kind=rk), intent(out) :: res 8 | 9 | integer :: i 10 | 11 | !print *, "size(x) = ", size(x) 12 | 13 | res = 0.0 14 | 15 | do i = 1, size(x) 16 | res = res + x(i) 17 | enddo 18 | 19 | end subroutine 20 | -------------------------------------------------------------------------------- /doc/source/reference/routines.emath.rst: -------------------------------------------------------------------------------- 1 | Mathematical functions with automatic domain (:mod:`numpy.emath`) 2 | *********************************************************************** 3 | 4 | .. currentmodule:: numpy 5 | 6 | .. note:: :mod:`numpy.emath` is a preferred alias for :mod:`numpy.lib.scimath`, 7 | available after :mod:`numpy` is imported. 8 | 9 | .. automodule:: numpy.lib.scimath 10 | -------------------------------------------------------------------------------- /doc/source/f2py/allocarr.f90: -------------------------------------------------------------------------------- 1 | module mod 2 | real, allocatable, dimension(:,:) :: b 3 | contains 4 | subroutine foo 5 | integer k 6 | if (allocated(b)) then 7 | print*, "b=[" 8 | do k = 1,size(b,1) 9 | print*, b(k,1:size(b,2)) 10 | enddo 11 | print*, "]" 12 | else 13 | print*, "b is not allocated" 14 | endif 15 | end subroutine foo 16 | end module mod 17 | -------------------------------------------------------------------------------- /doc/source/reference/routines.help.rst: -------------------------------------------------------------------------------- 1 | .. _routines.help: 2 | 3 | NumPy-specific help functions 4 | ============================= 5 | 6 | .. currentmodule:: numpy 7 | 8 | Finding help 9 | ------------ 10 | 11 | .. autosummary:: 12 | :toctree: generated/ 13 | 14 | lookfor 15 | 16 | 17 | Reading help 18 | ------------ 19 | 20 | .. autosummary:: 21 | :toctree: generated/ 22 | 23 | info 24 | source 25 | -------------------------------------------------------------------------------- /doc/source/reference/routines.set.rst: -------------------------------------------------------------------------------- 1 | Set routines 2 | ============ 3 | 4 | .. currentmodule:: numpy 5 | 6 | Making proper sets 7 | ------------------ 8 | .. autosummary:: 9 | :toctree: generated/ 10 | 11 | unique 12 | 13 | Boolean operations 14 | ------------------ 15 | .. autosummary:: 16 | :toctree: generated/ 17 | 18 | in1d 19 | intersect1d 20 | isin 21 | setdiff1d 22 | setxor1d 23 | union1d 24 | -------------------------------------------------------------------------------- /tools/allocation_tracking/setup.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, print_function 2 | 3 | from distutils.core import setup 4 | from distutils.extension import Extension 5 | from Cython.Distutils import build_ext 6 | import numpy 7 | 8 | setup( 9 | cmdclass = {'build_ext': build_ext}, 10 | ext_modules = [Extension("alloc_hook", ["alloc_hook.pyx"], 11 | include_dirs=[numpy.get_include()])]) 12 | -------------------------------------------------------------------------------- /tools/travis-upload-wheel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | set -ex 4 | 5 | export CLOUD_CONTAINER_NAME=travis-dev-wheels 6 | 7 | if [[ ( ${USE_WHEEL} == 1 ) \ 8 | && ( "${TRAVIS_BRANCH}" == "master" ) \ 9 | && ( "${TRAVIS_PULL_REQUEST}" == "false" ) ]]; then 10 | pip install wheelhouse_uploader 11 | python -m wheelhouse_uploader upload --local-folder \ 12 | ${TRAVIS_BUILD_DIR}/dist/ ${CLOUD_CONTAINER_NAME} 13 | fi 14 | -------------------------------------------------------------------------------- /doc/source/user/install.rst: -------------------------------------------------------------------------------- 1 | **************** 2 | Installing NumPy 3 | **************** 4 | 5 | In most use cases the best way to install NumPy on your system is by using a 6 | pre-built package for your operating system. Please see 7 | http://scipy.org/install.html for links to available options. 8 | 9 | For instructions on building for source package, see 10 | :doc:`building`. This information is useful mainly for advanced users. 11 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/buffer.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_PRIVATE_BUFFER_H_ 2 | #define _NPY_PRIVATE_BUFFER_H_ 3 | 4 | extern NPY_NO_EXPORT PyBufferProcs array_as_buffer; 5 | 6 | NPY_NO_EXPORT void 7 | _array_dealloc_buffer_info(PyArrayObject *self); 8 | 9 | NPY_NO_EXPORT PyArray_Descr* 10 | _descriptor_from_pep3118_format(char *s); 11 | 12 | NPY_NO_EXPORT int 13 | gentype_getbuffer(PyObject *obj, Py_buffer *view, int flags); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/ucsnarrow.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_UCSNARROW_H_ 2 | #define _NPY_UCSNARROW_H_ 3 | 4 | NPY_NO_EXPORT int 5 | PyUCS2Buffer_FromUCS4(Py_UNICODE *ucs2, npy_ucs4 *ucs4, int ucs4length); 6 | 7 | NPY_NO_EXPORT int 8 | PyUCS2Buffer_AsUCS4(Py_UNICODE *ucs2, npy_ucs4 *ucs4, int ucs2len, int ucs4len); 9 | 10 | NPY_NO_EXPORT PyUnicodeObject * 11 | PyUnicode_FromUCS4(char *src, Py_ssize_t size, int swap, int align); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /numpy/lib/setup.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, print_function 2 | 3 | def configuration(parent_package='',top_path=None): 4 | from numpy.distutils.misc_util import Configuration 5 | 6 | config = Configuration('lib', parent_package, top_path) 7 | config.add_data_dir('tests') 8 | return config 9 | 10 | if __name__ == '__main__': 11 | from numpy.distutils.core import setup 12 | setup(configuration=configuration) 13 | -------------------------------------------------------------------------------- /doc/source/f2py/fib1.f: -------------------------------------------------------------------------------- 1 | C FILE: FIB1.F 2 | SUBROUTINE FIB(A,N) 3 | C 4 | C CALCULATE FIRST N FIBONACCI NUMBERS 5 | C 6 | INTEGER N 7 | REAL*8 A(N) 8 | DO I=1,N 9 | IF (I.EQ.1) THEN 10 | A(I) = 0.0D0 11 | ELSEIF (I.EQ.2) THEN 12 | A(I) = 1.0D0 13 | ELSE 14 | A(I) = A(I-1) + A(I-2) 15 | ENDIF 16 | ENDDO 17 | END 18 | C END FILE FIB1.F 19 | -------------------------------------------------------------------------------- /numpy/linalg/lapack_lite/f2c_config.c.patch: -------------------------------------------------------------------------------- 1 | @@ -696,7 +696,7 @@ 2 | doublereal dlamc3_(doublereal *a, doublereal *b) 3 | { 4 | /* System generated locals */ 5 | - doublereal ret_val; 6 | + volatile doublereal ret_val; 7 | 8 | 9 | /* 10 | @@ -1773,7 +1773,7 @@ 11 | doublereal slamc3_(real *a, real *b) 12 | { 13 | /* System generated locals */ 14 | - real ret_val; 15 | + volatile real ret_val; 16 | 17 | 18 | /* 19 | -------------------------------------------------------------------------------- /doc/source/reference/routines.ctypeslib.rst: -------------------------------------------------------------------------------- 1 | *********************************************************** 2 | C-Types Foreign Function Interface (:mod:`numpy.ctypeslib`) 3 | *********************************************************** 4 | 5 | .. currentmodule:: numpy.ctypeslib 6 | 7 | .. autofunction:: as_array 8 | .. autofunction:: as_ctypes 9 | .. autofunction:: ctypes_load_library 10 | .. autofunction:: load_library 11 | .. autofunction:: ndpointer 12 | -------------------------------------------------------------------------------- /numpy/compat/setup.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, print_function 2 | 3 | def configuration(parent_package='',top_path=None): 4 | from numpy.distutils.misc_util import Configuration 5 | 6 | config = Configuration('compat', parent_package, top_path) 7 | config.add_data_dir('tests') 8 | return config 9 | 10 | if __name__ == '__main__': 11 | from numpy.distutils.core import setup 12 | setup(configuration=configuration) 13 | -------------------------------------------------------------------------------- /numpy/polynomial/setup.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, print_function 2 | 3 | def configuration(parent_package='',top_path=None): 4 | from numpy.distutils.misc_util import Configuration 5 | config = Configuration('polynomial', parent_package, top_path) 6 | config.add_data_dir('tests') 7 | return config 8 | 9 | if __name__ == '__main__': 10 | from numpy.distutils.core import setup 11 | setup(configuration=configuration) 12 | -------------------------------------------------------------------------------- /numpy/ma/version.py: -------------------------------------------------------------------------------- 1 | """Version number 2 | 3 | """ 4 | from __future__ import division, absolute_import, print_function 5 | 6 | version = '1.00' 7 | release = False 8 | 9 | if not release: 10 | from . import core 11 | from . import extras 12 | revision = [core.__revision__.split(':')[-1][:-1].strip(), 13 | extras.__revision__.split(':')[-1][:-1].strip(),] 14 | version += '.dev%04i' % max([int(rev) for rev in revision]) 15 | -------------------------------------------------------------------------------- /doc/source/f2py/fib1.pyf: -------------------------------------------------------------------------------- 1 | ! -*- f90 -*- 2 | python module fib2 ! in 3 | interface ! in :fib2 4 | subroutine fib(a,n) ! in :fib2:fib1.f 5 | real*8 dimension(n) :: a 6 | integer optional,check(len(a)>=n),depend(a) :: n=len(a) 7 | end subroutine fib 8 | end interface 9 | end python module fib2 10 | 11 | ! This file was auto-generated with f2py (version:2.28.198-1366). 12 | ! See http://cens.ioc.ee/projects/f2py2e/ 13 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/kind/foo.f90: -------------------------------------------------------------------------------- 1 | 2 | 3 | subroutine selectedrealkind(p, r, res) 4 | implicit none 5 | 6 | integer, intent(in) :: p, r 7 | !f2py integer :: r=0 8 | integer, intent(out) :: res 9 | res = selected_real_kind(p, r) 10 | 11 | end subroutine 12 | 13 | subroutine selectedintkind(p, res) 14 | implicit none 15 | 16 | integer, intent(in) :: p 17 | integer, intent(out) :: res 18 | res = selected_int_kind(p) 19 | 20 | end subroutine 21 | -------------------------------------------------------------------------------- /numpy/core/npymath.ini.in: -------------------------------------------------------------------------------- 1 | [meta] 2 | Name=npymath 3 | Description=Portable, core math library implementing C99 standard 4 | Version=0.1 5 | 6 | [variables] 7 | pkgname=@pkgname@ 8 | prefix=${pkgdir} 9 | libdir=${prefix}@sep@lib 10 | includedir=${prefix}@sep@include 11 | 12 | [default] 13 | Libs=-L${libdir} -lnpymath 14 | Cflags=-I${includedir} 15 | Requires=mlib 16 | 17 | [msvc] 18 | Libs=/LIBPATH:${libdir} npymath.lib 19 | Cflags=/INCLUDE:${includedir} 20 | Requires=mlib 21 | -------------------------------------------------------------------------------- /doc/newdtype_example/setup.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, print_function 2 | 3 | from numpy.distutils.core import setup 4 | 5 | def configuration(parent_package = '', top_path=None): 6 | from numpy.distutils.misc_util import Configuration 7 | config = Configuration('floatint', parent_package, top_path) 8 | 9 | config.add_extension('floatint', 10 | sources = ['floatint.c']) 11 | return config 12 | 13 | setup(configuration=configuration) 14 | -------------------------------------------------------------------------------- /doc/source/f2py/array.f: -------------------------------------------------------------------------------- 1 | C FILE: ARRAY.F 2 | SUBROUTINE FOO(A,N,M) 3 | C 4 | C INCREMENT THE FIRST ROW AND DECREMENT THE FIRST COLUMN OF A 5 | C 6 | INTEGER N,M,I,J 7 | REAL*8 A(N,M) 8 | Cf2py intent(in,out,copy) a 9 | Cf2py integer intent(hide),depend(a) :: n=shape(a,0), m=shape(a,1) 10 | DO J=1,M 11 | A(1,J) = A(1,J) + 1D0 12 | ENDDO 13 | DO I=1,N 14 | A(I,1) = A(I,1) - 1D0 15 | ENDDO 16 | END 17 | C END OF FILE ARRAY.F 18 | -------------------------------------------------------------------------------- /doc/source/reference/maskedarray.rst: -------------------------------------------------------------------------------- 1 | .. _maskedarray: 2 | 3 | ************* 4 | Masked arrays 5 | ************* 6 | 7 | Masked arrays are arrays that may have missing or invalid entries. 8 | The :mod:`numpy.ma` module provides a nearly work-alike replacement for numpy 9 | that supports data arrays with masks. 10 | 11 | .. index:: 12 | single: masked arrays 13 | 14 | .. toctree:: 15 | :maxdepth: 2 16 | 17 | maskedarray.generic 18 | maskedarray.baseclass 19 | routines.ma 20 | -------------------------------------------------------------------------------- /numpy/core/cversions.py: -------------------------------------------------------------------------------- 1 | """Simple script to compute the api hash of the current API. 2 | 3 | The API has is defined by numpy_api_order and ufunc_api_order. 4 | 5 | """ 6 | from __future__ import division, absolute_import, print_function 7 | 8 | from os.path import dirname 9 | 10 | from code_generators.genapi import fullapi_hash 11 | from code_generators.numpy_api import full_api 12 | 13 | if __name__ == '__main__': 14 | curdir = dirname(__file__) 15 | print(fullapi_hash(full_api)) 16 | -------------------------------------------------------------------------------- /numpy/ma/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import division, print_function 3 | 4 | def configuration(parent_package='',top_path=None): 5 | from numpy.distutils.misc_util import Configuration 6 | config = Configuration('ma', parent_package, top_path) 7 | config.add_data_dir('tests') 8 | return config 9 | 10 | if __name__ == "__main__": 11 | from numpy.distutils.core import setup 12 | config = configuration(top_path='').todict() 13 | setup(**config) 14 | -------------------------------------------------------------------------------- /numpy/testing/decorators.py: -------------------------------------------------------------------------------- 1 | """ 2 | Back compatibility decorators module. It will import the appropriate 3 | set of tools 4 | 5 | """ 6 | from __future__ import division, absolute_import, print_function 7 | 8 | import warnings 9 | 10 | # 2018-04-04, numpy 1.15.0 11 | warnings.warn("Importing from numpy.testing.decorators is deprecated, " 12 | "import from numpy.testing instead.", 13 | DeprecationWarning, stacklevel=2) 14 | 15 | from ._private.decorators import * 16 | -------------------------------------------------------------------------------- /numpy/testing/noseclasses.py: -------------------------------------------------------------------------------- 1 | """ 2 | Back compatibility noseclasses module. It will import the appropriate 3 | set of tools 4 | """ 5 | from __future__ import division, absolute_import, print_function 6 | 7 | import warnings 8 | 9 | # 2018-04-04, numpy 1.15.0 10 | warnings.warn("Importing from numpy.testing.noseclasses is deprecated, " 11 | "import from numpy.testing instead", 12 | DeprecationWarning, stacklevel=2) 13 | 14 | from ._private.noseclasses import * 15 | -------------------------------------------------------------------------------- /doc/source/f2py/extcallback_session.dat: -------------------------------------------------------------------------------- 1 | >>> import pfromf 2 | >>> pfromf.f2() 3 | Traceback (most recent call last): 4 | File "", line 1, in ? 5 | pfromf.error: Callback fpy not defined (as an argument or module pfromf attribute). 6 | 7 | >>> def f(): print "python f" 8 | ... 9 | >>> pfromf.fpy = f 10 | >>> pfromf.f2() 11 | in f2, calling f2py.. 12 | python f 13 | >>> pfromf.f1() 14 | in f1, calling f2 twice.. 15 | in f2, calling f2py.. 16 | python f 17 | in f2, calling f2py.. 18 | python f 19 | >>> -------------------------------------------------------------------------------- /doc/source/f2py/fib3.f: -------------------------------------------------------------------------------- 1 | C FILE: FIB3.F 2 | SUBROUTINE FIB(A,N) 3 | C 4 | C CALCULATE FIRST N FIBONACCI NUMBERS 5 | C 6 | INTEGER N 7 | REAL*8 A(N) 8 | Cf2py intent(in) n 9 | Cf2py intent(out) a 10 | Cf2py depend(n) a 11 | DO I=1,N 12 | IF (I.EQ.1) THEN 13 | A(I) = 0.0D0 14 | ELSEIF (I.EQ.2) THEN 15 | A(I) = 1.0D0 16 | ELSE 17 | A(I) = A(I-1) + A(I-2) 18 | ENDIF 19 | ENDDO 20 | END 21 | C END FILE FIB3.F 22 | -------------------------------------------------------------------------------- /doc/source/reference/routines.err.rst: -------------------------------------------------------------------------------- 1 | Floating point error handling 2 | ***************************** 3 | 4 | .. currentmodule:: numpy 5 | 6 | Setting and getting error handling 7 | ---------------------------------- 8 | 9 | .. autosummary:: 10 | :toctree: generated/ 11 | 12 | seterr 13 | geterr 14 | seterrcall 15 | geterrcall 16 | errstate 17 | 18 | Internal functions 19 | ------------------ 20 | 21 | .. autosummary:: 22 | :toctree: generated/ 23 | 24 | seterrobj 25 | geterrobj 26 | -------------------------------------------------------------------------------- /numpy/core/src/private/npy_longdouble.h: -------------------------------------------------------------------------------- 1 | #ifndef __NPY_LONGDOUBLE_H 2 | #define __NPY_LONGDOUBLE_H 3 | 4 | #include "npy_config.h" 5 | #include "numpy/ndarraytypes.h" 6 | 7 | /* Convert a npy_longdouble to a python `long` integer. 8 | * 9 | * Results are rounded towards zero. 10 | * 11 | * This performs the same task as PyLong_FromDouble, but for long doubles 12 | * which have a greater range. 13 | */ 14 | NPY_VISIBILITY_HIDDEN PyObject * 15 | npy_longdouble_to_PyLong(npy_longdouble ldval); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /doc/neps/nep-0009-structured_array_extensions.rst: -------------------------------------------------------------------------------- 1 | =========================== 2 | Structured array extensions 3 | =========================== 4 | 5 | :Status: Deferred 6 | 7 | 1. Create with-style context that makes "named-columns" available as names in the namespace. 8 | 9 | with np.columns(array): 10 | price = unit * quantityt 11 | 12 | 13 | 2. Allow structured arrays to be sliced by their column (i.e. one additional indexing option for structured arrays) so that a[:4, 'foo':'bar'] would be allowed. 14 | -------------------------------------------------------------------------------- /doc/source/f2py/moddata.f90: -------------------------------------------------------------------------------- 1 | module mod 2 | integer i 3 | integer :: x(4) 4 | real, dimension(2,3) :: a 5 | real, allocatable, dimension(:,:) :: b 6 | contains 7 | subroutine foo 8 | integer k 9 | print*, "i=",i 10 | print*, "x=[",x,"]" 11 | print*, "a=[" 12 | print*, "[",a(1,1),",",a(1,2),",",a(1,3),"]" 13 | print*, "[",a(2,1),",",a(2,2),",",a(2,3),"]" 14 | print*, "]" 15 | print*, "Setting a(1,2)=a(1,2)+3" 16 | a(1,2) = a(1,2)+3 17 | end subroutine foo 18 | end module mod 19 | -------------------------------------------------------------------------------- /doc/source/reference/routines.datetime.rst: -------------------------------------------------------------------------------- 1 | .. _routines.datetime: 2 | 3 | Datetime Support Functions 4 | ************************** 5 | 6 | .. currentmodule:: numpy 7 | 8 | .. autosummary:: 9 | :toctree: generated/ 10 | 11 | datetime_as_string 12 | datetime_data 13 | 14 | 15 | Business Day Functions 16 | ====================== 17 | 18 | .. currentmodule:: numpy 19 | 20 | .. autosummary:: 21 | :toctree: generated/ 22 | 23 | busdaycalendar 24 | is_busday 25 | busday_offset 26 | busday_count 27 | -------------------------------------------------------------------------------- /doc/source/reference/routines.polynomials.package.rst: -------------------------------------------------------------------------------- 1 | Polynomial Package 2 | ================== 3 | 4 | .. versionadded:: 1.4.0 5 | 6 | .. currentmodule:: numpy.polynomial 7 | 8 | .. toctree:: 9 | :maxdepth: 2 10 | 11 | routines.polynomials.classes 12 | routines.polynomials.polynomial 13 | routines.polynomials.chebyshev 14 | routines.polynomials.legendre 15 | routines.polynomials.laguerre 16 | routines.polynomials.hermite 17 | routines.polynomials.hermite_e 18 | routines.polynomials.polyutils 19 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/refcount.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_PRIVATE_REFCOUNT_H_ 2 | #define _NPY_PRIVATE_REFCOUNT_H_ 3 | 4 | NPY_NO_EXPORT void 5 | PyArray_Item_INCREF(char *data, PyArray_Descr *descr); 6 | 7 | NPY_NO_EXPORT void 8 | PyArray_Item_XDECREF(char *data, PyArray_Descr *descr); 9 | 10 | NPY_NO_EXPORT int 11 | PyArray_INCREF(PyArrayObject *mp); 12 | 13 | NPY_NO_EXPORT int 14 | PyArray_XDECREF(PyArrayObject *mp); 15 | 16 | NPY_NO_EXPORT void 17 | PyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /numpy/matrixlib/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import division, print_function 3 | 4 | import os 5 | 6 | def configuration(parent_package='', top_path=None): 7 | from numpy.distutils.misc_util import Configuration 8 | config = Configuration('matrixlib', parent_package, top_path) 9 | config.add_data_dir('tests') 10 | return config 11 | 12 | if __name__ == "__main__": 13 | from numpy.distutils.core import setup 14 | config = configuration(top_path='').todict() 15 | setup(**config) 16 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/temp_elide.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_ARRAY_TEMP_AVOID_H_ 2 | #define _NPY_ARRAY_TEMP_AVOID_H_ 3 | #define NPY_NO_DEPRECATED_API NPY_API_VERSION 4 | #define _MULTIARRAYMODULE 5 | #include 6 | 7 | NPY_NO_EXPORT int 8 | can_elide_temp_unary(PyArrayObject * m1); 9 | 10 | NPY_NO_EXPORT int 11 | try_binary_elide(PyArrayObject * m1, PyObject * m2, 12 | PyObject * (inplace_op)(PyArrayObject * m1, PyObject * m2), 13 | PyObject ** res, int commutative); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /numpy/core/umath_tests.py: -------------------------------------------------------------------------------- 1 | """ 2 | Shim for _umath_tests to allow a deprecation period for the new name. 3 | 4 | """ 5 | from __future__ import division, absolute_import, print_function 6 | 7 | import warnings 8 | 9 | # 2018-04-04, numpy 1.15.0 10 | warnings.warn(("numpy.core.umath_tests is an internal NumPy " 11 | "module and should not be imported. It will " 12 | "be removed in a future NumPy release."), 13 | category=DeprecationWarning, stacklevel=2) 14 | 15 | from ._umath_tests import * 16 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/strfuncs.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_ARRAY_STRFUNCS_H_ 2 | #define _NPY_ARRAY_STRFUNCS_H_ 3 | 4 | NPY_NO_EXPORT void 5 | PyArray_SetStringFunction(PyObject *op, int repr); 6 | 7 | NPY_NO_EXPORT PyObject * 8 | array_repr(PyArrayObject *self); 9 | 10 | NPY_NO_EXPORT PyObject * 11 | array_str(PyArrayObject *self); 12 | 13 | NPY_NO_EXPORT PyObject * 14 | array_format(PyArrayObject *self, PyObject *args); 15 | 16 | #ifndef NPY_PY3K 17 | NPY_NO_EXPORT PyObject * 18 | array_unicode(PyArrayObject *self); 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /doc/changelog/1.14.5-changelog.rst: -------------------------------------------------------------------------------- 1 | 2 | Contributors 3 | ============ 4 | 5 | A total of 1 person contributed to this release. People with a "+" by their 6 | names contributed a patch for the first time. 7 | 8 | * Charles Harris 9 | 10 | Pull requests merged 11 | ==================== 12 | 13 | A total of 2 pull requests were merged for this release. 14 | 15 | * `#11274 `__: BUG: Correct use of NPY_UNUSED. 16 | * `#11294 `__: BUG: Remove extra trailing parentheses. 17 | -------------------------------------------------------------------------------- /doc/source/f2py/string.f: -------------------------------------------------------------------------------- 1 | C FILE: STRING.F 2 | SUBROUTINE FOO(A,B,C,D) 3 | CHARACTER*5 A, B 4 | CHARACTER*(*) C,D 5 | Cf2py intent(in) a,c 6 | Cf2py intent(inout) b,d 7 | PRINT*, "A=",A 8 | PRINT*, "B=",B 9 | PRINT*, "C=",C 10 | PRINT*, "D=",D 11 | PRINT*, "CHANGE A,B,C,D" 12 | A(1:1) = 'A' 13 | B(1:1) = 'B' 14 | C(1:1) = 'C' 15 | D(1:1) = 'D' 16 | PRINT*, "A=",A 17 | PRINT*, "B=",B 18 | PRINT*, "C=",C 19 | PRINT*, "D=",D 20 | END 21 | C END OF FILE STRING.F 22 | -------------------------------------------------------------------------------- /doc/source/user/index.rst: -------------------------------------------------------------------------------- 1 | .. _user: 2 | 3 | ################ 4 | NumPy User Guide 5 | ################ 6 | 7 | This guide is intended as an introductory overview of NumPy and 8 | explains how to install and make use of the most important features of 9 | NumPy. For detailed reference documentation of the functions and 10 | classes contained in the package, see the :ref:`reference`. 11 | 12 | .. toctree:: 13 | :maxdepth: 1 14 | 15 | setting-up 16 | quickstart 17 | basics 18 | misc 19 | numpy-for-matlab-users 20 | building 21 | c-info 22 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/vdot.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_VDOT_H_ 2 | #define _NPY_VDOT_H_ 3 | 4 | #include "common.h" 5 | 6 | NPY_NO_EXPORT void 7 | CFLOAT_vdot(char *, npy_intp, char *, npy_intp, char *, npy_intp, void *); 8 | 9 | NPY_NO_EXPORT void 10 | CDOUBLE_vdot(char *, npy_intp, char *, npy_intp, char *, npy_intp, void *); 11 | 12 | NPY_NO_EXPORT void 13 | CLONGDOUBLE_vdot(char *, npy_intp, char *, npy_intp, char *, npy_intp, void *); 14 | 15 | NPY_NO_EXPORT void 16 | OBJECT_vdot(char *, npy_intp, char *, npy_intp, char *, npy_intp, void *); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /numpy/core/src/private/ufunc_override.h: -------------------------------------------------------------------------------- 1 | #ifndef __UFUNC_OVERRIDE_H 2 | #define __UFUNC_OVERRIDE_H 3 | 4 | #include "npy_config.h" 5 | 6 | /* 7 | * Check whether a set of input and output args have a non-default 8 | * `__array_ufunc__` method. Returns the number of overrides, setting 9 | * corresponding objects in PyObject array with_override (if not NULL). 10 | * returns -1 on failure. 11 | */ 12 | NPY_NO_EXPORT int 13 | PyUFunc_WithOverride(PyObject *args, PyObject *kwds, 14 | PyObject **with_override, PyObject **methods); 15 | #endif 16 | -------------------------------------------------------------------------------- /doc/source/f2py/callback2.pyf: -------------------------------------------------------------------------------- 1 | ! -*- f90 -*- 2 | python module __user__routines 3 | interface 4 | function fun(i) result (r) 5 | integer :: i 6 | real*8 :: r 7 | end function fun 8 | end interface 9 | end python module __user__routines 10 | 11 | python module callback2 12 | interface 13 | subroutine foo(f,r) 14 | use __user__routines, f=>fun 15 | external f 16 | real*8 intent(out) :: r 17 | end subroutine foo 18 | end interface 19 | end python module callback2 20 | -------------------------------------------------------------------------------- /doc/source/f2py/spam.pyf: -------------------------------------------------------------------------------- 1 | ! -*- f90 -*- 2 | python module spam 3 | usercode ''' 4 | static char doc_spam_system[] = "Execute a shell command."; 5 | static PyObject *spam_system(PyObject *self, PyObject *args) 6 | { 7 | char *command; 8 | int sts; 9 | 10 | if (!PyArg_ParseTuple(args, "s", &command)) 11 | return NULL; 12 | sts = system(command); 13 | return Py_BuildValue("i", sts); 14 | } 15 | ''' 16 | pymethoddef ''' 17 | {"system", spam_system, METH_VARARGS, doc_spam_system}, 18 | ''' 19 | end python module spam 20 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/parameter/constant_compound.f90: -------------------------------------------------------------------------------- 1 | ! Check that parameters are correct intercepted. 2 | ! Constants with comma separations are commonly 3 | ! used, for instance Pi = 3._dp 4 | subroutine foo_compound_int(x) 5 | implicit none 6 | integer, parameter :: ii = selected_int_kind(9) 7 | integer(ii), intent(inout) :: x 8 | dimension x(3) 9 | integer(ii), parameter :: three = 3_ii 10 | integer(ii), parameter :: two = 2_ii 11 | integer(ii), parameter :: six = three * 1_ii * two 12 | 13 | x(1) = x(1) + x(2) + x(3) * six 14 | return 15 | end subroutine 16 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/typeinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_PRIVATE_TYPEINFO_H_ 2 | #define _NPY_PRIVATE_TYPEINFO_H_ 3 | 4 | void typeinfo_init_structsequences(void); 5 | 6 | extern PyTypeObject PyArray_typeinfoType; 7 | extern PyTypeObject PyArray_typeinforangedType; 8 | 9 | PyObject * 10 | PyArray_typeinfo( 11 | char typechar, int typenum, int nbits, int align, 12 | PyTypeObject *type_obj); 13 | 14 | PyObject * 15 | PyArray_typeinforanged( 16 | char typechar, int typenum, int nbits, int align, 17 | PyObject *max, PyObject *min, PyTypeObject *type_obj); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /doc/source/f2py/callback_session.dat: -------------------------------------------------------------------------------- 1 | >>> import callback 2 | >>> print callback.foo.__doc__ 3 | foo - Function signature: 4 | r = foo(fun,[fun_extra_args]) 5 | Required arguments: 6 | fun : call-back function 7 | Optional arguments: 8 | fun_extra_args := () input tuple 9 | Return objects: 10 | r : float 11 | Call-back functions: 12 | def fun(i): return r 13 | Required arguments: 14 | i : input int 15 | Return objects: 16 | r : float 17 | 18 | >>> def f(i): return i*i 19 | ... 20 | >>> print callback.foo(f) 21 | 110.0 22 | >>> print callback.foo(lambda i:1) 23 | 11.0 24 | -------------------------------------------------------------------------------- /doc/source/f2py/scalar_session.dat: -------------------------------------------------------------------------------- 1 | >>> import scalar 2 | >>> print scalar.foo.__doc__ 3 | foo - Function signature: 4 | foo(a,b) 5 | Required arguments: 6 | a : input float 7 | b : in/output rank-0 array(float,'d') 8 | 9 | >>> scalar.foo(2,3) 10 | A= 2. B= 3. 11 | INCREMENT A AND B 12 | NEW A= 3. B= 4. 13 | >>> import numpy 14 | >>> a=numpy.array(2) # these are integer rank-0 arrays 15 | >>> b=numpy.array(3) 16 | >>> scalar.foo(a,b) 17 | A= 2. B= 3. 18 | INCREMENT A AND B 19 | NEW A= 3. B= 4. 20 | >>> print a,b # note that only b is changed in situ 21 | 2 4 22 | -------------------------------------------------------------------------------- /numpy/compat/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Compatibility module. 3 | 4 | This module contains duplicated code from Python itself or 3rd party 5 | extensions, which may be included for the following reasons: 6 | 7 | * compatibility 8 | * we may only need a small subset of the copied library/module 9 | 10 | """ 11 | from __future__ import division, absolute_import, print_function 12 | 13 | from . import _inspect 14 | from . import py3k 15 | from ._inspect import getargspec, formatargspec 16 | from .py3k import * 17 | 18 | __all__ = [] 19 | __all__.extend(_inspect.__all__) 20 | __all__.extend(py3k.__all__) 21 | -------------------------------------------------------------------------------- /numpy/random/mtrand/mtrand_py_helper.h: -------------------------------------------------------------------------------- 1 | #ifndef _MTRAND_PY_HELPER_H_ 2 | #define _MTRAND_PY_HELPER_H_ 3 | 4 | #include 5 | 6 | static PyObject *empty_py_bytes(npy_intp length, void **bytes) 7 | { 8 | PyObject *b; 9 | #if PY_MAJOR_VERSION >= 3 10 | b = PyBytes_FromStringAndSize(NULL, length); 11 | if (b) { 12 | *bytes = PyBytes_AS_STRING(b); 13 | } 14 | #else 15 | b = PyString_FromStringAndSize(NULL, length); 16 | if (b) { 17 | *bytes = PyString_AS_STRING(b); 18 | } 19 | #endif 20 | return b; 21 | } 22 | 23 | #endif /* _MTRAND_PY_HELPER_H_ */ 24 | -------------------------------------------------------------------------------- /doc/source/reference/routines.bitwise.rst: -------------------------------------------------------------------------------- 1 | Binary operations 2 | ***************** 3 | 4 | .. currentmodule:: numpy 5 | 6 | Elementwise bit operations 7 | -------------------------- 8 | .. autosummary:: 9 | :toctree: generated/ 10 | 11 | bitwise_and 12 | bitwise_or 13 | bitwise_xor 14 | invert 15 | left_shift 16 | right_shift 17 | 18 | Bit packing 19 | ----------- 20 | .. autosummary:: 21 | :toctree: generated/ 22 | 23 | packbits 24 | unpackbits 25 | 26 | Output formatting 27 | ----------------- 28 | .. autosummary:: 29 | :toctree: generated/ 30 | 31 | binary_repr 32 | -------------------------------------------------------------------------------- /numpy/core/src/npymath/_signbit.c: -------------------------------------------------------------------------------- 1 | /* Adapted from cephes */ 2 | 3 | int 4 | _npy_signbit_d(double x) 5 | { 6 | union 7 | { 8 | double d; 9 | short s[4]; 10 | int i[2]; 11 | } u; 12 | 13 | u.d = x; 14 | 15 | #if NPY_SIZEOF_INT == 4 16 | 17 | #ifdef WORDS_BIGENDIAN /* defined in pyconfig.h */ 18 | return u.i[0] < 0; 19 | #else 20 | return u.i[1] < 0; 21 | #endif 22 | 23 | #else /* NPY_SIZEOF_INT != 4 */ 24 | 25 | #ifdef WORDS_BIGENDIAN 26 | return u.s[0] < 0; 27 | #else 28 | return u.s[3] < 0; 29 | #endif 30 | 31 | #endif /* NPY_SIZEOF_INT */ 32 | } 33 | -------------------------------------------------------------------------------- /tools/allocation_tracking/README.md: -------------------------------------------------------------------------------- 1 | Example for using the `PyDataMem_SetEventHook` to track allocations inside numpy. 2 | 3 | `alloc_hook.pyx` implements a hook in Cython that calls back into a python 4 | function. `track_allocations.py` uses it for a simple listing of allocations. 5 | It can be built with the `setup.py` file in this folder. 6 | 7 | Note that since Python 3.6 the builtin tracemalloc module can be used to 8 | track allocations inside numpy. 9 | Numpy places its CPU memory allocations into the `np.lib.tracemalloc_domain` 10 | domain. 11 | See https://docs.python.org/3/library/tracemalloc.html. 12 | -------------------------------------------------------------------------------- /doc/source/f2py/run_main_session.dat: -------------------------------------------------------------------------------- 1 | >>> import f2py2e 2 | >>> r=f2py2e.run_main(['-m','scalar','docs/usersguide/scalar.f']) 3 | Reading fortran codes... 4 | Reading file 'docs/usersguide/scalar.f' 5 | Post-processing... 6 | Block: scalar 7 | Block: FOO 8 | Building modules... 9 | Building module "scalar"... 10 | Wrote C/API module "scalar" to file "./scalarmodule.c" 11 | >>> print r 12 | {'scalar': {'h': ['/home/users/pearu/src_cvs/f2py2e/src/fortranobject.h'], 13 | 'csrc': ['./scalarmodule.c', 14 | '/home/users/pearu/src_cvs/f2py2e/src/fortranobject.c']}} 15 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/usertypes.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_PRIVATE_USERTYPES_H_ 2 | #define _NPY_PRIVATE_USERTYPES_H_ 3 | 4 | extern NPY_NO_EXPORT PyArray_Descr **userdescrs; 5 | 6 | NPY_NO_EXPORT void 7 | PyArray_InitArrFuncs(PyArray_ArrFuncs *f); 8 | 9 | NPY_NO_EXPORT int 10 | PyArray_RegisterCanCast(PyArray_Descr *descr, int totype, 11 | NPY_SCALARKIND scalar); 12 | 13 | NPY_NO_EXPORT int 14 | PyArray_RegisterDataType(PyArray_Descr *descr); 15 | 16 | NPY_NO_EXPORT int 17 | PyArray_RegisterCastFunc(PyArray_Descr *descr, int totype, 18 | PyArray_VectorUnaryFunc *castfunc); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /doc/source/f2py/common_session.dat: -------------------------------------------------------------------------------- 1 | >>> import common 2 | >>> print common.data.__doc__ 3 | i - 'i'-scalar 4 | x - 'i'-array(4) 5 | a - 'f'-array(2,3) 6 | 7 | >>> common.data.i = 5 8 | >>> common.data.x[1] = 2 9 | >>> common.data.a = [[1,2,3],[4,5,6]] 10 | >>> common.foo() 11 | I= 5 12 | X=[ 0 2 0 0] 13 | A=[ 14 | [ 1., 2., 3.] 15 | [ 4., 5., 6.] 16 | ] 17 | >>> common.data.a[1] = 45 18 | >>> common.foo() 19 | I= 5 20 | X=[ 0 2 0 0] 21 | A=[ 22 | [ 1., 2., 3.] 23 | [ 45., 45., 45.] 24 | ] 25 | >>> common.data.a # a is Fortran-contiguous 26 | array([[ 1., 2., 3.], 27 | [ 45., 45., 45.]],'f') 28 | -------------------------------------------------------------------------------- /numpy/fft/setup.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, print_function 2 | 3 | 4 | def configuration(parent_package='',top_path=None): 5 | from numpy.distutils.misc_util import Configuration 6 | config = Configuration('fft', parent_package, top_path) 7 | 8 | config.add_data_dir('tests') 9 | 10 | # Configure fftpack_lite 11 | config.add_extension('fftpack_lite', 12 | sources=['fftpack_litemodule.c', 'fftpack.c'] 13 | ) 14 | 15 | return config 16 | 17 | if __name__ == '__main__': 18 | from numpy.distutils.core import setup 19 | setup(configuration=configuration) 20 | -------------------------------------------------------------------------------- /doc/source/f2py/ftype_session.dat: -------------------------------------------------------------------------------- 1 | >>> import ftype 2 | >>> print ftype.__doc__ 3 | This module 'ftype' is auto-generated with f2py (version:2.28.198-1366). 4 | Functions: 5 | foo(n=13) 6 | COMMON blocks: 7 | /data/ a,x(3) 8 | . 9 | >>> type(ftype.foo),type(ftype.data) 10 | (, ) 11 | >>> ftype.foo() 12 | IN FOO: N= 13 A= 0. X=[ 0. 0. 0.] 13 | >>> ftype.data.a = 3 14 | >>> ftype.data.x = [1,2,3] 15 | >>> ftype.foo() 16 | IN FOO: N= 13 A= 3. X=[ 1. 2. 3.] 17 | >>> ftype.data.x[1] = 45 18 | >>> ftype.foo(24) 19 | IN FOO: N= 24 A= 3. X=[ 1. 45. 3.] 20 | >>> ftype.data.x 21 | array([ 1., 45., 3.],'f') 22 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/assumed_shape/foo_free.f90: -------------------------------------------------------------------------------- 1 | 2 | subroutine sum(x, res) 3 | implicit none 4 | real, intent(in) :: x(:) 5 | real, intent(out) :: res 6 | 7 | integer :: i 8 | 9 | !print *, "sum: size(x) = ", size(x) 10 | 11 | res = 0.0 12 | 13 | do i = 1, size(x) 14 | res = res + x(i) 15 | enddo 16 | 17 | end subroutine sum 18 | 19 | function fsum(x) result (res) 20 | implicit none 21 | real, intent(in) :: x(:) 22 | real :: res 23 | 24 | integer :: i 25 | 26 | !print *, "fsum: size(x) = ", size(x) 27 | 28 | res = 0.0 29 | 30 | do i = 1, size(x) 31 | res = res + x(i) 32 | enddo 33 | 34 | end function fsum 35 | -------------------------------------------------------------------------------- /numpy/compat/tests/test_compat.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | from os.path import join 4 | 5 | from numpy.compat import isfileobj 6 | from numpy.testing import assert_ 7 | from numpy.testing import tempdir 8 | 9 | 10 | def test_isfileobj(): 11 | with tempdir(prefix="numpy_test_compat_") as folder: 12 | filename = join(folder, 'a.bin') 13 | 14 | with open(filename, 'wb') as f: 15 | assert_(isfileobj(f)) 16 | 17 | with open(filename, 'ab') as f: 18 | assert_(isfileobj(f)) 19 | 20 | with open(filename, 'rb') as f: 21 | assert_(isfileobj(f)) 22 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/iterators.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_ARRAYITERATORS_H_ 2 | #define _NPY_ARRAYITERATORS_H_ 3 | 4 | /* 5 | * Parses an index that has no fancy indexing. Populates 6 | * out_dimensions, out_strides, and out_offset. 7 | */ 8 | NPY_NO_EXPORT int 9 | parse_index(PyArrayObject *self, PyObject *op, 10 | npy_intp *out_dimensions, 11 | npy_intp *out_strides, 12 | npy_intp *out_offset, 13 | int check_index); 14 | 15 | NPY_NO_EXPORT PyObject 16 | *iter_subscript(PyArrayIterObject *, PyObject *); 17 | 18 | NPY_NO_EXPORT int 19 | iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /numpy/testing/nosetester.py: -------------------------------------------------------------------------------- 1 | """ 2 | Back compatibility nosetester module. It will import the appropriate 3 | set of tools 4 | 5 | """ 6 | from __future__ import division, absolute_import, print_function 7 | 8 | import warnings 9 | 10 | # 2018-04-04, numpy 1.15.0 11 | warnings.warn("Importing from numpy.testing.nosetester is deprecated, " 12 | "import from numpy.testing instead.", 13 | DeprecationWarning, stacklevel=2) 14 | 15 | from ._private.nosetester import * 16 | 17 | __all__ = ['get_package_name', 'run_module_suite', 'NoseTester', 18 | '_numpy_tester', 'get_package_name', 'import_nose', 19 | 'suppress_warnings'] 20 | -------------------------------------------------------------------------------- /doc/newdtype_example/example.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import floatint.floatint as ff 4 | import numpy as np 5 | 6 | # Setting using array is hard because 7 | # The parser doesn't stop at tuples always 8 | # So, the setitem code will be called with scalars on the 9 | # wrong shaped array. 10 | # But we can get a view as an ndarray of the given type: 11 | g = np.array([1, 2, 3, 4, 5, 6, 7, 8]).view(ff.floatint_type) 12 | 13 | # Now, the elements will be the scalar type associated 14 | # with the ndarray. 15 | print(g[0]) 16 | print(type(g[1])) 17 | 18 | # Now, you need to register ufuncs and more arrfuncs to do useful things... 19 | -------------------------------------------------------------------------------- /numpy/core/include/numpy/npy_no_deprecated_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This include file is provided for inclusion in Cython *.pyd files where 3 | * one would like to define the NPY_NO_DEPRECATED_API macro. It can be 4 | * included by 5 | * 6 | * cdef extern from "npy_no_deprecated_api.h": pass 7 | * 8 | */ 9 | #ifndef NPY_NO_DEPRECATED_API 10 | 11 | /* put this check here since there may be multiple includes in C extensions. */ 12 | #if defined(NDARRAYTYPES_H) || defined(_NPY_DEPRECATED_API_H) || \ 13 | defined(OLD_DEFINES_H) 14 | #error "npy_no_deprecated_api.h" must be first among numpy includes. 15 | #else 16 | #define NPY_NO_DEPRECATED_API NPY_API_VERSION 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /numpy/linalg/lapack_lite/wrapped_routines: -------------------------------------------------------------------------------- 1 | ccopy 2 | cgeev 3 | cgelsd 4 | cgemm 5 | cgesdd 6 | cgesv 7 | cgetrf 8 | cheevd 9 | cpotrf 10 | cpotri 11 | cpotrs 12 | dcopy 13 | dgeev 14 | dgelsd 15 | dgemm 16 | dgeqrf 17 | dgesdd 18 | dgesv 19 | dgetrf 20 | dorgqr 21 | dpotrf 22 | dpotri 23 | dpotrs 24 | dsyevd 25 | scopy 26 | sgeev 27 | sgelsd 28 | sgemm 29 | sgesdd 30 | sgesv 31 | sgetrf 32 | spotrf 33 | spotri 34 | spotrs 35 | ssyevd 36 | zcopy 37 | zgeev 38 | zgelsd 39 | zgemm 40 | zgeqrf 41 | zgesdd 42 | zgesv 43 | zgetrf 44 | zheevd 45 | zpotrf 46 | zpotri 47 | zpotrs 48 | zungqr 49 | # need this b/c it's not properly declared as external in the BLAS source 50 | dcabs1 51 | IGNORE: xerbla 52 | -------------------------------------------------------------------------------- /numpy/distutils/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import division, print_function 3 | 4 | def configuration(parent_package='',top_path=None): 5 | from numpy.distutils.misc_util import Configuration 6 | config = Configuration('distutils', parent_package, top_path) 7 | config.add_subpackage('command') 8 | config.add_subpackage('fcompiler') 9 | config.add_data_dir('tests') 10 | config.add_data_files('site.cfg') 11 | config.add_data_files('mingw/gfortran_vs2003_hack.c') 12 | config.make_config_py() 13 | return config 14 | 15 | if __name__ == '__main__': 16 | from numpy.distutils.core import setup 17 | setup(configuration=configuration) 18 | -------------------------------------------------------------------------------- /doc/source/f2py/setup_example.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | from numpy.distutils.core import Extension 4 | 5 | ext1 = Extension(name = 'scalar', 6 | sources = ['scalar.f']) 7 | ext2 = Extension(name = 'fib2', 8 | sources = ['fib2.pyf', 'fib1.f']) 9 | 10 | if __name__ == "__main__": 11 | from numpy.distutils.core import setup 12 | setup(name = 'f2py_example', 13 | description = "F2PY Users Guide examples", 14 | author = "Pearu Peterson", 15 | author_email = "pearu@cens.ioc.ee", 16 | ext_modules = [ext1, ext2] 17 | ) 18 | # End of setup_example.py 19 | -------------------------------------------------------------------------------- /doc/source/f2py/string_session.dat: -------------------------------------------------------------------------------- 1 | >>> import mystring 2 | >>> print mystring.foo.__doc__ 3 | foo - Function signature: 4 | foo(a,b,c,d) 5 | Required arguments: 6 | a : input string(len=5) 7 | b : in/output rank-0 array(string(len=5),'c') 8 | c : input string(len=-1) 9 | d : in/output rank-0 array(string(len=-1),'c') 10 | 11 | >>> import numpy 12 | >>> a=numpy.array('123') 13 | >>> b=numpy.array('123') 14 | >>> c=numpy.array('123') 15 | >>> d=numpy.array('123') 16 | >>> mystring.foo(a,b,c,d) 17 | A=123 18 | B=123 19 | C=123 20 | D=123 21 | CHANGE A,B,C,D 22 | A=A23 23 | B=B23 24 | C=C23 25 | D=D23 26 | >>> a.tostring(),b.tostring(),c.tostring(),d.tostring() 27 | ('123', 'B23', '123', 'D23') 28 | -------------------------------------------------------------------------------- /numpy/doc/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import os 4 | 5 | ref_dir = os.path.join(os.path.dirname(__file__)) 6 | 7 | __all__ = sorted(f[:-3] for f in os.listdir(ref_dir) if f.endswith('.py') and 8 | not f.startswith('__')) 9 | 10 | for f in __all__: 11 | __import__(__name__ + '.' + f) 12 | 13 | del f, ref_dir 14 | 15 | __doc__ = """\ 16 | Topical documentation 17 | ===================== 18 | 19 | The following topics are available: 20 | %s 21 | 22 | You can view them by 23 | 24 | >>> help(np.doc.TOPIC) #doctest: +SKIP 25 | 26 | """ % '\n- '.join([''] + __all__) 27 | 28 | __all__.extend(['__doc__']) 29 | -------------------------------------------------------------------------------- /doc/source/f2py/moddata_session.dat: -------------------------------------------------------------------------------- 1 | >>> import moddata 2 | >>> print moddata.mod.__doc__ 3 | i - 'i'-scalar 4 | x - 'i'-array(4) 5 | a - 'f'-array(2,3) 6 | foo - Function signature: 7 | foo() 8 | 9 | 10 | >>> moddata.mod.i = 5 11 | >>> moddata.mod.x[:2] = [1,2] 12 | >>> moddata.mod.a = [[1,2,3],[4,5,6]] 13 | >>> moddata.mod.foo() 14 | i= 5 15 | x=[ 1 2 0 0 ] 16 | a=[ 17 | [ 1.000000 , 2.000000 , 3.000000 ] 18 | [ 4.000000 , 5.000000 , 6.000000 ] 19 | ] 20 | Setting a(1,2)=a(1,2)+3 21 | >>> moddata.mod.a # a is Fortran-contiguous 22 | array([[ 1., 5., 3.], 23 | [ 4., 5., 6.]],'f') 24 | -------------------------------------------------------------------------------- /numpy/f2py/tests/test_block_docstring.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import textwrap 4 | import sys 5 | import pytest 6 | from . import util 7 | 8 | from numpy.testing import assert_equal 9 | 10 | class TestBlockDocString(util.F2PyTest): 11 | code = """ 12 | SUBROUTINE FOO() 13 | INTEGER BAR(2, 3) 14 | 15 | COMMON /BLOCK/ BAR 16 | RETURN 17 | END 18 | """ 19 | 20 | @pytest.mark.skipif(sys.platform=='win32', 21 | reason='Fails with MinGW64 Gfortran (Issue #9673)') 22 | def test_block_docstring(self): 23 | expected = "'i'-array(2,3)\n" 24 | assert_equal(self.module.block.__doc__, expected) 25 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/assumed_shape/foo_mod.f90: -------------------------------------------------------------------------------- 1 | 2 | module mod 3 | 4 | contains 5 | 6 | subroutine sum(x, res) 7 | implicit none 8 | real, intent(in) :: x(:) 9 | real, intent(out) :: res 10 | 11 | integer :: i 12 | 13 | !print *, "sum: size(x) = ", size(x) 14 | 15 | res = 0.0 16 | 17 | do i = 1, size(x) 18 | res = res + x(i) 19 | enddo 20 | 21 | end subroutine sum 22 | 23 | function fsum(x) result (res) 24 | implicit none 25 | real, intent(in) :: x(:) 26 | real :: res 27 | 28 | integer :: i 29 | 30 | !print *, "fsum: size(x) = ", size(x) 31 | 32 | res = 0.0 33 | 34 | do i = 1, size(x) 35 | res = res + x(i) 36 | enddo 37 | 38 | end function fsum 39 | 40 | 41 | end module mod 42 | -------------------------------------------------------------------------------- /doc/source/reference/routines.polynomials.poly1d.rst: -------------------------------------------------------------------------------- 1 | Poly1d 2 | ====== 3 | 4 | .. currentmodule:: numpy 5 | 6 | Basics 7 | ------ 8 | .. autosummary:: 9 | :toctree: generated/ 10 | 11 | poly1d 12 | polyval 13 | poly 14 | roots 15 | 16 | Fitting 17 | ------- 18 | .. autosummary:: 19 | :toctree: generated/ 20 | 21 | polyfit 22 | 23 | Calculus 24 | -------- 25 | .. autosummary:: 26 | :toctree: generated/ 27 | 28 | polyder 29 | polyint 30 | 31 | Arithmetic 32 | ---------- 33 | .. autosummary:: 34 | :toctree: generated/ 35 | 36 | polyadd 37 | polydiv 38 | polymul 39 | polysub 40 | 41 | Warnings 42 | -------- 43 | .. autosummary:: 44 | :toctree: generated/ 45 | 46 | RankWarning 47 | -------------------------------------------------------------------------------- /doc/source/reference/routines.sort.rst: -------------------------------------------------------------------------------- 1 | Sorting, searching, and counting 2 | ================================ 3 | 4 | .. currentmodule:: numpy 5 | 6 | Sorting 7 | ------- 8 | .. autosummary:: 9 | :toctree: generated/ 10 | 11 | sort 12 | lexsort 13 | argsort 14 | ndarray.sort 15 | msort 16 | sort_complex 17 | partition 18 | argpartition 19 | 20 | Searching 21 | --------- 22 | .. autosummary:: 23 | :toctree: generated/ 24 | 25 | argmax 26 | nanargmax 27 | argmin 28 | nanargmin 29 | argwhere 30 | nonzero 31 | flatnonzero 32 | where 33 | searchsorted 34 | extract 35 | 36 | Counting 37 | -------- 38 | .. autosummary:: 39 | :toctree: generated/ 40 | 41 | count_nonzero 42 | -------------------------------------------------------------------------------- /benchmarks/benchmarks/bench_lib.py: -------------------------------------------------------------------------------- 1 | """Benchmarks for `numpy.lib`.""" 2 | 3 | 4 | from __future__ import absolute_import, division, print_function 5 | 6 | from .common import Benchmark 7 | 8 | import numpy as np 9 | 10 | 11 | class Pad(Benchmark): 12 | """Benchmarks for `numpy.pad`.""" 13 | 14 | param_names = ["shape", "pad_width", "mode"] 15 | params = [ 16 | [(1000,), (10, 100), (10, 10, 10)], 17 | [1, 3, (0, 5)], 18 | ["constant", "edge", "linear_ramp", "mean", "reflect", "wrap"], 19 | ] 20 | 21 | def setup(self, shape, pad_width, mode): 22 | self.array = np.empty(shape) 23 | 24 | def time_pad(self, shape, pad_width, mode): 25 | np.pad(self.array, pad_width, mode) 26 | -------------------------------------------------------------------------------- /doc/source/bugs.rst: -------------------------------------------------------------------------------- 1 | ************** 2 | Reporting bugs 3 | ************** 4 | 5 | File bug reports or feature requests, and make contributions 6 | (e.g. code patches), by opening a "new issue" on GitHub: 7 | 8 | - NumPy Issues: http://github.com/numpy/numpy/issues 9 | 10 | Please give as much information as you can in the ticket. It is extremely 11 | useful if you can supply a small self-contained code snippet that reproduces 12 | the problem. Also specify the component, the version you are referring to and 13 | the milestone. 14 | 15 | Report bugs to the appropriate GitHub project (there is one for NumPy 16 | and a different one for SciPy). 17 | 18 | More information can be found on the http://scipy.org/Developer_Zone 19 | website. 20 | -------------------------------------------------------------------------------- /numpy/distutils/command/develop.py: -------------------------------------------------------------------------------- 1 | """ Override the develop command from setuptools so we can ensure that our 2 | generated files (from build_src or build_scripts) are properly converted to real 3 | files with filenames. 4 | 5 | """ 6 | from __future__ import division, absolute_import, print_function 7 | 8 | from setuptools.command.develop import develop as old_develop 9 | 10 | class develop(old_develop): 11 | __doc__ = old_develop.__doc__ 12 | def install_for_development(self): 13 | # Build sources in-place, too. 14 | self.reinitialize_command('build_src', inplace=1) 15 | # Make sure scripts are built. 16 | self.run_command('build_scripts') 17 | old_develop.install_for_development(self) 18 | -------------------------------------------------------------------------------- /numpy/testing/__init__.py: -------------------------------------------------------------------------------- 1 | """Common test support for all numpy test scripts. 2 | 3 | This single module should provide all the common functionality for numpy tests 4 | in a single location, so that test scripts can just import it and work right 5 | away. 6 | 7 | """ 8 | from __future__ import division, absolute_import, print_function 9 | 10 | from unittest import TestCase 11 | 12 | from ._private.utils import * 13 | from ._private import decorators as dec 14 | from ._private.nosetester import ( 15 | run_module_suite, NoseTester as Tester 16 | ) 17 | 18 | __all__ = _private.utils.__all__ + ['TestCase', 'run_module_suite'] 19 | 20 | from ._private.pytesttester import PytestTester 21 | test = PytestTester(__name__) 22 | del PytestTester 23 | -------------------------------------------------------------------------------- /doc/source/reference/routines.dual.rst: -------------------------------------------------------------------------------- 1 | Optionally Scipy-accelerated routines (:mod:`numpy.dual`) 2 | ********************************************************* 3 | 4 | .. automodule:: numpy.dual 5 | 6 | Linear algebra 7 | -------------- 8 | 9 | .. currentmodule:: numpy.linalg 10 | 11 | .. autosummary:: 12 | 13 | cholesky 14 | det 15 | eig 16 | eigh 17 | eigvals 18 | eigvalsh 19 | inv 20 | lstsq 21 | norm 22 | pinv 23 | solve 24 | svd 25 | 26 | FFT 27 | --- 28 | 29 | .. currentmodule:: numpy.fft 30 | 31 | .. autosummary:: 32 | 33 | fft 34 | fft2 35 | fftn 36 | ifft 37 | ifft2 38 | ifftn 39 | 40 | Other 41 | ----- 42 | 43 | .. currentmodule:: numpy 44 | 45 | .. autosummary:: 46 | 47 | i0 48 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/parameter/constant_integer.f90: -------------------------------------------------------------------------------- 1 | ! Check that parameters are correct intercepted. 2 | ! Constants with comma separations are commonly 3 | ! used, for instance Pi = 3._dp 4 | subroutine foo_int(x) 5 | implicit none 6 | integer, parameter :: ii = selected_int_kind(9) 7 | integer(ii), intent(inout) :: x 8 | dimension x(3) 9 | integer(ii), parameter :: three = 3_ii 10 | x(1) = x(1) + x(2) + x(3) * three 11 | return 12 | end subroutine 13 | 14 | subroutine foo_long(x) 15 | implicit none 16 | integer, parameter :: ii = selected_int_kind(18) 17 | integer(ii), intent(inout) :: x 18 | dimension x(3) 19 | integer(ii), parameter :: three = 3_ii 20 | x(1) = x(1) + x(2) + x(3) * three 21 | return 22 | end subroutine 23 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/parameter/constant_real.f90: -------------------------------------------------------------------------------- 1 | ! Check that parameters are correct intercepted. 2 | ! Constants with comma separations are commonly 3 | ! used, for instance Pi = 3._dp 4 | subroutine foo_single(x) 5 | implicit none 6 | integer, parameter :: rp = selected_real_kind(6) 7 | real(rp), intent(inout) :: x 8 | dimension x(3) 9 | real(rp), parameter :: three = 3._rp 10 | x(1) = x(1) + x(2) + x(3) * three 11 | return 12 | end subroutine 13 | 14 | subroutine foo_double(x) 15 | implicit none 16 | integer, parameter :: rp = selected_real_kind(15) 17 | real(rp), intent(inout) :: x 18 | dimension x(3) 19 | real(rp), parameter :: three = 3._rp 20 | x(1) = x(1) + x(2) + x(3) * three 21 | return 22 | end subroutine 23 | 24 | -------------------------------------------------------------------------------- /numpy/tests/test_numpy_version.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import re 4 | 5 | import numpy as np 6 | from numpy.testing import assert_ 7 | 8 | 9 | def test_valid_numpy_version(): 10 | # Verify that the numpy version is a valid one (no .post suffix or other 11 | # nonsense). See gh-6431 for an issue caused by an invalid version. 12 | version_pattern = r"^[0-9]+\.[0-9]+\.[0-9]+(|a[0-9]|b[0-9]|rc[0-9])" 13 | dev_suffix = r"(\.dev0\+([0-9a-f]{7}|Unknown))" 14 | if np.version.release: 15 | res = re.match(version_pattern, np.__version__) 16 | else: 17 | res = re.match(version_pattern + dev_suffix, np.__version__) 18 | 19 | assert_(res is not None, np.__version__) 20 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/parameter/constant_non_compound.f90: -------------------------------------------------------------------------------- 1 | ! Check that parameters are correct intercepted. 2 | ! Specifically that types of constants without 3 | ! compound kind specs are correctly inferred 4 | ! adapted Gibbs iteration code from pymc 5 | ! for this test case 6 | subroutine foo_non_compound_int(x) 7 | implicit none 8 | integer, parameter :: ii = selected_int_kind(9) 9 | 10 | integer(ii) maxiterates 11 | parameter (maxiterates=2) 12 | 13 | integer(ii) maxseries 14 | parameter (maxseries=2) 15 | 16 | integer(ii) wasize 17 | parameter (wasize=maxiterates*maxseries) 18 | integer(ii), intent(inout) :: x 19 | dimension x(wasize) 20 | 21 | x(1) = x(1) + x(2) + x(3) + x(4) * wasize 22 | return 23 | end subroutine 24 | -------------------------------------------------------------------------------- /doc/source/_templates/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "!layout.html" %} 2 | 3 | {% block rootrellink %} 4 | {% if pagename != 'index' %} 5 |
  • {{ shorttitle|e }}
  • 6 | {% endif %} 7 | {% endblock %} 8 | 9 | {% block sidebarsearch %} 10 | {%- if sourcename %} 11 | 18 | {%- endif %} 19 | {{ super() }} 20 | {% endblock %} 21 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/string/char.f90: -------------------------------------------------------------------------------- 1 | MODULE char_test 2 | 3 | CONTAINS 4 | 5 | SUBROUTINE change_strings(strings, n_strs, out_strings) 6 | IMPLICIT NONE 7 | 8 | ! Inputs 9 | INTEGER, INTENT(IN) :: n_strs 10 | CHARACTER, INTENT(IN), DIMENSION(2,n_strs) :: strings 11 | CHARACTER, INTENT(OUT), DIMENSION(2,n_strs) :: out_strings 12 | 13 | !f2py INTEGER, INTENT(IN) :: n_strs 14 | !f2py CHARACTER, INTENT(IN), DIMENSION(2,n_strs) :: strings 15 | !f2py CHARACTER, INTENT(OUT), DIMENSION(2,n_strs) :: strings 16 | 17 | ! Misc. 18 | INTEGER*4 :: j 19 | 20 | 21 | DO j=1, n_strs 22 | out_strings(1,j) = strings(1,j) 23 | out_strings(2,j) = 'A' 24 | END DO 25 | 26 | END SUBROUTINE change_strings 27 | 28 | END MODULE char_test 29 | 30 | -------------------------------------------------------------------------------- /numpy/testing/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import division, print_function 3 | 4 | 5 | def configuration(parent_package='',top_path=None): 6 | from numpy.distutils.misc_util import Configuration 7 | config = Configuration('testing', parent_package, top_path) 8 | 9 | config.add_subpackage('_private') 10 | config.add_data_dir('tests') 11 | return config 12 | 13 | if __name__ == '__main__': 14 | from numpy.distutils.core import setup 15 | setup(maintainer="NumPy Developers", 16 | maintainer_email="numpy-dev@numpy.org", 17 | description="NumPy test module", 18 | url="http://www.numpy.org", 19 | license="NumPy License (BSD Style)", 20 | configuration=configuration, 21 | ) 22 | -------------------------------------------------------------------------------- /doc/neps/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = -W 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = NumPyEnhancementProposals 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile index 16 | 17 | index: 18 | python tools/build_index.py 19 | 20 | # Catch-all target: route all unknown targets to Sphinx using the new 21 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 22 | %: Makefile index 23 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 24 | -------------------------------------------------------------------------------- /doc/cdoc/README: -------------------------------------------------------------------------------- 1 | cdoc 2 | ==== 3 | 4 | This is a simple Doxygen project for building NumPy C code documentation, 5 | with docstrings extracted from the C sources themselves. 6 | 7 | The understood syntax for documentation in the C source is 8 | 9 | /* 10 | * Some text in reStructuredText format 11 | */ 12 | int function_to_which_the_text_applies() 13 | { 14 | ... 15 | } 16 | 17 | /* 18 | * More text in reStructuredText format 19 | */ 20 | struct 21 | { 22 | int variable_1; /* Documentation for variable_1 */ 23 | 24 | /* 25 | * Documentation for variable_2 26 | */ 27 | int variable_2; 28 | } struct_name_t; 29 | 30 | Please do not use JavaDoc or Doxygen-specific formatting at the moment. 31 | 32 | -------------------------------------------------------------------------------- /numpy/f2py/tests/test_string.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import os 4 | import pytest 5 | 6 | from numpy.testing import assert_array_equal 7 | import numpy as np 8 | from . import util 9 | 10 | 11 | def _path(*a): 12 | return os.path.join(*((os.path.dirname(__file__),) + a)) 13 | 14 | class TestString(util.F2PyTest): 15 | sources = [_path('src', 'string', 'char.f90')] 16 | 17 | @pytest.mark.slow 18 | def test_char(self): 19 | strings = np.array(['ab', 'cd', 'ef'], dtype='c').T 20 | inp, out = self.module.char_test.change_strings(strings, strings.shape[1]) 21 | assert_array_equal(inp, strings) 22 | expected = strings.copy() 23 | expected[1, :] = 'AAA' 24 | assert_array_equal(out, expected) 25 | -------------------------------------------------------------------------------- /numpy/distutils/numpy_distribution.py: -------------------------------------------------------------------------------- 1 | # XXX: Handle setuptools ? 2 | from __future__ import division, absolute_import, print_function 3 | 4 | from distutils.core import Distribution 5 | 6 | # This class is used because we add new files (sconscripts, and so on) with the 7 | # scons command 8 | class NumpyDistribution(Distribution): 9 | def __init__(self, attrs = None): 10 | # A list of (sconscripts, pre_hook, post_hook, src, parent_names) 11 | self.scons_data = [] 12 | # A list of installable libraries 13 | self.installed_libraries = [] 14 | # A dict of pkg_config files to generate/install 15 | self.installed_pkg_config = {} 16 | Distribution.__init__(self, attrs) 17 | 18 | def has_scons_scripts(self): 19 | return bool(self.scons_data) 20 | -------------------------------------------------------------------------------- /doc/source/reference/routines.matlib.rst: -------------------------------------------------------------------------------- 1 | Matrix library (:mod:`numpy.matlib`) 2 | ************************************ 3 | 4 | .. currentmodule:: numpy 5 | 6 | This module contains all functions in the :mod:`numpy` namespace, with 7 | the following replacement functions that return :class:`matrices 8 | ` instead of :class:`ndarrays `. 9 | 10 | .. currentmodule:: numpy 11 | 12 | Functions that are also in the numpy namespace and return matrices 13 | 14 | .. autosummary:: 15 | 16 | mat 17 | matrix 18 | asmatrix 19 | bmat 20 | 21 | 22 | Replacement functions in `matlib` 23 | 24 | .. currentmodule:: numpy.matlib 25 | 26 | .. autosummary:: 27 | :toctree: generated/ 28 | 29 | empty 30 | zeros 31 | ones 32 | eye 33 | identity 34 | repmat 35 | rand 36 | randn 37 | -------------------------------------------------------------------------------- /doc/source/dev/gitwash/dot2_dot3.rst: -------------------------------------------------------------------------------- 1 | .. _dot2-dot3: 2 | 3 | ======================================== 4 | Two and three dots in difference specs 5 | ======================================== 6 | 7 | Thanks to Yarik Halchenko for this explanation. 8 | 9 | Imagine a series of commits A, B, C, D... Imagine that there are two 10 | branches, *topic* and *master*. You branched *topic* off *master* when 11 | *master* was at commit 'E'. The graph of the commits looks like this:: 12 | 13 | 14 | A---B---C topic 15 | / 16 | D---E---F---G master 17 | 18 | Then:: 19 | 20 | git diff master..topic 21 | 22 | will output the difference from G to C (i.e. with effects of F and G), 23 | while:: 24 | 25 | git diff master...topic 26 | 27 | would output just differences in the topic branch (i.e. only A, B, and 28 | C). 29 | -------------------------------------------------------------------------------- /numpy/linalg/tests/test_deprecations.py: -------------------------------------------------------------------------------- 1 | """Test deprecation and future warnings. 2 | 3 | """ 4 | from __future__ import division, absolute_import, print_function 5 | 6 | import numpy as np 7 | from numpy.testing import assert_warns 8 | 9 | 10 | def test_qr_mode_full_future_warning(): 11 | """Check mode='full' FutureWarning. 12 | 13 | In numpy 1.8 the mode options 'full' and 'economic' in linalg.qr were 14 | deprecated. The release date will probably be sometime in the summer 15 | of 2013. 16 | 17 | """ 18 | a = np.eye(2) 19 | assert_warns(DeprecationWarning, np.linalg.qr, a, mode='full') 20 | assert_warns(DeprecationWarning, np.linalg.qr, a, mode='f') 21 | assert_warns(DeprecationWarning, np.linalg.qr, a, mode='economic') 22 | assert_warns(DeprecationWarning, np.linalg.qr, a, mode='e') 23 | -------------------------------------------------------------------------------- /numpy/core/include/numpy/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef __NUMPY_UTILS_HEADER__ 2 | #define __NUMPY_UTILS_HEADER__ 3 | 4 | #ifndef __COMP_NPY_UNUSED 5 | #if defined(__GNUC__) 6 | #define __COMP_NPY_UNUSED __attribute__ ((__unused__)) 7 | # elif defined(__ICC) 8 | #define __COMP_NPY_UNUSED __attribute__ ((__unused__)) 9 | # elif defined(__clang__) 10 | #define __COMP_NPY_UNUSED __attribute__ ((unused)) 11 | #else 12 | #define __COMP_NPY_UNUSED 13 | #endif 14 | #endif 15 | 16 | /* Use this to tag a variable as not used. It will remove unused variable 17 | * warning on support platforms (see __COM_NPY_UNUSED) and mangle the variable 18 | * to avoid accidental use */ 19 | #define NPY_UNUSED(x) (__NPY_UNUSED_TAGGED ## x) __COMP_NPY_UNUSED 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /tools/swig/test/Fortran.h: -------------------------------------------------------------------------------- 1 | #ifndef FORTRAN_H 2 | #define FORTRAN_H 3 | 4 | #define TEST_FUNC_PROTOS(TYPE, SNAME) \ 5 | \ 6 | TYPE SNAME ## SecondElement( TYPE * matrix, int rows, int cols); \ 7 | 8 | TEST_FUNC_PROTOS(signed char , schar ) 9 | TEST_FUNC_PROTOS(unsigned char , uchar ) 10 | TEST_FUNC_PROTOS(short , short ) 11 | TEST_FUNC_PROTOS(unsigned short , ushort ) 12 | TEST_FUNC_PROTOS(int , int ) 13 | TEST_FUNC_PROTOS(unsigned int , uint ) 14 | TEST_FUNC_PROTOS(long , long ) 15 | TEST_FUNC_PROTOS(unsigned long , ulong ) 16 | TEST_FUNC_PROTOS(long long , longLong ) 17 | TEST_FUNC_PROTOS(unsigned long long, ulongLong) 18 | TEST_FUNC_PROTOS(float , float ) 19 | TEST_FUNC_PROTOS(double , double ) 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /numpy/core/include/numpy/oldnumeric.h: -------------------------------------------------------------------------------- 1 | #include "arrayobject.h" 2 | 3 | #ifndef PYPY_VERSION 4 | #ifndef REFCOUNT 5 | # define REFCOUNT NPY_REFCOUNT 6 | # define MAX_ELSIZE 16 7 | #endif 8 | #endif 9 | 10 | #define PyArray_UNSIGNED_TYPES 11 | #define PyArray_SBYTE NPY_BYTE 12 | #define PyArray_CopyArray PyArray_CopyInto 13 | #define _PyArray_multiply_list PyArray_MultiplyIntList 14 | #define PyArray_ISSPACESAVER(m) NPY_FALSE 15 | #define PyScalarArray_Check PyArray_CheckScalar 16 | 17 | #define CONTIGUOUS NPY_CONTIGUOUS 18 | #define OWN_DIMENSIONS 0 19 | #define OWN_STRIDES 0 20 | #define OWN_DATA NPY_OWNDATA 21 | #define SAVESPACE 0 22 | #define SAVESPACEBIT 0 23 | 24 | #undef import_array 25 | #define import_array() { if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); } } 26 | -------------------------------------------------------------------------------- /doc/release/1.6.1-notes.rst: -------------------------------------------------------------------------------- 1 | ========================= 2 | NumPy 1.6.1 Release Notes 3 | ========================= 4 | 5 | This is a bugfix only release in the 1.6.x series. 6 | 7 | 8 | Issues Fixed 9 | ============ 10 | 11 | * #1834: einsum fails for specific shapes 12 | * #1837: einsum throws nan or freezes python for specific array shapes 13 | * #1838: object <-> structured type arrays regression 14 | * #1851: regression for SWIG based code in 1.6.0 15 | * #1863: Buggy results when operating on array copied with astype() 16 | * #1870: Fix corner case of object array assignment 17 | * #1843: Py3k: fix error with recarray 18 | * #1885: nditer: Error in detecting double reduction loop 19 | * #1874: f2py: fix --include_paths bug 20 | * #1749: Fix ctypes.load_library() 21 | * #1895/1896: iter: writeonly operands weren't always being buffered correctly 22 | -------------------------------------------------------------------------------- /doc/source/reference/routines.other.rst: -------------------------------------------------------------------------------- 1 | Miscellaneous routines 2 | ********************** 3 | 4 | .. toctree:: 5 | 6 | .. currentmodule:: numpy 7 | 8 | Buffer objects 9 | -------------- 10 | .. autosummary:: 11 | :toctree: generated/ 12 | 13 | getbuffer 14 | newbuffer 15 | 16 | Performance tuning 17 | ------------------ 18 | .. autosummary:: 19 | :toctree: generated/ 20 | 21 | setbufsize 22 | getbufsize 23 | 24 | Memory ranges 25 | ------------- 26 | 27 | .. autosummary:: 28 | :toctree: generated/ 29 | 30 | shares_memory 31 | may_share_memory 32 | 33 | Array mixins 34 | ------------ 35 | .. autosummary:: 36 | :toctree: generated/ 37 | 38 | lib.mixins.NDArrayOperatorsMixin 39 | 40 | NumPy version comparison 41 | ------------------------ 42 | .. autosummary:: 43 | :toctree: generated/ 44 | 45 | lib.NumpyVersion 46 | -------------------------------------------------------------------------------- /numpy/fft/fftpack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of tela the Tensor Language. 3 | * Copyright (c) 1994-1995 Pekka Janhunen 4 | */ 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define DOUBLE 11 | 12 | #ifdef DOUBLE 13 | #define Treal double 14 | #else 15 | #define Treal float 16 | #endif 17 | 18 | extern NPY_VISIBILITY_HIDDEN void npy_cfftf(int N, Treal data[], const Treal wrk[]); 19 | extern NPY_VISIBILITY_HIDDEN void npy_cfftb(int N, Treal data[], const Treal wrk[]); 20 | extern NPY_VISIBILITY_HIDDEN void npy_cffti(int N, Treal wrk[]); 21 | 22 | extern NPY_VISIBILITY_HIDDEN void npy_rfftf(int N, Treal data[], const Treal wrk[]); 23 | extern NPY_VISIBILITY_HIDDEN void npy_rfftb(int N, Treal data[], const Treal wrk[]); 24 | extern NPY_VISIBILITY_HIDDEN void npy_rffti(int N, Treal wrk[]); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | -------------------------------------------------------------------------------- /numpy/f2py/__main__.py: -------------------------------------------------------------------------------- 1 | # See http://cens.ioc.ee/projects/f2py2e/ 2 | from __future__ import division, print_function 3 | 4 | import os 5 | import sys 6 | for mode in ["g3-numpy", "2e-numeric", "2e-numarray", "2e-numpy"]: 7 | try: 8 | i = sys.argv.index("--" + mode) 9 | del sys.argv[i] 10 | break 11 | except ValueError: 12 | pass 13 | os.environ["NO_SCIPY_IMPORT"] = "f2py" 14 | if mode == "g3-numpy": 15 | sys.stderr.write("G3 f2py support is not implemented, yet.\\n") 16 | sys.exit(1) 17 | elif mode == "2e-numeric": 18 | from f2py2e import main 19 | elif mode == "2e-numarray": 20 | sys.argv.append("-DNUMARRAY") 21 | from f2py2e import main 22 | elif mode == "2e-numpy": 23 | from numpy.f2py import main 24 | else: 25 | sys.stderr.write("Unknown mode: " + repr(mode) + "\\n") 26 | sys.exit(1) 27 | main() 28 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/datetime_busday.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_PRIVATE__DATETIME_BUSDAY_H_ 2 | #define _NPY_PRIVATE__DATETIME_BUSDAY_H_ 3 | 4 | /* 5 | * This is the 'busday_offset' function exposed for calling 6 | * from Python. 7 | */ 8 | NPY_NO_EXPORT PyObject * 9 | array_busday_offset(PyObject *NPY_UNUSED(self), 10 | PyObject *args, PyObject *kwds); 11 | 12 | /* 13 | * This is the 'busday_count' function exposed for calling 14 | * from Python. 15 | */ 16 | NPY_NO_EXPORT PyObject * 17 | array_busday_count(PyObject *NPY_UNUSED(self), 18 | PyObject *args, PyObject *kwds); 19 | 20 | /* 21 | * This is the 'is_busday' function exposed for calling 22 | * from Python. 23 | */ 24 | NPY_NO_EXPORT PyObject * 25 | array_is_busday(PyObject *NPY_UNUSED(self), 26 | PyObject *args, PyObject *kwds); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/multiarraymodule.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_MULTIARRAY_H_ 2 | #define _NPY_MULTIARRAY_H_ 3 | 4 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array; 5 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_prepare; 6 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_wrap; 7 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_array_finalize; 8 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_buffer; 9 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_ufunc; 10 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_order; 11 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_copy; 12 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_dtype; 13 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_ndmin; 14 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_axis1; 15 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_ma_str_axis2; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /tools/travis-before-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | uname -a 4 | free -m 5 | df -h 6 | ulimit -a 7 | mkdir builds 8 | pushd builds 9 | 10 | # Build into own virtualenv 11 | # We therefore control our own environment, avoid travis' numpy 12 | # 13 | # Some change in virtualenv 14.0.5 caused `test_f2py` to fail. So, we have 14 | # pinned `virtualenv` to the last known working version to avoid this failure. 15 | # Appears we had some issues with certificates on Travis. It looks like 16 | # bumping to 14.0.6 will help. 17 | pip install -U 'virtualenv==14.0.6' 18 | 19 | if [ -n "$USE_DEBUG" ] 20 | then 21 | virtualenv --python=python3-dbg venv 22 | else 23 | virtualenv --python=python venv 24 | fi 25 | 26 | source venv/bin/activate 27 | python -V 28 | pip install --upgrade pip setuptools 29 | pip install nose pytz cython pytest 30 | if [ -n "$USE_ASV" ]; then pip install asv; fi 31 | popd 32 | -------------------------------------------------------------------------------- /numpy/distutils/pathccompiler.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | from distutils.unixccompiler import UnixCCompiler 4 | 5 | class PathScaleCCompiler(UnixCCompiler): 6 | 7 | """ 8 | PathScale compiler compatible with an gcc built Python. 9 | """ 10 | 11 | compiler_type = 'pathcc' 12 | cc_exe = 'pathcc' 13 | cxx_exe = 'pathCC' 14 | 15 | def __init__ (self, verbose=0, dry_run=0, force=0): 16 | UnixCCompiler.__init__ (self, verbose, dry_run, force) 17 | cc_compiler = self.cc_exe 18 | cxx_compiler = self.cxx_exe 19 | self.set_executables(compiler=cc_compiler, 20 | compiler_so=cc_compiler, 21 | compiler_cxx=cxx_compiler, 22 | linker_exe=cc_compiler, 23 | linker_so=cc_compiler + ' -shared') 24 | -------------------------------------------------------------------------------- /numpy/matrixlib/tests/test_numeric.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | # As we are testing matrices, we ignore its PendingDeprecationWarnings 4 | try: 5 | import pytest 6 | pytestmark = pytest.mark.filterwarnings( 7 | 'ignore:the matrix subclass is not:PendingDeprecationWarning') 8 | except ImportError: 9 | pass 10 | 11 | import numpy as np 12 | from numpy.testing import assert_equal 13 | 14 | class TestDot(object): 15 | def test_matscalar(self): 16 | b1 = np.matrix(np.ones((3, 3), dtype=complex)) 17 | assert_equal(b1*1.0, b1) 18 | 19 | 20 | def test_diagonal(): 21 | b1 = np.matrix([[1,2],[3,4]]) 22 | diag_b1 = np.matrix([[1, 4]]) 23 | array_b1 = np.array([1, 4]) 24 | 25 | assert_equal(b1.diagonal(), diag_b1) 26 | assert_equal(np.diagonal(b1), array_b1) 27 | assert_equal(np.diag(b1), array_b1) 28 | -------------------------------------------------------------------------------- /numpy/distutils/command/bdist_rpm.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import os 4 | import sys 5 | if 'setuptools' in sys.modules: 6 | from setuptools.command.bdist_rpm import bdist_rpm as old_bdist_rpm 7 | else: 8 | from distutils.command.bdist_rpm import bdist_rpm as old_bdist_rpm 9 | 10 | class bdist_rpm(old_bdist_rpm): 11 | 12 | def _make_spec_file(self): 13 | spec_file = old_bdist_rpm._make_spec_file(self) 14 | 15 | # Replace hardcoded setup.py script name 16 | # with the real setup script name. 17 | setup_py = os.path.basename(sys.argv[0]) 18 | if setup_py == 'setup.py': 19 | return spec_file 20 | new_spec_file = [] 21 | for line in spec_file: 22 | line = line.replace('setup.py', setup_py) 23 | new_spec_file.append(line) 24 | return new_spec_file 25 | -------------------------------------------------------------------------------- /numpy/core/src/umath/ufunc_object.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_UMATH_UFUNC_OBJECT_H_ 2 | #define _NPY_UMATH_UFUNC_OBJECT_H_ 3 | 4 | NPY_NO_EXPORT PyObject * 5 | ufunc_geterr(PyObject *NPY_UNUSED(dummy), PyObject *args); 6 | 7 | NPY_NO_EXPORT PyObject * 8 | ufunc_seterr(PyObject *NPY_UNUSED(dummy), PyObject *args); 9 | 10 | NPY_NO_EXPORT const char* 11 | ufunc_get_name_cstr(PyUFuncObject *ufunc); 12 | 13 | /* interned strings (on umath import) */ 14 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_um_str_out; 15 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_um_str_subok; 16 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_um_str_array_prepare; 17 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_um_str_array_wrap; 18 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_um_str_array_finalize; 19 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_um_str_ufunc; 20 | NPY_VISIBILITY_HIDDEN extern PyObject * npy_um_str_pyvals_name; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /doc/source/_templates/searchbox.html: -------------------------------------------------------------------------------- 1 | {# 2 | basic/searchbox.html 3 | ~~~~~~~~~~~~~~~~~~~~ 4 | 5 | Sphinx sidebar template: quick search box. 6 | 7 | :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | #} 10 | {%- if pagename != "search" and builder != "singlehtml" %} 11 | 22 | 23 | {%- endif %} 24 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/alloc.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_ARRAY_ALLOC_H_ 2 | #define _NPY_ARRAY_ALLOC_H_ 3 | #define NPY_NO_DEPRECATED_API NPY_API_VERSION 4 | #define _MULTIARRAYMODULE 5 | #include 6 | 7 | #define NPY_TRACE_DOMAIN 389047 8 | 9 | NPY_NO_EXPORT void * 10 | npy_alloc_cache(npy_uintp sz); 11 | 12 | NPY_NO_EXPORT void * 13 | npy_alloc_cache_zero(npy_uintp sz); 14 | 15 | NPY_NO_EXPORT void 16 | npy_free_cache(void * p, npy_uintp sd); 17 | 18 | NPY_NO_EXPORT void * 19 | npy_alloc_cache_dim(npy_uintp sz); 20 | 21 | NPY_NO_EXPORT void 22 | npy_free_cache_dim(void * p, npy_uintp sd); 23 | 24 | static NPY_INLINE void 25 | npy_free_cache_dim_obj(PyArray_Dims dims) 26 | { 27 | npy_free_cache_dim(dims.ptr, dims.len); 28 | } 29 | 30 | static NPY_INLINE void 31 | npy_free_cache_dim_array(PyArrayObject * arr) 32 | { 33 | npy_free_cache_dim(PyArray_DIMS(arr), PyArray_NDIM(arr)); 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | addopts = -l 3 | norecursedirs = doc tools numpy/linalg/lapack_lite numpy/core/code_generators 4 | doctest_optionflags = NORMALIZE_WHITESPACE 5 | 6 | filterwarnings = 7 | error 8 | # Filter out annoying import messages. 9 | ignore:Not importing directory 10 | ignore:numpy.dtype size changed 11 | ignore:numpy.ufunc size changed 12 | # Ignore python2.7 -3 warnings 13 | ignore:sys\.exc_clear\(\) not supported in 3\.x:DeprecationWarning 14 | ignore:in 3\.x, __setslice__:DeprecationWarning 15 | ignore:in 3\.x, __getslice__:DeprecationWarning 16 | ignore:buffer\(\) not supported in 3\.x:DeprecationWarning 17 | ignore:CObject type is not supported in 3\.x:DeprecationWarning 18 | ignore:comparing unequal types not supported in 3\.x:DeprecationWarning 19 | ignore:the commands module has been removed in Python 3\.0:DeprecationWarning 20 | env = 21 | PYTHONHASHSEED=0 22 | -------------------------------------------------------------------------------- /doc/release/1.8.2-notes.rst: -------------------------------------------------------------------------------- 1 | ========================= 2 | NumPy 1.8.2 Release Notes 3 | ========================= 4 | 5 | This is a bugfix only release in the 1.8.x series. 6 | 7 | Issues fixed 8 | ============ 9 | 10 | * gh-4836: partition produces wrong results for multiple selections in equal ranges 11 | * gh-4656: Make fftpack._raw_fft threadsafe 12 | * gh-4628: incorrect argument order to _copyto in in np.nanmax, np.nanmin 13 | * gh-4642: Hold GIL for converting dtypes types with fields 14 | * gh-4733: fix np.linalg.svd(b, compute_uv=False) 15 | * gh-4853: avoid unaligned simd load on reductions on i386 16 | * gh-4722: Fix seg fault converting empty string to object 17 | * gh-4613: Fix lack of NULL check in array_richcompare 18 | * gh-4774: avoid unaligned access for strided byteswap 19 | * gh-650: Prevent division by zero when creating arrays from some buffers 20 | * gh-4602: ifort has issues with optimization flag O2, use O1 21 | -------------------------------------------------------------------------------- /numpy/f2py/tests/test_regression.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import os 4 | import math 5 | import pytest 6 | 7 | import numpy as np 8 | from numpy.testing import assert_raises, assert_equal 9 | 10 | from . import util 11 | 12 | 13 | def _path(*a): 14 | return os.path.join(*((os.path.dirname(__file__),) + a)) 15 | 16 | 17 | class TestIntentInOut(util.F2PyTest): 18 | # Check that intent(in out) translates as intent(inout) 19 | sources = [_path('src', 'regression', 'inout.f90')] 20 | 21 | @pytest.mark.slow 22 | def test_inout(self): 23 | # non-contiguous should raise error 24 | x = np.arange(6, dtype=np.float32)[::2] 25 | assert_raises(ValueError, self.module.foo, x) 26 | 27 | # check values with contiguous array 28 | x = np.arange(3, dtype=np.float32) 29 | self.module.foo(x) 30 | assert_equal(x, [3, 1, 2]) 31 | -------------------------------------------------------------------------------- /doc/release/1.11.3-notes.rst: -------------------------------------------------------------------------------- 1 | ========================== 2 | NumPy 1.11.3 Release Notes 3 | ========================== 4 | 5 | Numpy 1.11.3 fixes a bug that leads to file corruption when very large files 6 | opened in append mode are used in ``ndarray.tofile``. It supports Python 7 | versions 2.6 - 2.7 and 3.2 - 3.5. Wheels for Linux, Windows, and OS X can be 8 | found on PyPI. 9 | 10 | 11 | Contributors to maintenance/1.11.3 12 | ================================== 13 | 14 | A total of 2 people contributed to this release. People with a "+" by their 15 | names contributed a patch for the first time. 16 | 17 | - Charles Harris 18 | - Pavel Potocek + 19 | 20 | Pull Requests Merged 21 | ==================== 22 | 23 | - `#8341 `__: BUG: Fix ndarray.tofile large file corruption in append mode. 24 | - `#8346 `__: TST: Fix tests in PR #8341 for NumPy 1.11.x 25 | 26 | -------------------------------------------------------------------------------- /doc/source/reference/index.rst: -------------------------------------------------------------------------------- 1 | .. _reference: 2 | 3 | ############### 4 | NumPy Reference 5 | ############### 6 | 7 | :Release: |version| 8 | :Date: |today| 9 | 10 | 11 | .. module:: numpy 12 | 13 | This reference manual details functions, modules, and objects 14 | included in NumPy, describing what they are and what they do. 15 | For learning how to use NumPy, see also :ref:`user`. 16 | 17 | 18 | .. toctree:: 19 | :maxdepth: 2 20 | 21 | arrays 22 | constants 23 | ufuncs 24 | routines 25 | distutils 26 | c-api 27 | internals 28 | swig 29 | 30 | 31 | Acknowledgements 32 | ================ 33 | 34 | Large parts of this manual originate from Travis E. Oliphant's book 35 | `Guide to NumPy `__ (which generously 36 | entered Public Domain in August 2008). The reference documentation for many of 37 | the functions are written by numerous contributors and developers of 38 | NumPy. -------------------------------------------------------------------------------- /numpy/distutils/command/sdist.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import sys 4 | if 'setuptools' in sys.modules: 5 | from setuptools.command.sdist import sdist as old_sdist 6 | else: 7 | from distutils.command.sdist import sdist as old_sdist 8 | 9 | from numpy.distutils.misc_util import get_data_files 10 | 11 | class sdist(old_sdist): 12 | 13 | def add_defaults (self): 14 | old_sdist.add_defaults(self) 15 | 16 | dist = self.distribution 17 | 18 | if dist.has_data_files(): 19 | for data in dist.data_files: 20 | self.filelist.extend(get_data_files(data)) 21 | 22 | if dist.has_headers(): 23 | headers = [] 24 | for h in dist.headers: 25 | if isinstance(h, str): headers.append(h) 26 | else: headers.append(h[1]) 27 | self.filelist.extend(headers) 28 | 29 | return 30 | -------------------------------------------------------------------------------- /tools/swig/Makefile: -------------------------------------------------------------------------------- 1 | # List all of the subdirectories here for recursive make 2 | SUBDIRS = test 3 | 4 | # Default target 5 | .PHONY : default 6 | default: 7 | @echo "There is no default make target for this Makefile" 8 | @echo "Valid make targets are:" 9 | @echo " test - Compile and run tests of numpy.i" 10 | @echo " doc - Generate numpy.i documentation" 11 | @echo " all - make test + doc" 12 | @echo " clean - Remove generated files recursively" 13 | 14 | # Target all 15 | .PHONY : all 16 | all: $(SUBDIRS) 17 | 18 | # Target test 19 | .PHONY : test 20 | test: 21 | cd $@ && make $@ 22 | 23 | # Target clean 24 | .PHONY : clean 25 | clean: 26 | @for dir in $(SUBDIRS); do \ 27 | echo ; \ 28 | echo Running \'make clean\' in $$dir; \ 29 | cd $$dir && make clean && cd ..; \ 30 | done; \ 31 | echo 32 | -------------------------------------------------------------------------------- /numpy/core/include/numpy/npy_os.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_OS_H_ 2 | #define _NPY_OS_H_ 3 | 4 | #if defined(linux) || defined(__linux) || defined(__linux__) 5 | #define NPY_OS_LINUX 6 | #elif defined(__FreeBSD__) || defined(__NetBSD__) || \ 7 | defined(__OpenBSD__) || defined(__DragonFly__) 8 | #define NPY_OS_BSD 9 | #ifdef __FreeBSD__ 10 | #define NPY_OS_FREEBSD 11 | #elif defined(__NetBSD__) 12 | #define NPY_OS_NETBSD 13 | #elif defined(__OpenBSD__) 14 | #define NPY_OS_OPENBSD 15 | #elif defined(__DragonFly__) 16 | #define NPY_OS_DRAGONFLY 17 | #endif 18 | #elif defined(sun) || defined(__sun) 19 | #define NPY_OS_SOLARIS 20 | #elif defined(__CYGWIN__) 21 | #define NPY_OS_CYGWIN 22 | #elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) 23 | #define NPY_OS_WIN32 24 | #elif defined(__APPLE__) 25 | #define NPY_OS_DARWIN 26 | #else 27 | #define NPY_OS_UNKNOWN 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /numpy/core/src/umath/extobj.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_PRIVATE__EXTOBJ_H_ 2 | #define _NPY_PRIVATE__EXTOBJ_H_ 3 | 4 | #include /* for NPY_NO_EXPORT */ 5 | 6 | NPY_NO_EXPORT int 7 | _error_handler(int method, PyObject *errobj, char *errtype, int retstatus, int *first); 8 | 9 | NPY_NO_EXPORT PyObject * 10 | get_global_ext_obj(void); 11 | 12 | NPY_NO_EXPORT int 13 | _extract_pyvals(PyObject *ref, const char *name, int *bufsize, 14 | int *errmask, PyObject **errobj); 15 | 16 | NPY_NO_EXPORT int 17 | _check_ufunc_fperr(int errmask, PyObject *extobj, const char *ufunc_name); 18 | 19 | NPY_NO_EXPORT int 20 | _get_bufsize_errmask(PyObject * extobj, const char *ufunc_name, 21 | int *buffersize, int *errormask); 22 | 23 | /********************/ 24 | #define USE_USE_DEFAULTS 1 25 | /********************/ 26 | 27 | #if USE_USE_DEFAULTS==1 28 | NPY_NO_EXPORT int 29 | ufunc_update_use_defaults(void); 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /doc/source/reference/routines.statistics.rst: -------------------------------------------------------------------------------- 1 | Statistics 2 | ========== 3 | 4 | .. currentmodule:: numpy 5 | 6 | 7 | Order statistics 8 | ---------------- 9 | 10 | .. autosummary:: 11 | :toctree: generated/ 12 | 13 | amin 14 | amax 15 | nanmin 16 | nanmax 17 | ptp 18 | percentile 19 | nanpercentile 20 | quantile 21 | nanquantile 22 | 23 | Averages and variances 24 | ---------------------- 25 | 26 | .. autosummary:: 27 | :toctree: generated/ 28 | 29 | median 30 | average 31 | mean 32 | std 33 | var 34 | nanmedian 35 | nanmean 36 | nanstd 37 | nanvar 38 | 39 | Correlating 40 | ----------- 41 | 42 | .. autosummary:: 43 | :toctree: generated/ 44 | 45 | corrcoef 46 | correlate 47 | cov 48 | 49 | Histograms 50 | ---------- 51 | 52 | .. autosummary:: 53 | :toctree: generated/ 54 | 55 | histogram 56 | histogram2d 57 | histogramdd 58 | bincount 59 | histogram_bin_edges 60 | digitize 61 | -------------------------------------------------------------------------------- /numpy/distutils/fcompiler/none.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | from numpy.distutils.fcompiler import FCompiler 4 | from numpy.distutils import customized_fcompiler 5 | 6 | compilers = ['NoneFCompiler'] 7 | 8 | class NoneFCompiler(FCompiler): 9 | 10 | compiler_type = 'none' 11 | description = 'Fake Fortran compiler' 12 | 13 | executables = {'compiler_f77': None, 14 | 'compiler_f90': None, 15 | 'compiler_fix': None, 16 | 'linker_so': None, 17 | 'linker_exe': None, 18 | 'archiver': None, 19 | 'ranlib': None, 20 | 'version_cmd': None, 21 | } 22 | 23 | def find_executables(self): 24 | pass 25 | 26 | 27 | if __name__ == '__main__': 28 | from distutils import log 29 | log.set_verbosity(2) 30 | print(customized_fcompiler(compiler='none').get_version()) 31 | -------------------------------------------------------------------------------- /doc/source/f2py/allocarr_session.dat: -------------------------------------------------------------------------------- 1 | >>> import allocarr 2 | >>> print allocarr.mod.__doc__ 3 | b - 'f'-array(-1,-1), not allocated 4 | foo - Function signature: 5 | foo() 6 | 7 | >>> allocarr.mod.foo() 8 | b is not allocated 9 | >>> allocarr.mod.b = [[1,2,3],[4,5,6]] # allocate/initialize b 10 | >>> allocarr.mod.foo() 11 | b=[ 12 | 1.000000 2.000000 3.000000 13 | 4.000000 5.000000 6.000000 14 | ] 15 | >>> allocarr.mod.b # b is Fortran-contiguous 16 | array([[ 1., 2., 3.], 17 | [ 4., 5., 6.]],'f') 18 | >>> allocarr.mod.b = [[1,2,3],[4,5,6],[7,8,9]] # reallocate/initialize b 19 | >>> allocarr.mod.foo() 20 | b=[ 21 | 1.000000 2.000000 3.000000 22 | 4.000000 5.000000 6.000000 23 | 7.000000 8.000000 9.000000 24 | ] 25 | >>> allocarr.mod.b = None # deallocate array 26 | >>> allocarr.mod.foo() 27 | b is not allocated 28 | -------------------------------------------------------------------------------- /tools/swig/test/Fortran.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "Fortran.h" 5 | 6 | #define TEST_FUNCS(TYPE, SNAME) \ 7 | \ 8 | TYPE SNAME ## SecondElement(TYPE * matrix, int rows, int cols) { \ 9 | TYPE result = matrix[1]; \ 10 | return result; \ 11 | } \ 12 | 13 | TEST_FUNCS(signed char , schar ) 14 | TEST_FUNCS(unsigned char , uchar ) 15 | TEST_FUNCS(short , short ) 16 | TEST_FUNCS(unsigned short , ushort ) 17 | TEST_FUNCS(int , int ) 18 | TEST_FUNCS(unsigned int , uint ) 19 | TEST_FUNCS(long , long ) 20 | TEST_FUNCS(unsigned long , ulong ) 21 | TEST_FUNCS(long long , longLong ) 22 | TEST_FUNCS(unsigned long long, ulongLong) 23 | TEST_FUNCS(float , float ) 24 | TEST_FUNCS(double , double ) 25 | -------------------------------------------------------------------------------- /tools/commitstats.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | # Run svn log -l 4 | 5 | import re 6 | import numpy as np 7 | import os 8 | 9 | names = re.compile(r'r\d+\s[|]\s(.*)\s[|]\s200') 10 | 11 | def get_count(filename, repo): 12 | mystr = open(filename).read() 13 | result = names.findall(mystr) 14 | u = np.unique(result) 15 | count = [(x, result.count(x), repo) for x in u] 16 | return count 17 | 18 | 19 | command = 'svn log -l 2300 > output.txt' 20 | os.chdir('..') 21 | os.system(command) 22 | 23 | count = get_count('output.txt', 'NumPy') 24 | 25 | 26 | os.chdir('../scipy') 27 | os.system(command) 28 | 29 | count.extend(get_count('output.txt', 'SciPy')) 30 | 31 | os.chdir('../scikits') 32 | os.system(command) 33 | count.extend(get_count('output.txt', 'SciKits')) 34 | count.sort() 35 | 36 | 37 | 38 | print("** SciPy and NumPy **") 39 | print("=====================") 40 | for val in count: 41 | print(val) 42 | -------------------------------------------------------------------------------- /doc/changelog/1.14.2-changelog.rst: -------------------------------------------------------------------------------- 1 | 2 | Contributors 3 | ============ 4 | 5 | A total of 4 people contributed to this release. People with a "+" by their 6 | names contributed a patch for the first time. 7 | 8 | * Allan Haldane 9 | * Charles Harris 10 | * Eric Wieser 11 | * Pauli Virtanen 12 | 13 | Pull requests merged 14 | ==================== 15 | 16 | A total of 5 pull requests were merged for this release. 17 | 18 | * `#10674 `__: BUG: Further back-compat fix for subclassed array repr 19 | * `#10725 `__: BUG: dragon4 fractional output mode adds too many trailing zeros 20 | * `#10726 `__: BUG: Fix f2py generated code to work on PyPy 21 | * `#10727 `__: BUG: Fix missing NPY_VISIBILITY_HIDDEN on npy_longdouble_to_PyLong 22 | * `#10729 `__: DOC: Create 1.14.2 notes and changelog. 23 | -------------------------------------------------------------------------------- /doc/source/reference/routines.dtype.rst: -------------------------------------------------------------------------------- 1 | .. _routines.dtype: 2 | 3 | Data type routines 4 | ================== 5 | 6 | .. currentmodule:: numpy 7 | 8 | .. autosummary:: 9 | :toctree: generated/ 10 | 11 | can_cast 12 | promote_types 13 | min_scalar_type 14 | result_type 15 | common_type 16 | obj2sctype 17 | 18 | Creating data types 19 | ------------------- 20 | 21 | .. autosummary:: 22 | :toctree: generated/ 23 | 24 | 25 | dtype 26 | format_parser 27 | 28 | Data type information 29 | --------------------- 30 | .. autosummary:: 31 | :toctree: generated/ 32 | 33 | finfo 34 | iinfo 35 | MachAr 36 | 37 | Data type testing 38 | ----------------- 39 | .. autosummary:: 40 | :toctree: generated/ 41 | 42 | issctype 43 | issubdtype 44 | issubsctype 45 | issubclass_ 46 | find_common_type 47 | 48 | Miscellaneous 49 | ------------- 50 | .. autosummary:: 51 | :toctree: generated/ 52 | 53 | typename 54 | sctype2char 55 | mintypecode 56 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/arraytypes.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_ARRAYTYPES_H_ 2 | #define _NPY_ARRAYTYPES_H_ 3 | 4 | #include "common.h" 5 | 6 | NPY_NO_EXPORT int 7 | set_typeinfo(PyObject *dict); 8 | 9 | /* needed for blasfuncs */ 10 | NPY_NO_EXPORT void 11 | FLOAT_dot(char *, npy_intp, char *, npy_intp, char *, npy_intp, void *); 12 | 13 | NPY_NO_EXPORT void 14 | CFLOAT_dot(char *, npy_intp, char *, npy_intp, char *, npy_intp, void *); 15 | 16 | NPY_NO_EXPORT void 17 | DOUBLE_dot(char *, npy_intp, char *, npy_intp, char *, npy_intp, void *); 18 | 19 | NPY_NO_EXPORT void 20 | CDOUBLE_dot(char *, npy_intp, char *, npy_intp, char *, npy_intp, void *); 21 | 22 | 23 | /* for _pyarray_correlate */ 24 | NPY_NO_EXPORT int 25 | small_correlate(const char * d_, npy_intp dstride, 26 | npy_intp nd, enum NPY_TYPES dtype, 27 | const char * k_, npy_intp kstride, 28 | npy_intp nk, enum NPY_TYPES ktype, 29 | char * out_, npy_intp ostride); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /numpy/f2py/tests/test_common.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import os 4 | import sys 5 | import pytest 6 | 7 | import numpy as np 8 | from . import util 9 | 10 | from numpy.testing import assert_array_equal 11 | 12 | def _path(*a): 13 | return os.path.join(*((os.path.dirname(__file__),) + a)) 14 | 15 | class TestCommonBlock(util.F2PyTest): 16 | sources = [_path('src', 'common', 'block.f')] 17 | 18 | @pytest.mark.skipif(sys.platform=='win32', 19 | reason='Fails with MinGW64 Gfortran (Issue #9673)') 20 | def test_common_block(self): 21 | self.module.initcb() 22 | assert_array_equal(self.module.block.long_bn, 23 | np.array(1.0, dtype=np.float64)) 24 | assert_array_equal(self.module.block.string_bn, 25 | np.array('2', dtype='|S1')) 26 | assert_array_equal(self.module.block.ok, 27 | np.array(3, dtype=np.int32)) 28 | -------------------------------------------------------------------------------- /doc/source/_templates/autosummary/class.rst: -------------------------------------------------------------------------------- 1 | {% extends "!autosummary/class.rst" %} 2 | 3 | {% block methods %} 4 | {% if methods %} 5 | .. HACK -- the point here is that we don't want this to appear in the output, but the autosummary should still generate the pages. 6 | .. autosummary:: 7 | :toctree: 8 | {% for item in all_methods %} 9 | {%- if not item.startswith('_') or item in ['__call__'] %} 10 | {{ name }}.{{ item }} 11 | {%- endif -%} 12 | {%- endfor %} 13 | {% endif %} 14 | {% endblock %} 15 | 16 | {% block attributes %} 17 | {% if attributes %} 18 | .. HACK -- the point here is that we don't want this to appear in the output, but the autosummary should still generate the pages. 19 | .. autosummary:: 20 | :toctree: 21 | {% for item in all_attributes %} 22 | {%- if not item.startswith('_') %} 23 | {{ name }}.{{ item }} 24 | {%- endif -%} 25 | {%- endfor %} 26 | {% endif %} 27 | {% endblock %} 28 | -------------------------------------------------------------------------------- /numpy/matrixlib/tests/test_multiarray.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | # As we are testing matrices, we ignore its PendingDeprecationWarnings 4 | try: 5 | import pytest 6 | pytestmark = pytest.mark.filterwarnings( 7 | 'ignore:the matrix subclass is not:PendingDeprecationWarning') 8 | except ImportError: 9 | pass 10 | 11 | import numpy as np 12 | from numpy.testing import assert_, assert_equal, assert_array_equal 13 | 14 | class TestView(object): 15 | def test_type(self): 16 | x = np.array([1, 2, 3]) 17 | assert_(isinstance(x.view(np.matrix), np.matrix)) 18 | 19 | def test_keywords(self): 20 | x = np.array([(1, 2)], dtype=[('a', np.int8), ('b', np.int8)]) 21 | # We must be specific about the endianness here: 22 | y = x.view(dtype=' 4 | 5 | NPY_NO_EXPORT PyObject * 6 | arr_insert(PyObject *, PyObject *, PyObject *); 7 | NPY_NO_EXPORT PyObject * 8 | arr_bincount(PyObject *, PyObject *, PyObject *); 9 | NPY_NO_EXPORT PyObject * 10 | arr_digitize(PyObject *, PyObject *, PyObject *kwds); 11 | NPY_NO_EXPORT PyObject * 12 | arr_interp(PyObject *, PyObject *, PyObject *); 13 | NPY_NO_EXPORT PyObject * 14 | arr_interp_complex(PyObject *, PyObject *, PyObject *); 15 | NPY_NO_EXPORT PyObject * 16 | arr_ravel_multi_index(PyObject *, PyObject *, PyObject *); 17 | NPY_NO_EXPORT PyObject * 18 | arr_unravel_index(PyObject *, PyObject *, PyObject *); 19 | NPY_NO_EXPORT PyObject * 20 | arr_add_docstring(PyObject *, PyObject *); 21 | NPY_NO_EXPORT PyObject * 22 | io_pack(PyObject *, PyObject *, PyObject *); 23 | NPY_NO_EXPORT PyObject * 24 | io_unpack(PyObject *, PyObject *, PyObject *); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /numpy/f2py/tests/src/size/foo.f90: -------------------------------------------------------------------------------- 1 | 2 | subroutine foo(a, n, m, b) 3 | implicit none 4 | 5 | real, intent(in) :: a(n, m) 6 | integer, intent(in) :: n, m 7 | real, intent(out) :: b(size(a, 1)) 8 | 9 | integer :: i 10 | 11 | do i = 1, size(b) 12 | b(i) = sum(a(i,:)) 13 | enddo 14 | end subroutine 15 | 16 | subroutine trans(x,y) 17 | implicit none 18 | real, intent(in), dimension(:,:) :: x 19 | real, intent(out), dimension( size(x,2), size(x,1) ) :: y 20 | integer :: N, M, i, j 21 | N = size(x,1) 22 | M = size(x,2) 23 | DO i=1,N 24 | do j=1,M 25 | y(j,i) = x(i,j) 26 | END DO 27 | END DO 28 | end subroutine trans 29 | 30 | subroutine flatten(x,y) 31 | implicit none 32 | real, intent(in), dimension(:,:) :: x 33 | real, intent(out), dimension( size(x) ) :: y 34 | integer :: N, M, i, j, k 35 | N = size(x,1) 36 | M = size(x,2) 37 | k = 1 38 | DO i=1,N 39 | do j=1,M 40 | y(k) = x(i,j) 41 | k = k + 1 42 | END DO 43 | END DO 44 | end subroutine flatten 45 | -------------------------------------------------------------------------------- /numpy/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import division, print_function 3 | 4 | 5 | def configuration(parent_package='',top_path=None): 6 | from numpy.distutils.misc_util import Configuration 7 | config = Configuration('numpy', parent_package, top_path) 8 | 9 | config.add_subpackage('compat') 10 | config.add_subpackage('core') 11 | config.add_subpackage('distutils') 12 | config.add_subpackage('doc') 13 | config.add_subpackage('f2py') 14 | config.add_subpackage('fft') 15 | config.add_subpackage('lib') 16 | config.add_subpackage('linalg') 17 | config.add_subpackage('ma') 18 | config.add_subpackage('matrixlib') 19 | config.add_subpackage('polynomial') 20 | config.add_subpackage('random') 21 | config.add_subpackage('testing') 22 | config.add_data_dir('doc') 23 | config.add_data_dir('tests') 24 | config.make_config_py() # installs __config__.py 25 | return config 26 | 27 | if __name__ == '__main__': 28 | print('This is the wrong setup.py file to run') 29 | -------------------------------------------------------------------------------- /numpy/distutils/command/install_data.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import sys 4 | have_setuptools = ('setuptools' in sys.modules) 5 | 6 | from distutils.command.install_data import install_data as old_install_data 7 | 8 | #data installer with improved intelligence over distutils 9 | #data files are copied into the project directory instead 10 | #of willy-nilly 11 | class install_data (old_install_data): 12 | 13 | def run(self): 14 | old_install_data.run(self) 15 | 16 | if have_setuptools: 17 | # Run install_clib again, since setuptools does not run sub-commands 18 | # of install automatically 19 | self.run_command('install_clib') 20 | 21 | def finalize_options (self): 22 | self.set_undefined_options('install', 23 | ('install_lib', 'install_dir'), 24 | ('root', 'root'), 25 | ('force', 'force'), 26 | ) 27 | -------------------------------------------------------------------------------- /tools/swig/test/Flat.i: -------------------------------------------------------------------------------- 1 | // -*- c++ -*- 2 | %module Flat 3 | 4 | %{ 5 | #define SWIG_FILE_WITH_INIT 6 | #include "Flat.h" 7 | %} 8 | 9 | // Get the NumPy typemaps 10 | %include "../numpy.i" 11 | 12 | %init %{ 13 | import_array(); 14 | %} 15 | 16 | %define %apply_numpy_typemaps(TYPE) 17 | 18 | %apply (TYPE* INPLACE_ARRAY_FLAT, int DIM_FLAT) {(TYPE* array, int size)}; 19 | 20 | %enddef /* %apply_numpy_typemaps() macro */ 21 | 22 | %apply_numpy_typemaps(signed char ) 23 | %apply_numpy_typemaps(unsigned char ) 24 | %apply_numpy_typemaps(short ) 25 | %apply_numpy_typemaps(unsigned short ) 26 | %apply_numpy_typemaps(int ) 27 | %apply_numpy_typemaps(unsigned int ) 28 | %apply_numpy_typemaps(long ) 29 | %apply_numpy_typemaps(unsigned long ) 30 | %apply_numpy_typemaps(long long ) 31 | %apply_numpy_typemaps(unsigned long long) 32 | %apply_numpy_typemaps(float ) 33 | %apply_numpy_typemaps(double ) 34 | 35 | // Include the header file to be wrapped 36 | %include "Flat.h" 37 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/numpyos.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_NUMPYOS_H_ 2 | #define _NPY_NUMPYOS_H_ 3 | 4 | NPY_NO_EXPORT char* 5 | NumPyOS_ascii_formatd(char *buffer, size_t buf_size, 6 | const char *format, 7 | double val, int decimal); 8 | 9 | NPY_NO_EXPORT char* 10 | NumPyOS_ascii_formatf(char *buffer, size_t buf_size, 11 | const char *format, 12 | float val, int decimal); 13 | 14 | NPY_NO_EXPORT char* 15 | NumPyOS_ascii_formatl(char *buffer, size_t buf_size, 16 | const char *format, 17 | long double val, int decimal); 18 | 19 | NPY_NO_EXPORT double 20 | NumPyOS_ascii_strtod(const char *s, char** endptr); 21 | 22 | NPY_NO_EXPORT long double 23 | NumPyOS_ascii_strtold(const char *s, char** endptr); 24 | 25 | NPY_NO_EXPORT int 26 | NumPyOS_ascii_ftolf(FILE *fp, double *value); 27 | 28 | NPY_NO_EXPORT int 29 | NumPyOS_ascii_ftoLf(FILE *fp, long double *value); 30 | 31 | NPY_NO_EXPORT int 32 | NumPyOS_ascii_isspace(int c); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /doc/source/f2py/index.rst: -------------------------------------------------------------------------------- 1 | ##################################### 2 | F2PY Users Guide and Reference Manual 3 | ##################################### 4 | 5 | The purpose of the ``F2PY`` --*Fortran to Python interface generator*-- 6 | is to provide a connection between Python and Fortran 7 | languages. F2PY is a part of NumPy_ (``numpy.f2py``) and also available as a 8 | standalone command line tool ``f2py`` when ``numpy`` is installed that 9 | facilitates creating/building Python C/API extension modules that make it 10 | possible 11 | 12 | * to call Fortran 77/90/95 external subroutines and Fortran 90/95 13 | module subroutines as well as C functions; 14 | * to access Fortran 77 ``COMMON`` blocks and Fortran 90/95 module data, 15 | including allocatable arrays 16 | 17 | from Python. 18 | 19 | .. toctree:: 20 | :maxdepth: 2 21 | 22 | getting-started 23 | signature-file 24 | python-usage 25 | usage 26 | distutils 27 | advanced 28 | 29 | .. _Python: http://www.python.org/ 30 | .. _NumPy: http://www.numpy.org/ 31 | .. _SciPy: http://www.numpy.org/ 32 | -------------------------------------------------------------------------------- /tools/swig/test/Makefile: -------------------------------------------------------------------------------- 1 | # SWIG 2 | INTERFACES = Array.i Farray.i Vector.i Matrix.i Tensor.i Fortran.i Flat.i 3 | WRAPPERS = $(INTERFACES:.i=_wrap.cxx) 4 | PROXIES = $(INTERFACES:.i=.py ) 5 | 6 | # Default target: build the tests 7 | .PHONY : all 8 | all: $(WRAPPERS) Array1.cxx Array1.h Array2.cxx Array2.h ArrayZ.cxx ArrayZ.h \ 9 | Farray.cxx Farray.h Vector.cxx Vector.h \ 10 | Matrix.cxx Matrix.h Tensor.cxx Tensor.h Fortran.h Fortran.cxx \ 11 | Flat.h Flat.cxx 12 | ./setup.py build_ext -i 13 | 14 | # Test target: run the tests 15 | .PHONY : test 16 | test: all 17 | python testVector.py 18 | python testMatrix.py 19 | python testTensor.py 20 | python testArray.py 21 | python testFarray.py 22 | python testFortran.py 23 | python testFlat.py 24 | 25 | # Rule: %.i -> %_wrap.cxx 26 | %_wrap.cxx: %.i %.h ../numpy.i 27 | swig -c++ -python $< 28 | %_wrap.cxx: %.i %1.h %2.h ../numpy.i 29 | swig -c++ -python $< 30 | 31 | # Clean target 32 | .PHONY : clean 33 | clean: 34 | $(RM) -r build 35 | $(RM) *.so 36 | $(RM) $(WRAPPERS) 37 | $(RM) $(PROXIES) 38 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/arrayobject.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_INTERNAL_ARRAYOBJECT_H_ 2 | #define _NPY_INTERNAL_ARRAYOBJECT_H_ 3 | 4 | #ifndef _MULTIARRAYMODULE 5 | #error You should not include this 6 | #endif 7 | 8 | NPY_NO_EXPORT PyObject * 9 | _strings_richcompare(PyArrayObject *self, PyArrayObject *other, int cmp_op, 10 | int rstrip); 11 | 12 | NPY_NO_EXPORT PyObject * 13 | array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op); 14 | 15 | NPY_NO_EXPORT int 16 | array_might_be_written(PyArrayObject *obj); 17 | 18 | /* 19 | * This flag is used to mark arrays which we would like to, in the future, 20 | * turn into views. It causes a warning to be issued on the first attempt to 21 | * write to the array (but the write is allowed to succeed). 22 | * 23 | * This flag is for internal use only, and may be removed in a future release, 24 | * which is why the #define is not exposed to user code. Currently it is set 25 | * on arrays returned by ndarray.diagonal. 26 | */ 27 | static const int NPY_ARRAY_WARN_ON_WRITE = (1 << 31); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /tools/swig/test/Fortran.i: -------------------------------------------------------------------------------- 1 | // -*- c++ -*- 2 | %module Fortran 3 | 4 | %{ 5 | #define SWIG_FILE_WITH_INIT 6 | #include "Fortran.h" 7 | %} 8 | 9 | // Get the NumPy typemaps 10 | %include "../numpy.i" 11 | 12 | %init %{ 13 | import_array(); 14 | %} 15 | 16 | %define %apply_numpy_typemaps(TYPE) 17 | 18 | %apply (TYPE* IN_FARRAY2, int DIM1, int DIM2) {(TYPE* matrix, int rows, int cols)}; 19 | 20 | %enddef /* %apply_numpy_typemaps() macro */ 21 | 22 | %apply_numpy_typemaps(signed char ) 23 | %apply_numpy_typemaps(unsigned char ) 24 | %apply_numpy_typemaps(short ) 25 | %apply_numpy_typemaps(unsigned short ) 26 | %apply_numpy_typemaps(int ) 27 | %apply_numpy_typemaps(unsigned int ) 28 | %apply_numpy_typemaps(long ) 29 | %apply_numpy_typemaps(unsigned long ) 30 | %apply_numpy_typemaps(long long ) 31 | %apply_numpy_typemaps(unsigned long long) 32 | %apply_numpy_typemaps(float ) 33 | %apply_numpy_typemaps(double ) 34 | 35 | // Include the header file to be wrapped 36 | %include "Fortran.h" 37 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/item_selection.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_PRIVATE__ITEM_SELECTION_H_ 2 | #define _NPY_PRIVATE__ITEM_SELECTION_H_ 3 | 4 | /* 5 | * Counts the number of True values in a raw boolean array. This 6 | * is a low-overhead function which does no heap allocations. 7 | * 8 | * Returns -1 on error. 9 | */ 10 | NPY_NO_EXPORT npy_intp 11 | count_boolean_trues(int ndim, char *data, npy_intp *ashape, npy_intp *astrides); 12 | 13 | /* 14 | * Gets a single item from the array, based on a single multi-index 15 | * array of values, which must be of length PyArray_NDIM(self). 16 | */ 17 | NPY_NO_EXPORT PyObject * 18 | PyArray_MultiIndexGetItem(PyArrayObject *self, npy_intp *multi_index); 19 | 20 | /* 21 | * Sets a single item in the array, based on a single multi-index 22 | * array of values, which must be of length PyArray_NDIM(self). 23 | * 24 | * Returns 0 on success, -1 on failure. 25 | */ 26 | NPY_NO_EXPORT int 27 | PyArray_MultiIndexSetItem(PyArrayObject *self, npy_intp *multi_index, 28 | PyObject *obj); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /numpy/core/src/private/npy_fpmath.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_NPY_FPMATH_H_ 2 | #define _NPY_NPY_FPMATH_H_ 3 | 4 | #include "npy_config.h" 5 | 6 | #include "numpy/npy_os.h" 7 | #include "numpy/npy_cpu.h" 8 | #include "numpy/npy_common.h" 9 | 10 | #if !(defined(HAVE_LDOUBLE_IEEE_QUAD_BE) || \ 11 | defined(HAVE_LDOUBLE_IEEE_QUAD_LE) || \ 12 | defined(HAVE_LDOUBLE_IEEE_DOUBLE_LE) || \ 13 | defined(HAVE_LDOUBLE_IEEE_DOUBLE_BE) || \ 14 | defined(HAVE_LDOUBLE_INTEL_EXTENDED_16_BYTES_LE) || \ 15 | defined(HAVE_LDOUBLE_INTEL_EXTENDED_12_BYTES_LE) || \ 16 | defined(HAVE_LDOUBLE_MOTOROLA_EXTENDED_12_BYTES_BE) || \ 17 | defined(HAVE_LDOUBLE_IBM_DOUBLE_DOUBLE_BE) || \ 18 | defined(HAVE_LDOUBLE_IBM_DOUBLE_DOUBLE_LE)) 19 | #error No long double representation defined 20 | #endif 21 | 22 | /* for back-compat, also keep old name for double-double */ 23 | #ifdef HAVE_LDOUBLE_IBM_DOUBLE_DOUBLE_LE 24 | #define HAVE_LDOUBLE_DOUBLE_DOUBLE_LE 25 | #endif 26 | #ifdef HAVE_LDOUBLE_IBM_DOUBLE_DOUBLE_BE 27 | #define HAVE_LDOUBLE_DOUBLE_DOUBLE_BE 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /numpy/_build_utils/apple_accelerate.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import os 4 | import sys 5 | import re 6 | 7 | __all__ = ['uses_accelerate_framework', 'get_sgemv_fix'] 8 | 9 | def uses_accelerate_framework(info): 10 | """ Returns True if Accelerate framework is used for BLAS/LAPACK """ 11 | # If we're not building on Darwin (macOS), don't use Accelerate 12 | if sys.platform != "darwin": 13 | return False 14 | # If we're building on macOS, but targeting a different platform, 15 | # don't use Accelerate. 16 | if os.getenv('_PYTHON_HOST_PLATFORM', None): 17 | return False 18 | r_accelerate = re.compile("Accelerate") 19 | extra_link_args = info.get('extra_link_args', '') 20 | for arg in extra_link_args: 21 | if r_accelerate.search(arg): 22 | return True 23 | return False 24 | 25 | def get_sgemv_fix(): 26 | """ Returns source file needed to correct SGEMV """ 27 | path = os.path.abspath(os.path.dirname(__file__)) 28 | return [os.path.join(path, 'src', 'apple_sgemv_fix.c')] 29 | -------------------------------------------------------------------------------- /numpy/core/src/dummymodule.c: -------------------------------------------------------------------------------- 1 | /* -*- c -*- */ 2 | 3 | /* 4 | * This is a dummy module whose purpose is to get distutils to generate the 5 | * configuration files before the libraries are made. 6 | */ 7 | 8 | #define NPY_NO_DEPRECATED_API NPY_API_VERSION 9 | #define NO_IMPORT_ARRAY 10 | 11 | #include 12 | #include 13 | 14 | static struct PyMethodDef methods[] = { 15 | {NULL, NULL, 0, NULL} 16 | }; 17 | 18 | 19 | #if defined(NPY_PY3K) 20 | static struct PyModuleDef moduledef = { 21 | PyModuleDef_HEAD_INIT, 22 | "dummy", 23 | NULL, 24 | -1, 25 | methods, 26 | NULL, 27 | NULL, 28 | NULL, 29 | NULL 30 | }; 31 | #endif 32 | 33 | /* Initialization function for the module */ 34 | #if defined(NPY_PY3K) 35 | PyMODINIT_FUNC PyInit__dummy(void) { 36 | PyObject *m; 37 | m = PyModule_Create(&moduledef); 38 | if (!m) { 39 | return NULL; 40 | } 41 | return m; 42 | } 43 | #else 44 | PyMODINIT_FUNC 45 | init_dummy(void) { 46 | Py_InitModule("_dummy", methods); 47 | } 48 | #endif 49 | -------------------------------------------------------------------------------- /numpy/core/src/private/npy_import.h: -------------------------------------------------------------------------------- 1 | #ifndef NPY_IMPORT_H 2 | #define NPY_IMPORT_H 3 | 4 | #include 5 | 6 | /*! \brief Fetch and cache Python function. 7 | * 8 | * Import a Python function and cache it for use. The function checks if 9 | * cache is NULL, and if not NULL imports the Python function specified by 10 | * \a module and \a function, increments its reference count, and stores 11 | * the result in \a cache. Usually \a cache will be a static variable and 12 | * should be initialized to NULL. On error \a cache will contain NULL on 13 | * exit, 14 | * 15 | * @param module Absolute module name. 16 | * @param attr module attribute to cache. 17 | * @param cache Storage location for imported function. 18 | */ 19 | NPY_INLINE static void 20 | npy_cache_import(const char *module, const char *attr, PyObject **cache) 21 | { 22 | if (*cache == NULL) { 23 | PyObject *mod = PyImport_ImportModule(module); 24 | 25 | if (mod != NULL) { 26 | *cache = PyObject_GetAttrString(mod, attr); 27 | Py_DECREF(mod); 28 | } 29 | } 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /numpy/f2py/tests/test_assumed_shape.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import os 4 | import pytest 5 | 6 | from numpy.testing import assert_ 7 | from . import util 8 | 9 | 10 | def _path(*a): 11 | return os.path.join(*((os.path.dirname(__file__),) + a)) 12 | 13 | 14 | class TestAssumedShapeSumExample(util.F2PyTest): 15 | sources = [_path('src', 'assumed_shape', 'foo_free.f90'), 16 | _path('src', 'assumed_shape', 'foo_use.f90'), 17 | _path('src', 'assumed_shape', 'precision.f90'), 18 | _path('src', 'assumed_shape', 'foo_mod.f90'), 19 | ] 20 | 21 | @pytest.mark.slow 22 | def test_all(self): 23 | r = self.module.fsum([1, 2]) 24 | assert_(r == 3, repr(r)) 25 | r = self.module.sum([1, 2]) 26 | assert_(r == 3, repr(r)) 27 | r = self.module.sum_with_use([1, 2]) 28 | assert_(r == 3, repr(r)) 29 | 30 | r = self.module.mod.sum([1, 2]) 31 | assert_(r == 3, repr(r)) 32 | r = self.module.mod.fsum([1, 2]) 33 | assert_(r == 3, repr(r)) 34 | -------------------------------------------------------------------------------- /numpy/f2py/tests/test_mixed.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import os 4 | import textwrap 5 | import pytest 6 | 7 | from numpy.testing import assert_, assert_equal 8 | from . import util 9 | 10 | 11 | def _path(*a): 12 | return os.path.join(*((os.path.dirname(__file__),) + a)) 13 | 14 | 15 | class TestMixed(util.F2PyTest): 16 | sources = [_path('src', 'mixed', 'foo.f'), 17 | _path('src', 'mixed', 'foo_fixed.f90'), 18 | _path('src', 'mixed', 'foo_free.f90')] 19 | 20 | @pytest.mark.slow 21 | def test_all(self): 22 | assert_(self.module.bar11() == 11) 23 | assert_(self.module.foo_fixed.bar12() == 12) 24 | assert_(self.module.foo_free.bar13() == 13) 25 | 26 | @pytest.mark.slow 27 | def test_docstring(self): 28 | expected = """ 29 | a = bar11() 30 | 31 | Wrapper for ``bar11``. 32 | 33 | Returns 34 | ------- 35 | a : int 36 | """ 37 | assert_equal(self.module.bar11.__doc__, 38 | textwrap.dedent(expected).lstrip()) 39 | -------------------------------------------------------------------------------- /numpy/distutils/command/egg_info.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import sys 4 | 5 | from setuptools.command.egg_info import egg_info as _egg_info 6 | 7 | class egg_info(_egg_info): 8 | def run(self): 9 | if 'sdist' in sys.argv: 10 | import warnings 11 | import textwrap 12 | msg = textwrap.dedent(""" 13 | `build_src` is being run, this may lead to missing 14 | files in your sdist! You want to use distutils.sdist 15 | instead of the setuptools version: 16 | 17 | from distutils.command.sdist import sdist 18 | cmdclass={'sdist': sdist}" 19 | 20 | See numpy's setup.py or gh-7131 for details.""") 21 | warnings.warn(msg, UserWarning, stacklevel=2) 22 | 23 | # We need to ensure that build_src has been executed in order to give 24 | # setuptools' egg_info command real filenames instead of functions which 25 | # generate files. 26 | self.run_command("build_src") 27 | _egg_info.run(self) 28 | -------------------------------------------------------------------------------- /numpy/distutils/command/install_headers.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import os 4 | from distutils.command.install_headers import install_headers as old_install_headers 5 | 6 | class install_headers (old_install_headers): 7 | 8 | def run (self): 9 | headers = self.distribution.headers 10 | if not headers: 11 | return 12 | 13 | prefix = os.path.dirname(self.install_dir) 14 | for header in headers: 15 | if isinstance(header, tuple): 16 | # Kind of a hack, but I don't know where else to change this... 17 | if header[0] == 'numpy.core': 18 | header = ('numpy', header[1]) 19 | if os.path.splitext(header[1])[1] == '.inc': 20 | continue 21 | d = os.path.join(*([prefix]+header[0].split('.'))) 22 | header = header[1] 23 | else: 24 | d = self.install_dir 25 | self.mkpath(d) 26 | (out, _) = self.copy_file(header, d) 27 | self.outfiles.append(out) 28 | -------------------------------------------------------------------------------- /doc/release/1.14.5-notes.rst: -------------------------------------------------------------------------------- 1 | ========================== 2 | NumPy 1.14.5 Release Notes 3 | ========================== 4 | 5 | This is a bugfix release for bugs reported following the 1.14.4 release. The 6 | most significant fixes are: 7 | 8 | * fixes for compilation errors on alpine and NetBSD 9 | 10 | The Python versions supported in this release are 2.7 and 3.4 - 3.6. The Python 11 | 3.6 wheels available from PIP are built with Python 3.6.2 and should be 12 | compatible with all previous versions of Python 3.6. The source releases were 13 | cythonized with Cython 0.28.2 and should work for the upcoming Python 3.7. 14 | 15 | Contributors 16 | ============ 17 | 18 | A total of 1 person contributed to this release. People with a "+" by their 19 | names contributed a patch for the first time. 20 | 21 | * Charles Harris 22 | 23 | Pull requests merged 24 | ==================== 25 | 26 | A total of 2 pull requests were merged for this release. 27 | 28 | * `#11274 `__: BUG: Correct use of NPY_UNUSED. 29 | * `#11294 `__: BUG: Remove extra trailing parentheses. 30 | 31 | -------------------------------------------------------------------------------- /doc/source/reference/routines.logic.rst: -------------------------------------------------------------------------------- 1 | Logic functions 2 | *************** 3 | 4 | .. currentmodule:: numpy 5 | 6 | Truth value testing 7 | ------------------- 8 | .. autosummary:: 9 | :toctree: generated/ 10 | 11 | all 12 | any 13 | 14 | Array contents 15 | -------------- 16 | .. autosummary:: 17 | :toctree: generated/ 18 | 19 | isfinite 20 | isinf 21 | isnan 22 | isnat 23 | isneginf 24 | isposinf 25 | 26 | Array type testing 27 | ------------------ 28 | .. autosummary:: 29 | :toctree: generated/ 30 | 31 | iscomplex 32 | iscomplexobj 33 | isfortran 34 | isreal 35 | isrealobj 36 | isscalar 37 | 38 | Logical operations 39 | ------------------ 40 | .. autosummary:: 41 | :toctree: generated/ 42 | 43 | logical_and 44 | logical_or 45 | logical_not 46 | logical_xor 47 | 48 | Comparison 49 | ---------- 50 | .. autosummary:: 51 | :toctree: generated/ 52 | 53 | allclose 54 | isclose 55 | array_equal 56 | array_equiv 57 | 58 | .. autosummary:: 59 | :toctree: generated/ 60 | 61 | greater 62 | greater_equal 63 | less 64 | less_equal 65 | equal 66 | not_equal 67 | -------------------------------------------------------------------------------- /tools/swig/test/Array1.h: -------------------------------------------------------------------------------- 1 | #ifndef ARRAY1_H 2 | #define ARRAY1_H 3 | 4 | #include 5 | #include 6 | 7 | class Array1 8 | { 9 | public: 10 | 11 | // Default/length/array constructor 12 | Array1(int length = 0, long* data = 0); 13 | 14 | // Copy constructor 15 | Array1(const Array1 & source); 16 | 17 | // Destructor 18 | ~Array1(); 19 | 20 | // Assignment operator 21 | Array1 & operator=(const Array1 & source); 22 | 23 | // Equals operator 24 | bool operator==(const Array1 & other) const; 25 | 26 | // Length accessor 27 | int length() const; 28 | 29 | // Resize array 30 | void resize(int length, long* data = 0); 31 | 32 | // Set item accessor 33 | long & operator[](int i); 34 | 35 | // Get item accessor 36 | const long & operator[](int i) const; 37 | 38 | // String output 39 | std::string asString() const; 40 | 41 | // Get view 42 | void view(long** data, int* length) const; 43 | 44 | private: 45 | // Members 46 | bool _ownData; 47 | int _length; 48 | long * _buffer; 49 | 50 | // Methods 51 | void allocateMemory(); 52 | void deallocateMemory(); 53 | }; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/scalartypes.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_SCALARTYPES_H_ 2 | #define _NPY_SCALARTYPES_H_ 3 | 4 | /* Internal look-up tables */ 5 | extern NPY_NO_EXPORT unsigned char 6 | _npy_can_cast_safely_table[NPY_NTYPES][NPY_NTYPES]; 7 | extern NPY_NO_EXPORT signed char 8 | _npy_scalar_kinds_table[NPY_NTYPES]; 9 | extern NPY_NO_EXPORT signed char 10 | _npy_type_promotion_table[NPY_NTYPES][NPY_NTYPES]; 11 | extern NPY_NO_EXPORT signed char 12 | _npy_smallest_type_of_kind_table[NPY_NSCALARKINDS]; 13 | extern NPY_NO_EXPORT signed char 14 | _npy_next_larger_type_table[NPY_NTYPES]; 15 | 16 | NPY_NO_EXPORT void 17 | initialize_casting_tables(void); 18 | 19 | NPY_NO_EXPORT void 20 | initialize_numeric_types(void); 21 | 22 | #if PY_VERSION_HEX >= 0x03000000 23 | NPY_NO_EXPORT void 24 | gentype_struct_free(PyObject *ptr); 25 | #else 26 | NPY_NO_EXPORT void 27 | gentype_struct_free(void *ptr, void *arg); 28 | #endif 29 | 30 | NPY_NO_EXPORT int 31 | is_anyscalar_exact(PyObject *obj); 32 | 33 | NPY_NO_EXPORT int 34 | _typenum_fromtypeobj(PyObject *type, int user); 35 | 36 | NPY_NO_EXPORT void * 37 | scalar_value(PyObject *scalar, PyArray_Descr *descr); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /doc/source/reference/routines.polynomials.rst: -------------------------------------------------------------------------------- 1 | Polynomials 2 | *********** 3 | 4 | Polynomials in NumPy can be *created*, *manipulated*, and even *fitted* using 5 | the :doc:`routines.polynomials.classes` 6 | of the `numpy.polynomial` package, introduced in NumPy 1.4. 7 | 8 | Prior to NumPy 1.4, `numpy.poly1d` was the class of choice and it is still 9 | available in order to maintain backward compatibility. 10 | However, the newer Polynomial package is more complete than `numpy.poly1d` 11 | and its convenience classes are better behaved in the numpy environment. 12 | Therefore Polynomial is recommended for new coding. 13 | 14 | Transition notice 15 | ----------------- 16 | The various routines in the Polynomial package all deal with 17 | series whose coefficients go from degree zero upward, 18 | which is the *reverse order* of the Poly1d convention. 19 | The easy way to remember this is that indexes 20 | correspond to degree, i.e., coef[i] is the coefficient of the term of 21 | degree i. 22 | 23 | 24 | .. toctree:: 25 | :maxdepth: 2 26 | 27 | routines.polynomials.package 28 | 29 | .. toctree:: 30 | :maxdepth: 2 31 | 32 | routines.polynomials.poly1d 33 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/shape.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_ARRAY_SHAPE_H_ 2 | #define _NPY_ARRAY_SHAPE_H_ 3 | 4 | /* 5 | * Builds a string representation of the shape given in 'vals'. 6 | * A negative value in 'vals' gets interpreted as newaxis. 7 | */ 8 | NPY_NO_EXPORT PyObject * 9 | build_shape_string(npy_intp n, npy_intp *vals); 10 | 11 | /* 12 | * Creates a sorted stride perm matching the KEEPORDER behavior 13 | * of the NpyIter object. Because this operates based on multiple 14 | * input strides, the 'stride' member of the npy_stride_sort_item 15 | * would be useless and we simply argsort a list of indices instead. 16 | * 17 | * The caller should have already validated that 'ndim' matches for 18 | * every array in the arrays list. 19 | */ 20 | NPY_NO_EXPORT void 21 | PyArray_CreateMultiSortedStridePerm(int narrays, PyArrayObject **arrays, 22 | int ndim, int *out_strideperm); 23 | 24 | /* 25 | * Just like PyArray_Squeeze, but allows the caller to select 26 | * a subset of the size-one dimensions to squeeze out. 27 | */ 28 | NPY_NO_EXPORT PyObject * 29 | PyArray_SqueezeSelected(PyArrayObject *self, npy_bool *axis_flags); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /doc/release/1.7.1-notes.rst: -------------------------------------------------------------------------------- 1 | ========================= 2 | NumPy 1.7.1 Release Notes 3 | ========================= 4 | 5 | This is a bugfix only release in the 1.7.x series. 6 | It supports Python 2.4 - 2.7 and 3.1 - 3.3 and is the last series that 7 | supports Python 2.4 - 2.5. 8 | 9 | 10 | Issues fixed 11 | ============ 12 | 13 | * gh-2973: Fix `1` is printed during numpy.test() 14 | * gh-2983: BUG: gh-2969: Backport memory leak fix 80b3a34. 15 | * gh-3007: Backport gh-3006 16 | * gh-2984: Backport fix complex polynomial fit 17 | * gh-2982: BUG: Make nansum work with booleans. 18 | * gh-2985: Backport large sort fixes 19 | * gh-3039: Backport object take 20 | * gh-3105: Backport nditer fix op axes initialization 21 | * gh-3108: BUG: npy-pkg-config ini files were missing after Bento build. 22 | * gh-3124: BUG: PyArray_LexSort allocates too much temporary memory. 23 | * gh-3131: BUG: Exported f2py_size symbol prevents linking multiple f2py modules. 24 | * gh-3117: Backport gh-2992 25 | * gh-3135: DOC: Add mention of PyArray_SetBaseObject stealing a reference 26 | * gh-3134: DOC: Fix typo in fft docs (the indexing variable is 'm', not 'n'). 27 | * gh-3136: Backport #3128 28 | -------------------------------------------------------------------------------- /tools/swig/test/Farray.h: -------------------------------------------------------------------------------- 1 | #ifndef FARRAY_H 2 | #define FARRAY_H 3 | 4 | #include 5 | #include 6 | 7 | class Farray 8 | { 9 | public: 10 | 11 | // Size constructor 12 | Farray(int nrows, int ncols); 13 | 14 | // Copy constructor 15 | Farray(const Farray & source); 16 | 17 | // Destructor 18 | ~Farray(); 19 | 20 | // Assignment operator 21 | Farray & operator=(const Farray & source); 22 | 23 | // Equals operator 24 | bool operator==(const Farray & other) const; 25 | 26 | // Length accessors 27 | int nrows() const; 28 | int ncols() const; 29 | 30 | // Set item accessor 31 | long & operator()(int i, int j); 32 | 33 | // Get item accessor 34 | const long & operator()(int i, int j) const; 35 | 36 | // String output 37 | std::string asString() const; 38 | 39 | // Get view 40 | void view(int* nrows, int* ncols, long** data) const; 41 | 42 | private: 43 | // Members 44 | int _nrows; 45 | int _ncols; 46 | long * _buffer; 47 | 48 | // Default constructor: not implemented 49 | Farray(); 50 | 51 | // Methods 52 | void allocateMemory(); 53 | int offset(int i, int j) const; 54 | }; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /doc/source/dev/governance/people.rst: -------------------------------------------------------------------------------- 1 | .. _governance-people: 2 | 3 | Current steering council and institutional partners 4 | =================================================== 5 | 6 | Steering council 7 | ---------------- 8 | 9 | * Sebastian Berg 10 | 11 | * Jaime Fernández del Río 12 | 13 | * Ralf Gommers 14 | 15 | * Charles Harris 16 | 17 | * Nathaniel Smith 18 | 19 | * Julian Taylor 20 | 21 | * Pauli Virtanen 22 | 23 | * Eric Wieser 24 | 25 | * Marten van Kerkwijk 26 | 27 | * Stephan Hoyer 28 | 29 | * Allan Haldane 30 | 31 | 32 | Emeritus members 33 | ---------------- 34 | 35 | * Travis Oliphant - Project Founder / Emeritus Leader (served: 2005-2012) 36 | 37 | * Alex Griffing (served: 2015-2017) 38 | 39 | 40 | NumFOCUS Subcommittee 41 | --------------------- 42 | 43 | * Chuck Harris 44 | 45 | * Ralf Gommers 46 | 47 | * Jaime Fernández del Río 48 | 49 | * Nathaniel Smith 50 | 51 | * External member: Thomas Caswell 52 | 53 | 54 | Institutional Partners 55 | ---------------------- 56 | 57 | * UC Berkeley (Nathaniel Smith) 58 | 59 | 60 | Document history 61 | ---------------- 62 | 63 | https://github.com/numpy/numpy/commits/master/doc/source/dev/governance/governance.rst 64 | -------------------------------------------------------------------------------- /tools/npy_tempita/license.txt: -------------------------------------------------------------------------------- 1 | License 2 | ------- 3 | 4 | Copyright (c) 2008 Ian Bicking and Contributors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining 7 | a copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /numpy/core/src/multiarray/convert_datatype.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_ARRAY_CONVERT_DATATYPE_H_ 2 | #define _NPY_ARRAY_CONVERT_DATATYPE_H_ 3 | 4 | NPY_NO_EXPORT PyArray_VectorUnaryFunc * 5 | PyArray_GetCastFunc(PyArray_Descr *descr, int type_num); 6 | 7 | NPY_NO_EXPORT int 8 | PyArray_ObjectType(PyObject *op, int minimum_type); 9 | 10 | NPY_NO_EXPORT PyArrayObject ** 11 | PyArray_ConvertToCommonType(PyObject *op, int *retn); 12 | 13 | NPY_NO_EXPORT int 14 | PyArray_ValidType(int type); 15 | 16 | /* Like PyArray_CanCastArrayTo */ 17 | NPY_NO_EXPORT npy_bool 18 | can_cast_scalar_to(PyArray_Descr *scal_type, char *scal_data, 19 | PyArray_Descr *to, NPY_CASTING casting); 20 | 21 | /* 22 | * This function calls Py_DECREF on flex_dtype, and replaces it with 23 | * a new dtype that has been adapted based on the values in data_dtype 24 | * and data_obj. If the flex_dtype is not flexible, it leaves it as is. 25 | * 26 | * The current flexible dtypes include NPY_STRING, NPY_UNICODE, NPY_VOID, 27 | * and NPY_DATETIME with generic units. 28 | */ 29 | NPY_NO_EXPORT void 30 | PyArray_AdaptFlexibleDType(PyObject *data_obj, PyArray_Descr *data_dtype, 31 | PyArray_Descr **flex_dtype); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /numpy/f2py/tests/test_kind.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import os 4 | import pytest 5 | 6 | from numpy.testing import assert_ 7 | from numpy.f2py.crackfortran import ( 8 | _selected_int_kind_func as selected_int_kind, 9 | _selected_real_kind_func as selected_real_kind 10 | ) 11 | from . import util 12 | 13 | 14 | def _path(*a): 15 | return os.path.join(*((os.path.dirname(__file__),) + a)) 16 | 17 | 18 | class TestKind(util.F2PyTest): 19 | sources = [_path('src', 'kind', 'foo.f90')] 20 | 21 | @pytest.mark.slow 22 | def test_all(self): 23 | selectedrealkind = self.module.selectedrealkind 24 | selectedintkind = self.module.selectedintkind 25 | 26 | for i in range(40): 27 | assert_(selectedintkind(i) in [selected_int_kind(i), -1], 28 | 'selectedintkind(%s): expected %r but got %r' % 29 | (i, selected_int_kind(i), selectedintkind(i))) 30 | 31 | for i in range(20): 32 | assert_(selectedrealkind(i) in [selected_real_kind(i), -1], 33 | 'selectedrealkind(%s): expected %r but got %r' % 34 | (i, selected_real_kind(i), selectedrealkind(i))) 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NumPy 2 | 3 | [![Travis](https://img.shields.io/travis/numpy/numpy/master.svg?label=Travis%20CI)](https://travis-ci.org/numpy/numpy) 4 | [![AppVeyor](https://img.shields.io/appveyor/ci/charris/numpy/master.svg?label=AppVeyor)](https://ci.appveyor.com/project/charris/numpy) 5 | 6 | NumPy is the fundamental package needed for scientific computing with Python. 7 | 8 | - **Website (including documentation):** http://www.numpy.org 9 | - **Mailing list:** https://mail.python.org/mailman/listinfo/numpy-discussion 10 | - **Source:** https://github.com/numpy/numpy 11 | - **Bug reports:** https://github.com/numpy/numpy/issues 12 | 13 | It provides: 14 | 15 | - a powerful N-dimensional array object 16 | - sophisticated (broadcasting) functions 17 | - tools for integrating C/C++ and Fortran code 18 | - useful linear algebra, Fourier transform, and random number capabilities 19 | 20 | If ``nose`` is installed, tests can be run after installation with: 21 | 22 | python -c 'import numpy; numpy.test()' 23 | 24 | [![Powered by NumFOCUS](https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A)](https://numfocus.org) 25 | -------------------------------------------------------------------------------- /doc/release/1.12.1-notes.rst: -------------------------------------------------------------------------------- 1 | ========================== 2 | NumPy 1.12.1 Release Notes 3 | ========================== 4 | 5 | NumPy 1.12.1 supports Python 2.7 and 3.4 - 3.6 and fixes bugs and regressions 6 | found in NumPy 1.12.0. In particular, the regression in f2py constant parsing 7 | is fixed. Wheels for Linux, Windows, and OSX can be found on pypi, 8 | 9 | Bugs Fixed 10 | ========== 11 | 12 | * BUG: Fix wrong future nat warning and equiv type logic error... 13 | * BUG: Fix wrong masked median for some special cases 14 | * DOC: Place np.average in inline code 15 | * TST: Work around isfinite inconsistency on i386 16 | * BUG: Guard against replacing constants without '_' spec in f2py. 17 | * BUG: Fix mean for float 16 non-array inputs for 1.12 18 | * BUG: Fix calling python api with error set and minor leaks for... 19 | * BUG: Make iscomplexobj compatible with custom dtypes again 20 | * BUG: Fix undefined behaviour induced by bad __array_wrap__ 21 | * BUG: Fix MaskedArray.__setitem__ 22 | * BUG: PPC64el machines are POWER for Fortran in f2py 23 | * BUG: Look up methods on MaskedArray in `_frommethod` 24 | * BUG: Remove extra digit in binary_repr at limit 25 | * BUG: Fix deepcopy regression for empty arrays. 26 | * BUG: Fix ma.median for empty ndarrays 27 | -------------------------------------------------------------------------------- /tools/swig/test/ArrayZ.h: -------------------------------------------------------------------------------- 1 | #ifndef ARRAYZ_H 2 | #define ARRAYZ_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class ArrayZ 9 | { 10 | public: 11 | 12 | // Default/length/array constructor 13 | ArrayZ(int length = 0, std::complex* data = 0); 14 | 15 | // Copy constructor 16 | ArrayZ(const ArrayZ & source); 17 | 18 | // Destructor 19 | ~ArrayZ(); 20 | 21 | // Assignment operator 22 | ArrayZ & operator=(const ArrayZ & source); 23 | 24 | // Equals operator 25 | bool operator==(const ArrayZ & other) const; 26 | 27 | // Length accessor 28 | int length() const; 29 | 30 | // Resize array 31 | void resize(int length, std::complex* data = 0); 32 | 33 | // Set item accessor 34 | std::complex & operator[](int i); 35 | 36 | // Get item accessor 37 | const std::complex & operator[](int i) const; 38 | 39 | // String output 40 | std::string asString() const; 41 | 42 | // Get view 43 | void view(std::complex** data, int* length) const; 44 | 45 | private: 46 | // Members 47 | bool _ownData; 48 | int _length; 49 | std::complex * _buffer; 50 | 51 | // Methods 52 | void allocateMemory(); 53 | void deallocateMemory(); 54 | }; 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /numpy/polynomial/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | A sub-package for efficiently dealing with polynomials. 3 | 4 | Within the documentation for this sub-package, a "finite power series," 5 | i.e., a polynomial (also referred to simply as a "series") is represented 6 | by a 1-D numpy array of the polynomial's coefficients, ordered from lowest 7 | order term to highest. For example, array([1,2,3]) represents 8 | ``P_0 + 2*P_1 + 3*P_2``, where P_n is the n-th order basis polynomial 9 | applicable to the specific module in question, e.g., `polynomial` (which 10 | "wraps" the "standard" basis) or `chebyshev`. For optimal performance, 11 | all operations on polynomials, including evaluation at an argument, are 12 | implemented as operations on the coefficients. Additional (module-specific) 13 | information can be found in the docstring for the module of interest. 14 | 15 | """ 16 | from __future__ import division, absolute_import, print_function 17 | 18 | from .polynomial import Polynomial 19 | from .chebyshev import Chebyshev 20 | from .legendre import Legendre 21 | from .hermite import Hermite 22 | from .hermite_e import HermiteE 23 | from .laguerre import Laguerre 24 | 25 | from numpy.testing._private.pytesttester import PytestTester 26 | test = PytestTester(__name__) 27 | del PytestTester 28 | -------------------------------------------------------------------------------- /numpy/distutils/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import sys 4 | 5 | from .__version__ import version as __version__ 6 | # Must import local ccompiler ASAP in order to get 7 | # customized CCompiler.spawn effective. 8 | from . import ccompiler 9 | from . import unixccompiler 10 | 11 | from .info import __doc__ 12 | from .npy_pkg_config import * 13 | 14 | # If numpy is installed, add distutils.test() 15 | try: 16 | from . import __config__ 17 | # Normally numpy is installed if the above import works, but an interrupted 18 | # in-place build could also have left a __config__.py. In that case the 19 | # next import may still fail, so keep it inside the try block. 20 | from numpy.testing._private.pytesttester import PytestTester 21 | test = PytestTester(__name__) 22 | del PytestTester 23 | except ImportError: 24 | pass 25 | 26 | 27 | def customized_fcompiler(plat=None, compiler=None): 28 | from numpy.distutils.fcompiler import new_fcompiler 29 | c = new_fcompiler(plat=plat, compiler=compiler) 30 | c.customize() 31 | return c 32 | 33 | def customized_ccompiler(plat=None, compiler=None): 34 | c = ccompiler.new_compiler(plat=plat, compiler=compiler) 35 | c.customize('') 36 | return c 37 | -------------------------------------------------------------------------------- /doc/source/dev/gitwash/git_intro.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Introduction 3 | ============ 4 | 5 | These pages describe a git_ and github_ workflow for the NumPy_ 6 | project. 7 | 8 | There are several different workflows here, for different ways of 9 | working with *NumPy*. 10 | 11 | This is not a comprehensive git_ reference, it's just a workflow for our 12 | own project. It's tailored to the github_ hosting service. You may well 13 | find better or quicker ways of getting stuff done with git_, but these 14 | should get you started. 15 | 16 | For general resources for learning git_ see :ref:`git-resources`. 17 | 18 | .. _install-git: 19 | 20 | Install git 21 | =========== 22 | 23 | Overview 24 | -------- 25 | 26 | ================ ============= 27 | Debian / Ubuntu ``sudo apt-get install git-core`` 28 | Fedora ``sudo yum install git-core`` 29 | Windows Download and install msysGit_ 30 | OS X Use the git-osx-installer_ 31 | ================ ============= 32 | 33 | In detail 34 | --------- 35 | 36 | See the git_ page for the most recent information. 37 | 38 | Have a look at the github_ install help pages available from `github help`_ 39 | 40 | There are good instructions here: http://book.git-scm.com/2_installing_git.html 41 | 42 | .. include:: git_links.inc 43 | -------------------------------------------------------------------------------- /doc/source/reference/routines.rst: -------------------------------------------------------------------------------- 1 | .. _routines: 2 | 3 | ******** 4 | Routines 5 | ******** 6 | 7 | In this chapter routine docstrings are presented, grouped by functionality. 8 | Many docstrings contain example code, which demonstrates basic usage 9 | of the routine. The examples assume that NumPy is imported with:: 10 | 11 | >>> import numpy as np 12 | 13 | A convenient way to execute examples is the ``%doctest_mode`` mode of 14 | IPython, which allows for pasting of multi-line examples and preserves 15 | indentation. 16 | 17 | .. toctree:: 18 | :maxdepth: 2 19 | 20 | routines.array-creation 21 | routines.array-manipulation 22 | routines.bitwise 23 | routines.char 24 | routines.ctypeslib 25 | routines.datetime 26 | routines.dtype 27 | routines.dual 28 | routines.emath 29 | routines.err 30 | routines.fft 31 | routines.financial 32 | routines.functional 33 | routines.help 34 | routines.indexing 35 | routines.io 36 | routines.linalg 37 | routines.logic 38 | routines.ma 39 | routines.math 40 | routines.matlib 41 | routines.other 42 | routines.padding 43 | routines.polynomials 44 | routines.random 45 | routines.set 46 | routines.sort 47 | routines.statistics 48 | routines.testing 49 | routines.window 50 | -------------------------------------------------------------------------------- /numpy/core/tests/test_machar.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test machar. Given recent changes to hardcode type data, we might want to get 3 | rid of both MachAr and this test at some point. 4 | 5 | """ 6 | from __future__ import division, absolute_import, print_function 7 | 8 | from numpy.core.machar import MachAr 9 | import numpy.core.numerictypes as ntypes 10 | from numpy import errstate, array 11 | 12 | 13 | class TestMachAr(object): 14 | def _run_machar_highprec(self): 15 | # Instantiate MachAr instance with high enough precision to cause 16 | # underflow 17 | try: 18 | hiprec = ntypes.float96 19 | MachAr(lambda v:array([v], hiprec)) 20 | except AttributeError: 21 | # Fixme, this needs to raise a 'skip' exception. 22 | "Skipping test: no ntypes.float96 available on this platform." 23 | 24 | def test_underlow(self): 25 | # Regression test for #759: 26 | # instantiating MachAr for dtype = np.float96 raises spurious warning. 27 | with errstate(all='raise'): 28 | try: 29 | self._run_machar_highprec() 30 | except FloatingPointError as e: 31 | msg = "Caught %s exception, should not have been raised." % e 32 | raise AssertionError(msg) 33 | -------------------------------------------------------------------------------- /numpy/distutils/fcompiler/pathf95.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | from numpy.distutils.fcompiler import FCompiler 4 | 5 | compilers = ['PathScaleFCompiler'] 6 | 7 | class PathScaleFCompiler(FCompiler): 8 | 9 | compiler_type = 'pathf95' 10 | description = 'PathScale Fortran Compiler' 11 | version_pattern = r'PathScale\(TM\) Compiler Suite: Version (?P[\d.]+)' 12 | 13 | executables = { 14 | 'version_cmd' : ["pathf95", "-version"], 15 | 'compiler_f77' : ["pathf95", "-fixedform"], 16 | 'compiler_fix' : ["pathf95", "-fixedform"], 17 | 'compiler_f90' : ["pathf95"], 18 | 'linker_so' : ["pathf95", "-shared"], 19 | 'archiver' : ["ar", "-cr"], 20 | 'ranlib' : ["ranlib"] 21 | } 22 | pic_flags = ['-fPIC'] 23 | module_dir_switch = '-module ' # Don't remove ending space! 24 | module_include_switch = '-I' 25 | 26 | def get_flags_opt(self): 27 | return ['-O3'] 28 | def get_flags_debug(self): 29 | return ['-g'] 30 | 31 | if __name__ == '__main__': 32 | from distutils import log 33 | log.set_verbosity(2) 34 | from numpy.distutils import customized_fcompiler 35 | print(customized_fcompiler(compiler='pathf95').get_version()) 36 | -------------------------------------------------------------------------------- /numpy/distutils/tests/test_fcompiler_nagfor.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | from numpy.testing import assert_ 4 | import numpy.distutils.fcompiler 5 | 6 | nag_version_strings = [('nagfor', 'NAG Fortran Compiler Release ' 7 | '6.2(Chiyoda) Build 6200', '6.2'), 8 | ('nagfor', 'NAG Fortran Compiler Release ' 9 | '6.1(Tozai) Build 6136', '6.1'), 10 | ('nagfor', 'NAG Fortran Compiler Release ' 11 | '6.0(Hibiya) Build 1021', '6.0'), 12 | ('nagfor', 'NAG Fortran Compiler Release ' 13 | '5.3.2(971)', '5.3.2'), 14 | ('nag', 'NAGWare Fortran 95 compiler Release 5.1' 15 | '(347,355-367,375,380-383,389,394,399,401-402,407,' 16 | '431,435,437,446,459-460,463,472,494,496,503,508,' 17 | '511,517,529,555,557,565)', '5.1')] 18 | 19 | class TestNagFCompilerVersions(object): 20 | def test_version_match(self): 21 | for comp, vs, version in nag_version_strings: 22 | fc = numpy.distutils.fcompiler.new_fcompiler(compiler=comp) 23 | v = fc.version_match(vs) 24 | assert_(v == version) 25 | -------------------------------------------------------------------------------- /numpy/distutils/tests/test_fcompiler_intel.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import numpy.distutils.fcompiler 4 | from numpy.testing import assert_ 5 | 6 | 7 | intel_32bit_version_strings = [ 8 | ("Intel(R) Fortran Intel(R) 32-bit Compiler Professional for applications" 9 | "running on Intel(R) 32, Version 11.1", '11.1'), 10 | ] 11 | 12 | intel_64bit_version_strings = [ 13 | ("Intel(R) Fortran IA-64 Compiler Professional for applications" 14 | "running on IA-64, Version 11.0", '11.0'), 15 | ("Intel(R) Fortran Intel(R) 64 Compiler Professional for applications" 16 | "running on Intel(R) 64, Version 11.1", '11.1') 17 | ] 18 | 19 | class TestIntelFCompilerVersions(object): 20 | def test_32bit_version(self): 21 | fc = numpy.distutils.fcompiler.new_fcompiler(compiler='intel') 22 | for vs, version in intel_32bit_version_strings: 23 | v = fc.version_match(vs) 24 | assert_(v == version) 25 | 26 | 27 | class TestIntelEM64TFCompilerVersions(object): 28 | def test_64bit_version(self): 29 | fc = numpy.distutils.fcompiler.new_fcompiler(compiler='intelem') 30 | for vs, version in intel_64bit_version_strings: 31 | v = fc.version_match(vs) 32 | assert_(v == version) 33 | -------------------------------------------------------------------------------- /numpy/distutils/command/__init__.py: -------------------------------------------------------------------------------- 1 | """distutils.command 2 | 3 | Package containing implementation of all the standard Distutils 4 | commands. 5 | 6 | """ 7 | from __future__ import division, absolute_import, print_function 8 | 9 | def test_na_writable_attributes_deletion(): 10 | a = np.NA(2) 11 | attr = ['payload', 'dtype'] 12 | for s in attr: 13 | assert_raises(AttributeError, delattr, a, s) 14 | 15 | 16 | __revision__ = "$Id: __init__.py,v 1.3 2005/05/16 11:08:49 pearu Exp $" 17 | 18 | distutils_all = [ #'build_py', 19 | 'clean', 20 | 'install_clib', 21 | 'install_scripts', 22 | 'bdist', 23 | 'bdist_dumb', 24 | 'bdist_wininst', 25 | ] 26 | 27 | __import__('distutils.command', globals(), locals(), distutils_all) 28 | 29 | __all__ = ['build', 30 | 'config_compiler', 31 | 'config', 32 | 'build_src', 33 | 'build_py', 34 | 'build_ext', 35 | 'build_clib', 36 | 'build_scripts', 37 | 'install', 38 | 'install_data', 39 | 'install_headers', 40 | 'install_lib', 41 | 'bdist_rpm', 42 | 'sdist', 43 | ] + distutils_all 44 | -------------------------------------------------------------------------------- /doc/source/dev/gitwash/following_latest.rst: -------------------------------------------------------------------------------- 1 | .. _following-latest: 2 | 3 | ============================= 4 | Following the latest source 5 | ============================= 6 | 7 | These are the instructions if you just want to follow the latest 8 | *NumPy* source, but you don't need to do any development for now. 9 | If you do want to contribute a patch (excellent!) or do more extensive 10 | NumPy development, see :ref:`development-workflow`. 11 | 12 | The steps are: 13 | 14 | * :ref:`install-git` 15 | * get local copy of the git repository from Github_ 16 | * update local copy from time to time 17 | 18 | Get the local copy of the code 19 | ============================== 20 | 21 | From the command line:: 22 | 23 | git clone git://github.com/numpy/numpy.git 24 | 25 | You now have a copy of the code tree in the new ``numpy`` directory. 26 | If this doesn't work you can try the alternative read-only url:: 27 | 28 | git clone https://github.com/numpy/numpy.git 29 | 30 | Updating the code 31 | ================= 32 | 33 | From time to time you may want to pull down the latest code. Do this with:: 34 | 35 | cd numpy 36 | git fetch 37 | git merge --ff-only 38 | 39 | The tree in ``numpy`` will now have the latest changes from the initial 40 | repository. 41 | 42 | .. _Github: https://github.com/numpy 43 | -------------------------------------------------------------------------------- /numpy/distutils/tests/test_from_template.py: -------------------------------------------------------------------------------- 1 | 2 | from numpy.distutils.from_template import process_str 3 | from numpy.testing import assert_equal 4 | 5 | 6 | pyf_src = """ 7 | python module foo 8 | <_rd=real,double precision> 9 | interface 10 | subroutine foosub(tol) 11 | <_rd>, intent(in,out) :: tol 12 | end subroutine foosub 13 | end interface 14 | end python module foo 15 | """ 16 | 17 | expected_pyf = """ 18 | python module foo 19 | interface 20 | subroutine sfoosub(tol) 21 | real, intent(in,out) :: tol 22 | end subroutine sfoosub 23 | subroutine dfoosub(tol) 24 | double precision, intent(in,out) :: tol 25 | end subroutine dfoosub 26 | end interface 27 | end python module foo 28 | """ 29 | 30 | 31 | def normalize_whitespace(s): 32 | """ 33 | Remove leading and trailing whitespace, and convert internal 34 | stretches of whitespace to a single space. 35 | """ 36 | return ' '.join(s.split()) 37 | 38 | 39 | def test_from_template(): 40 | """Regression test for gh-10712.""" 41 | pyf = process_str(pyf_src) 42 | normalized_pyf = normalize_whitespace(pyf) 43 | normalized_expected_pyf = normalize_whitespace(expected_pyf) 44 | assert_equal(normalized_pyf, normalized_expected_pyf) 45 | -------------------------------------------------------------------------------- /numpy/tests/test_reloading.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | import sys 4 | import pickle 5 | 6 | from numpy.testing import assert_raises, assert_, assert_equal 7 | 8 | if sys.version_info[:2] >= (3, 4): 9 | from importlib import reload 10 | else: 11 | from imp import reload 12 | 13 | def test_numpy_reloading(): 14 | # gh-7844. Also check that relevant globals retain their identity. 15 | import numpy as np 16 | import numpy._globals 17 | 18 | _NoValue = np._NoValue 19 | VisibleDeprecationWarning = np.VisibleDeprecationWarning 20 | ModuleDeprecationWarning = np.ModuleDeprecationWarning 21 | 22 | reload(np) 23 | assert_(_NoValue is np._NoValue) 24 | assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) 25 | assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning) 26 | 27 | assert_raises(RuntimeError, reload, numpy._globals) 28 | reload(np) 29 | assert_(_NoValue is np._NoValue) 30 | assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) 31 | assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning) 32 | 33 | def test_novalue(): 34 | import numpy as np 35 | assert_equal(repr(np._NoValue), '') 36 | assert_(pickle.loads(pickle.dumps(np._NoValue)) is np._NoValue) 37 | -------------------------------------------------------------------------------- /doc/source/reference/routines.indexing.rst: -------------------------------------------------------------------------------- 1 | .. _routines.indexing: 2 | 3 | Indexing routines 4 | ================= 5 | 6 | .. seealso:: :ref:`Indexing ` 7 | 8 | .. currentmodule:: numpy 9 | 10 | Generating index arrays 11 | ----------------------- 12 | .. autosummary:: 13 | :toctree: generated/ 14 | 15 | c_ 16 | r_ 17 | s_ 18 | nonzero 19 | where 20 | indices 21 | ix_ 22 | ogrid 23 | ravel_multi_index 24 | unravel_index 25 | diag_indices 26 | diag_indices_from 27 | mask_indices 28 | tril_indices 29 | tril_indices_from 30 | triu_indices 31 | triu_indices_from 32 | 33 | Indexing-like operations 34 | ------------------------ 35 | .. autosummary:: 36 | :toctree: generated/ 37 | 38 | take 39 | take_along_axis 40 | choose 41 | compress 42 | diag 43 | diagonal 44 | select 45 | lib.stride_tricks.as_strided 46 | 47 | Inserting data into arrays 48 | -------------------------- 49 | .. autosummary:: 50 | :toctree: generated/ 51 | 52 | place 53 | put 54 | put_along_axis 55 | putmask 56 | fill_diagonal 57 | 58 | Iterating over arrays 59 | --------------------- 60 | .. autosummary:: 61 | :toctree: generated/ 62 | 63 | nditer 64 | ndenumerate 65 | ndindex 66 | nested_iters 67 | flatiter 68 | lib.Arrayterator 69 | -------------------------------------------------------------------------------- /tools/swig/test/Array2.h: -------------------------------------------------------------------------------- 1 | #ifndef ARRAY2_H 2 | #define ARRAY2_H 3 | 4 | #include "Array1.h" 5 | #include 6 | #include 7 | 8 | class Array2 9 | { 10 | public: 11 | 12 | // Default constructor 13 | Array2(); 14 | 15 | // Size/array constructor 16 | Array2(int nrows, int ncols, long* data=0); 17 | 18 | // Copy constructor 19 | Array2(const Array2 & source); 20 | 21 | // Destructor 22 | ~Array2(); 23 | 24 | // Assignment operator 25 | Array2 & operator=(const Array2 & source); 26 | 27 | // Equals operator 28 | bool operator==(const Array2 & other) const; 29 | 30 | // Length accessors 31 | int nrows() const; 32 | int ncols() const; 33 | 34 | // Resize array 35 | void resize(int nrows, int ncols, long* data=0); 36 | 37 | // Set item accessor 38 | Array1 & operator[](int i); 39 | 40 | // Get item accessor 41 | const Array1 & operator[](int i) const; 42 | 43 | // String output 44 | std::string asString() const; 45 | 46 | // Get view 47 | void view(int* nrows, int* ncols, long** data) const; 48 | 49 | private: 50 | // Members 51 | bool _ownData; 52 | int _nrows; 53 | int _ncols; 54 | long * _buffer; 55 | Array1 * _rows; 56 | 57 | // Methods 58 | void allocateMemory(); 59 | void allocateRows(); 60 | void deallocateMemory(); 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /numpy/testing/utils.py: -------------------------------------------------------------------------------- 1 | """ 2 | Back compatibility utils module. It will import the appropriate 3 | set of tools 4 | 5 | """ 6 | from __future__ import division, absolute_import, print_function 7 | 8 | import warnings 9 | 10 | # 2018-04-04, numpy 1.15.0 11 | warnings.warn("Importing from numpy.testing.utils is deprecated, " 12 | "import from numpy.testing instead.", 13 | ImportWarning, stacklevel=2) 14 | 15 | from ._private.utils import * 16 | 17 | __all__ = [ 18 | 'assert_equal', 'assert_almost_equal', 'assert_approx_equal', 19 | 'assert_array_equal', 'assert_array_less', 'assert_string_equal', 20 | 'assert_array_almost_equal', 'assert_raises', 'build_err_msg', 21 | 'decorate_methods', 'jiffies', 'memusage', 'print_assert_equal', 22 | 'raises', 'rand', 'rundocs', 'runstring', 'verbose', 'measure', 23 | 'assert_', 'assert_array_almost_equal_nulp', 'assert_raises_regex', 24 | 'assert_array_max_ulp', 'assert_warns', 'assert_no_warnings', 25 | 'assert_allclose', 'IgnoreException', 'clear_and_catch_warnings', 26 | 'SkipTest', 'KnownFailureException', 'temppath', 'tempdir', 'IS_PYPY', 27 | 'HAS_REFCOUNT', 'suppress_warnings', 'assert_array_compare', 28 | '_assert_valid_refcount', '_gen_alignment_data', 'assert_no_gc_cycles' 29 | ] 30 | -------------------------------------------------------------------------------- /numpy/random/mtrand/Python.pxi: -------------------------------------------------------------------------------- 1 | # :Author: Robert Kern 2 | # :Copyright: 2004, Enthought, Inc. 3 | # :License: BSD Style 4 | 5 | 6 | cdef extern from "Python.h": 7 | # Not part of the Python API, but we might as well define it here. 8 | # Note that the exact type doesn't actually matter for Pyrex. 9 | ctypedef int size_t 10 | 11 | # String API 12 | char* PyString_AsString(object string) 13 | char* PyString_AS_STRING(object string) 14 | object PyString_FromString(char* c_string) 15 | object PyString_FromStringAndSize(char* c_string, int length) 16 | 17 | # Float API 18 | double PyFloat_AsDouble(object ob) except? -1.0 19 | long PyInt_AsLong(object ob) except? -1 20 | 21 | # Memory API 22 | void* PyMem_Malloc(size_t n) 23 | void* PyMem_Realloc(void* buf, size_t n) 24 | void PyMem_Free(void* buf) 25 | 26 | void Py_DECREF(object obj) 27 | void Py_XDECREF(object obj) 28 | void Py_INCREF(object obj) 29 | void Py_XINCREF(object obj) 30 | 31 | # TypeCheck API 32 | int PyFloat_Check(object obj) 33 | int PyInt_Check(object obj) 34 | 35 | # Error API 36 | int PyErr_Occurred() 37 | void PyErr_Clear() 38 | 39 | cdef extern from "string.h": 40 | void *memcpy(void *s1, void *s2, int n) 41 | 42 | cdef extern from "math.h": 43 | double fabs(double x) 44 | -------------------------------------------------------------------------------- /tools/npy_tempita/compat3.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import, division, print_function 2 | 3 | import sys 4 | 5 | __all__ = ['PY3', 'b', 'basestring_', 'bytes', 'next', 'is_unicode', 6 | 'iteritems'] 7 | 8 | PY3 = True if sys.version_info[0] == 3 else False 9 | 10 | if sys.version_info[0] < 3: 11 | 12 | def next(obj): 13 | return obj.next() 14 | 15 | def iteritems(d, **kw): 16 | return d.iteritems(**kw) 17 | 18 | b = bytes = str 19 | basestring_ = basestring 20 | 21 | else: 22 | 23 | def b(s): 24 | if isinstance(s, str): 25 | return s.encode('latin1') 26 | return bytes(s) 27 | 28 | def iteritems(d, **kw): 29 | return iter(d.items(**kw)) 30 | 31 | next = next 32 | basestring_ = (bytes, str) 33 | bytes = bytes 34 | 35 | text = str 36 | 37 | 38 | def is_unicode(obj): 39 | if sys.version_info[0] < 3: 40 | return isinstance(obj, unicode) 41 | else: 42 | return isinstance(obj, str) 43 | 44 | 45 | def coerce_text(v): 46 | if not isinstance(v, basestring_): 47 | if sys.version_info[0] < 3: 48 | attr = '__unicode__' 49 | else: 50 | attr = '__str__' 51 | if hasattr(v, attr): 52 | return unicode(v) 53 | else: 54 | return bytes(v) 55 | return v 56 | -------------------------------------------------------------------------------- /numpy/linalg/info.py: -------------------------------------------------------------------------------- 1 | """\ 2 | Core Linear Algebra Tools 3 | ------------------------- 4 | Linear algebra basics: 5 | 6 | - norm Vector or matrix norm 7 | - inv Inverse of a square matrix 8 | - solve Solve a linear system of equations 9 | - det Determinant of a square matrix 10 | - lstsq Solve linear least-squares problem 11 | - pinv Pseudo-inverse (Moore-Penrose) calculated using a singular 12 | value decomposition 13 | - matrix_power Integer power of a square matrix 14 | 15 | Eigenvalues and decompositions: 16 | 17 | - eig Eigenvalues and vectors of a square matrix 18 | - eigh Eigenvalues and eigenvectors of a Hermitian matrix 19 | - eigvals Eigenvalues of a square matrix 20 | - eigvalsh Eigenvalues of a Hermitian matrix 21 | - qr QR decomposition of a matrix 22 | - svd Singular value decomposition of a matrix 23 | - cholesky Cholesky decomposition of a matrix 24 | 25 | Tensor operations: 26 | 27 | - tensorsolve Solve a linear tensor equation 28 | - tensorinv Calculate an inverse of a tensor 29 | 30 | Exceptions: 31 | 32 | - LinAlgError Indicates a failed linear algebra operation 33 | 34 | """ 35 | from __future__ import division, absolute_import, print_function 36 | 37 | depends = ['core'] 38 | -------------------------------------------------------------------------------- /numpy/distutils/command/build_py.py: -------------------------------------------------------------------------------- 1 | from __future__ import division, absolute_import, print_function 2 | 3 | from distutils.command.build_py import build_py as old_build_py 4 | from numpy.distutils.misc_util import is_string 5 | 6 | class build_py(old_build_py): 7 | 8 | def run(self): 9 | build_src = self.get_finalized_command('build_src') 10 | if build_src.py_modules_dict and self.packages is None: 11 | self.packages = list(build_src.py_modules_dict.keys ()) 12 | old_build_py.run(self) 13 | 14 | def find_package_modules(self, package, package_dir): 15 | modules = old_build_py.find_package_modules(self, package, package_dir) 16 | 17 | # Find build_src generated *.py files. 18 | build_src = self.get_finalized_command('build_src') 19 | modules += build_src.py_modules_dict.get(package, []) 20 | 21 | return modules 22 | 23 | def find_modules(self): 24 | old_py_modules = self.py_modules[:] 25 | new_py_modules = [_m for _m in self.py_modules if is_string(_m)] 26 | self.py_modules[:] = new_py_modules 27 | modules = old_build_py.find_modules(self) 28 | self.py_modules[:] = old_py_modules 29 | 30 | return modules 31 | 32 | # XXX: Fix find_source_files for item in py_modules such that item is 3-tuple 33 | # and item[2] is source file. 34 | -------------------------------------------------------------------------------- /doc/source/f2py/advanced.rst: -------------------------------------------------------------------------------- 1 | ====================== 2 | Advanced F2PY usages 3 | ====================== 4 | 5 | Adding self-written functions to F2PY generated modules 6 | ======================================================= 7 | 8 | Self-written Python C/API functions can be defined inside 9 | signature files using ``usercode`` and ``pymethoddef`` statements 10 | (they must be used inside the ``python module`` block). For 11 | example, the following signature file ``spam.pyf`` 12 | 13 | .. include:: spam.pyf 14 | :literal: 15 | 16 | wraps the C library function ``system()``:: 17 | 18 | f2py -c spam.pyf 19 | 20 | In Python: 21 | 22 | .. include:: spam_session.dat 23 | :literal: 24 | 25 | Modifying the dictionary of a F2PY generated module 26 | =================================================== 27 | 28 | The following example illustrates how to add a user-defined 29 | variables to a F2PY generated extension module. Given the following 30 | signature file 31 | 32 | .. include:: var.pyf 33 | :literal: 34 | 35 | compile it as ``f2py -c var.pyf``. 36 | 37 | Notice that the second ``usercode`` statement must be defined inside 38 | an ``interface`` block and where the module dictionary is available through 39 | the variable ``d`` (see ``f2py var.pyf``-generated ``varmodule.c`` for 40 | additional details). 41 | 42 | In Python: 43 | 44 | .. include:: var_session.dat 45 | :literal: 46 | -------------------------------------------------------------------------------- /doc/changelog/1.14.3-changelog.rst: -------------------------------------------------------------------------------- 1 | 2 | Contributors 3 | ============ 4 | 5 | A total of 6 people contributed to this release. People with a "+" by their 6 | names contributed a patch for the first time. 7 | 8 | * Allan Haldane 9 | * Charles Harris 10 | * Jonathan March + 11 | * Malcolm Smith + 12 | * Matti Picus 13 | * Pauli Virtanen 14 | 15 | Pull requests merged 16 | ==================== 17 | 18 | A total of 8 pull requests were merged for this release. 19 | 20 | * `#10862 `__: BUG: floating types should override tp_print (1.14 backport) 21 | * `#10905 `__: BUG: for 1.14 back-compat, accept list-of-lists in fromrecords 22 | * `#10947 `__: BUG: 'style' arg to array2string broken in legacy mode (1.14... 23 | * `#10959 `__: BUG: test, fix for missing flags['WRITEBACKIFCOPY'] key 24 | * `#10960 `__: BUG: Add missing underscore to prototype in check_embedded_lapack 25 | * `#10961 `__: BUG: Fix encoding regression in ma/bench.py (Issue #10868) 26 | * `#10962 `__: BUG: core: fix NPY_TITLE_KEY macro on pypy 27 | * `#10974 `__: BUG: test, fix PyArray_DiscardWritebackIfCopy... 28 | -------------------------------------------------------------------------------- /numpy/core/include/numpy/numpyconfig.h: -------------------------------------------------------------------------------- 1 | #ifndef _NPY_NUMPYCONFIG_H_ 2 | #define _NPY_NUMPYCONFIG_H_ 3 | 4 | #include "_numpyconfig.h" 5 | 6 | /* 7 | * On Mac OS X, because there is only one configuration stage for all the archs 8 | * in universal builds, any macro which depends on the arch needs to be 9 | * hardcoded 10 | */ 11 | #ifdef __APPLE__ 12 | #undef NPY_SIZEOF_LONG 13 | #undef NPY_SIZEOF_PY_INTPTR_T 14 | 15 | #ifdef __LP64__ 16 | #define NPY_SIZEOF_LONG 8 17 | #define NPY_SIZEOF_PY_INTPTR_T 8 18 | #else 19 | #define NPY_SIZEOF_LONG 4 20 | #define NPY_SIZEOF_PY_INTPTR_T 4 21 | #endif 22 | #endif 23 | 24 | /** 25 | * To help with the NPY_NO_DEPRECATED_API macro, we include API version 26 | * numbers for specific versions of NumPy. To exclude all API that was 27 | * deprecated as of 1.7, add the following before #including any NumPy 28 | * headers: 29 | * #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION 30 | */ 31 | #define NPY_1_7_API_VERSION 0x00000007 32 | #define NPY_1_8_API_VERSION 0x00000008 33 | #define NPY_1_9_API_VERSION 0x00000008 34 | #define NPY_1_10_API_VERSION 0x00000008 35 | #define NPY_1_11_API_VERSION 0x00000008 36 | #define NPY_1_12_API_VERSION 0x00000008 37 | #define NPY_1_13_API_VERSION 0x00000008 38 | #define NPY_1_14_API_VERSION 0x00000008 39 | #define NPY_1_15_API_VERSION 0x00000008 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /tools/swig/test/Flat.h: -------------------------------------------------------------------------------- 1 | #ifndef FLAT_H 2 | #define FLAT_H 3 | 4 | // The following macro defines the prototypes for a family of 5 | // functions that work with arrays with the forms 6 | // 7 | // void SNAMEProcess(TYPE * array, int size); 8 | // 9 | // for any specified type TYPE (for example: short, unsigned int, long 10 | // long, etc.) with given short name SNAME (for example: short, uint, 11 | // longLong, etc.). The macro is then expanded for the given 12 | // TYPE/SNAME pairs. The resulting functions are for testing numpy 13 | // interfaces for: 14 | // 15 | // * in-place arrays (arbitrary number of dimensions) with a fixed number of elements 16 | // 17 | #define TEST_FUNC_PROTOS(TYPE, SNAME) \ 18 | \ 19 | void SNAME ## Process(TYPE * array, int size); \ 20 | 21 | TEST_FUNC_PROTOS(signed char , schar ) 22 | TEST_FUNC_PROTOS(unsigned char , uchar ) 23 | TEST_FUNC_PROTOS(short , short ) 24 | TEST_FUNC_PROTOS(unsigned short , ushort ) 25 | TEST_FUNC_PROTOS(int , int ) 26 | TEST_FUNC_PROTOS(unsigned int , uint ) 27 | TEST_FUNC_PROTOS(long , long ) 28 | TEST_FUNC_PROTOS(unsigned long , ulong ) 29 | TEST_FUNC_PROTOS(long long , longLong ) 30 | TEST_FUNC_PROTOS(unsigned long long, ulongLong) 31 | TEST_FUNC_PROTOS(float , float ) 32 | TEST_FUNC_PROTOS(double , double ) 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /tools/swig/test/Flat.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "Flat.h" 5 | 6 | // The following macro defines a family of functions that work with 1D 7 | // arrays with the forms 8 | // 9 | // void SNAMEProcess(TYPE * array, int size); 10 | // 11 | // for any specified type TYPE (for example: short, unsigned int, long 12 | // long, etc.) with given short name SNAME (for example: short, uint, 13 | // longLong, etc.). The macro is then expanded for the given 14 | // TYPE/SNAME pairs. The resulting functions are for testing numpy 15 | // interfaces for: 16 | // 17 | // * in-place arrays (arbitrary number of dimensions) with a fixed number of elements 18 | // 19 | #define TEST_FUNCS(TYPE, SNAME) \ 20 | \ 21 | void SNAME ## Process(TYPE * array, int size) { \ 22 | for (int i=0; i