提交 0cc0a9d9 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Python 2.4 compatibility fixes

上级 12152e3d
...@@ -16,6 +16,7 @@ from theano import tensor ...@@ -16,6 +16,7 @@ from theano import tensor
from theano import compile from theano import compile
from theano import scalar from theano import scalar
from theano import config from theano import config
from theano.gof.python25 import all, any
#TODO: move this decorator to the compile submodule #TODO: move this decorator to the compile submodule
def register_specialize(lopt, *tags, **kwargs): def register_specialize(lopt, *tags, **kwargs):
......
...@@ -13,6 +13,7 @@ from scipy import sparse as scipy_sparse ...@@ -13,6 +13,7 @@ from scipy import sparse as scipy_sparse
import theano import theano
import theano.sparse import theano.sparse
from theano import sparse, gof, Op, tensor from theano import sparse, gof, Op, tensor
from theano.gof.python25 import all, any
from theano.printing import Print from theano.printing import Print
def register_specialize(lopt, *tags, **kwargs): def register_specialize(lopt, *tags, **kwargs):
...@@ -346,16 +347,22 @@ class ConvolutionIndices(Op): ...@@ -346,16 +347,22 @@ class ConvolutionIndices(Op):
insize = N.prod(inshp) insize = N.prod(inshp)
# range of output units over which to iterate # range of output units over which to iterate
lbound = N.array([kshp[0]-1,kshp[1]-1]) if mode=='valid' else N.zeros(2) if mode == 'valid':
ubound = lbound + (inshp[1:]-kshp+1) if mode=='valid' else fulloutshp lbound = N.array([kshp[0]-1,kshp[1]-1])
ubound = lbound + (inshp[1:]-kshp+1)
else:
lbound = N.zeros(2)
ubound = fulloutshp
# coordinates of image in "fulloutshp" coordinates # coordinates of image in "fulloutshp" coordinates
topleft = N.array([kshp[0]-1,kshp[1]-1]) topleft = N.array([kshp[0]-1,kshp[1]-1])
botright = topleft + inshp[1:] # bound when counting the receptive field botright = topleft + inshp[1:] # bound when counting the receptive field
# sparse matrix specifics... # sparse matrix specifics...
spmatshp = (outsize*N.prod(kshp)*inshp[0],insize) if ws else\ if ws:
(nkern*outsize,insize) spmatshp = (outsize * N.prod(kshp) * inshp[0], insize)
else:
spmatshp = (nkern * outsize, insize)
spmat = scipy_sparse.lil_matrix(spmatshp) spmat = scipy_sparse.lil_matrix(spmatshp)
# loop over output image pixels # loop over output image pixels
...@@ -396,11 +403,16 @@ class ConvolutionIndices(Op): ...@@ -396,11 +403,16 @@ class ConvolutionIndices(Op):
fmapi*N.prod(inshp[1:]) # taking into account multiple input features fmapi*N.prod(inshp[1:]) # taking into account multiple input features
# convert oy,ox values to output space coordinates # convert oy,ox values to output space coordinates
(y,x) = (oy,ox) if mode=='full' else (oy,ox) - topleft if mode == 'full':
(y, x) = (oy, ox)
else:
(y, x) = (oy, ox) - topleft
(y,x) = N.array([y,x]) / (dy,dx) # taking into account step size (y,x) = N.array([y,x]) / (dy,dx) # taking into account step size
# convert to row index of sparse matrix # convert to row index of sparse matrix
row = (y*outshp[1]+x)*inshp[0]*ksize + l + fmapi*ksize if ws else\ if ws:
y*outshp[1] + x row = (y*outshp[1]+x)*inshp[0]*ksize + l + fmapi*ksize
else:
row = y*outshp[1] + x
# Store something at that location in sparse matrix. # Store something at that location in sparse matrix.
# The written value is only useful for the sparse case. It # The written value is only useful for the sparse case. It
...@@ -444,7 +456,8 @@ class ConvolutionIndices(Op): ...@@ -444,7 +456,8 @@ class ConvolutionIndices(Op):
rval = (spmat.indices[:spmat.size], rval = (spmat.indices[:spmat.size],
spmat.indptr, spmatshp, sptype, outshp) spmat.indptr, spmatshp, sptype, outshp)
rval += (kmap,) if kmap!=None else () if kmap is not None:
rval += (kmap,)
return rval return rval
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论