提交 4155d8bb authored 作者: Gabe Schwartz's avatar Gabe Schwartz

Replaced plain StringIO with the one from six.py.

StringIO was moved in python 3.
上级 2febf197
......@@ -7,13 +7,13 @@ __docformat__ = "restructuredtext en"
import copy, sys, copy_reg, gc
from itertools import izip
from StringIO import StringIO
import numpy
import theano
from theano import gof
from theano.compat import get_unbound_function
from theano.compat.six import StringIO
from theano.gof import FunctionGraph,graph, utils, link, ops_with_inner_function
from theano.gof.link import raise_with_op
from theano.gof.cc import CLinker
......
......@@ -720,9 +720,10 @@ def test_pickle_aliased_memory():
m.x[0,0] = 3.14
assert m.y[0,0] == 3.14
import StringIO, logging
import logging
from theano.compat.six import StringIO
sio = StringIO.StringIO()
sio = StringIO()
handler = logging.StreamHandler(sio)
logging.getLogger('theano.compile.function_module').addHandler(handler)
# Silence original handler when intentionnally generating warning messages
......
......@@ -7,7 +7,7 @@ import os
import sys
import warnings
import StringIO
from theano.compat.six import StringIO
import theano
from theano.compat import configparser as ConfigParser
......@@ -150,7 +150,7 @@ class TheanoConfigParser(object):
_i_am_a_config_class = True
def __str__(self):
sio = StringIO.StringIO()
sio = StringIO()
_config_print(self.__class__, sio)
return sio.getvalue()
......
......@@ -5,13 +5,13 @@ Defines Linkers that deal with C implementations.
# Python imports
from copy import copy
import os
import StringIO
import sys
from itertools import izip
import numpy
from theano.compat import PY3
from theano.compat.six import StringIO
if PY3:
import hashlib
......@@ -1320,7 +1320,7 @@ class CLinker(link.Linker):
return ret
def instantiate_code(self, n_args):
code = StringIO.StringIO()
code = StringIO()
struct_name = self.struct_name
print >> code, "static PyObject * instantiate(PyObject * self, PyObject *argtuple) {"
print >> code, ' assert(PyTuple_Check(argtuple));'
......
......@@ -8,7 +8,6 @@ import os
import re
import shutil
import stat
import StringIO
import subprocess
import sys
import tempfile
......@@ -21,6 +20,7 @@ import numpy.distutils # TODO: TensorType should handle this
import theano
from theano.compat import PY3, next, decode, decode_iter
from theano.compat.six import StringIO
from theano.gof.utils import flatten
from theano.configparser import config
from theano.gof.cc import hash_from_code
......@@ -196,7 +196,7 @@ static struct PyModuleDef moduledef = {{
self.functions.append(fn)
def code(self):
sio = StringIO.StringIO()
sio = StringIO()
for inc in self.includes:
if not inc:
continue
......
......@@ -274,7 +274,7 @@ class SeqOptimizer(Optimizer, list):
new_sub_profile.append(None)
# merge not common opt
import StringIO
from theano.compat.six import StringIO
for l in set(prof1[0]).symmetric_difference(set(prof2[0])):
#The set trick above only work for the same object optimization
#It don't work for equivalent optimization.
......@@ -282,8 +282,8 @@ class SeqOptimizer(Optimizer, list):
new_l_names = [o.name for o in new_l]
if l.name in new_l_names:
idx = new_l_names.index(l.name)
io1 = StringIO.StringIO()
io2 = StringIO.StringIO()
io1 = StringIO()
io2 = StringIO()
l.print_summary(io1)
new_l[idx].print_summary(io2)
if io1.read() == io2.read():
......
import StringIO
import sys
from theano.gof.python25 import DefaultOrderedDict
import numpy
from theano.compat.six import StringIO
from theano.gof import opt
from theano.configparser import AddConfigVar, FloatParam
from theano import config
......@@ -258,7 +258,7 @@ class SequenceDB(DB):
print >> stream, " db", self.__db__
def __str__(self):
sio = StringIO.StringIO()
sio = StringIO()
self.print_summary(sio)
return sio.getvalue()
......
......@@ -5,7 +5,6 @@ import difflib
import operator
import os
import string
from StringIO import StringIO
from subprocess import Popen, PIPE
import sys
import tabnanny
......@@ -13,6 +12,7 @@ import tokenize
import argparse
import reindent
from theano.compat.six.StringIO import StringIO
SKIP_WHITESPACE_CHECK_FILENAME = ".hg/skip_whitespace_check"
......
......@@ -6,7 +6,6 @@ in a graph(Print Op)
from copy import copy
import logging
import os
import StringIO
import sys
# Not available on all platforms
hashlib = None
......@@ -26,6 +25,7 @@ except ImportError:
import theano
from theano import gof
from theano import config
from theano.compat.six import StringIO
from theano.gof import Op, Apply
from theano.gof.python25 import any
from theano.compile import Function, debugmode
......@@ -74,7 +74,7 @@ def debugprint(obj, depth=-1, print_type=False,
"""
if file == 'str':
_file = StringIO.StringIO()
_file = StringIO()
elif file is None:
_file = sys.stdout
else:
......
import copy
import logging
import StringIO
import sys
import numpy
......@@ -8,6 +7,7 @@ import numpy
import theano
from theano import Op, Type, Apply, Variable, Constant
from theano import tensor, scalar, config
from theano.compat.six import StringIO
from theano.scalar import Scalar
scal = scalar # somewhere scalar gets reassigned to be a function
......@@ -385,7 +385,7 @@ class GpuDimShuffle(GpuOp):
nd_in = len(self.input_broadcastable)
nd_out = len(self.new_order)
sio = StringIO.StringIO()
sio = StringIO()
fail = sub['fail']
#check input
......@@ -618,7 +618,7 @@ class GpuCAReduce(GpuOp):
assert nd_in - nd_out == sum(self.reduce_mask)
sio = StringIO.StringIO()
sio = StringIO()
fail = sub['fail']
#check input
......@@ -750,7 +750,7 @@ class GpuCAReduce(GpuOp):
%(fail)s;
}
"""
sio = StringIO.StringIO()
sio = StringIO()
if pattern is None:
pattern = ''.join(str(c) for c in self.reduce_mask)
ndim = len(self.reduce_mask)
......@@ -843,7 +843,7 @@ class GpuCAReduce(GpuOp):
ndim = len(reduce_mask)
if pattern is None:
pattern = ''.join(str(i) for i in reduce_mask)
sio = StringIO.StringIO()
sio = StringIO()
print >> sio, """
static __global__ void kernel_reduce_%(pattern)s_%(nodename)s(
......@@ -1590,7 +1590,7 @@ class GpuCAReduce(GpuOp):
raise NotImplementedError()
def c_support_code_apply(self, node, nodename):
sio = StringIO.StringIO()
sio = StringIO()
nd_in = len(self.reduce_mask)
if all(i == 1 for i in self.reduce_mask):
self._op_guard()
......
import copy
import os
import StringIO
import theano
from theano import Apply
from theano import tensor
from theano.compat.six import StringIO
from theano.sandbox.cuda.type import CudaNdarrayType
from theano.sandbox.cuda import GpuOp
......@@ -226,7 +226,7 @@ class GpuGemm(GpuOp):
z_out, = outputs
inplace = int(self.inplace)
fail = sub['fail']
sio = StringIO.StringIO()
sio = StringIO()
print >> sio, """
......@@ -341,7 +341,7 @@ class GpuGemv(GpuOp):
z_out, = outputs
inplace = int(self.inplace)
fail = sub['fail']
sio = StringIO.StringIO()
sio = StringIO()
print >> sio, """
float %(name)s_alpha = ((dtype_%(a)s*)(%(a)s->data))[0];
......@@ -438,7 +438,7 @@ class GpuGer(GpuOp):
z_out, = outputs
inplace = int(self.inplace)
fail = sub['fail']
sio = StringIO.StringIO()
sio = StringIO()
print >> sio, """
float %(name)s_alpha = ((dtype_%(a)s*)(%(a)s->data))[0];
......
......@@ -5,12 +5,13 @@ The elemwise fct are also used with scalar operation! So it can happen that ndim
"""
import copy, logging, StringIO, sys
import copy, logging, sys
import numpy
from theano.scalar.basic import upgrade_to_float_no_complex, complex_types
from theano.scalar.basic_scipy import Erfinv
from theano.compat.six import StringIO
from theano import Apply, Constant, Op, Type, Variable
from theano import gof, scalar, tensor
......@@ -65,7 +66,7 @@ class NaiveAlgo(object):
self.inplace_pattern = inplace_pattern
def c_src_kernel(self, node, nodename, nd):
sio = StringIO.StringIO()
sio = StringIO()
#print 'C_SRC_KERNEL', sio.getvalue()
for ipos, i in enumerate(node.inputs):
......@@ -166,7 +167,7 @@ class NaiveAlgo(object):
"""
nd = node.outputs[0].type.ndim
sio = StringIO.StringIO()
sio = StringIO()
#print 'C_SRC_KERNEL', sio.getvalue()
if nd in (4,):
......@@ -267,7 +268,7 @@ class NaiveAlgo(object):
nd = node.outputs[0].type.ndim
n_in = len(node.inputs)
n_out = len(node.outputs)
sio = StringIO.StringIO()
sio = StringIO()
if nd not in (2,):
return sio.getvalue()
......@@ -418,7 +419,7 @@ class NaiveAlgo(object):
def c_src_kernel_Ccontiguous(self, node, nodename):
nd = node.outputs[0].type.ndim
sio = StringIO.StringIO()
sio = StringIO()
#print 'C_SRC_KERNEL', sio.getvalue()
for ipos, i in enumerate(node.inputs):
......@@ -503,7 +504,7 @@ class NaiveAlgo(object):
scalar_op=self.scalar_op.__class__.__name__
sio = StringIO.StringIO()
sio = StringIO()
print >> sio, """
static void can_collapse_%(nodename)s(int nd, const int * dims, const int * strides, int collapse[])
{
......@@ -856,7 +857,7 @@ nd_collapse_[i]=0;
d = dict(sub)
nd = node.outputs[0].type.ndim
d.update(locals())
sio = StringIO.StringIO()
sio = StringIO()
nin = len(inputs)
nout = len(outputs)
fail = sub['fail']
......
from theano import Op, Apply
import StringIO
from theano.compat.six import StringIO
from theano.sandbox.cuda import GpuOp
......@@ -92,7 +92,7 @@ class GpuCrossentropySoftmaxArgmax1HotWithBias (GpuOp):
nll, sm, am = out
classname = self.__class__.__name__
fail = sub['fail']
sio = StringIO.StringIO()
sio = StringIO()
print >> sio, """
if (%(y_idx)s->nd != 1)
{
......
"""Provide CudaNdarrayType
"""
import os
import StringIO
import copy_reg
import numpy
......@@ -10,6 +9,7 @@ import theano
from theano import Type, Variable
from theano import tensor, config
from theano import scalar as scal
from theano.compat.six import StringIO
try:
# We must do those import to be able to create the full doc when nvcc
......@@ -274,7 +274,7 @@ class CudaNdarrayType(Type):
return "%(name)s = NULL;" % locals()
def c_extract(self, name, sub):
sio = StringIO.StringIO()
sio = StringIO()
fail = sub['fail']
nd = self.ndim
print >> sio, """
......
......@@ -9,7 +9,6 @@ _logger = logging.getLogger('theano.tensor.opt')
import operator
import itertools
import StringIO
import sys
import traceback
from itertools import izip
......@@ -35,7 +34,7 @@ from theano.gof.opt import (Optimizer, pre_constant_merge,
from theano.gof.opt import merge_optimizer
from theano.gof import toolbox, DestroyHandler
from theano.tensor.basic import get_scalar_constant_value, ShapeError, NotScalarConstantError
from theano.compat.six import StringIO
theano.configparser.AddConfigVar('on_shape_error',
"warn: print a warning and use the default"
......@@ -836,7 +835,7 @@ class ShapeFeature(object):
raise TypeError('shapes must be tuple/list', (r, s))
if r.ndim != len(s):
sio = StringIO.StringIO()
sio = StringIO()
theano.printing.debugprint(r, file=sio, print_type=True)
raise AssertionError(
"Something inferred a shape with %d dimensions "
......
......@@ -2,7 +2,6 @@ import itertools
import logging
import operator
import os
import StringIO
import sys
from tempfile import mkstemp
import unittest
......@@ -20,6 +19,7 @@ from numpy.testing.noseclasses import KnownFailureTest
import theano
from theano.compat import PY3, exc_message, operator_div
from theano.compat.six import StringIO
from theano import compile, config, function, gof, tensor, shared
from theano.compile import DeepCopyOp
from theano.compile.mode import get_default_mode
......@@ -2269,7 +2269,7 @@ class T_max_and_argmax(unittest.TestCase):
def test2_invalid_neg(self):
n = as_tensor_variable(rand(2, 3))
old_stderr = sys.stderr
sys.stderr = StringIO.StringIO()
sys.stderr = StringIO()
try:
try:
eval_outputs(max_and_argmax(n, -3))
......@@ -2463,7 +2463,7 @@ class T_argmin_argmax(unittest.TestCase):
for fct, nfct in [(argmax, numpy.argmax), (argmin, numpy.argmin)]:
n = as_tensor_variable(rand(2, 3))
old_stderr = sys.stderr
sys.stderr = StringIO.StringIO()
sys.stderr = StringIO()
try:
try:
eval_outputs(fct(n, -3))
......@@ -2596,7 +2596,7 @@ class T_min_max(unittest.TestCase):
for fct in [max, min]:
n = as_tensor_variable(rand(2, 3))
old_stderr = sys.stderr
sys.stderr = StringIO.StringIO()
sys.stderr = StringIO()
try:
try:
eval_outputs(fct(n, -3))
......@@ -2931,7 +2931,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
t = n[4:5, 3]
self.assertTrue(isinstance(t.owner.op, Subtensor))
old_stderr = sys.stderr
sys.stderr = StringIO.StringIO()
sys.stderr = StringIO()
try:
self.assertRaises(IndexError,
self.eval_output_and_check, [t])
......
......@@ -652,10 +652,10 @@ def profile_main():
# We've renamed our original main() above to real_main()
import cProfile
import pstats
import StringIO
from theano.compat.six import StringIO
prof = cProfile.Profile()
prof = prof.runctx("real_main()", globals(), locals())
stream = StringIO.StringIO()
stream = StringIO()
stats = pstats.Stats(prof)
stats.sort_stats("time") # Or cumulative
stats.print_stats(80) # 80 = how many to print
......
......@@ -2,7 +2,6 @@
import copy
import logging
import StringIO
import time
import unittest
......@@ -13,6 +12,7 @@ from numpy.testing.noseclasses import KnownFailureTest
import theano
import theano.scalar as scal
from theano.compat.six import StringIO
from theano import compile
from theano.compile import deep_copy_op, DeepCopyOp
from theano import config
......@@ -742,7 +742,7 @@ class test_canonize(unittest.TestCase):
This bug caused an infinite loop which was caught by the equilibrium
optimizer, resulting in an error log message.
"""
sio = StringIO.StringIO()
sio = StringIO()
handler = logging.StreamHandler(sio)
handler.setLevel(logging.ERROR)
logging.getLogger('theano.gof.opt').addHandler(handler)
......
......@@ -5,12 +5,11 @@ from theano.tests import disturb_mem
import numpy as np
import theano
from theano.printing import var_descriptor
from cStringIO import StringIO
from nose.plugins.skip import SkipTest
from theano import config
from theano import shared
from theano.compat.six import StringIO
def sharedX(x, name=None):
x = np.cast[config.floatX](x)
......
"""
Tests of printing functionality
"""
import logging
import StringIO
from nose.plugins.skip import SkipTest
......@@ -12,7 +9,7 @@ import theano
import theano.tensor as tensor
from theano.printing import min_informative_str, debugprint
from theano.compat.six import StringIO
def test_pydotprint_cond_highlight():
"""
......@@ -29,7 +26,7 @@ def test_pydotprint_cond_highlight():
f = theano.function([x], x * 2)
f([1, 2, 3, 4])
s = StringIO.StringIO()
s = StringIO()
new_handler = logging.StreamHandler(s)
new_handler.setLevel(logging.DEBUG)
orig_handler = theano.logging_default_handler
......@@ -65,7 +62,7 @@ def test_pydotprint_long_name():
f = theano.function([x], [x * 2, x + x], mode=mode)
f([1, 2, 3, 4])
s = StringIO.StringIO()
s = StringIO()
new_handler = logging.StreamHandler(s)
new_handler.setLevel(logging.DEBUG)
orig_handler = theano.logging_default_handler
......@@ -131,7 +128,7 @@ def test_debugprint():
debugprint(G)
# test ids=int
s = StringIO.StringIO()
s = StringIO()
debugprint(G, file=s, ids='int')
s = s.getvalue()
# The additional white space are needed!
......@@ -151,7 +148,7 @@ def test_debugprint():
assert s == reference
# test ids=CHAR
s = StringIO.StringIO()
s = StringIO()
debugprint(G, file=s, ids='CHAR')
s = s.getvalue()
# The additional white space are needed!
......@@ -171,7 +168,7 @@ def test_debugprint():
assert s == reference
# test ids=CHAR, stop_on_name=True
s = StringIO.StringIO()
s = StringIO()
debugprint(G, file=s, ids='CHAR', stop_on_name=True)
s = s.getvalue()
# The additional white space are needed!
......@@ -189,7 +186,7 @@ def test_debugprint():
assert s == reference
# test ids=
s = StringIO.StringIO()
s = StringIO()
debugprint(G, file=s, ids='')
s = s.getvalue()
# The additional white space are needed!
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论