提交 4fe8381e authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Merge pull request #792 from nouiz/fix_py2.4

small Fix py2.4
...@@ -41,17 +41,23 @@ if (not hasattr(theano.sandbox, 'cuda') or ...@@ -41,17 +41,23 @@ if (not hasattr(theano.sandbox, 'cuda') or
import pycuda.autoinit import pycuda.autoinit
pycuda_available = True pycuda_available = True
else: else:
import pycuda.driver try:
if hasattr(pycuda.driver.Context, "attach"): import pycuda.driver
pycuda.driver.Context.attach() pycuda_available = True
else: except ImportError:
# Now we always import this file when we call theano.sandbox.cuda.use pass
# So this should not happen normally. if pycuda_available:
# TODO: make this an error. if hasattr(pycuda.driver.Context, "attach"):
warnings.warn("For some unknow reason, theano.misc.pycuda_init was not" pycuda.driver.Context.attach()
" imported before Theano initialized the GPU and" else:
" your PyCUDA version is 2011.2.2 or earlier." # Now we always import this file when we call
" To fix the problem, import theano.misc.pycuda_init" # theano.sandbox.cuda.use. So this should not happen
" manually before using/initializing the GPU, use the" # normally.
" Theano flag pycuda.init=True or use a" # TODO: make this an error.
" more recent version of PyCUDA.") warnings.warn("For some unknow reason, theano.misc.pycuda_init was"
" not imported before Theano initialized the GPU and"
" your PyCUDA version is 2011.2.2 or earlier."
" To fix the problem, import theano.misc.pycuda_init"
" manually before using/initializing the GPU, use the"
" Theano flag pycuda.init=True or use a"
" more recent version of PyCUDA.")
...@@ -89,7 +89,7 @@ class Fourier(gof.Op): ...@@ -89,7 +89,7 @@ class Fourier(gof.Op):
if len(shape_a) == 1: if len(shape_a) == 1:
return [(n,)] return [(n,)]
elif isinstance(axis, tensor.TensorConstant): elif isinstance(axis, tensor.TensorConstant):
out_shape = list(shape_a[0: axis.data]) + [n] +\ out_shape = list(shape_a[0: axis.data.item()]) + [n] +\
list(shape_a[axis.data + 1:]) list(shape_a[axis.data + 1:])
else: else:
l = len(shape_a) l = len(shape_a)
...@@ -105,7 +105,7 @@ class Fourier(gof.Op): ...@@ -105,7 +105,7 @@ class Fourier(gof.Op):
a = inputs[0] a = inputs[0]
n = inputs[1] n = inputs[1]
axis = inputs[2] axis = inputs[2]
output_storage[0][0] = numpy.fft.fft(a, n=int(n), axis=axis) output_storage[0][0] = numpy.fft.fft(a, n=int(n), axis=axis.item())
def grad(self, inputs, cost_grad): def grad(self, inputs, cost_grad):
""" """
......
...@@ -121,7 +121,7 @@ class Conv3D(theano.Op): ...@@ -121,7 +121,7 @@ class Conv3D(theano.Op):
def perform(self, node, inputs, output_storage): def perform(self, node, inputs, output_storage):
V, W, b, d = inputs V, W, b, d = inputs
print "Conv3D python code" # print "Conv3D python code"
output_storage[0][0] = computeH(V,W,b,d) output_storage[0][0] = computeH(V,W,b,d)
def infer_shape(self, node, input_shapes): def infer_shape(self, node, input_shapes):
......
...@@ -44,7 +44,7 @@ class ConvGrad3D(theano.Op): ...@@ -44,7 +44,7 @@ class ConvGrad3D(theano.Op):
def perform(self, node, inputs, output_storage): def perform(self, node, inputs, output_storage):
V, d, WShape, dCdH = inputs V, d, WShape, dCdH = inputs
print "ConvGradW3D python code" # print "ConvGradW3D python code"
#partial C / partial W[j,z,k,l,m] = sum_i sum_p sum_q sum_r (partial C /partial H[i,j,p,q,r] ) * V[i,z,dr*p+k,dc*q+l,dt*r+m] #partial C / partial W[j,z,k,l,m] = sum_i sum_p sum_q sum_r (partial C /partial H[i,j,p,q,r] ) * V[i,z,dr*p+k,dc*q+l,dt*r+m]
......
...@@ -83,7 +83,7 @@ class ConvTransp3D(theano.Op): ...@@ -83,7 +83,7 @@ class ConvTransp3D(theano.Op):
def perform(self, node, inputs, output_storage): def perform(self, node, inputs, output_storage):
W, b, d, H, RShape = inputs W, b, d, H, RShape = inputs
print "\t\t\t\tConvTransp3D python code" # print "\t\t\t\tConvTransp3D python code"
output_storage[0][0] = computeR(W,b,d,H,RShape) output_storage[0][0] = computeR(W,b,d,H,RShape)
def c_code(self, node, nodename, inputs, outputs, sub): def c_code(self, node, nodename, inputs, outputs, sub):
......
...@@ -97,8 +97,8 @@ class DummyConvTransp3D: ...@@ -97,8 +97,8 @@ class DummyConvTransp3D:
self.dW = rng.uniform(-1, 1, self.W.get_value(borrow=True).shape) self.dW = rng.uniform(-1, 1, self.W.get_value(borrow=True).shape)
self.db = rng.uniform(-1, 1, self.b.get_value(borrow=True).shape) self.db = rng.uniform(-1, 1, self.b.get_value(borrow=True).shape)
self.dH = rng.uniform(-1, 1, self.H.get_value(borrow=True).shape) self.dH = rng.uniform(-1, 1, self.H.get_value(borrow=True).shape)
self.dW, self.db, self.dH = shared(self.dW), shared(self.db), self.dW, self.db = shared(self.dW), shared(self.db),
shared(self.dH) self.dH = shared(self.dH)
self.d = d self.d = d
self.RShape = RShape self.RShape = RShape
......
...@@ -276,7 +276,7 @@ class T_prepend(utt.InferShapeTester): ...@@ -276,7 +276,7 @@ class T_prepend(utt.InferShapeTester):
def test0(self): def test0(self):
x = tensor.matrix('x') x = tensor.matrix('x')
y = Prepend_scalar_constant_to_each_row(4.)(x) y = Prepend_scalar_constant_to_each_row(4.)(x)
f = theano.function([x], [y]) f = theano.function([x], y)
m = numpy.random.rand(3, 5) m = numpy.random.rand(3, 5)
my = f(m) my = f(m)
self.assertTrue(my.shape == (3, 6), my.shape) self.assertTrue(my.shape == (3, 6), my.shape)
......
...@@ -1245,6 +1245,8 @@ if imported_scipy_special: ...@@ -1245,6 +1245,8 @@ if imported_scipy_special:
else: else:
expected_erf = [] expected_erf = []
expected_erfc = [] expected_erfc = []
expected_gammaln = []
expected_psi = []
skip_scipy = "scipy is not present" skip_scipy = "scipy is not present"
ErfTester = makeBroadcastTester( ErfTester = makeBroadcastTester(
......
...@@ -8,6 +8,7 @@ import numpy ...@@ -8,6 +8,7 @@ import numpy
from numpy.testing import dec from numpy.testing import dec
import theano import theano
from theano.gof.python25 import all
from theano.gof import Variable, Op from theano.gof import Variable, Op
from theano import gof, scalar, config from theano import gof, scalar, config
......
...@@ -16,6 +16,7 @@ from theano import tensor ...@@ -16,6 +16,7 @@ from theano import tensor
import theano.ifelse import theano.ifelse
from theano.ifelse import IfElse, ifelse from theano.ifelse import IfElse, ifelse
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
from theano.gof.python25 import all
class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin): class test_ifelse(unittest.TestCase, utt.TestOptimizationMixin):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论