提交 402a0a85 authored 作者: David Warde-Farley's avatar David Warde-Farley 提交者: Arnaud Bergeron

iterkeys, itervalues, iteritems

上级 5720b290
...@@ -17,7 +17,7 @@ import numpy ...@@ -17,7 +17,7 @@ import numpy
import theano import theano
from theano import gof from theano import gof
from theano.compat import get_unbound_function from theano.compat import get_unbound_function
from theano.compat.six import string_types from theano.compat.six import string_types, iteritems
from theano.compat.six.moves import StringIO, xrange from theano.compat.six.moves import StringIO, xrange
from theano.gof import (FunctionGraph, graph, utils, link, from theano.gof import (FunctionGraph, graph, utils, link,
ops_with_inner_function) ops_with_inner_function)
...@@ -795,13 +795,13 @@ def _check_inputs(node, storage_map, r_vals, dr_vals, active_nodes, ...@@ -795,13 +795,13 @@ def _check_inputs(node, storage_map, r_vals, dr_vals, active_nodes,
""" """
destroyed_idx_list = [] destroyed_idx_list = []
destroy_map = getattr(node.op, 'destroy_map', {}) destroy_map = getattr(node.op, 'destroy_map', {})
for o_pos, i_pos_list in destroy_map.iteritems(): for o_pos, i_pos_list in iteritems(destroy_map):
destroyed_idx_list.extend(i_pos_list) destroyed_idx_list.extend(i_pos_list)
destroyed_res_list = [node.inputs[i] for i in destroyed_idx_list] destroyed_res_list = [node.inputs[i] for i in destroyed_idx_list]
actually_inplace_outputs = [] actually_inplace_outputs = []
dmap = getattr(node.op, 'destroy_map', {}) dmap = getattr(node.op, 'destroy_map', {})
for oo, ii in dmap.iteritems(): for oo, ii in iteritems(dmap):
var = node.outputs[oo] var = node.outputs[oo]
out_var = storage_map[var][0] out_var = storage_map[var][0]
in_var = storage_map[node.inputs[ii[0]]][0] in_var = storage_map[node.inputs[ii[0]]][0]
...@@ -820,7 +820,7 @@ def _check_inputs(node, storage_map, r_vals, dr_vals, active_nodes, ...@@ -820,7 +820,7 @@ def _check_inputs(node, storage_map, r_vals, dr_vals, active_nodes,
ii[0], str(node)) ii[0], str(node))
vmap = getattr(node.op, 'view_map', {}) vmap = getattr(node.op, 'view_map', {})
for oo, ii in vmap.iteritems(): for oo, ii in iteritems(vmap):
var = node.outputs[oo] var = node.outputs[oo]
out_var = storage_map[var][0] out_var = storage_map[var][0]
in_var = storage_map[node.inputs[ii[0]]][0] in_var = storage_map[node.inputs[ii[0]]][0]
...@@ -913,7 +913,7 @@ def _check_viewmap(node, storage_map): ...@@ -913,7 +913,7 @@ def _check_viewmap(node, storage_map):
# TODO: make sure this is correct # TODO: make sure this is correct
# According to OB, duplicate inputs are rejected on build graph time # According to OB, duplicate inputs are rejected on build graph time
# if they cause problems. So if they are here it should be ok. # if they cause problems. So if they are here it should be ok.
for key, val in good_alias.iteritems(): for key, val in iteritems(good_alias):
bad_alias.pop(key, None) bad_alias.pop(key, None)
if bad_alias: if bad_alias:
raise BadViewMap(node, oi, outstorage, bad_alias.values()) raise BadViewMap(node, oi, outstorage, bad_alias.values())
...@@ -1048,7 +1048,7 @@ def _find_bad_optimizations1(order, reasons, r_vals): ...@@ -1048,7 +1048,7 @@ def _find_bad_optimizations1(order, reasons, r_vals):
# identify equivalence sets that are broken # identify equivalence sets that are broken
equivalence_sets_broken = {} # id(set) -> Bool equivalence_sets_broken = {} # id(set) -> Bool
there_is_a_problem = False there_is_a_problem = False
for r, r_equiv in equivalence_sets.iteritems(): for r, r_equiv in iteritems(equivalence_sets):
if id(r_equiv) not in equivalence_sets_broken: if id(r_equiv) not in equivalence_sets_broken:
equivalence_sets_broken[id(r_equiv)] = False equivalence_sets_broken[id(r_equiv)] = False
# loop over the variables in the set comparing them to be # loop over the variables in the set comparing them to be
...@@ -1888,7 +1888,7 @@ class _Linker(gof.link.LocalLinker): ...@@ -1888,7 +1888,7 @@ class _Linker(gof.link.LocalLinker):
# Precondition: the storage map is empty, transferred # Precondition: the storage map is empty, transferred
# completely to r_vals # completely to r_vals
##### #####
for r, s in storage_map.iteritems(): for r, s in iteritems(storage_map):
if s[0] is not None: if s[0] is not None:
print(r, s) print(r, s)
assert s[0] is None assert s[0] is None
...@@ -2146,7 +2146,7 @@ class _Linker(gof.link.LocalLinker): ...@@ -2146,7 +2146,7 @@ class _Linker(gof.link.LocalLinker):
# Nothing should be in storage map after evaluating # Nothing should be in storage map after evaluating
# each the thunk (specifically the last one) # each the thunk (specifically the last one)
for r, s in storage_map.iteritems(): for r, s in iteritems(storage_map):
assert type(s) is list assert type(s) is list
assert s[0] is None assert s[0] is None
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
from __future__ import print_function from __future__ import print_function
import copy import copy
from theano.compat.six import iteritems
import theano.compat.six.moves.copyreg as copyreg import theano.compat.six.moves.copyreg as copyreg
import theano.compat.six.moves.cPickle as pickle import theano.compat.six.moves.cPickle as pickle
import itertools import itertools
...@@ -544,7 +545,7 @@ returned directly?""" ...@@ -544,7 +545,7 @@ returned directly?"""
# Set keyword arguments # Set keyword arguments
if kwargs: # for speed, skip the iteritems for empty kwargs if kwargs: # for speed, skip the iteritems for empty kwargs
for k, arg in kwargs.iteritems(): for k, arg in iteritems(kwargs):
self[k] = arg self[k] = arg
if (not self.trust_input and if (not self.trust_input and
...@@ -979,7 +980,7 @@ class FunctionMaker(object): ...@@ -979,7 +980,7 @@ class FunctionMaker(object):
# The sole purpose of this loop is to set 'need_optimize' by # The sole purpose of this loop is to set 'need_optimize' by
# going through graph_db, looking for graph that has the same # going through graph_db, looking for graph that has the same
# computation performed. # computation performed.
for graph_old, graph_optimized in graph_db.iteritems(): for graph_old, graph_optimized in iteritems(graph_db):
inputs_old = graph_old.inputs inputs_old = graph_old.inputs
outputs_old = graph_old.outputs outputs_old = graph_old.outputs
size_old = len(graph_old.apply_nodes) size_old = len(graph_old.apply_nodes)
...@@ -1054,7 +1055,7 @@ class FunctionMaker(object): ...@@ -1054,7 +1055,7 @@ class FunctionMaker(object):
# hack to remove inconstent entry in givens # hack to remove inconstent entry in givens
# seems to work that but source of inconsistency # seems to work that but source of inconsistency
# could be worth investigating. # could be worth investigating.
for key, value in temp.iteritems(): for key, value in iteritems(temp):
if key.type != value.type: if key.type != value.type:
del givens[key] del givens[key]
......
...@@ -9,6 +9,7 @@ import warnings ...@@ -9,6 +9,7 @@ import warnings
import theano import theano
from theano import gof from theano import gof
from theano.compat.six import iteritems
from theano.compat.six.moves import xrange from theano.compat.six.moves import xrange
...@@ -621,7 +622,7 @@ class Rebroadcast(gof.Op): ...@@ -621,7 +622,7 @@ class Rebroadcast(gof.Op):
def __init__(self, *axis): def __init__(self, *axis):
self.axis = dict(axis) self.axis = dict(axis)
for axis, broad in self.axis.iteritems(): for axis, broad in iteritems(self.axis):
assert isinstance(axis, (numpy.integer, int)), ( assert isinstance(axis, (numpy.integer, int)), (
"Rebroadcast needs integer axes. Got ", axis) "Rebroadcast needs integer axes. Got ", axis)
...@@ -630,7 +631,7 @@ class Rebroadcast(gof.Op): ...@@ -630,7 +631,7 @@ class Rebroadcast(gof.Op):
def __hash__(self): def __hash__(self):
# no ambiguity because each item key is unique # no ambiguity because each item key is unique
items = sorted(self.axis.iteritems()) items = sorted(iteritems(self.axis))
return hash((type(self), tuple(items))) return hash((type(self), tuple(items)))
def __str__(self): def __str__(self):
...@@ -639,7 +640,7 @@ class Rebroadcast(gof.Op): ...@@ -639,7 +640,7 @@ class Rebroadcast(gof.Op):
else: else:
broadcast_pattern = ['?' for i broadcast_pattern = ['?' for i
in xrange(1 + numpy.max(self.axis.keys()))] in xrange(1 + numpy.max(self.axis.keys()))]
for k, v in self.axis.iteritems(): for k, v in iteritems(self.axis):
broadcast_pattern[k] = str(int(v)) broadcast_pattern[k] = str(int(v))
return '%s{%s}' % (self.__class__.__name__, return '%s{%s}' % (self.__class__.__name__,
','.join(broadcast_pattern)) ','.join(broadcast_pattern))
...@@ -655,7 +656,7 @@ class Rebroadcast(gof.Op): ...@@ -655,7 +656,7 @@ class Rebroadcast(gof.Op):
def perform(self, node, inp, out_): def perform(self, node, inp, out_):
x, = inp x, = inp
out, = out_ out, = out_
for axis, value in self.axis.iteritems(): for axis, value in iteritems(self.axis):
if value and x.shape[axis] != 1: if value and x.shape[axis] != 1:
raise ValueError('Dimension %s in Rebroadcast\'s input was' raise ValueError('Dimension %s in Rebroadcast\'s input was'
' supposed to be 1 (got %s instead)' % ' supposed to be 1 (got %s instead)' %
...@@ -667,7 +668,7 @@ class Rebroadcast(gof.Op): ...@@ -667,7 +668,7 @@ class Rebroadcast(gof.Op):
gz, = grads gz, = grads
# restore the broadcasting pattern of the input # restore the broadcasting pattern of the input
return Rebroadcast(*[(axis, x.type.broadcastable[axis]) return Rebroadcast(*[(axis, x.type.broadcastable[axis])
for axis, value in self.axis.iteritems()])(gz), for axis, value in iteritems(self.axis)])(gz),
def infer_shape(self, node, ishapes): def infer_shape(self, node, ishapes):
assert len(ishapes) == 1 assert len(ishapes) == 1
...@@ -695,7 +696,7 @@ class Rebroadcast(gof.Op): ...@@ -695,7 +696,7 @@ class Rebroadcast(gof.Op):
if itype in self.c_code_and_version: if itype in self.c_code_and_version:
code, version = self.c_code_and_version[itype] code, version = self.c_code_and_version[itype]
final_code = "" final_code = ""
for axis, value in self.axis.iteritems(): for axis, value in iteritems(self.axis):
if value: if value:
final_code += code % locals() final_code += code % locals()
return final_code + """ return final_code + """
......
"""Provide a simple user friendly API """ """Provide a simple user friendly API """
from theano import config from theano import config
from theano.compat.six import iteritems
from theano.compile import orig_function, In, Out from theano.compile import orig_function, In, Out
from theano.compile import UnusedInputError from theano.compile import UnusedInputError
from theano.compile.sharedvalue import SharedVariable, shared from theano.compile.sharedvalue import SharedVariable, shared
...@@ -554,6 +555,6 @@ def iter_over_pairs(pairs): ...@@ -554,6 +555,6 @@ def iter_over_pairs(pairs):
""" """
if isinstance(pairs, dict): if isinstance(pairs, dict):
return pairs.iteritems() return iteritems(pairs)
else: else:
return pairs return pairs
...@@ -7,7 +7,7 @@ import warnings ...@@ -7,7 +7,7 @@ import warnings
import theano import theano
from theano.gof.link import WrapLinker from theano.gof.link import WrapLinker
from theano.compat.six import string_types from theano.compat.six import string_types, iteritems
from theano.compile.mode import (Mode, register_mode, from theano.compile.mode import (Mode, register_mode,
predefined_modes, predefined_linkers, predefined_modes, predefined_linkers,
predefined_optimizers) predefined_optimizers)
...@@ -667,7 +667,7 @@ Test them first, as they are not guaranteed to always provide a speedup.""") ...@@ -667,7 +667,7 @@ Test them first, as they are not guaranteed to always provide a speedup.""")
printed_tip = True printed_tip = True
# tip 4 # tip 4
for a, t in apply_time.iteritems(): for a, t in iteritems(apply_time):
node = a[1] node = a[1]
if (isinstance(node.op, T.Dot) and if (isinstance(node.op, T.Dot) and
all([len(i.type.broadcastable) == 2 all([len(i.type.broadcastable) == 2
...@@ -680,7 +680,7 @@ Test them first, as they are not guaranteed to always provide a speedup.""") ...@@ -680,7 +680,7 @@ Test them first, as they are not guaranteed to always provide a speedup.""")
printed_tip = True printed_tip = True
# tip 5 # tip 5
for a, t in apply_time.iteritems(): for a, t in iteritems(apply_time):
node = a[1] node = a[1]
if isinstance(node.op, RandomFunction): if isinstance(node.op, RandomFunction):
printed_tip = True printed_tip = True
......
...@@ -25,6 +25,7 @@ from collections import defaultdict ...@@ -25,6 +25,7 @@ from collections import defaultdict
import numpy import numpy
import theano import theano
from theano.compat.six import iteritems
from theano.gof import graph from theano.gof import graph
from theano.configparser import AddConfigVar, BoolParam, IntParam, StrParam from theano.configparser import AddConfigVar, BoolParam, IntParam, StrParam
...@@ -112,7 +113,7 @@ def _atexit_print_fn(): ...@@ -112,7 +113,7 @@ def _atexit_print_fn():
for attr in ["apply_time", "apply_callcount", for attr in ["apply_time", "apply_callcount",
"apply_cimpl", "variable_shape", "variable_strides"]: "apply_cimpl", "variable_shape", "variable_strides"]:
cum_attr = getattr(cum, attr) cum_attr = getattr(cum, attr)
for key, val in getattr(ps, attr).iteritems(): for key, val in iteritems(getattr(ps, attr)):
assert key not in cum_attr assert key not in cum_attr
cum_attr[key] = val cum_attr[key] = val
...@@ -1004,11 +1005,11 @@ class ProfileStats(object): ...@@ -1004,11 +1005,11 @@ class ProfileStats(object):
for var in node.outputs: for var in node.outputs:
compute_map[var][0] = 0 compute_map[var][0] = 0
for k_remove, v_remove in viewedby_remove.iteritems(): for k_remove, v_remove in iteritems(viewedby_remove):
for i in v_remove: for i in v_remove:
viewed_by[k_remove].append(i) viewed_by[k_remove].append(i)
for k_add, v_add in viewedby_add.iteritems(): for k_add, v_add in iteritems(viewedby_add):
for i in v_add: for i in v_add:
viewed_by[k_add].remove(i) viewed_by[k_add].remove(i)
...@@ -1030,10 +1031,10 @@ class ProfileStats(object): ...@@ -1030,10 +1031,10 @@ class ProfileStats(object):
return mem_bound return mem_bound
for fgraph, nodes_mem in fct_memory.iteritems(): for fgraph, nodes_mem in iteritems(fct_memory):
# Sum of the size of all variables in bytes # Sum of the size of all variables in bytes
sum_size = sum([sum([v for v in val if not isinstance(v, str)]) sum_size = sum([sum([v for v in val if not isinstance(v, str)])
for key, val in nodes_mem.iteritems()]) for key, val in iteritems(nodes_mem)])
order = fgraph.toposort() order = fgraph.toposort()
# A list of intermediate variable that are not need # A list of intermediate variable that are not need
...@@ -1184,9 +1185,9 @@ class ProfileStats(object): ...@@ -1184,9 +1185,9 @@ class ProfileStats(object):
items.sort(key=lambda a: a[1], reverse=True) items.sort(key=lambda a: a[1], reverse=True)
for idx, (node, node_outputs_size) in enumerate(items[:N]): for idx, (node, node_outputs_size) in enumerate(items[:N]):
code = ['c'] * len(node.outputs) code = ['c'] * len(node.outputs)
for out, inp in getattr(node.op, 'destroy_map', {}).iteritems(): for out, inp in iteritems(getattr(node.op, 'destroy_map', {})):
code[out] = "i" code[out] = "i"
for out, inp in getattr(node.op, 'view_map', {}).iteritems(): for out, inp in iteritems(getattr(node.op, 'view_map', {})):
code[out] = "v" code[out] = "v"
shapes = str(fct_shapes[node.fgraph][node]) shapes = str(fct_shapes[node.fgraph][node])
...@@ -1432,7 +1433,7 @@ if False: # old code still to be ported from ProfileMode ...@@ -1432,7 +1433,7 @@ if False: # old code still to be ported from ProfileMode
print(" - With the default gcc libm, exp in float32 is slower than in float64! Try Theano flags floatX=float64 or install amdlibm and set the theano flags lib.amdlibm=True") print(" - With the default gcc libm, exp in float32 is slower than in float64! Try Theano flags floatX=float64 or install amdlibm and set the theano flags lib.amdlibm=True")
# tip 4 # tip 4
for a, t in apply_time.iteritems(): for a, t in iteritems(apply_time):
node = a node = a
if (isinstance(node.op, T.Dot) and if (isinstance(node.op, T.Dot) and
all([len(i.type.broadcastable) == 2 for i in node.inputs])): all([len(i.type.broadcastable) == 2 for i in node.inputs])):
...@@ -1443,7 +1444,7 @@ if False: # old code still to be ported from ProfileMode ...@@ -1443,7 +1444,7 @@ if False: # old code still to be ported from ProfileMode
[i.type for i in node.inputs])) [i.type for i in node.inputs]))
# tip 5 # tip 5
for a, t in apply_time.iteritems(): for a, t in iteritems(apply_time):
node = a node = a
if isinstance(node.op, RandomFunction): if isinstance(node.op, RandomFunction):
print (" - Replace the default random number generator by " print (" - Replace the default random number generator by "
......
...@@ -5,6 +5,7 @@ import unittest ...@@ -5,6 +5,7 @@ import unittest
from theano import config, gof from theano import config, gof
from theano.compat.six import iteritems
from theano.compile.io import In, Out from theano.compile.io import In, Out
from theano.compile import function from theano.compile import function
from theano.compile import UnusedInputError from theano.compile import UnusedInputError
...@@ -408,14 +409,14 @@ class T_function(unittest.TestCase): ...@@ -408,14 +409,14 @@ class T_function(unittest.TestCase):
func([1]) func([1])
check_list = [] check_list = []
for key, val in func.fn.storage_map.iteritems(): for key, val in iteritems(func.fn.storage_map):
if not isinstance(key, theano.gof.Constant): if not isinstance(key, theano.gof.Constant):
check_list.append(val) check_list.append(val)
assert any([val[0] for val in check_list]) assert any([val[0] for val in check_list])
func.free() func.free()
for key, val in func.fn.storage_map.iteritems(): for key, val in iteritems(func.fn.storage_map):
if not isinstance(key, theano.gof.Constant): if not isinstance(key, theano.gof.Constant):
assert (val[0] == None) assert (val[0] == None)
......
...@@ -25,7 +25,7 @@ import numpy.distutils # TODO: TensorType should handle this ...@@ -25,7 +25,7 @@ import numpy.distutils # TODO: TensorType should handle this
import theano import theano
from theano.compat import PY3, decode, decode_iter from theano.compat import PY3, decode, decode_iter
from theano.compat.six import b, BytesIO, StringIO, string_types from theano.compat.six import b, BytesIO, StringIO, string_types, iteritems
from theano.gof.utils import flatten from theano.gof.utils import flatten
from theano.configparser import config from theano.configparser import config
from theano.gof.cc import hash_from_code from theano.gof.cc import hash_from_code
...@@ -510,7 +510,7 @@ class KeyData(object): ...@@ -510,7 +510,7 @@ class KeyData(object):
del entry_from_key[key] del entry_from_key[key]
if do_manual_check: if do_manual_check:
to_del = [] to_del = []
for key, key_entry in entry_from_key.iteritems(): for key, key_entry in iteritems(entry_from_key):
if key_entry == entry: if key_entry == entry:
to_del.append(key) to_del.append(key)
for key in to_del: for key in to_del:
...@@ -869,7 +869,7 @@ class ModuleCache(object): ...@@ -869,7 +869,7 @@ class ModuleCache(object):
del root, files, subdirs del root, files, subdirs
# Remove entries that are not in the filesystem. # Remove entries that are not in the filesystem.
items_copy = list(self.module_hash_to_key_data.iteritems()) items_copy = list(self.module_hash_to_key_data.items())
for module_hash, key_data in items_copy: for module_hash, key_data in items_copy:
entry = key_data.get_entry() entry = key_data.get_entry()
try: try:
......
...@@ -14,7 +14,7 @@ import textwrap ...@@ -14,7 +14,7 @@ import textwrap
import numpy import numpy
import theano import theano
from theano.compat.six import string_types from theano.compat.six import string_types, iteritems
from theano.configparser import config, AddConfigVar, ConfigParam, StrParam from theano.configparser import config, AddConfigVar, ConfigParam, StrParam
from theano.gof.utils import flatten from theano.gof.utils import flatten
from theano.misc.windows import output_subprocess_Popen from theano.misc.windows import output_subprocess_Popen
...@@ -390,7 +390,7 @@ def print_compiledir_content(): ...@@ -390,7 +390,7 @@ def print_compiledir_content():
print() print()
print(("List of %d individual compiled Op classes and " print(("List of %d individual compiled Op classes and "
"the number of times they got compiled" % len(table_op_class))) "the number of times they got compiled" % len(table_op_class)))
table_op_class = sorted(table_op_class.iteritems(), key=lambda t: t[1]) table_op_class = sorted(iteritems(table_op_class), key=lambda t: t[1])
for op_class, nb in table_op_class: for op_class, nb in table_op_class:
print(op_class, nb) print(op_class, nb)
...@@ -406,7 +406,7 @@ def print_compiledir_content(): ...@@ -406,7 +406,7 @@ def print_compiledir_content():
for dir, size, ops in big_key_files: for dir, size, ops in big_key_files:
print(dir, size, ops) print(dir, size, ops)
nb_keys = sorted(nb_keys.iteritems()) nb_keys = sorted(iteritems(nb_keys))
print() print()
print("Number of keys for a compiled module") print("Number of keys for a compiled module")
print("number of keys/number of modules with that number of keys") print("number of keys/number of modules with that number of keys")
......
...@@ -16,7 +16,7 @@ from itertools import count ...@@ -16,7 +16,7 @@ from itertools import count
import theano import theano
import warnings import warnings
from theano.gof import utils from theano.gof import utils
from theano.compat.six import string_types, integer_types from theano.compat.six import string_types, integer_types, iteritems
from theano.misc.ordered_set import OrderedSet from theano.misc.ordered_set import OrderedSet
# Lazy imports to avoid circular dependencies. # Lazy imports to avoid circular dependencies.
...@@ -936,7 +936,7 @@ def is_same_graph(var1, var2, givens=None, debug=False): ...@@ -936,7 +936,7 @@ def is_same_graph(var1, var2, givens=None, debug=False):
# Return True iff `x` is in computation graph of variable `vark`. # Return True iff `x` is in computation graph of variable `vark`.
return x in all_vars[k - 1] return x in all_vars[k - 1]
for to_replace, replace_by in givens.iteritems(): for to_replace, replace_by in iteritems(givens):
# Map a substitution variable to the computational graphs it # Map a substitution variable to the computational graphs it
# belongs to. # belongs to.
inside = dict((v, [in_var(v, k) for k in (1, 2)]) inside = dict((v, [in_var(v, k) for k in (1, 2)])
......
...@@ -25,6 +25,7 @@ import theano ...@@ -25,6 +25,7 @@ import theano
from theano import config from theano import config
import theano.gof.cc import theano.gof.cc
from theano.compat.six import itervalues
from theano.compat.six.moves import StringIO from theano.compat.six.moves import StringIO
from theano.gof import graph from theano.gof import graph
from theano.gof import utils from theano.gof import utils
...@@ -538,7 +539,7 @@ class PureOp(object): ...@@ -538,7 +539,7 @@ class PureOp(object):
# copy the values of the inputs in destroy_map # copy the values of the inputs in destroy_map
destroyed_inputs_idx = set() destroyed_inputs_idx = set()
if getattr(node.op, 'destroy_map', None): if getattr(node.op, 'destroy_map', None):
for i_pos_list in node.op.destroy_map.itervalues(): for i_pos_list in itervalues(node.op.destroy_map):
destroyed_inputs_idx.update(i_pos_list) destroyed_inputs_idx.update(i_pos_list)
for inp_idx in destroyed_inputs_idx: for inp_idx in destroyed_inputs_idx:
inp = node.inputs[inp_idx] inp = node.inputs[inp_idx]
......
...@@ -17,7 +17,7 @@ import numpy ...@@ -17,7 +17,7 @@ import numpy
import theano import theano
from theano import config from theano import config
from theano.compat.six import string_types from theano.compat.six import string_types, iteritems
from theano.compat.six.moves import reduce from theano.compat.six.moves import reduce
from theano.gof import graph, op, utils, unify, toolbox from theano.gof import graph, op, utils, unify, toolbox
from theano.gof.fg import InconsistencyError from theano.gof.fg import InconsistencyError
...@@ -631,7 +631,7 @@ class MergeOptimizer(Optimizer): ...@@ -631,7 +631,7 @@ class MergeOptimizer(Optimizer):
validate_time = fgraph.profile.validate_time - validate_before validate_time = fgraph.profile.validate_time - validate_before
callback_time = fgraph.execute_callbacks_time - callback_before callback_time = fgraph.execute_callbacks_time - callback_before
callbacks_time = {} callbacks_time = {}
for k, v in fgraph.execute_callbacks_times.iteritems(): for k, v in iteritems(fgraph.execute_callbacks_times):
if k in callbacks_before: if k in callbacks_before:
callbacks_time[k] = v - callbacks_before[k] callbacks_time[k] = v - callbacks_before[k]
else: else:
...@@ -661,7 +661,7 @@ class MergeOptimizer(Optimizer): ...@@ -661,7 +661,7 @@ class MergeOptimizer(Optimizer):
print(blanc, " callback_time", callback_time, file=stream) print(blanc, " callback_time", callback_time, file=stream)
if callback_time > 1: if callback_time > 1:
print(blanc, " callbacks_time", file=stream) print(blanc, " callbacks_time", file=stream)
for i in sorted(callbacks_time.iteritems(), key=lambda a: a[1]): for i in sorted(iteritems(callbacks_time), key=lambda a: a[1]):
if i[1] > 0: if i[1] > 0:
print(i) print(i)
print(blanc, " nb_merged", nb_merged, file=stream) print(blanc, " nb_merged", nb_merged, file=stream)
...@@ -689,7 +689,7 @@ def is_same_graph_with_merge(var1, var2, givens=None): ...@@ -689,7 +689,7 @@ def is_same_graph_with_merge(var1, var2, givens=None):
# break the mapping in givens. # break the mapping in givens.
fgraph = theano.gof.fg.FunctionGraph(inputs, vars, clone=False) fgraph = theano.gof.fg.FunctionGraph(inputs, vars, clone=False)
# Perform Variable substitution. # Perform Variable substitution.
for to_replace, replace_by in givens.iteritems(): for to_replace, replace_by in iteritems(givens):
fgraph.replace(to_replace, replace_by) fgraph.replace(to_replace, replace_by)
# Perform merge optimization. # Perform merge optimization.
merge_optimizer.optimize(fgraph) merge_optimizer.optimize(fgraph)
...@@ -1928,7 +1928,7 @@ class EquilibriumOptimizer(NavigatorOptimizer): ...@@ -1928,7 +1928,7 @@ class EquilibriumOptimizer(NavigatorOptimizer):
for i in range(len(loop_timing)): for i in range(len(loop_timing)):
lopt = "" lopt = ""
if loop_process_count[i]: if loop_process_count[i]:
d = list(reversed(sorted(loop_process_count[i].iteritems(), d = list(reversed(sorted(iteritems(loop_process_count[i]),
key=lambda a: a[1]))) key=lambda a: a[1])))
lopt = " ".join([str((str(k), v)) for k, v lopt = " ".join([str((str(k), v)) for k, v
in d[:5]]) in d[:5]])
...@@ -1951,9 +1951,9 @@ class EquilibriumOptimizer(NavigatorOptimizer): ...@@ -1951,9 +1951,9 @@ class EquilibriumOptimizer(NavigatorOptimizer):
opt.final_optimizers): opt.final_optimizers):
process_count.setdefault(o, 0) process_count.setdefault(o, 0)
for count in loop_process_count: for count in loop_process_count:
for o, v in count.iteritems(): for o, v in iteritems(count):
process_count[o] += v process_count[o] += v
for opt, count in process_count.iteritems(): for opt, count in iteritems(process_count):
if count > 0: if count > 0:
count_opt.append((time_opts[opt], count, count_opt.append((time_opts[opt], count,
node_created[opt], opt)) node_created[opt], opt))
...@@ -2010,7 +2010,7 @@ class EquilibriumOptimizer(NavigatorOptimizer): ...@@ -2010,7 +2010,7 @@ class EquilibriumOptimizer(NavigatorOptimizer):
loop_process_count = list(prof1[2]) loop_process_count = list(prof1[2])
for i in range(min(len(loop_process_count), len(prof2[2]))): for i in range(min(len(loop_process_count), len(prof2[2]))):
process_count = loop_process_count[i] process_count = loop_process_count[i]
for process, count in prof2[2][i].iteritems(): for process, count in iteritems(prof2[2][i]):
if process in process_count: if process in process_count:
process_count[process] += count process_count[process] += count
else: else:
...@@ -2024,7 +2024,7 @@ class EquilibriumOptimizer(NavigatorOptimizer): ...@@ -2024,7 +2024,7 @@ class EquilibriumOptimizer(NavigatorOptimizer):
nb_nodes = merge_list(prof1[5], prof2[5]) nb_nodes = merge_list(prof1[5], prof2[5])
time_opts = prof1[6].copy() time_opts = prof1[6].copy()
for opt, t in prof2[6].iteritems(): for opt, t in iteritems(prof2[6]):
if opt in time_opts: if opt in time_opts:
time_opts[opt] += t time_opts[opt] += t
else: else:
......
...@@ -104,7 +104,7 @@ if 0: ...@@ -104,7 +104,7 @@ if 0:
u = self.attach_updater(fgraph, importer, pruner, chin) u = self.attach_updater(fgraph, importer, pruner, chin)
print('KEYS', list(map(hash, tasks.keys()))) print('KEYS', list(map(hash, tasks.keys())))
while tasks: while tasks:
for node in tasks.iterkeys(): for node in tasks:
todo = tasks.pop(node) todo = tasks.pop(node)
break break
for lopt in todo: for lopt in todo:
......
...@@ -16,6 +16,7 @@ from theano.configparser import (config, AddConfigVar, ...@@ -16,6 +16,7 @@ from theano.configparser import (config, AddConfigVar,
import theano.gof.cmodule import theano.gof.cmodule
from theano.compat.six import iteritems
from theano.compat.six.moves import xrange from theano.compat.six.moves import xrange
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -436,7 +437,7 @@ class Stack(VM): ...@@ -436,7 +437,7 @@ class Stack(VM):
last_apply_stack_len = -1 last_apply_stack_len = -1
# This record all function inputs/shared varibles and constants # This record all function inputs/shared varibles and constants
for var, data in self.storage_map.iteritems(): for var, data in iteritems(self.storage_map):
if data[0] is None: if data[0] is None:
continue continue
if hasattr(var.type, 'get_shape_info'): if hasattr(var.type, 'get_shape_info'):
......
...@@ -3,6 +3,7 @@ import theano.compat.six.moves.cPickle as pickle ...@@ -3,6 +3,7 @@ import theano.compat.six.moves.cPickle as pickle
import os, sys import os, sys
import theano import theano
from theano.compat.six import iteritems
DISPLAY_DUPLICATE_KEYS = False DISPLAY_DUPLICATE_KEYS = False
DISPLAY_MOST_FREQUENT_DUPLICATE_CCODE = False DISPLAY_MOST_FREQUENT_DUPLICATE_CCODE = False
...@@ -46,7 +47,7 @@ for dir in dirs: ...@@ -46,7 +47,7 @@ for dir in dirs:
pass pass
if DISPLAY_DUPLICATE_KEYS: if DISPLAY_DUPLICATE_KEYS:
for k, v in keys.iteritems(): for k, v in iteritems(keys):
if v > 1: if v > 1:
print("Duplicate key (%i copies): %s" % (v, pickle.loads(k))) print("Duplicate key (%i copies): %s" % (v, pickle.loads(k)))
...@@ -58,7 +59,7 @@ for val in keys.values(): ...@@ -58,7 +59,7 @@ for val in keys.values():
nbs_mod = {} # nb seen -> how many key nbs_mod = {} # nb seen -> how many key
nbs_mod_to_key = {} # nb seen -> keys nbs_mod_to_key = {} # nb seen -> keys
more_than_one = 0 more_than_one = 0
for mod, kk in mods.iteritems(): for mod, kk in iteritems(mods):
val = len(kk) val = len(kk)
nbs_mod.setdefault(val, 0) nbs_mod.setdefault(val, 0)
nbs_mod[val] += 1 nbs_mod[val] += 1
......
...@@ -13,7 +13,7 @@ import hashlib ...@@ -13,7 +13,7 @@ import hashlib
import numpy as np import numpy as np
import collections import collections
from theano.compat.six import string_types, integer_types from theano.compat.six import string_types, integer_types, iteritems
try: try:
import pydot as pd import pydot as pd
...@@ -489,7 +489,7 @@ class PPrinter: ...@@ -489,7 +489,7 @@ class PPrinter:
strings = [] strings = []
pprinter = self.clone_assign(lambda pstate, r: r.name is not None and pprinter = self.clone_assign(lambda pstate, r: r.name is not None and
r is not current, LeafPrinter()) r is not current, LeafPrinter())
inv_updates = dict((b, a) for (a, b) in updates.iteritems()) inv_updates = dict((b, a) for (a, b) in iteritems(updates))
i = 1 i = 1
for node in gof.graph.io_toposort(list(inputs) + updates.keys(), for node in gof.graph.io_toposort(list(inputs) + updates.keys(),
list(outputs) + list(outputs) +
......
from __future__ import print_function from __future__ import print_function
import sys, time import sys, time
from theano.compat.six import iteritems
from theano.compile.pfunc import pfunc from theano.compile.pfunc import pfunc
from theano import tensor from theano import tensor
...@@ -10,7 +11,7 @@ import theano.sandbox.cuda as tcn ...@@ -10,7 +11,7 @@ import theano.sandbox.cuda as tcn
def compare_fns(fns, input, reps=10): def compare_fns(fns, input, reps=10):
times = {} times = {}
for implname, impl in fns.iteritems(): for implname, impl in iteritems(fns):
try: try:
print('TOPOSORT', implname) print('TOPOSORT', implname)
for i, n in enumerate(impl.maker.fgraph.toposort()): for i, n in enumerate(impl.maker.fgraph.toposort()):
...@@ -26,7 +27,7 @@ def compare_fns(fns, input, reps=10): ...@@ -26,7 +27,7 @@ def compare_fns(fns, input, reps=10):
def showtimes(times): def showtimes(times):
for impl, dt in times.iteritems(): for impl, dt in iteritems(times):
print(impl, dt) print(impl, dt)
......
...@@ -16,6 +16,7 @@ import numpy ...@@ -16,6 +16,7 @@ import numpy
import warnings import warnings
from theano.compile import SharedVariable, function from theano.compile import SharedVariable, function
from theano.compat.six import iteritems
from theano import compile from theano import compile
from theano import gof from theano import gof
from theano.compat import OrderedDict from theano.compat import OrderedDict
...@@ -599,7 +600,7 @@ def scan(fn, ...@@ -599,7 +600,7 @@ def scan(fn,
if condition is not None: if condition is not None:
inner_outs.append(condition) inner_outs.append(condition)
new_givens = OrderedDict() new_givens = OrderedDict()
for w, w_copy in givens.iteritems(): for w, w_copy in iteritems(givens):
new_givens[w] = w.type.filter_variable(w_copy) new_givens[w] = w.type.filter_variable(w_copy)
new_outs = scan_utils.clone(inner_outs, replace=new_givens) new_outs = scan_utils.clone(inner_outs, replace=new_givens)
......
...@@ -47,6 +47,7 @@ import logging ...@@ -47,6 +47,7 @@ import logging
import numpy import numpy
import warnings import warnings
from theano.compat.six import iteritems
from theano.compile import SharedVariable, function from theano.compile import SharedVariable, function
from theano import compile from theano import compile
from theano import gof from theano import gof
...@@ -972,11 +973,10 @@ def scan(fn, ...@@ -972,11 +973,10 @@ def scan(fn,
# variables are put on GPU right aways >:| , # variables are put on GPU right aways >:| ,
new_givens = OrderedDict() new_givens = OrderedDict()
for w, w_copy in givens.iteritems(): for w, w_copy in iteritems(givens):
if ((isinstance(w.type, cuda.CudaNdarrayType) or if ((isinstance(w.type, cuda.CudaNdarrayType) or
isinstance(w.type, gpuarray.GpuArrayType)) and isinstance(w.type, gpuarray.GpuArrayType)) and
isinstance(w_copy.type, tensor.TensorType)): isinstance(w_copy.type, tensor.TensorType)):
for o in inner_outs: for o in inner_outs:
new_givens = traverse(o, w, w_copy, new_givens) new_givens = traverse(o, w, w_copy, new_givens)
else: else:
......
...@@ -21,7 +21,7 @@ from itertools import izip ...@@ -21,7 +21,7 @@ from itertools import izip
import numpy import numpy
import theano import theano
from theano.compat.six import string_types from theano.compat.six import string_types, iteritems
from theano.compile.pfunc import rebuild_collect_shared from theano.compile.pfunc import rebuild_collect_shared
from theano import gof, compat from theano import gof, compat
from theano import tensor, scalar from theano import tensor, scalar
...@@ -170,7 +170,7 @@ def traverse(out, x, x_copy, d, visited=None): ...@@ -170,7 +170,7 @@ def traverse(out, x, x_copy, d, visited=None):
def hash_listsDictsTuples(x): def hash_listsDictsTuples(x):
hash_value = 0 hash_value = 0
if isinstance(x, dict): if isinstance(x, dict):
for k, v in x.iteritems(): for k, v in iteritems(x):
hash_value ^= hash_listsDictsTuples(k) hash_value ^= hash_listsDictsTuples(k)
hash_value ^= hash_listsDictsTuples(v) hash_value ^= hash_listsDictsTuples(v)
elif isinstance(x, (list, tuple)): elif isinstance(x, (list, tuple)):
...@@ -302,7 +302,7 @@ def get_updates_and_outputs(ls): ...@@ -302,7 +302,7 @@ def get_updates_and_outputs(ls):
if isinstance(x, list) or isinstance(x, tuple): if isinstance(x, list) or isinstance(x, tuple):
iter_on = x iter_on = x
elif isinstance(x, dict): elif isinstance(x, dict):
iter_on = x.iteritems() iter_on = iteritems(x)
if iter_on is not None: if iter_on is not None:
return all(_filter(y) for y in iter_on) return all(_filter(y) for y in iter_on)
else: else:
......
...@@ -140,6 +140,7 @@ except ImportError: ...@@ -140,6 +140,7 @@ except ImportError:
pass pass
from theano.configparser import config, AddConfigVar, StrParam from theano.configparser import config, AddConfigVar, StrParam
from theano.compat.six import iteritems
from theano.compat.six.moves import reduce from theano.compat.six.moves import reduce
from theano.gof import (utils, Op, view_roots, from theano.gof import (utils, Op, view_roots,
local_optimizer, Optimizer, local_optimizer, Optimizer,
...@@ -1598,7 +1599,7 @@ class GemmOptimizer(Optimizer): ...@@ -1598,7 +1599,7 @@ class GemmOptimizer(Optimizer):
validate_time = fgraph.profile.validate_time - validate_before validate_time = fgraph.profile.validate_time - validate_before
callback_time = fgraph.execute_callbacks_time - callback_before callback_time = fgraph.execute_callbacks_time - callback_before
callbacks_time = {} callbacks_time = {}
for k, v in fgraph.execute_callbacks_times.iteritems(): for k, v in iteritems(fgraph.execute_callbacks_times):
if k in callbacks_before: if k in callbacks_before:
callbacks_time[k] = v - callbacks_before[k] callbacks_time[k] = v - callbacks_before[k]
else: else:
...@@ -1631,7 +1632,7 @@ class GemmOptimizer(Optimizer): ...@@ -1631,7 +1632,7 @@ class GemmOptimizer(Optimizer):
print(blanc, " callback_time", prof[11], file=stream) print(blanc, " callback_time", prof[11], file=stream)
if prof[11] > 1: if prof[11] > 1:
print(blanc, " callbacks_time", file=stream) print(blanc, " callbacks_time", file=stream)
for i in sorted(prof[12].iteritems(), key=lambda a: a[1]): for i in sorted(iteritems(prof[12]), key=lambda a: a[1]):
if i[1] > 0: if i[1] > 0:
print(i) print(i)
......
...@@ -7,6 +7,7 @@ import numpy ...@@ -7,6 +7,7 @@ import numpy
import theano import theano
from theano import gof from theano import gof
from theano.compat.six import iteritems
from theano.gof import Apply, Op, OpenMPOp from theano.gof import Apply, Op, OpenMPOp
from theano import scalar from theano import scalar
from theano.scalar import Scalar, get_scalar_type from theano.scalar import Scalar, get_scalar_type
...@@ -940,7 +941,7 @@ class Elemwise(OpenMPOp): ...@@ -940,7 +941,7 @@ class Elemwise(OpenMPOp):
# that overwrite them. We just convert them to the actual # that overwrite them. We just convert them to the actual
# Variables. # Variables.
dmap = dict([(node.outputs[o], [node.inputs[i]]) dmap = dict([(node.outputs[o], [node.inputs[i]])
for o, i in self.inplace_pattern.iteritems()]) for o, i in iteritems(self.inplace_pattern)])
# dtypes of the inputs # dtypes of the inputs
idtypes = [input.type.dtype_specs()[1] for input in inputs] idtypes = [input.type.dtype_specs()[1] for input in inputs]
......
...@@ -21,7 +21,7 @@ import numpy as N # guys... please don't do this in the library :( ...@@ -21,7 +21,7 @@ import numpy as N # guys... please don't do this in the library :(
import theano import theano
from theano import gof from theano import gof
from theano.compat.six import integer_types from theano.compat.six import integer_types, iteritems
from theano.compat.six.moves import reduce from theano.compat.six.moves import reduce
from theano.gof import opt, InconsistencyError, TopoOptimizer, graph from theano.gof import opt, InconsistencyError, TopoOptimizer, graph
from theano.gof import Variable, Constant from theano.gof import Variable, Constant
...@@ -5789,7 +5789,7 @@ class FusionOptimizer(Optimizer): ...@@ -5789,7 +5789,7 @@ class FusionOptimizer(Optimizer):
validate_time = fgraph.profile.validate_time - validate_before validate_time = fgraph.profile.validate_time - validate_before
callback_time = fgraph.execute_callbacks_time - callback_before callback_time = fgraph.execute_callbacks_time - callback_before
callbacks_time = {} callbacks_time = {}
for k, v in fgraph.execute_callbacks_times.iteritems(): for k, v in iteritems(fgraph.execute_callbacks_times):
if k in callbacks_before: if k in callbacks_before:
callbacks_time[k] = v - callbacks_before[k] callbacks_time[k] = v - callbacks_before[k]
else: else:
...@@ -5814,7 +5814,7 @@ class FusionOptimizer(Optimizer): ...@@ -5814,7 +5814,7 @@ class FusionOptimizer(Optimizer):
print(blanc, " callback_time", prof[5], file=stream) print(blanc, " callback_time", prof[5], file=stream)
if prof[5] > 1: if prof[5] > 1:
print(blanc, " callbacks_time", file=stream) print(blanc, " callbacks_time", file=stream)
for i in sorted(prof[6].iteritems(), key=lambda a: a[1]): for i in sorted(iteritems(prof[6]), key=lambda a: a[1]):
if i[1] > 0: if i[1] > 0:
print(i) print(i)
print(blanc, " time_toposort", prof[7], file=stream) print(blanc, " time_toposort", prof[7], file=stream)
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
""" """
from theano.compat import OrderedDict from theano.compat import OrderedDict
from theano.compat.six import iteritems
from theano.compile.sharedvalue import SharedVariable from theano.compile.sharedvalue import SharedVariable
import logging import logging
import warnings import warnings
...@@ -70,7 +71,7 @@ class OrderedUpdates(OrderedDict): ...@@ -70,7 +71,7 @@ class OrderedUpdates(OrderedDict):
'non-ordered dictionary with 2+ elements could ' 'non-ordered dictionary with 2+ elements could '
'make your code non-deterministic', 'make your code non-deterministic',
stacklevel=2) stacklevel=2)
for key, val in OrderedDict(other).iteritems(): for key, val in iteritems(OrderedDict(other)):
if key in self: if key in self:
if self[key] == val: if self[key] == val:
continue continue
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论