提交 2febf197 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #1398 from HapeMask/py3k-fixes

Py3k Fixes Part 2
......@@ -8,7 +8,7 @@ class CallCache(object):
try:
if filename is None:
raise IOError('bad filename') #just goes to except
f = file(filename, 'r')
f = open(filename, 'r')
self.cache = cPickle.load(f)
f.close()
except IOError:
......@@ -20,7 +20,7 @@ class CallCache(object):
#backport
#filename = self.filename if filename is None else filename
f = file(filename, 'w')
f = open(filename, 'w')
cPickle.dump(self.cache, f)
f.close()
......
......@@ -635,10 +635,8 @@ class GpuCAReduce(GpuOp):
# but tensor.elemwise.CAReduce has this exact same check so I guess
# this is OK to do
if self.scalar_op in [scal.minimum, scal.maximum]:
conds = []
for i in xrange(nd_in):
if self.reduce_mask[i]:
conds.append("(CudaNdarray_HOST_DIMS(%(x)s)[%(i)s] == 0)" % locals())
conds = ["(CudaNdarray_HOST_DIMS(%s)[%d] == 0)" % (x, i) for i in xrange(nd_in) \
if self.reduce_mask[i]]
assert len(conds) > 0
cond = "(" + " || ".join(conds) + ")"
print >> sio, """
......@@ -663,7 +661,7 @@ class GpuCAReduce(GpuOp):
j = 0
for i in xrange(nd_in):
if not self.reduce_mask[i]:
print >> sio, " || (CudaNdarray_HOST_DIMS(%(z)s)[%(j)s] !=CudaNdarray_HOST_DIMS(%(x)s)[%(i)s]) " % locals()
print >> sio, " || (CudaNdarray_HOST_DIMS(%(z)s)[%(j)s] !=CudaNdarray_HOST_DIMS(%s)[%d]) " % (x, i)
j += 1
print >> sio, """
......@@ -791,7 +789,7 @@ class GpuCAReduce(GpuOp):
""" % locals()
shapes_format = "shape=(%s)" % ",".join(["%d"] * node.inputs[0].ndim)
shapes_data = ",".join(["CudaNdarray_HOST_DIMS(%(x)s)[%(i)s]" % locals()
shapes_data = ",".join(["CudaNdarray_HOST_DIMS(%s)[%d]" % (x, i)
for i in range(node.inputs[0].ndim)])
print >> sio, """
);
......
#ifndef _CUDA_NDARRAY_H
#define _CUDA_NDARRAY_H
// Defines for Python 2/3 compatibility.
#if PY_MAJOR_VERSION == 3
// Py3k treats all ints as longs.
#define PyInt_Check PyLong_Check
#define PyInt_CheckExact PyLong_CheckExact
#define PyInt_AsLong PyLong_AsLong
#define PyInt_FromLong PyLong_FromLong
#define PyNumber_Int PyNumber_Long
// Py3k strings are unicode, these mimic old functionality.
#define PyString_Check PyUnicode_Check
#define PyString_FromString PyUnicode_FromString
#define PyString_AsString PyUnicode_AsUTF8
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
#define PyString_Size PyUnicode_GET_SIZE
#define PyCObject_AsVoidPtr NpyCapsule_AsVoidPtr
#define PyCObject_GetDesc NpyCapsule_GetDesc
#define PyCObject_Check NpyCapsule_Check
// Python 3 expects a PyObject* as the first argument to PySlice_GetIndicesEx().
#define SLICE_CAST(x) (x)
#else
// Python 2 expects a PySliceObject* as the first argument to PySlice_GetIndicesEx().
#define SLICE_CAST(x) ((PySliceObject*)(x))
#endif
#include <numpy/arrayobject.h>
#include <stdio.h>
......
......@@ -9,6 +9,7 @@ import warnings
import numpy
from theano.compat import decode, decode_iter
from theano.gof import local_bitwidth
from theano.gof.cc import hash_from_file
from theano.gof.cmodule import (std_libs, std_lib_dirs,
......@@ -69,10 +70,13 @@ def is_nvcc_available():
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
p.wait()
s = p.stdout.readlines()[-1].split(',')[1].strip().split()
assert s[0] == 'release'
ver_line = decode(p.stdout.readlines()[-1])
build, version = ver_line.split(',')[1].strip().split()
assert build == 'release'
global nvcc_version
nvcc_version = s[1]
nvcc_version = version
try:
set_version()
return True
......@@ -247,7 +251,7 @@ class NVCC_compiler(object):
lib_dirs.append(python_lib)
cppfilename = os.path.join(location, 'mod.cu')
cppfile = file(cppfilename, 'w')
cppfile = open(cppfilename, 'w')
_logger.debug('Writing module C++ code to %s', cppfilename)
......@@ -354,7 +358,7 @@ class NVCC_compiler(object):
os.chdir(location)
p = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
nvcc_stdout, nvcc_stderr = p.communicate()[:2]
nvcc_stdout, nvcc_stderr = decode_iter(p.communicate()[:2])
finally:
os.chdir(orig_dir)
......@@ -401,7 +405,7 @@ class NVCC_compiler(object):
if py_module:
#touch the __init__ file
file(os.path.join(location, "__init__.py"), 'w').close()
open(os.path.join(location, "__init__.py"), 'w').close()
return dlimport(lib_filename)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论