提交 36a01bb6 authored 作者: nouiz's avatar nouiz

Merge pull request #556 from lamblin/fix_cudandarray_python24

Fix a number of tests for Python 2.4
......@@ -5,6 +5,8 @@ import theano
from theano import Op, Type, Apply, Variable, Constant
from theano import tensor, scalar, config
from theano.gof.python25 import all, any
from theano.sandbox.cuda import GpuOp
from theano.sandbox.cuda.type import CudaNdarrayType
from theano.sandbox.cuda import filter as type_support_filter
......@@ -1754,7 +1756,17 @@ class GpuSubtensor(tensor.Subtensor, GpuOp):
def convert(entry):
if isinstance(entry, Type):
return indices.pop()
rval = indices.pop()
if sys.version_info < (2, 5):
# Before Python 2.5, PySlice_GetIndicesEx requires
# Python int to be passed.
rval_ = int(rval)
if rval_ != rval:
raise IndexError((
"Invalid value for indexing: %s. "
"That value may be too big.") % rval)
return rval_
return rval
elif isinstance(entry, slice):
return slice(convert(entry.start),
convert(entry.stop),
......
......@@ -868,11 +868,15 @@ nd_collapse_[i]=0;
#check that all inputs have valid dimensions
emitted_inames = {}
for id,iname in enumerate(inputs):
for id, iname in enumerate(inputs):
if iname in emitted_inames:
assert emitted_inames[iname] is node.inputs[id]
continue
broadcasts = ', '.join(map(str,map(int,node.inputs[id].broadcastable)))
# with python 2.4 (at least), if a broadcastable pattern is made of
# numpy.bool_ instead of bool, calling int() once is not enough.
broadcasts = map(int, map(int, node.inputs[id].broadcastable))
broadcasts = ', '.join(map(str, broadcasts))
nd = node.inputs[id].ndim
if nd > 0:
print >> sio, """
......@@ -883,9 +887,10 @@ nd_collapse_[i]=0;
int *broadcasts_%(iname)s = NULL;
""" % locals()
emitted_inames[iname] = node.inputs[id]
#check that all inputs have valid dimensions
emitted_inames = {}
for id,iname in enumerate(inputs):
for id, iname in enumerate(inputs):
if iname in emitted_inames:
continue
print >> sio, """
......
......@@ -2,16 +2,18 @@ import logging
_logger = logging.getLogger('theano.sandbox.cuda.opt')
import sys
import theano
import numpy
from theano.scan_module import scan_utils, scan_op
import theano
from theano import scalar as scal
from theano import tensor, compile, gof
from theano.compile import optdb
from theano.gof import (local_optimizer, EquilibriumDB, SequenceDB, ProxyDB,
Optimizer, toolbox, DestroyHandler,
EquilibriumOptimizer)
from theano.gof.python25 import all, any
from theano.sandbox.cuda.basic_ops import *
from theano.sandbox.cuda.type import CudaNdarrayType
from theano.sandbox.cuda.blas import (gpu_dot22, gpu_dot22scalar,
......@@ -27,7 +29,7 @@ from theano.sandbox.cuda.nnet import (
GpuCrossentropySoftmax1HotWithBiasDx,
GpuSoftmax, GpuSoftmaxWithBias)
from theano.sandbox.cuda.elemwise import SupportCodeError
from theano.compile import optdb
from theano.scan_module import scan_utils, scan_op
from theano.tensor.blas import _is_real_vector, _is_real_matrix
#optdb.print_summary() # shows what is currently registered
......
......@@ -7,9 +7,9 @@ __copyright__ = "(c) 2011, University of Montreal"
__license__ = "3-clause BSD License"
__contact__ = "theano-dev@googlegroups.com"
import sys
import numpy
import theano.gof
from theano.gof.python25 import all
from theano.sandbox.cuda import CudaNdarrayType, GpuOp
from theano.tensor import (get_vector_length, cast, opt)
from theano.compile import optdb
......
......@@ -13,6 +13,7 @@ import theano.sandbox.cuda as cuda_ndarray
if cuda_ndarray.cuda_available == False:
raise SkipTest('Optional package cuda disabled')
from theano.gof.python25 import any
import theano.sandbox.cuda as tcn
import theano.sandbox.cuda as cuda
import theano.sandbox.cuda.basic_ops as B
......
......@@ -16,6 +16,7 @@ import theano.sandbox.cuda as tcn
from theano.tensor.signal.downsample import (DownsampleFactorMax,
DownsampleFactorMaxGrad)
from theano.gof.python25 import any
import theano.compile.mode
from theano.tensor.tests.test_blas import BaseGemv, TestBlasStrides, TestGer
......
......@@ -5,6 +5,7 @@ from nose.plugins.skip import SkipTest
import numpy
import theano
from theano.gof.python25 import all
import theano.sandbox.cuda as cuda_ndarray
from theano.tensor.basic import _allclose
from theano.tests import unittest_tools as utt
......
......@@ -7,6 +7,7 @@ import theano.sandbox.cuda as cuda_ndarray
if cuda_ndarray.cuda_available == False:
raise SkipTest('Optional package cuda disabled')
from theano.gof.python25 import any
import theano.sandbox.cuda as cuda
import theano.sandbox.cuda.basic_ops as B
......
......@@ -2,6 +2,7 @@ from nose.plugins.skip import SkipTest
import numpy
import theano
from theano.gof.python25 import any
import theano.tensor as T
import theano.tests.unittest_tools as utt
......
......@@ -2,6 +2,7 @@ import theano
from theano import Op, Apply
import theano.tensor as T
from theano.gof import local_optimizer
from theano.gof.python25 import any
from theano.sandbox.cuda import cuda_available, GpuOp
if cuda_available:
......
......@@ -6,6 +6,7 @@ import theano
from theano import config, function, tensor
import multinomial
from theano.compile.mode import get_default_mode, predefined_linkers
from theano.gof.python25 import any
import theano.sandbox.cuda as cuda
def get_mode(gpu):
......
......@@ -7,6 +7,7 @@ from neighbours import (images2neibs, neibs2images,
# Skip test if cuda_ndarray is not available.
from nose.plugins.skip import SkipTest
import theano.sandbox.cuda as cuda
from theano.gof.python25 import any
from theano.tests import unittest_tools
......
......@@ -4126,7 +4126,17 @@ class IncSubtensor(Op):
def convert(entry):
if isinstance(entry, gof.Type):
return indices.pop()
rval = indices.pop()
if sys.version_info < (2, 5):
# Before Python 2.5, PySlice_GetIndicesEx requires
# Python int to be passed.
rval_ = int(rval)
if rval_ != rval:
raise IndexError((
"Invalid value for indexing: %s. "
"That value may be too big.") % rval)
return rval_
return rval
elif isinstance(entry, slice):
return slice(convert(entry.start),
convert(entry.stop),
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论