提交 b56a541c authored 作者: notoraptor's avatar notoraptor 提交者: GitHub

Merge pull request #6446 from nouiz/no_scipy_tests

Fix opt crash and crash/tests when SciPy is not there.
......@@ -45,7 +45,7 @@ def pygpu_parse_version(version_string):
from collections import namedtuple
version_type = namedtuple('version_type', ('major', 'minor', 'patch', 'fullversion'))
pieces = version_string.split('.', 2)
assert len(pieces) == 3
assert len(pieces) == 3, version_string
major = int(pieces[0])
minor = int(pieces[1])
if "+" in pieces[2]: # It contain a git commit.
......
......@@ -12,8 +12,6 @@ from theano.tensor import (DimShuffle, get_scalar_constant_value,
from .basic_ops import GpuFromHost, HostFromGpu, GpuAllocEmpty, GpuReshape
from .elemwise import GpuDimShuffle, GpuElemwise
_one = scal.constant(np.asarray(1.0, dtype='float32'))
def grab_cpu_scalar(v, nd):
"""
......@@ -273,7 +271,9 @@ def output_merge(cls, alpha_in, beta_in, out_in):
return None
inputs = list(targ.inputs)
inputs[out_in] = W
inputs[beta_in] = _one.clone()
dtype = inputs[beta_in].dtype
one = scal.constant(np.asarray(1.0, dtype=dtype))
inputs[beta_in] = one
with inherit_stack_trace(node.outputs):
return maker(targ, *inputs)
return opt
......
......@@ -3,7 +3,6 @@ from copy import copy
from unittest import TestCase
import numpy as np
import scipy.special
import theano
from theano import scalar, gof, tensor
......@@ -22,6 +21,13 @@ from ..type import GpuArrayType, get_context, gpuarray_shared_constructor
from pygpu import ndgpuarray as gpuarray
imported_scipy_special = False
try:
import scipy.special
imported_scipy_special = True
except ImportError:
pass
# This is actually a test for GpuElemwise
class test_gpu_Broadcast(test_elemwise.test_Broadcast):
......@@ -73,6 +79,8 @@ class TestMathErrorFunctions(TestCase):
@classmethod
def setUpClass(cls):
if not imported_scipy_special:
raise SkipTest("scipy.special needed")
# NB: erfinv is defined in ]-1;1[, and erfcinv is defined in ]0;2[,
# so we just take some values in an interval that covers both domains
# (this will also allow to test some values outside the domains).
......
......@@ -14,7 +14,7 @@ from theano.gpuarray.linalg import (GpuCholesky, GpuMagmaCholesky,
gpu_solve, gpu_svd, gpu_qr)
from theano.tensor.nlinalg import (SVD, MatrixInverse, QRFull,
QRIncomplete, eigh, matrix_inverse, qr)
from theano.tensor.slinalg import Cholesky, cholesky
from theano.tensor.slinalg import Cholesky, cholesky, imported_scipy
from theano.tests import unittest_tools as utt
from .. import gpuarray_shared_constructor
......@@ -149,6 +149,8 @@ class TestGpuCholesky(unittest.TestCase):
utt.assert_allclose(chol_A_res, chol_A_val)
def test_gpu_cholesky_opt(self):
if not imported_scipy:
self.skipTest('SciPy is not enabled, skipping test')
A = theano.tensor.matrix("A", dtype="float32")
fn = theano.function([A], cholesky(A), mode=mode_with_gpu)
assert any([isinstance(node.op, GpuCholesky)
......
......@@ -642,8 +642,8 @@ def test_no_complex():
@utt.assertFailure_fast
def test_local_lift_solve():
if not cusolver_available:
raise SkipTest('No cuSolver')
if not cusolver_available or not slinalg.imported_scipy:
raise SkipTest('No cuSolver or SciPy')
A = tensor.fmatrix()
b = tensor.fmatrix()
o = slinalg.solve(A, b)
......@@ -660,8 +660,8 @@ def test_local_lift_solve():
def test_gpu_solve_not_inplace():
if not cusolver_available:
raise SkipTest('No cuSolver')
if not cusolver_available or not slinalg.imported_scipy:
raise SkipTest('No cuSolver or Scipy')
A = tensor.fmatrix()
b = tensor.fmatrix()
s = slinalg.solve(A, b)
......@@ -678,8 +678,8 @@ def test_gpu_solve_not_inplace():
@utt.assertFailure_fast
def test_local_lift_cholesky():
if not cusolver_available:
raise SkipTest('No cuSolver')
if not cusolver_available or not slinalg.imported_scipy:
raise SkipTest('No cuSolver or Scipy')
A = tensor.fmatrix()
o = slinalg.cholesky(A)
f_cpu = theano.function([A], o, mode=mode_without_gpu)
......@@ -696,8 +696,8 @@ def test_local_lift_cholesky():
def test_gpu_cholesky_not_inplace():
if not cusolver_available:
raise SkipTest('No cuSolver')
if not cusolver_available or not slinalg.imported_scipy:
raise SkipTest('No cuSolver or SciPy')
A = tensor.fmatrix()
A_squared = A**2
B = slinalg.cholesky(A_squared)
......
......@@ -649,7 +649,7 @@ second dimension
# - NumPy ufunc support only up to 31 inputs.
# But our c code support more.
# - nfunc is reused for scipy and scipy is optional
if getattr(self, 'nfunc_spec', None):
if getattr(self, 'nfunc_spec', None) and impl != 'c':
self.nfunc = getattr(np, self.nfunc_spec[0], None)
if self.nfunc is None:
# Not inside NumPy. So probably another package like scipy.
......
......@@ -741,6 +741,8 @@ class TestAbstractConvNoOptim(BaseTestConv2d):
cls.border_modes = ["valid", "half", "full"]
cls.filter_flip = [True]
cls.provide_shape = [False]
if not theano.tensor.nnet.abstract_conv.imported_scipy_signal:
raise SkipTest("SciPy needed")
def tcase(self, i, f, s, b, flip, provide_shape, fd=(1, 1)):
o = self.get_output_shape(i, f, s, b, fd)
......@@ -1454,8 +1456,8 @@ class Grouped_conv_noOptim(unittest.TestCase):
self.corr_fwd = conv2d_corr
self.corr_gradw = conv2d_corr_gw
self.corr_gradi = conv2d_corr_gi
if theano.config.cxx == "":
raise SkipTest("CorrMM needs cxx")
if theano.config.cxx == "" or not theano.tensor.nnet.abstract_conv.imported_scipy_signal:
raise SkipTest("CorrMM needs cxx and SciPy")
def test_fwd(self):
if self.convdim == 2:
......@@ -1621,7 +1623,7 @@ class Grouped_conv3d_noOptim(Grouped_conv_noOptim):
self.corr_fwd = conv3d_corr
self.corr_gradw = conv3d_corr_gw
self.corr_gradi = conv3d_corr_gi
if theano.config.cxx == "":
if theano.config.cxx == "" or not theano.tensor.nnet.abstract_conv.imported_scipy_signal:
raise SkipTest("CorrMM needs cxx")
......@@ -1770,8 +1772,8 @@ class TestUnsharedConv(unittest.TestCase):
self.verify_flags = [True] * 4
self.ref_mode = 'FAST_RUN'
if theano.config.cxx == "":
raise SkipTest("CorrMM needs cxx")
if theano.config.cxx == "" or not theano.tensor.nnet.abstract_conv.imported_scipy_signal:
raise SkipTest("CorrMM needs cxx or SciPy")
def test_fwd(self):
tensor6 = theano.tensor.TensorType(theano.config.floatX, (False,) * 6)
......@@ -1913,6 +1915,8 @@ class TestAsymmetricPadding(unittest.TestCase):
border_mode = [((1, 2), (2, 1)), ((1, 1), (0, 3)), ((2, 1), (0, 0))]
def test_fwd(self):
if not theano.tensor.nnet.abstract_conv.imported_scipy_signal:
raise SkipTest("SciPy needed")
img_sym = theano.tensor.tensor4('img')
kern_sym = theano.tensor.tensor4('kern')
......@@ -1947,6 +1951,9 @@ class TestAsymmetricPadding(unittest.TestCase):
utt.verify_grad(asymmetric_conv_op, [img, kern], mode=self.mode, eps=1)
def test_gradweight(self):
if not theano.tensor.nnet.abstract_conv.imported_scipy_signal:
raise SkipTest("SciPy needed")
img_sym = theano.tensor.tensor4('img')
top_sym = theano.tensor.tensor4('top')
......@@ -1984,6 +1991,8 @@ class TestAsymmetricPadding(unittest.TestCase):
utt.verify_grad(conv_gradweight, [img, top], mode=self.mode, eps=1)
def test_gradinput(self):
if not theano.tensor.nnet.abstract_conv.imported_scipy_signal:
raise SkipTest("SciPy needed")
kern_sym = theano.tensor.tensor4('kern')
top_sym = theano.tensor.tensor4('top')
......@@ -2035,7 +2044,8 @@ class TestCausalConv(unittest.TestCase):
def test_interface(self):
img_sym = theano.tensor.tensor3('img')
kern_sym = theano.tensor.tensor3('kern')
if not theano.tensor.nnet.abstract_conv.imported_scipy_signal:
raise SkipTest("SciPy needed")
sym_out = causal_conv1d(img_sym, kern_sym, self.kern.shape, filter_dilation=self.dilation)
causal_func = theano.function([img_sym, kern_sym], sym_out, mode=self.mode)
......
......@@ -42,6 +42,7 @@ if rank == 0:
_, zz = f(xx)
same = np.linalg.norm(zz - expected) < .001
# The parent test will look for "True" in the output
stdout.write(str(same))
if rank == 1:
......
from __future__ import absolute_import, print_function, division
from theano.tensor.io import (send, recv, mpi_cmps, MPISend, MPISendWait,
mpi_send_wait_cmp, mpi_tag_cmp, mpi_enabled)
import theano
import subprocess
import os
from theano.gof.sched import sort_schedule_fn
from theano import change_flags
import subprocess
from nose.plugins.skip import SkipTest
import theano
from theano import change_flags
from theano.compat import PY3
from theano.gof.sched import sort_schedule_fn
from theano.tensor.io import (send, recv, mpi_cmps, MPISend, MPISendWait,
mpi_send_wait_cmp, mpi_tag_cmp, mpi_enabled)
mpi_scheduler = sort_schedule_fn(*mpi_cmps)
mpi_linker = theano.OpWiseCLinker(schedule=mpi_scheduler)
mpi_mode = theano.Mode(linker=mpi_linker)
......@@ -45,15 +46,21 @@ def test_mpi_roundtrip():
if not mpi_enabled:
raise SkipTest('MPI not enabled')
theano_root = theano.__file__.split('__init__')[0]
d = {}
if PY3:
# Is some not understood cases, the subprocess never finish.
d = dict(timeout=5*60)
p = subprocess.Popen("mpiexec -np 2 python " + theano_root +
"tensor/tests/_test_mpi_roundtrip.py",
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
close_fds=True)
result = theano.compat.decode(p.stdout.read())
assert "True" in result, theano.compat.decode(p.stderr.read())
close_fds=True, **d)
(stdout, stderr) = p.communicate()
result = theano.compat.decode(stdout)
assert "True" in result, theano.compat.decode(stderr)
def test_mpi_send_wait_cmp():
......
......@@ -139,7 +139,7 @@ def test_format_flake8():
raise AssertionError("FLAKE8 Format not respected")
def print_files_information_flake8():
def print_files_information_flake8(files):
"""
Print the list of files which can be removed from the whitelist and the
list of files which do not respect FLAKE8 formatting that aren't in the
......@@ -147,7 +147,9 @@ def print_files_information_flake8():
"""
infracting_files = []
non_infracting_files = []
for path in list_files():
if not files:
files = list_files()
for path in files:
rel_path = os.path.relpath(path, theano.__path__[0])
number_of_infractions = flake8.main.check_file(path,
ignore=ignore)
......@@ -186,4 +188,4 @@ def check_all_files(dir_path=theano.__path__[0], pattern='*.py'):
if __name__ == "__main__":
print_files_information_flake8()
print_files_information_flake8(sys.argv[1:])
......@@ -15,6 +15,9 @@ try:
release = True
except ValueError:
release = False
except IndexError:
print(short_version)
raise
if release:
version = short_version
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论