diff options
25 files changed, 239 insertions, 85 deletions
diff --git a/doc/HOWTO_DOCUMENT.rst.txt b/doc/HOWTO_DOCUMENT.rst.txt index e815e1d68..813626ea0 100644 --- a/doc/HOWTO_DOCUMENT.rst.txt +++ b/doc/HOWTO_DOCUMENT.rst.txt @@ -322,7 +322,7 @@ The sections of the docstring are: See Also -------- func_a : Function a with its description. - func_b, func_c_, func_d + func_b, func_c, func_d func_e 10. **Notes** diff --git a/doc/changelog/1.14.2-changelog.rst b/doc/changelog/1.14.2-changelog.rst new file mode 100644 index 000000000..fae815c8e --- /dev/null +++ b/doc/changelog/1.14.2-changelog.rst @@ -0,0 +1,22 @@ + +Contributors +============ + +A total of 4 people contributed to this release. People with a "+" by their +names contributed a patch for the first time. + +* Allan Haldane +* Charles Harris +* Eric Wieser +* Pauli Virtanen + +Pull requests merged +==================== + +A total of 5 pull requests were merged for this release. + +* `#10674 <https://github.com/numpy/numpy/pull/10674>`__: BUG: Further back-compat fix for subclassed array repr +* `#10725 <https://github.com/numpy/numpy/pull/10725>`__: BUG: dragon4 fractional output mode adds too many trailing zeros +* `#10726 <https://github.com/numpy/numpy/pull/10726>`__: BUG: Fix f2py generated code to work on PyPy +* `#10727 <https://github.com/numpy/numpy/pull/10727>`__: BUG: Fix missing NPY_VISIBILITY_HIDDEN on npy_longdouble_to_PyLong +* `#10729 <https://github.com/numpy/numpy/pull/10729>`__: DOC: Create 1.14.2 notes and changelog. diff --git a/doc/release/1.14.2-notes.rst b/doc/release/1.14.2-notes.rst new file mode 100644 index 000000000..3f47cb5f5 --- /dev/null +++ b/doc/release/1.14.2-notes.rst @@ -0,0 +1,40 @@ +========================== +NumPy 1.14.2 Release Notes +========================== + +This is a bugfix release for some bugs reported following the 1.14.1 release. The major +problems dealt with are as follows. + +* Residual bugs in the new array printing functionality. +* Regression resulting in a relocation problem with shared library. +* Improved PyPy compatibility. + +The Python versions supported in this release are 2.7 and 3.4 - 3.6. The Python +3.6 wheels available from PIP are built with Python 3.6.2 and should be +compatible with all previous versions of Python 3.6. The source releases were +cythonized with Cython 0.26.1, which is known to **not** support the upcoming +Python 3.7 release. People who wish to run Python 3.7 should check out the +NumPy repo and try building with the, as yet, unreleased master branch of +Cython. + +Contributors +============ + +A total of 4 people contributed to this release. People with a "+" by their +names contributed a patch for the first time. + +* Allan Haldane +* Charles Harris +* Eric Wieser +* Pauli Virtanen + +Pull requests merged +==================== + +A total of 5 pull requests were merged for this release. + +* `#10674 <https://github.com/numpy/numpy/pull/10674>`__: BUG: Further back-compat fix for subclassed array repr +* `#10725 <https://github.com/numpy/numpy/pull/10725>`__: BUG: dragon4 fractional output mode adds too many trailing zeros +* `#10726 <https://github.com/numpy/numpy/pull/10726>`__: BUG: Fix f2py generated code to work on PyPy +* `#10727 <https://github.com/numpy/numpy/pull/10727>`__: BUG: Fix missing NPY_VISIBILITY_HIDDEN on npy_longdouble_to_PyLong +* `#10729 <https://github.com/numpy/numpy/pull/10729>`__: DOC: Create 1.14.2 notes and changelog. diff --git a/doc/source/reference/constants.rst b/doc/source/reference/constants.rst new file mode 100644 index 000000000..46de7552a --- /dev/null +++ b/doc/source/reference/constants.rst @@ -0,0 +1,5 @@ +********* +Constants +********* + +.. automodule:: numpy.doc.constants diff --git a/doc/source/reference/index.rst b/doc/source/reference/index.rst index 4f246096d..a2a8a0966 100644 --- a/doc/source/reference/index.rst +++ b/doc/source/reference/index.rst @@ -19,6 +19,7 @@ For learning how to use NumPy, see also :ref:`user`. :maxdepth: 2 arrays + constants ufuncs routines distutils diff --git a/doc/source/release.rst b/doc/source/release.rst index 0bb759dce..224436b82 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -3,6 +3,7 @@ Release Notes ************* .. include:: ../release/1.15.0-notes.rst +.. include:: ../release/1.14.2-notes.rst .. include:: ../release/1.14.1-notes.rst .. include:: ../release/1.14.0-notes.rst .. include:: ../release/1.13.3-notes.rst diff --git a/numpy/core/src/multiarray/dragon4.c b/numpy/core/src/multiarray/dragon4.c index e256b0ad7..e005234a0 100644 --- a/numpy/core/src/multiarray/dragon4.c +++ b/numpy/core/src/multiarray/dragon4.c @@ -1588,12 +1588,12 @@ FormatPositional(char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa, npy_int32 digits_right) { npy_int32 printExponent; - npy_int32 numDigits, numWholeDigits, has_sign=0; + npy_int32 numDigits, numWholeDigits=0, has_sign=0; npy_int32 maxPrintLen = (npy_int32)bufferSize - 1, pos = 0; /* track the # of digits past the decimal point that have been printed */ - npy_int32 numFractionDigits = 0; + npy_int32 numFractionDigits = 0, desiredFractionalDigits; DEBUG_ASSERT(bufferSize > 0); @@ -1711,6 +1711,11 @@ FormatPositional(char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa, buffer[pos++] = '.'; } + desiredFractionalDigits = precision; + if (cutoff_mode == CutoffMode_TotalLength && precision >= 0) { + desiredFractionalDigits = precision - numWholeDigits; + } + if (trim_mode == TrimMode_LeaveOneZero) { /* if we didn't print any fractional digits, add a trailing 0 */ if (numFractionDigits == 0 && pos < maxPrintLen) { @@ -1719,11 +1724,12 @@ FormatPositional(char *buffer, npy_uint32 bufferSize, npy_uint64 mantissa, } } else if (trim_mode == TrimMode_None && - digit_mode != DigitMode_Unique && - precision > numFractionDigits && pos < maxPrintLen) { + digit_mode != DigitMode_Unique && + desiredFractionalDigits > numFractionDigits && + pos < maxPrintLen) { /* add trailing zeros up to precision length */ /* compute the number of trailing zeros needed */ - npy_int32 count = precision - numFractionDigits; + npy_int32 count = desiredFractionalDigits - numFractionDigits; if (pos + count > maxPrintLen) { count = maxPrintLen - pos; } diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py index 309df8545..6c2403e67 100644 --- a/numpy/core/tests/test_arrayprint.py +++ b/numpy/core/tests/test_arrayprint.py @@ -5,7 +5,7 @@ import sys, gc import numpy as np from numpy.testing import ( - run_module_suite, assert_, assert_equal, assert_raises, assert_warns, dec + run_module_suite, assert_, assert_equal, assert_raises, assert_warns, dec, ) import textwrap @@ -388,6 +388,7 @@ class TestArray2String(object): "[ 'xxxxx']" ) + @dec._needs_refcount def test_refcount(self): # make sure we do not hold references to the array due to a recursive # closure (gh-10620) diff --git a/numpy/core/tests/test_indexing.py b/numpy/core/tests/test_indexing.py index cd4ea611a..26882c593 100644 --- a/numpy/core/tests/test_indexing.py +++ b/numpy/core/tests/test_indexing.py @@ -14,20 +14,6 @@ from numpy.testing import ( ) -try: - cdll = None - if hasattr(sys, 'gettotalrefcount'): - try: - cdll = np.ctypeslib.load_library('multiarray_d', np.core.multiarray.__file__) - except OSError: - pass - if cdll is None: - cdll = np.ctypeslib.load_library('multiarray', np.core.multiarray.__file__) - _HAS_CTYPE = True -except ImportError: - _HAS_CTYPE = False - - class TestIndexing(object): def test_index_no_floats(self): a = np.array([[[5]]]) @@ -622,7 +608,7 @@ class TestSubclasses(object): assert_array_equal(new_s.finalize_status, new_s) assert_array_equal(new_s.old, s) - @dec.skipif(not HAS_REFCOUNT) + @dec._needs_refcount def test_slice_decref_getsetslice(self): # See gh-10066, a temporary slice object should be discarted. # This test is only really interesting on Python 2 since diff --git a/numpy/core/tests/test_nditer.py b/numpy/core/tests/test_nditer.py index f3f8706b5..1b2485a87 100644 --- a/numpy/core/tests/test_nditer.py +++ b/numpy/core/tests/test_nditer.py @@ -33,7 +33,7 @@ def iter_iterindices(i): i.iternext() return ret -@dec.skipif(not HAS_REFCOUNT, "python does not have sys.getrefcount") +@dec._needs_refcount def test_iter_refcount(): # Make sure the iterator doesn't leak diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index 7c012e9e8..d7cdd77f1 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -12,7 +12,7 @@ from numpy.random import rand, randint, randn from numpy.testing import ( run_module_suite, assert_, assert_equal, assert_raises, assert_raises_regex, assert_array_equal, assert_almost_equal, - assert_array_almost_equal, dec, HAS_REFCOUNT, suppress_warnings + assert_array_almost_equal, dec, suppress_warnings ) @@ -2092,7 +2092,7 @@ class TestCreationFuncs(object): self.check_function(np.full, 0) self.check_function(np.full, 1) - @dec.skipif(not HAS_REFCOUNT, "python has no sys.getrefcount") + @dec._needs_refcount def test_for_reference_leak(self): # Make sure we have an object for reference dim = 1 diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index a3b011454..016b720f3 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -1424,7 +1424,7 @@ class TestRegression(object): x[x.nonzero()] = x.ravel()[:1] assert_(x[0, 1] == x[0, 0]) - @dec.skipif(not HAS_REFCOUNT, "python has no sys.getrefcount") + @dec._needs_refcount def test_structured_arrays_with_objects2(self): # Ticket #1299 second test stra = 'aaaa' @@ -1537,7 +1537,7 @@ class TestRegression(object): y = np.add(x, x, x) assert_equal(id(x), id(y)) - @dec.skipif(not HAS_REFCOUNT, "python has no sys.getrefcount") + @dec._needs_refcount def test_take_refcount(self): # ticket #939 a = np.arange(16, dtype=float) @@ -1937,7 +1937,7 @@ class TestRegression(object): a = np.empty((100000000,), dtype='i1') del a - @dec.skipif(not HAS_REFCOUNT, "python has no sys.getrefcount") + @dec._needs_refcount def test_ufunc_reduce_memoryleak(self): a = np.arange(6) acnt = sys.getrefcount(a) @@ -2167,7 +2167,7 @@ class TestRegression(object): assert_equal(uf(a), ()) assert_array_equal(a, [[3, 2, 1], [5, 4], [9, 7, 8, 6]]) - @dec.skipif(not HAS_REFCOUNT, "python has no sys.getrefcount") + @dec._needs_refcount def test_leak_in_structured_dtype_comparison(self): # gh-6250 recordtype = np.dtype([('a', np.float64), diff --git a/numpy/core/tests/test_scalarprint.py b/numpy/core/tests/test_scalarprint.py index 164ab06c7..d57f1a890 100644 --- a/numpy/core/tests/test_scalarprint.py +++ b/numpy/core/tests/test_scalarprint.py @@ -152,6 +152,8 @@ class TestRealScalars(object): assert_equal(fpos64('1.5', unique=False, precision=3), "1.500") assert_equal(fsci32('1.5', unique=False, precision=3), "1.500e+00") assert_equal(fsci64('1.5', unique=False, precision=3), "1.500e+00") + # gh-10713 + assert_equal(fpos64('324', unique=False, precision=5, fractional=False), "324.00") def test_dragon4_interface(self): tps = [np.float16, np.float32, np.float64] diff --git a/numpy/distutils/from_template.py b/numpy/distutils/from_template.py index 8f587eab9..65c60c498 100644 --- a/numpy/distutils/from_template.py +++ b/numpy/distutils/from_template.py @@ -98,6 +98,11 @@ def find_repl_patterns(astr): names[name] = thelist return names +def find_and_remove_repl_patterns(astr): + names = find_repl_patterns(astr) + astr = re.subn(named_re, '', astr)[0] + return astr, names + item_re = re.compile(r"\A\\(?P<index>\d+)\Z") def conv(astr): b = astr.split(',') @@ -186,7 +191,7 @@ def expand_sub(substr, names): def process_str(allstr): newstr = allstr - writestr = '' #_head # using _head will break free-format files + writestr = '' struct = parse_structure(newstr) @@ -194,8 +199,9 @@ def process_str(allstr): names = {} names.update(_special_names) for sub in struct: - writestr += newstr[oldend:sub[0]] - names.update(find_repl_patterns(newstr[oldend:sub[0]])) + cleanedstr, defs = find_and_remove_repl_patterns(newstr[oldend:sub[0]]) + writestr += cleanedstr + names.update(defs) writestr += expand_sub(newstr[sub[0]:sub[1]], names) oldend = sub[1] writestr += newstr[oldend:] diff --git a/numpy/distutils/tests/test_from_template.py b/numpy/distutils/tests/test_from_template.py new file mode 100644 index 000000000..d3c513437 --- /dev/null +++ b/numpy/distutils/tests/test_from_template.py @@ -0,0 +1,48 @@ + +from numpy.distutils.from_template import process_str +from numpy.testing import assert_equal, run_module_suite + + +pyf_src = """ +python module foo + <_rd=real,double precision> + interface + subroutine <s,d>foosub(tol) + <_rd>, intent(in,out) :: tol + end subroutine <s,d>foosub + end interface +end python module foo +""" + +expected_pyf = """ +python module foo + interface + subroutine sfoosub(tol) + real, intent(in,out) :: tol + end subroutine sfoosub + subroutine dfoosub(tol) + double precision, intent(in,out) :: tol + end subroutine dfoosub + end interface +end python module foo +""" + + +def normalize_whitespace(s): + """ + Remove leading and trailing whitespace, and convert internal + stretches of whitespace to a single space. + """ + return ' '.join(s.split()) + + +def test_from_template(): + """Regression test for gh-10712.""" + pyf = process_str(pyf_src) + normalized_pyf = normalize_whitespace(pyf) + normalized_expected_pyf = normalize_whitespace(expected_pyf) + assert_equal(normalized_pyf, normalized_expected_pyf) + + +if __name__ == "__main__": + run_module_suite() diff --git a/numpy/doc/constants.py b/numpy/doc/constants.py index 6246813b7..f3b835085 100644 --- a/numpy/doc/constants.py +++ b/numpy/doc/constants.py @@ -1,8 +1,11 @@ +# -*- coding: utf-8 -*- """ ========= Constants ========= +.. currentmodule:: numpy + NumPy includes several constants: %(constant_list)s @@ -225,7 +228,7 @@ add_newdoc('numpy', 'e', References ---------- - .. [1] http://en.wikipedia.org/wiki/Napier_constant + https://en.wikipedia.org/wiki/E_%28mathematical_constant%29 """) @@ -363,6 +366,26 @@ add_newdoc('numpy', 'newaxis', """) +add_newdoc('numpy', 'pi', + """ + ``pi = 3.1415926535897932384626433...`` + + References + ---------- + https://en.wikipedia.org/wiki/Pi + + """) + +add_newdoc('numpy', 'euler_gamma', + """ + ``γ = 0.5772156649015328606065120900824024310421...`` + + References + ---------- + https://en.wikipedia.org/wiki/Euler-Mascheroni_constant + + """) + if __doc__: constants_str = [] constants.sort() @@ -383,7 +406,7 @@ if __doc__: s = "\n".join(new_lines) # Done. - constants_str.append(""".. const:: %s\n %s""" % (name, s)) + constants_str.append(""".. data:: %s\n %s""" % (name, s)) constants_str = "\n".join(constants_str) __doc__ = __doc__ % dict(constant_list=constants_str) diff --git a/numpy/f2py/src/test/foomodule.c b/numpy/f2py/src/test/foomodule.c index 10f02f42b..d7ecc2519 100644 --- a/numpy/f2py/src/test/foomodule.c +++ b/numpy/f2py/src/test/foomodule.c @@ -5,7 +5,7 @@ * $Revision: 1.2 $ * $Date: 2000/09/17 16:10:27 $ */ -#ifdef __CPLUSPLUS__ +#ifdef __cplusplus extern "C" { #endif @@ -139,6 +139,6 @@ void initfoo() { Py_FatalError("can't initialize module foo"); } -#ifdef __CPLUSCPLUS__ +#ifdef __cplusplus } #endif diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 959574594..0f338d781 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -1104,7 +1104,7 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, nshape = list(X.shape) pos = nshape[0] nshape[0] += len(x) - X.resize(nshape) + X.resize(nshape, refcheck=False) X[pos:, ...] = x finally: if fown: diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 49b450175..2b1ac1cc0 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -11,7 +11,7 @@ from numpy.testing import ( run_module_suite, assert_, assert_equal, assert_array_equal, assert_almost_equal, assert_array_almost_equal, assert_raises, assert_allclose, assert_array_max_ulp, assert_warns, assert_raises_regex, - dec, suppress_warnings, HAS_REFCOUNT, + dec, suppress_warnings, ) import numpy.lib.function_base as nfb from numpy.random import rand @@ -2141,7 +2141,7 @@ class TestBincount(object): "must not be negative", lambda: np.bincount(x, minlength=-1)) - @dec.skipif(not HAS_REFCOUNT, "python has no sys.getrefcount") + @dec._needs_refcount def test_dtype_reference_leaks(self): # gh-6805 intp_refcount = sys.getrefcount(np.dtype(np.intp)) diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index ae40cf73b..a0f256726 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -22,7 +22,7 @@ from numpy.ma.testutils import assert_equal from numpy.testing import ( run_module_suite, assert_warns, assert_, SkipTest, assert_raises_regex, assert_raises, assert_allclose, - assert_array_equal, temppath, tempdir, dec, IS_PYPY, suppress_warnings + assert_array_equal, temppath, tempdir, dec, IS_PYPY, suppress_warnings, ) @@ -2364,6 +2364,7 @@ def test_npzfile_dict(): assert_('x' in z.keys()) +@dec._needs_refcount def test_load_refcount(): # Check that objects returned by np.load are directly freed based on # their refcount, rather than needing the gc to collect them. diff --git a/numpy/linalg/lapack_lite/clapack_scrub.py b/numpy/linalg/lapack_lite/clapack_scrub.py index ee4d9c265..e72a39e64 100644 --- a/numpy/linalg/lapack_lite/clapack_scrub.py +++ b/numpy/linalg/lapack_lite/clapack_scrub.py @@ -229,7 +229,7 @@ def removeHeader(source): def removeSubroutinePrototypes(source): expression = re.compile( - '/\* Subroutine \*/^\s*(?:(?:inline|static)\s+){0,2}(?!else|typedef|return)\w+\s+\*?\s*(\w+)\s*\([^0]+\)\s*;?' + r'/[*] Subroutine [*]/^\s*(?:(?:inline|static)\s+){0,2}(?!else|typedef|return)\w+\s+\*?\s*(\w+)\s*\([^0]+\)\s*;?' ) lines = LineQueue() for line in UStringIO(source): diff --git a/numpy/testing/nose_tools/decorators.py b/numpy/testing/nose_tools/decorators.py index 243c0c8c1..dda2c1b74 100644 --- a/numpy/testing/nose_tools/decorators.py +++ b/numpy/testing/nose_tools/decorators.py @@ -17,10 +17,10 @@ from __future__ import division, absolute_import, print_function import collections -from .utils import SkipTest, assert_warns +from .utils import SkipTest, assert_warns, HAS_REFCOUNT __all__ = ['slow', 'setastest', 'skipif', 'knownfailureif', 'deprecated', - 'parametrize',] + 'parametrize', '_needs_refcount',] def slow(t): @@ -283,3 +283,5 @@ def parametrize(vars, input): from .parameterized import parameterized return parameterized(input) + +_needs_refcount = skipif(not HAS_REFCOUNT, "python has no sys.getrefcount") diff --git a/numpy/testing/pytest_tools/decorators.py b/numpy/testing/pytest_tools/decorators.py index 08a39e0c0..bbca34035 100644 --- a/numpy/testing/pytest_tools/decorators.py +++ b/numpy/testing/pytest_tools/decorators.py @@ -14,10 +14,10 @@ from __future__ import division, absolute_import, print_function import collections -from .utils import SkipTest, assert_warns +from .utils import SkipTest, assert_warns, HAS_REFCOUNT __all__ = ['slow', 'setastest', 'skipif', 'knownfailureif', 'deprecated', - 'parametrize',] + 'parametrize', '_needs_refcount',] def slow(t): @@ -276,3 +276,6 @@ def parametrize(vars, input): import pytest return pytest.mark.parametrize(vars, input) + + +_needs_refcount = skipif(not HAS_REFCOUNT, "python has no sys.getrefcount") @@ -219,7 +219,9 @@ def parse_setuppy_commands(): Return a boolean value for whether or not to run the build or not (avoid parsing Cython and template files if False). """ - if len(sys.argv) < 2: + args = sys.argv[1:] + + if not args: # User forgot to give an argument probably, let setuptools handle that. return True @@ -229,12 +231,9 @@ def parse_setuppy_commands(): '--contact-email', '--url', '--license', '--description', '--long-description', '--platforms', '--classifiers', '--keywords', '--provides', '--requires', '--obsoletes'] - # Add commands that do more than print info, but also don't need Cython and - # template parsing. - info_commands.extend(['egg_info', 'install_egg_info', 'rotate']) for command in info_commands: - if command in sys.argv[1:]: + if command in args: return False # Note that 'alias', 'saveopts' and 'setopt' commands also seem to work @@ -245,12 +244,12 @@ def parse_setuppy_commands(): 'bdist_wininst', 'bdist_msi', 'bdist_mpkg') for command in good_commands: - if command in sys.argv[1:]: + if command in args: return True # The following commands are supported, but we need to show more # useful messages to the user - if 'install' in sys.argv[1:]: + if 'install' in args: print(textwrap.dedent(""" Note: if you need reliable uninstall behavior, then install with pip instead of using `setup.py install`: @@ -262,7 +261,7 @@ def parse_setuppy_commands(): """)) return True - if '--help' in sys.argv[1:] or '-h' in sys.argv[1]: + if '--help' in args or '-h' in sys.argv[1]: print(textwrap.dedent(""" NumPy-specific help ------------------- @@ -280,6 +279,7 @@ def parse_setuppy_commands(): """)) return False + # The following commands aren't supported. They can only be executed when # the user explicitly adds a --force command-line argument. bad_commands = dict( @@ -322,12 +322,19 @@ def parse_setuppy_commands(): bad_commands[command] = "`setup.py %s` is not supported" % command for command in bad_commands.keys(): - if command in sys.argv[1:]: + if command in args: print(textwrap.dedent(bad_commands[command]) + "\nAdd `--force` to your command to use it anyway if you " "must (unsupported).\n") sys.exit(1) + # Commands that do more than print info, but also don't need Cython and + # template parsing. + other_commands = ['egg_info', 'install_egg_info', 'rotate'] + for command in other_commands: + if command in args: + return False + # If we got here, we didn't detect what setup.py command was given import warnings warnings.warn("Unrecognized setuptools command, proceeding with " diff --git a/tools/swig/test/testSuperTensor.py b/tools/swig/test/testSuperTensor.py index b7765ea0a..cdd88530b 100644 --- a/tools/swig/test/testSuperTensor.py +++ b/tools/swig/test/testSuperTensor.py @@ -1,5 +1,5 @@ #! /usr/bin/env python -from __future__ import division +from __future__ import division, print_function # System imports from distutils.util import get_platform @@ -28,7 +28,7 @@ class SuperTensorTestCase(unittest.TestCase): # Test (type IN_ARRAY3[ANY][ANY][ANY]) typemap def testNorm(self): "Test norm function" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) norm = SuperTensor.__dict__[self.typeStr + "Norm"] supertensor = np.arange(2*2*2*2, dtype=self.typeCode).reshape((2, 2, 2, 2)) #Note: cludge to get an answer of the same type as supertensor. @@ -39,7 +39,7 @@ class SuperTensorTestCase(unittest.TestCase): # Test (type IN_ARRAY3[ANY][ANY][ANY]) typemap def testNormBadList(self): "Test norm function with bad list" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) norm = SuperTensor.__dict__[self.typeStr + "Norm"] supertensor = [[[[0, "one"], [2, 3]], [[3, "two"], [1, 0]]], [[[0, "one"], [2, 3]], [[3, "two"], [1, 0]]]] self.assertRaises(BadListError, norm, supertensor) @@ -47,7 +47,7 @@ class SuperTensorTestCase(unittest.TestCase): # Test (type IN_ARRAY3[ANY][ANY][ANY]) typemap def testNormWrongDim(self): "Test norm function with wrong dimensions" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) norm = SuperTensor.__dict__[self.typeStr + "Norm"] supertensor = np.arange(2*2*2, dtype=self.typeCode).reshape((2, 2, 2)) self.assertRaises(TypeError, norm, supertensor) @@ -55,7 +55,7 @@ class SuperTensorTestCase(unittest.TestCase): # Test (type IN_ARRAY3[ANY][ANY][ANY]) typemap def testNormWrongSize(self): "Test norm function with wrong size" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) norm = SuperTensor.__dict__[self.typeStr + "Norm"] supertensor = np.arange(3*2*2, dtype=self.typeCode).reshape((3, 2, 2)) self.assertRaises(TypeError, norm, supertensor) @@ -63,14 +63,14 @@ class SuperTensorTestCase(unittest.TestCase): # Test (type IN_ARRAY3[ANY][ANY][ANY]) typemap def testNormNonContainer(self): "Test norm function with non-container" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) norm = SuperTensor.__dict__[self.typeStr + "Norm"] self.assertRaises(TypeError, norm, None) # Test (type* IN_ARRAY3, int DIM1, int DIM2, int DIM3) typemap def testMax(self): "Test max function" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) max = SuperTensor.__dict__[self.typeStr + "Max"] supertensor = [[[[1, 2], [3, 4]], [[5, 6], [7, 8]]], [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]] self.assertEquals(max(supertensor), 8) @@ -78,7 +78,7 @@ class SuperTensorTestCase(unittest.TestCase): # Test (type* IN_ARRAY3, int DIM1, int DIM2, int DIM3) typemap def testMaxBadList(self): "Test max function with bad list" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) max = SuperTensor.__dict__[self.typeStr + "Max"] supertensor = [[[[1, "two"], [3, 4]], [[5, "six"], [7, 8]]], [[[1, "two"], [3, 4]], [[5, "six"], [7, 8]]]] self.assertRaises(BadListError, max, supertensor) @@ -86,21 +86,21 @@ class SuperTensorTestCase(unittest.TestCase): # Test (type* IN_ARRAY3, int DIM1, int DIM2, int DIM3) typemap def testMaxNonContainer(self): "Test max function with non-container" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) max = SuperTensor.__dict__[self.typeStr + "Max"] self.assertRaises(TypeError, max, None) # Test (type* IN_ARRAY3, int DIM1, int DIM2, int DIM3) typemap def testMaxWrongDim(self): "Test max function with wrong dimensions" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) max = SuperTensor.__dict__[self.typeStr + "Max"] self.assertRaises(TypeError, max, [0, -1, 2, -3]) # Test (int DIM1, int DIM2, int DIM3, type* IN_ARRAY3) typemap def testMin(self): "Test min function" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) min = SuperTensor.__dict__[self.typeStr + "Min"] supertensor = [[[[9, 8], [7, 6]], [[5, 4], [3, 2]]], [[[9, 8], [7, 6]], [[5, 4], [3, 2]]]] self.assertEquals(min(supertensor), 2) @@ -108,7 +108,7 @@ class SuperTensorTestCase(unittest.TestCase): # Test (int DIM1, int DIM2, int DIM3, type* IN_ARRAY3) typemap def testMinBadList(self): "Test min function with bad list" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) min = SuperTensor.__dict__[self.typeStr + "Min"] supertensor = [[[["nine", 8], [7, 6]], [["five", 4], [3, 2]]], [[["nine", 8], [7, 6]], [["five", 4], [3, 2]]]] self.assertRaises(BadListError, min, supertensor) @@ -116,21 +116,21 @@ class SuperTensorTestCase(unittest.TestCase): # Test (int DIM1, int DIM2, int DIM3, type* IN_ARRAY3) typemap def testMinNonContainer(self): "Test min function with non-container" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) min = SuperTensor.__dict__[self.typeStr + "Min"] self.assertRaises(TypeError, min, True) # Test (int DIM1, int DIM2, int DIM3, type* IN_ARRAY3) typemap def testMinWrongDim(self): "Test min function with wrong dimensions" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) min = SuperTensor.__dict__[self.typeStr + "Min"] self.assertRaises(TypeError, min, [[1, 3], [5, 7]]) # Test (type INPLACE_ARRAY3[ANY][ANY][ANY]) typemap def testScale(self): "Test scale function" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) scale = SuperTensor.__dict__[self.typeStr + "Scale"] supertensor = np.arange(3*3*3*3, dtype=self.typeCode).reshape((3, 3, 3, 3)) answer = supertensor.copy()*4 @@ -140,7 +140,7 @@ class SuperTensorTestCase(unittest.TestCase): # Test (type INPLACE_ARRAY3[ANY][ANY][ANY]) typemap def testScaleWrongType(self): "Test scale function with wrong type" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) scale = SuperTensor.__dict__[self.typeStr + "Scale"] supertensor = np.array([[[1, 0, 1], [0, 1, 0], [1, 0, 1]], [[0, 1, 0], [1, 0, 1], [0, 1, 0]], @@ -150,7 +150,7 @@ class SuperTensorTestCase(unittest.TestCase): # Test (type INPLACE_ARRAY3[ANY][ANY][ANY]) typemap def testScaleWrongDim(self): "Test scale function with wrong dimensions" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) scale = SuperTensor.__dict__[self.typeStr + "Scale"] supertensor = np.array([[1, 0, 1], [0, 1, 0], [1, 0, 1], [0, 1, 0], [1, 0, 1], [0, 1, 0]], self.typeCode) @@ -159,7 +159,7 @@ class SuperTensorTestCase(unittest.TestCase): # Test (type INPLACE_ARRAY3[ANY][ANY][ANY]) typemap def testScaleWrongSize(self): "Test scale function with wrong size" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) scale = SuperTensor.__dict__[self.typeStr + "Scale"] supertensor = np.array([[[1, 0], [0, 1], [1, 0]], [[0, 1], [1, 0], [0, 1]], @@ -169,14 +169,14 @@ class SuperTensorTestCase(unittest.TestCase): # Test (type INPLACE_ARRAY3[ANY][ANY][ANY]) typemap def testScaleNonArray(self): "Test scale function with non-array" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) scale = SuperTensor.__dict__[self.typeStr + "Scale"] self.assertRaises(TypeError, scale, True) # Test (type* INPLACE_ARRAY3, int DIM1, int DIM2, int DIM3) typemap def testFloor(self): "Test floor function" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) supertensor = np.arange(2*2*2*2, dtype=self.typeCode).reshape((2, 2, 2, 2)) answer = supertensor.copy() answer[answer < 4] = 4 @@ -188,7 +188,7 @@ class SuperTensorTestCase(unittest.TestCase): # Test (type* INPLACE_ARRAY3, int DIM1, int DIM2, int DIM3) typemap def testFloorWrongType(self): "Test floor function with wrong type" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) floor = SuperTensor.__dict__[self.typeStr + "Floor"] supertensor = np.ones(2*2*2*2, dtype='c').reshape((2, 2, 2, 2)) self.assertRaises(TypeError, floor, supertensor) @@ -196,7 +196,7 @@ class SuperTensorTestCase(unittest.TestCase): # Test (type* INPLACE_ARRAY3, int DIM1, int DIM2, int DIM3) typemap def testFloorWrongDim(self): "Test floor function with wrong type" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) floor = SuperTensor.__dict__[self.typeStr + "Floor"] supertensor = np.arange(2*2*2, dtype=self.typeCode).reshape((2, 2, 2)) self.assertRaises(TypeError, floor, supertensor) @@ -204,14 +204,14 @@ class SuperTensorTestCase(unittest.TestCase): # Test (type* INPLACE_ARRAY3, int DIM1, int DIM2, int DIM3) typemap def testFloorNonArray(self): "Test floor function with non-array" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) floor = SuperTensor.__dict__[self.typeStr + "Floor"] self.assertRaises(TypeError, floor, object) # Test (int DIM1, int DIM2, int DIM3, type* INPLACE_ARRAY3) typemap def testCeil(self): "Test ceil function" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) supertensor = np.arange(2*2*2*2, dtype=self.typeCode).reshape((2, 2, 2, 2)) answer = supertensor.copy() answer[answer > 5] = 5 @@ -222,7 +222,7 @@ class SuperTensorTestCase(unittest.TestCase): # Test (int DIM1, int DIM2, int DIM3, type* INPLACE_ARRAY3) typemap def testCeilWrongType(self): "Test ceil function with wrong type" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) ceil = SuperTensor.__dict__[self.typeStr + "Ceil"] supertensor = np.ones(2*2*2*2, 'c').reshape((2, 2, 2, 2)) self.assertRaises(TypeError, ceil, supertensor) @@ -230,7 +230,7 @@ class SuperTensorTestCase(unittest.TestCase): # Test (int DIM1, int DIM2, int DIM3, type* INPLACE_ARRAY3) typemap def testCeilWrongDim(self): "Test ceil function with wrong dimensions" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) ceil = SuperTensor.__dict__[self.typeStr + "Ceil"] supertensor = np.arange(2*2*2, dtype=self.typeCode).reshape((2, 2, 2)) self.assertRaises(TypeError, ceil, supertensor) @@ -238,7 +238,7 @@ class SuperTensorTestCase(unittest.TestCase): # Test (int DIM1, int DIM2, int DIM3, type* INPLACE_ARRAY3) typemap def testCeilNonArray(self): "Test ceil function with non-array" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) ceil = SuperTensor.__dict__[self.typeStr + "Ceil"] supertensor = np.arange(2*2*2*2, dtype=self.typeCode).reshape((2, 2, 2, 2)).tolist() self.assertRaises(TypeError, ceil, supertensor) @@ -246,7 +246,7 @@ class SuperTensorTestCase(unittest.TestCase): # Test (type ARGOUT_ARRAY3[ANY][ANY][ANY]) typemap def testLUSplit(self): "Test luSplit function" - print >>sys.stderr, self.typeStr, "... ", + print(self.typeStr, "... ", file=sys.stderr) luSplit = SuperTensor.__dict__[self.typeStr + "LUSplit"] supertensor = np.ones(2*2*2*2, dtype=self.typeCode).reshape((2, 2, 2, 2)) answer_upper = [[[[0, 0], [0, 1]], [[0, 1], [1, 1]]], [[[0, 1], [1, 1]], [[1, 1], [1, 1]]]] @@ -381,8 +381,8 @@ if __name__ == "__main__": suite.addTest(unittest.makeSuite( doubleTestCase)) # Execute the test suite - print "Testing 4D Functions of Module SuperTensor" - print "NumPy version", np.__version__ - print + print("Testing 4D Functions of Module SuperTensor") + print("NumPy version", np.__version__) + print() result = unittest.TextTestRunner(verbosity=2).run(suite) sys.exit(bool(result.errors + result.failures)) |