提交 2848ff23 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Fixed some broken tests when scipy is not available

上级 c2ee569c
import numpy import numpy
import theano import theano
import theano.sparse # To know if scipy is available.
from theano import tensor, function from theano import tensor, function
from theano.tensor.basic import _allclose from theano.tensor.basic import _allclose
from theano.sandbox.linalg.ops import * from theano.sandbox.linalg.ops import *
from nose.plugins.skip import SkipTest
if 0: if 0:
def test_cholesky(): def test_cholesky():
#TODO: test upper and lower triangular #TODO: test upper and lower triangular
...@@ -59,6 +63,11 @@ def test_inverse_grad(): ...@@ -59,6 +63,11 @@ def test_inverse_grad():
def test_det_grad(): def test_det_grad():
# If scipy is not available, this test will fail, thus we skip it.
# Note that currently we re-use the `enable_sparse` flag, but it may be
# cleaner to have a different `scipy_available` flag in the future.
if not theano.sparse.enable_sparse:
raise SkipTest('Scipy is not available')
rng = numpy.random.RandomState(1234) rng = numpy.random.RandomState(1234)
r = rng.randn(5,5) r = rng.randn(5,5)
......
import sys import sys
from nose.plugins.skip import SkipTest
import theano.sparse
if not theano.sparse.enable_sparse:
raise SkipTest('Optional package sparse disabled')
from theano import function, Mode from theano import function, Mode
from theano.gof import OpWiseCLinker from theano.gof import OpWiseCLinker
import theano, numpy import theano, numpy
import theano.tensor as T import theano.tensor as T
import theano.sparse
import scipy.sparse import scipy.sparse
from scipy.signal import convolve2d from scipy.signal import convolve2d
......
import unittest import unittest
import theano import theano
import theano.tensor as T import theano.tensor as T
from theano import function from theano import function, shared
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
from theano.tensor.nnet.ConvTransp3D import convTransp3D from theano.tensor.nnet.ConvTransp3D import convTransp3D
from theano.tensor.nnet.ConvGrad3D import convGrad3D from theano.tensor.nnet.ConvGrad3D import convGrad3D
from theano.tensor.nnet.Conv3D import conv3D from theano.tensor.nnet.Conv3D import conv3D
import numpy as N import numpy as N
import copy import copy
from scipy import sparse import theano.sparse
from theano import shared if theano.sparse.enable_sparse:
from scipy import sparse
from nose.plugins.skip import SkipTest
floatX = theano.config.floatX floatX = theano.config.floatX
...@@ -311,6 +313,8 @@ class TestConv3D(unittest.TestCase): ...@@ -311,6 +313,8 @@ class TestConv3D(unittest.TestCase):
def test_c_against_sparse_mat_transp_mul(self): def test_c_against_sparse_mat_transp_mul(self):
#like test_c_against_mat_transp_mul but using a sparse matrix and a kernel that is smaller than the image #like test_c_against_mat_transp_mul but using a sparse matrix and a kernel that is smaller than the image
if not theano.sparse.enable_sparse:
raise SkipTest('Optional package sparse disabled')
batchSize = self.rng.randint(1,3) batchSize = self.rng.randint(1,3)
filterWidth = self.rng.randint(1,8) filterWidth = self.rng.randint(1,8)
......
...@@ -7,6 +7,7 @@ from theano.gof.python25 import all ...@@ -7,6 +7,7 @@ from theano.gof.python25 import all
from theano import tensor from theano import tensor
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
from theano.misc.may_share_memory import may_share_memory from theano.misc.may_share_memory import may_share_memory
import theano.sparse
utt.seed_rng() utt.seed_rng()
...@@ -445,7 +446,8 @@ def makeSharedTester(shared_constructor_, ...@@ -445,7 +446,8 @@ def makeSharedTester(shared_constructor_,
topo_cst[0].op == theano.compile.function_module.deep_copy_op topo_cst[0].op == theano.compile.function_module.deep_copy_op
# Test that we can take the grad. # Test that we can take the grad.
if isinstance(x1_specify_shape.type, theano.sparse.SparseType): if (theano.sparse.enable_sparse and
isinstance(x1_specify_shape.type, theano.sparse.SparseType)):
#SparseVariable don't support sum for now. #SparseVariable don't support sum for now.
assert not hasattr(x1_specify_shape, 'sum') assert not hasattr(x1_specify_shape, 'sum')
else: else:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论