Commit 88181305 authored by Boxiang Sun's avatar Boxiang Sun

Rename numpy_test to scipy_test and add scipy test suite.

Because scipy rely on NumPy, so add scipy test to numpy_test.py. And
rename it to scipy_test.py. numpy_full_test.py will check numpy test
suite. The scipy_test.py only for check scipy test suite. But scipy test
will take a long time. So disabled it by default.
parent a597d1b6
# skip-if: True
# This test will take a long time(51mins).
# 3100.61s user 490.14s system 118% cpu 50:30.63 total
# So please test it manually.
import os
import sys
import subprocess
sys.path.append(os.path.dirname(__file__) + "/../lib")
from test_helper import run_test
"""
Using this test file.
We apply some patches on NumPy for some issues that we can't fix at the moment. The
patches are applied directly to the NumPy subrepository (test/lib/numpy). If you need,
you can make modifications in that folder directly for testing purposes. Just make sure
that everytime you do, run this script again, so that the contents of numpy_test_env_*
are updated (this is where the code and binaries that get tested are located).
Note that sometimes it can be a pain to run this script everytime you make a change,
as it does take a while. You can cd to the numpy_test_env_* directory and run the
binaries inside of that folder, which will be able to "see" the NumPy module. For example:
Note that sometimes it can be a pain to run this script everytime you make a
change, as it does take a while. You can cd to the scipy_test_env_* directory
and run the binaries inside of that folder, which will be able to "see" the
SciPy module. For example:
~/pyston/numpy_test_env_pyston_dbg$ gdb --args ./bin/python -c "import numpy as np; np.test()"
~/pyston/scipy_test_env_pyston_dbg$ gdb --args ./bin/python -c "import scipy; scipy.test()"
The /bin/python is the pyston executable so if you recompile pyston, you need to run this
script again to update it.
Currently this script is not running the NumPy tests since there are still crashes
happening. If you want to run the test, go to the bottom of the file and uncomment
the subprocess call to the test suite.
Some test cases in test/lib/numpy are commented out by the patch since they caused
a crash where the cause was not immediately obvious and I wanted to make progress. Those
will need to be uncommented at some point.
"""
def print_progress_header(text):
......@@ -34,7 +29,7 @@ def print_progress_header(text):
print ">>> " + text + "..."
print ">>>"
ENV_NAME = "numpy_test_env_" + os.path.basename(sys.executable)
ENV_NAME = "scipy_test_env_" + os.path.basename(sys.executable)
DEPENDENCIES = ["nose==1.3.7"]
import platform
......@@ -61,19 +56,18 @@ if not os.path.exists(ENV_NAME) or os.stat(sys.executable).st_mtime > os.stat(EN
SRC_DIR = ENV_NAME
PYTHON_EXE = os.path.abspath(ENV_NAME + "/bin/python")
CYTHON_DIR = os.path.abspath(os.path.join(SRC_DIR, "cython-0.22"))
CYTHON_DIR = os.path.abspath(os.path.join(SRC_DIR, "cython"))
NUMPY_DIR = os.path.abspath(os.path.join(SRC_DIR, "numpy"))
SCIPY_DIR = os.path.abspath(os.path.join(SRC_DIR, "scipy"))
print_progress_header("Setting up Cython...")
if not os.path.exists(CYTHON_DIR):
url = "https://github.com/cython/cython/archive/0.22.tar.gz"
subprocess.check_call(["wget", url, "-O", "Cython-0.22.tar.gz"], cwd=SRC_DIR)
subprocess.check_call(["tar", "-zxf", "Cython-0.22.tar.gz"], cwd=SRC_DIR)
url = "https://github.com/cython/cython"
subprocess.check_call(["git", "clone", "--depth", "1", "--branch", "0.24", url], cwd=SRC_DIR)
if USE_CUSTOM_PATCHES:
PATCH_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__), "Cython-0.22.patch"))
PATCH_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__), "Cython-0.24.patch"))
subprocess.check_call(["patch", "-p1", "--input=" + PATCH_FILE], cwd=CYTHON_DIR)
print ">>> Applied Cython patch"
......@@ -108,91 +102,29 @@ except:
raise
print_progress_header("Cloning up SciPy...")
if not os.path.exists(SCIPY_DIR):
print_progress_header("Cloning up SciPy...")
url = "https://github.com/scipy/scipy"
# subprocess.check_call(["git", "clone", "--depth", "1", "--branch", "v0.17.1", url], cwd=SRC_DIR)
subprocess.check_call(["git", "clone", "--depth", "1", "--branch", "v0.17.1", url], cwd=SRC_DIR)
else:
print ">>> SciPy already installed."
try:
print_progress_header("Setting up SciPy...")
# subprocess.check_call([PYTHON_EXE, "setup.py", "build"], cwd=SCIPY_DIR, env=env)
subprocess.check_call([PYTHON_EXE, "setup.py", "build"], cwd=SCIPY_DIR, env=env)
print_progress_header("Installing SciPy...")
# subprocess.check_call([PYTHON_EXE, "setup.py", "install"], cwd=SCIPY_DIR, env=env)
subprocess.check_call([PYTHON_EXE, "setup.py", "install"], cwd=SCIPY_DIR, env=env)
except:
subprocess.check_call(["rm", "-rf", SCIPY_DIR + "/build"])
subprocess.check_call(["rm", "-rf", SCIPY_DIR + "/dist"])
raise
# From Wikipedia
script = """
import numpy as np
from numpy.linalg import solve, inv
a = np.array([[1, 2, 3], [3, 4, 6.7], [5, 9.0, 5]])
b = np.array([3, 2, 1])
a.transpose()
inv(a)
solve(a, b)
print a, b
"""
# http://wiki.scipy.org/Tentative_NumPy_Tutorial/Mandelbrot_Set_Example
mandelbrot = """
from numpy import *
def mandelbrot( h,w, maxit=20 ):
'''Returns an image of the Mandelbrot fractal of size (h,w).
'''
y,x = ogrid[ -1.4:1.4:h*1j, -2:0.8:w*1j ]
c = x+y*1j
z = c
divtime = maxit + zeros(z.shape, dtype=int)
for i in xrange(maxit):
z = z**2 + c
diverge = z*conj(z) > 2**2
div_now = diverge & (divtime==maxit)
divtime[div_now] = i
z[diverge] = 2
return divtime
m = mandelbrot(complex(400),complex(400))
print m
"""
# this is just a small test which checks if numpy is able to manually create a pyston string
string_test = """
import numpy as np
a = np.array([1, 2**16, 2**32], dtype=int)
s = a.astype(str)
print s
assert repr(s) == "array(['1', '65536', '4294967296'], \\n dtype='|S21')"
"""
numpy_test = "import numpy as np; np.test(verbose=2)"
print_progress_header("Running NumPy linear algebra test...")
subprocess.check_call([PYTHON_EXE, "-c", script], cwd=CYTHON_DIR)
print_progress_header("Running NumPy mandelbrot test...")
subprocess.check_call([PYTHON_EXE, "-c", mandelbrot], cwd=CYTHON_DIR)
print_progress_header("Running NumPy str test...")
subprocess.check_call([PYTHON_EXE, "-c", string_test], cwd=CYTHON_DIR)
# fails in release mode
#print_progress_header("Running NumPy test_abc.py test...")
#subprocess.check_call([PYTHON_EXE, os.path.join(NUMPY_DIR, "numpy/core/tests/test_abc.py")], cwd=CYTHON_DIR)
scip_test = "import scipy; scipy.test(verbose=2)"
print_progress_header("Running NumPy test suite...")
# Currently we crash running the test suite. Uncomment for testing or
# when all the crashes are fixed.
# subprocess.check_call([PYTHON_EXE, "-c", numpy_test], cwd=CYTHON_DIR)
print_progress_header("Running SciPy test suite...")
expected = [{'ran': 20391}]
run_test([PYTHON_EXE, "-c", scip_test], cwd=CYTHON_DIR, expected=expected)
print
print "PASSED"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment