Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
feabe7f9
提交
feabe7f9
authored
5月 03, 2015
作者:
David Warde-Farley
提交者:
Arnaud Bergeron
6月 22, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use six.string_types instead of basestring
上级
2108b783
隐藏空白字符变更
内嵌
并排
正在显示
24 个修改的文件
包含
68 行增加
和
45 行删除
+68
-45
debugmode.py
theano/compile/debugmode.py
+2
-1
function.py
theano/compile/function.py
+3
-2
function_module.py
theano/compile/function_module.py
+1
-1
io.py
theano/compile/io.py
+4
-2
mode.py
theano/compile/mode.py
+6
-5
profilemode.py
theano/compile/profilemode.py
+3
-2
configparser.py
theano/configparser.py
+2
-1
cc.py
theano/gof/cc.py
+7
-6
cmodule.py
theano/gof/cmodule.py
+3
-3
compiledir.py
theano/gof/compiledir.py
+2
-1
graph.py
theano/gof/graph.py
+2
-2
opt.py
theano/gof/opt.py
+3
-2
equilibrium.py
theano/gof/sandbox/equilibrium.py
+3
-2
test_op.py
theano/gof/tests/test_op.py
+2
-1
type.py
theano/gof/type.py
+3
-2
ordered_set.py
theano/misc/ordered_set.py
+3
-1
pycuda_example.py
theano/misc/pycuda_example.py
+2
-1
printing.py
theano/printing.py
+2
-1
basic_ops.py
theano/sandbox/gpuarray/basic_ops.py
+2
-1
symbolic_module.py
theano/sandbox/symbolic_module.py
+3
-2
scan_op.py
theano/scan_module/scan_op.py
+3
-2
scan_utils.py
theano/scan_module/scan_utils.py
+3
-2
type.py
theano/sparse/type.py
+2
-1
raw_random.py
theano/tensor/raw_random.py
+2
-1
没有找到文件。
theano/compile/debugmode.py
浏览文件 @
feabe7f9
...
@@ -17,6 +17,7 @@ import numpy
...
@@ -17,6 +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.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
)
...
@@ -66,7 +67,7 @@ AddConfigVar('DebugMode.warn_input_not_reused',
...
@@ -66,7 +67,7 @@ AddConfigVar('DebugMode.warn_input_not_reused',
def
is_valid_check_preallocated_output_param
(
param
):
def
is_valid_check_preallocated_output_param
(
param
):
if
not
isinstance
(
param
,
basestring
):
if
not
isinstance
(
param
,
string_types
):
return
False
return
False
valid
=
[
"initial"
,
"previous"
,
"c_contiguous"
,
"f_contiguous"
,
valid
=
[
"initial"
,
"previous"
,
"c_contiguous"
,
"f_contiguous"
,
"strided"
,
"wrong_size"
,
"ALL"
,
""
]
"strided"
,
"wrong_size"
,
"ALL"
,
""
]
...
...
theano/compile/function.py
浏览文件 @
feabe7f9
...
@@ -6,6 +6,7 @@ import logging
...
@@ -6,6 +6,7 @@ import logging
import
traceback
as
tb
import
traceback
as
tb
import
re
import
re
from
theano.compat.six
import
string_types
from
theano.compile.io
import
In
from
theano.compile.io
import
In
from
theano.compile.function_module
import
orig_function
from
theano.compile.function_module
import
orig_function
from
theano.compile.pfunc
import
pfunc
from
theano.compile.pfunc
import
pfunc
...
@@ -40,7 +41,7 @@ def function_dump(filename, inputs, outputs=None, mode=None, updates=None,
...
@@ -40,7 +41,7 @@ def function_dump(filename, inputs, outputs=None, mode=None, updates=None,
calling set_value(...) on them before calling `function_dump`.
calling set_value(...) on them before calling `function_dump`.
"""
"""
assert
isinstance
(
filename
,
basestring
)
assert
isinstance
(
filename
,
string_types
)
d
=
dict
(
inputs
=
inputs
,
outputs
=
outputs
,
mode
=
mode
,
updates
=
updates
,
d
=
dict
(
inputs
=
inputs
,
outputs
=
outputs
,
mode
=
mode
,
updates
=
updates
,
givens
=
givens
,
no_default_updates
=
no_default_updates
,
givens
=
givens
,
no_default_updates
=
no_default_updates
,
accept_inplace
=
accept_inplace
,
name
=
name
,
accept_inplace
=
accept_inplace
,
name
=
name
,
...
@@ -212,7 +213,7 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None,
...
@@ -212,7 +213,7 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None,
output_items
=
outputs
.
items
()
output_items
=
outputs
.
items
()
for
item_pair
in
output_items
:
for
item_pair
in
output_items
:
assert
isinstance
(
item_pair
[
0
],
basestring
)
assert
isinstance
(
item_pair
[
0
],
string_types
)
output_items_sorted
=
sorted
(
output_items
)
output_items_sorted
=
sorted
(
output_items
)
...
...
theano/compile/function_module.py
浏览文件 @
feabe7f9
...
@@ -1565,7 +1565,7 @@ def convert_function_input(input):
...
@@ -1565,7 +1565,7 @@ def convert_function_input(input):
orig
=
input
orig
=
input
if
not
input
:
if
not
input
:
raise
TypeError
(
"Nonsensical input specification:
%
s"
%
input
)
raise
TypeError
(
"Nonsensical input specification:
%
s"
%
input
)
if
isinstance
(
input
[
0
],
basestring
):
if
isinstance
(
input
[
0
],
string_types
):
name
=
input
[
0
]
name
=
input
[
0
]
input
=
input
[
1
:]
input
=
input
[
1
:]
else
:
else
:
...
...
theano/compile/io.py
浏览文件 @
feabe7f9
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
from
theano
import
gof
from
theano
import
gof
from
.sharedvalue
import
SharedVariable
from
.sharedvalue
import
SharedVariable
from
theano.compat.six
import
string_types
import
logging
import
logging
_logger
=
logging
.
getLogger
(
"theano.compile.io"
)
_logger
=
logging
.
getLogger
(
"theano.compile.io"
)
...
@@ -71,7 +73,7 @@ class SymbolicInput(object):
...
@@ -71,7 +73,7 @@ class SymbolicInput(object):
else
:
else
:
self
.
name
=
name
self
.
name
=
name
if
self
.
name
is
not
None
and
not
isinstance
(
self
.
name
,
basestring
):
if
self
.
name
is
not
None
and
not
isinstance
(
self
.
name
,
string_types
):
raise
TypeError
(
"name must be a string! (got:
%
s)"
%
self
.
name
)
raise
TypeError
(
"name must be a string! (got:
%
s)"
%
self
.
name
)
self
.
update
=
update
self
.
update
=
update
if
(
mutable
is
not
None
):
if
(
mutable
is
not
None
):
...
@@ -106,7 +108,7 @@ class SymbolicInputKit(object):
...
@@ -106,7 +108,7 @@ class SymbolicInputKit(object):
"""
"""
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
):
if
not
isinstance
(
name
,
basestring
):
if
not
isinstance
(
name
,
string_types
):
raise
TypeError
(
'naem must be a string (got:
%
s)'
%
name
)
raise
TypeError
(
'naem must be a string (got:
%
s)'
%
name
)
self
.
name
=
name
self
.
name
=
name
self
.
sinputs
=
[]
self
.
sinputs
=
[]
...
...
theano/compile/mode.py
浏览文件 @
feabe7f9
...
@@ -10,6 +10,7 @@ from theano import gof
...
@@ -10,6 +10,7 @@ from theano import gof
import
theano.gof.vm
import
theano.gof.vm
from
theano.configparser
import
config
,
AddConfigVar
,
StrParam
from
theano.configparser
import
config
,
AddConfigVar
,
StrParam
from
theano.compile.ops
import
_output_guard
from
theano.compile.ops
import
_output_guard
from
theano.compat.six
import
string_types
_logger
=
logging
.
getLogger
(
'theano.compile.mode'
)
_logger
=
logging
.
getLogger
(
'theano.compile.mode'
)
...
@@ -271,10 +272,10 @@ class Mode(object):
...
@@ -271,10 +272,10 @@ class Mode(object):
linker
,
optimizer
=
state
linker
,
optimizer
=
state
self
.
provided_linker
=
linker
self
.
provided_linker
=
linker
self
.
provided_optimizer
=
optimizer
self
.
provided_optimizer
=
optimizer
if
isinstance
(
linker
,
basestring
)
or
linker
is
None
:
if
isinstance
(
linker
,
string_types
)
or
linker
is
None
:
linker
=
predefined_linkers
[
linker
]
linker
=
predefined_linkers
[
linker
]
self
.
linker
=
linker
self
.
linker
=
linker
if
isinstance
(
optimizer
,
basestring
)
or
optimizer
is
None
:
if
isinstance
(
optimizer
,
string_types
)
or
optimizer
is
None
:
optimizer
=
predefined_optimizers
[
optimizer
]
optimizer
=
predefined_optimizers
[
optimizer
]
if
isinstance
(
optimizer
,
gof
.
Query
):
if
isinstance
(
optimizer
,
gof
.
Query
):
self
.
provided_optimizer
=
optimizer
self
.
provided_optimizer
=
optimizer
...
@@ -297,9 +298,9 @@ class Mode(object):
...
@@ -297,9 +298,9 @@ class Mode(object):
optimizer
=
property
(
__get_optimizer
)
optimizer
=
property
(
__get_optimizer
)
def
get_linker_optimizer
(
self
,
linker
,
optimizer
):
def
get_linker_optimizer
(
self
,
linker
,
optimizer
):
if
isinstance
(
linker
,
basestring
)
or
linker
is
None
:
if
isinstance
(
linker
,
string_types
)
or
linker
is
None
:
linker
=
predefined_linkers
[
linker
]
linker
=
predefined_linkers
[
linker
]
if
isinstance
(
optimizer
,
basestring
)
or
optimizer
is
None
:
if
isinstance
(
optimizer
,
string_types
)
or
optimizer
is
None
:
optimizer
=
predefined_optimizers
[
optimizer
]
optimizer
=
predefined_optimizers
[
optimizer
]
return
(
linker
,
optimizer
)
return
(
linker
,
optimizer
)
...
@@ -341,7 +342,7 @@ def get_mode(orig_string):
...
@@ -341,7 +342,7 @@ def get_mode(orig_string):
string
=
config
.
mode
string
=
config
.
mode
else
:
else
:
string
=
orig_string
string
=
orig_string
if
not
isinstance
(
string
,
basestring
):
if
not
isinstance
(
string
,
string_types
):
return
string
# it is hopefully already a mode...
return
string
# it is hopefully already a mode...
global
instanciated_default_mode
global
instanciated_default_mode
...
...
theano/compile/profilemode.py
浏览文件 @
feabe7f9
...
@@ -7,6 +7,7 @@ import warnings
...
@@ -7,6 +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.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
)
...
@@ -192,7 +193,7 @@ class ProfileMode(Mode):
...
@@ -192,7 +193,7 @@ class ProfileMode(Mode):
self
.
provided_linker
=
linker
self
.
provided_linker
=
linker
self
.
provided_optimizer
=
optimizer
self
.
provided_optimizer
=
optimizer
if
isinstance
(
linker
,
basestring
)
or
linker
is
None
:
if
isinstance
(
linker
,
string_types
)
or
linker
is
None
:
linker
=
predefined_linkers
[
linker
]
linker
=
predefined_linkers
[
linker
]
if
not
config
.
ProfileMode
.
profile_memory
:
if
not
config
.
ProfileMode
.
profile_memory
:
...
@@ -202,7 +203,7 @@ class ProfileMode(Mode):
...
@@ -202,7 +203,7 @@ class ProfileMode(Mode):
linker
=
WrapLinker
([
linker
],
p_thunk
)
linker
=
WrapLinker
([
linker
],
p_thunk
)
self
.
linker
=
linker
self
.
linker
=
linker
if
isinstance
(
optimizer
,
basestring
)
or
optimizer
is
None
:
if
isinstance
(
optimizer
,
string_types
)
or
optimizer
is
None
:
optimizer
=
predefined_optimizers
[
optimizer
]
optimizer
=
predefined_optimizers
[
optimizer
]
self
.
_optimizer
=
optimizer
self
.
_optimizer
=
optimizer
...
...
theano/configparser.py
浏览文件 @
feabe7f9
...
@@ -14,6 +14,7 @@ from theano.compat.six import StringIO
...
@@ -14,6 +14,7 @@ from theano.compat.six import StringIO
import
theano
import
theano
from
theano.compat
import
configparser
as
ConfigParser
from
theano.compat
import
configparser
as
ConfigParser
from
theano.compat.six
import
string_types
import
collections
import
collections
_logger
=
logging
.
getLogger
(
'theano.configparser'
)
_logger
=
logging
.
getLogger
(
'theano.configparser'
)
...
@@ -337,7 +338,7 @@ class EnumStr(ConfigParam):
...
@@ -337,7 +338,7 @@ class EnumStr(ConfigParam):
# All options should be strings
# All options should be strings
for
val
in
self
.
all
:
for
val
in
self
.
all
:
if
not
isinstance
(
val
,
basestring
):
if
not
isinstance
(
val
,
string_types
):
raise
ValueError
(
'Valid values for an EnumStr parameter '
raise
ValueError
(
'Valid values for an EnumStr parameter '
'should be strings'
,
val
,
type
(
val
))
'should be strings'
,
val
,
type
(
val
))
...
...
theano/gof/cc.py
浏览文件 @
feabe7f9
...
@@ -12,6 +12,7 @@ from itertools import izip
...
@@ -12,6 +12,7 @@ from itertools import izip
import
numpy
import
numpy
from
theano.compat
import
PY3
from
theano.compat
import
PY3
from
theano.compat.six
import
string_types
from
theano.compat.six.moves
import
StringIO
,
xrange
from
theano.compat.six.moves
import
StringIO
,
xrange
from
theano.gof.utils
import
MethodNotDefined
from
theano.gof.utils
import
MethodNotDefined
...
@@ -702,7 +703,7 @@ class CLinker(link.Linker):
...
@@ -702,7 +703,7 @@ class CLinker(link.Linker):
pass
pass
else
:
else
:
# The following will be executed if the "try" block succeeds
# The following will be executed if the "try" block succeeds
assert
isinstance
(
c_support_code_apply
[
-
1
],
basestring
),
(
assert
isinstance
(
c_support_code_apply
[
-
1
],
string_types
),
(
str
(
node
.
op
)
+
str
(
node
.
op
)
+
" didn't return a string for c_support_code_apply"
)
" didn't return a string for c_support_code_apply"
)
...
@@ -711,13 +712,13 @@ class CLinker(link.Linker):
...
@@ -711,13 +712,13 @@ class CLinker(link.Linker):
except
utils
.
MethodNotDefined
:
except
utils
.
MethodNotDefined
:
pass
pass
else
:
else
:
assert
isinstance
(
c_init_code_apply
[
-
1
],
basestring
),
(
assert
isinstance
(
c_init_code_apply
[
-
1
],
string_types
),
(
str
(
node
.
op
)
+
str
(
node
.
op
)
+
" didn't return a string for c_init_code_apply"
)
" didn't return a string for c_init_code_apply"
)
try
:
try
:
struct_init
=
op
.
c_init_code_struct
(
node
,
name
,
sub_struct
)
struct_init
=
op
.
c_init_code_struct
(
node
,
name
,
sub_struct
)
assert
isinstance
(
struct_init
,
basestring
),
(
assert
isinstance
(
struct_init
,
string_types
),
(
str
(
node
.
op
)
+
str
(
node
.
op
)
+
" didn't return a string for c_init_code_struct"
)
" didn't return a string for c_init_code_struct"
)
except
utils
.
MethodNotDefined
:
except
utils
.
MethodNotDefined
:
...
@@ -725,7 +726,7 @@ class CLinker(link.Linker):
...
@@ -725,7 +726,7 @@ class CLinker(link.Linker):
try
:
try
:
struct_support
=
op
.
c_support_code_struct
(
node
,
name
)
struct_support
=
op
.
c_support_code_struct
(
node
,
name
)
assert
isinstance
(
struct_support
,
basestring
),
(
assert
isinstance
(
struct_support
,
string_types
),
(
str
(
node
.
op
)
+
str
(
node
.
op
)
+
" didn't return a string for c_support_code_struct"
)
" didn't return a string for c_support_code_struct"
)
except
utils
.
MethodNotDefined
:
except
utils
.
MethodNotDefined
:
...
@@ -733,7 +734,7 @@ class CLinker(link.Linker):
...
@@ -733,7 +734,7 @@ class CLinker(link.Linker):
try
:
try
:
struct_cleanup
=
op
.
c_cleanup_code_struct
(
node
,
name
)
struct_cleanup
=
op
.
c_cleanup_code_struct
(
node
,
name
)
assert
isinstance
(
struct_cleanup
,
basestring
),
(
assert
isinstance
(
struct_cleanup
,
string_types
),
(
str
(
node
.
op
)
+
str
(
node
.
op
)
+
" didn't return a string for c_cleanup_code_struct"
)
" didn't return a string for c_cleanup_code_struct"
)
except
utils
.
MethodNotDefined
:
except
utils
.
MethodNotDefined
:
...
@@ -744,7 +745,7 @@ class CLinker(link.Linker):
...
@@ -744,7 +745,7 @@ class CLinker(link.Linker):
behavior
=
op
.
c_code
(
node
,
name
,
isyms
,
osyms
,
sub
)
behavior
=
op
.
c_code
(
node
,
name
,
isyms
,
osyms
,
sub
)
except
utils
.
MethodNotDefined
:
except
utils
.
MethodNotDefined
:
raise
NotImplementedError
(
"
%
s cannot produce C code"
%
op
)
raise
NotImplementedError
(
"
%
s cannot produce C code"
%
op
)
assert
isinstance
(
behavior
,
basestring
),
(
assert
isinstance
(
behavior
,
string_types
),
(
str
(
node
.
op
)
+
" didn't return a string for c_code"
)
str
(
node
.
op
)
+
" didn't return a string for c_code"
)
# To help understand what is following. It help read the c code.
# To help understand what is following. It help read the c code.
# This prevent different op that generate the same c code
# This prevent different op that generate the same c code
...
...
theano/gof/cmodule.py
浏览文件 @
feabe7f9
...
@@ -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
from
theano.compat.six
import
b
,
BytesIO
,
StringIO
,
string_types
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
...
@@ -396,7 +396,7 @@ def get_module_hash(src_code, key):
...
@@ -396,7 +396,7 @@ def get_module_hash(src_code, key):
# This should be the C++ compilation command line parameters or the
# This should be the C++ compilation command line parameters or the
# libraries to link against.
# libraries to link against.
to_hash
+=
list
(
key_element
)
to_hash
+=
list
(
key_element
)
elif
isinstance
(
key_element
,
basestring
):
elif
isinstance
(
key_element
,
string_types
):
if
key_element
.
startswith
(
'md5:'
):
if
key_element
.
startswith
(
'md5:'
):
# This is the md5 hash of the config options. We can stop
# This is the md5 hash of the config options. We can stop
# here.
# here.
...
@@ -429,7 +429,7 @@ def get_safe_part(key):
...
@@ -429,7 +429,7 @@ def get_safe_part(key):
# Find the md5 hash part.
# Find the md5 hash part.
c_link_key
=
key
[
1
]
c_link_key
=
key
[
1
]
for
key_element
in
c_link_key
[
1
:]:
for
key_element
in
c_link_key
[
1
:]:
if
(
isinstance
(
key_element
,
basestring
)
if
(
isinstance
(
key_element
,
string_types
)
and
key_element
.
startswith
(
'md5:'
)):
and
key_element
.
startswith
(
'md5:'
)):
md5
=
key_element
[
4
:]
md5
=
key_element
[
4
:]
break
break
...
...
theano/gof/compiledir.py
浏览文件 @
feabe7f9
...
@@ -14,6 +14,7 @@ import textwrap
...
@@ -14,6 +14,7 @@ import textwrap
import
numpy
import
numpy
import
theano
import
theano
from
theano.compat.six
import
string_types
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
...
@@ -289,7 +290,7 @@ def cleanup():
...
@@ -289,7 +290,7 @@ def cleanup():
# force the removing of key
# force the removing of key
have_npy_abi_version
=
False
have_npy_abi_version
=
False
break
break
elif
isinstance
(
obj
,
basestring
):
elif
isinstance
(
obj
,
string_types
):
if
obj
.
startswith
(
'NPY_ABI_VERSION=0x'
):
if
obj
.
startswith
(
'NPY_ABI_VERSION=0x'
):
have_npy_abi_version
=
True
have_npy_abi_version
=
True
elif
obj
.
startswith
(
'c_compiler_str='
):
elif
obj
.
startswith
(
'c_compiler_str='
):
...
...
theano/gof/graph.py
浏览文件 @
feabe7f9
...
@@ -13,10 +13,10 @@ from collections import deque
...
@@ -13,10 +13,10 @@ from collections import deque
from
copy
import
copy
from
copy
import
copy
from
itertools
import
count
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
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.
...
@@ -340,7 +340,7 @@ class Variable(Node):
...
@@ -340,7 +340,7 @@ class Variable(Node):
if
index
is
not
None
and
not
isinstance
(
index
,
int
):
if
index
is
not
None
and
not
isinstance
(
index
,
int
):
raise
TypeError
(
"index must be an int"
,
index
)
raise
TypeError
(
"index must be an int"
,
index
)
self
.
index
=
index
self
.
index
=
index
if
name
is
not
None
and
not
isinstance
(
name
,
basestring
):
if
name
is
not
None
and
not
isinstance
(
name
,
string_types
):
raise
TypeError
(
"name must be a string"
,
name
)
raise
TypeError
(
"name must be a string"
,
name
)
self
.
name
=
name
self
.
name
=
name
self
.
auto_name
=
'auto_'
+
str
(
next
(
self
.
__count__
))
self
.
auto_name
=
'auto_'
+
str
(
next
(
self
.
__count__
))
...
...
theano/gof/opt.py
浏览文件 @
feabe7f9
...
@@ -17,6 +17,7 @@ import numpy
...
@@ -17,6 +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.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
...
@@ -1255,7 +1256,7 @@ class PatternSub(LocalOptimizer):
...
@@ -1255,7 +1256,7 @@ class PatternSub(LocalOptimizer):
allow_multiple_clients
))
allow_multiple_clients
))
else
:
else
:
return
retry_with_equiv
()
return
retry_with_equiv
()
elif
isinstance
(
pattern
,
basestring
):
elif
isinstance
(
pattern
,
string_types
):
v
=
unify
.
Var
(
pattern
)
v
=
unify
.
Var
(
pattern
)
if
u
[
v
]
is
not
v
and
u
[
v
]
is
not
expr
:
if
u
[
v
]
is
not
v
and
u
[
v
]
is
not
expr
:
return
retry_with_equiv
()
return
retry_with_equiv
()
...
@@ -1286,7 +1287,7 @@ class PatternSub(LocalOptimizer):
...
@@ -1286,7 +1287,7 @@ class PatternSub(LocalOptimizer):
if
isinstance
(
pattern
,
(
list
,
tuple
)):
if
isinstance
(
pattern
,
(
list
,
tuple
)):
args
=
[
build
(
p
,
u
)
for
p
in
pattern
[
1
:]]
args
=
[
build
(
p
,
u
)
for
p
in
pattern
[
1
:]]
return
pattern
[
0
](
*
args
)
return
pattern
[
0
](
*
args
)
elif
isinstance
(
pattern
,
basestring
):
elif
isinstance
(
pattern
,
string_types
):
return
u
[
unify
.
Var
(
pattern
)]
return
u
[
unify
.
Var
(
pattern
)]
elif
isinstance
(
pattern
,
(
int
,
float
)):
elif
isinstance
(
pattern
,
(
int
,
float
)):
return
pattern
return
pattern
...
...
theano/gof/sandbox/equilibrium.py
浏览文件 @
feabe7f9
from
__future__
import
print_function
from
__future__
import
print_function
from
theano.compat.six.moves
import
reduce
from
theano.compat.six.moves
import
reduce
from
theano.compat.six
import
string_types
if
0
:
if
0
:
class
_EquilibriumOptimizer
(
NavigatorOptimizer
):
class
_EquilibriumOptimizer
(
NavigatorOptimizer
):
...
@@ -66,7 +67,7 @@ if 0:
...
@@ -66,7 +67,7 @@ if 0:
_nodes
=
nodes
_nodes
=
nodes
nodes
=
reduce
(
list
.
__iadd__
,
nodes
=
reduce
(
list
.
__iadd__
,
[
reduce
(
list
.
__iadd__
,
[
reduce
(
list
.
__iadd__
,
[[
n
for
n
,
i
in
out
.
clients
if
not
isinstance
(
n
,
basestring
)]
for
out
in
node
.
outputs
],
[[
n
for
n
,
i
in
out
.
clients
if
not
isinstance
(
n
,
string_types
)]
for
out
in
node
.
outputs
],
[])
for
node
in
nodes
],
[])
for
node
in
nodes
],
[])
[])
candidates
=
tracks
candidates
=
tracks
...
@@ -123,7 +124,7 @@ if 0:
...
@@ -123,7 +124,7 @@ if 0:
# for candidate in candidates:
# for candidate in candidates:
# if candidate.current.inputs is not None:
# if candidate.current.inputs is not None:
# for in1, in2 in zip(candidate.current.inputs, node.inputs):
# for in1, in2 in zip(candidate.current.inputs, node.inputs):
# if isinstance(in1,
basestring
):
# if isinstance(in1,
string_types
):
# candidate.match[in1] = in2
# candidate.match[in1] = in2
# for client in node.clients:
# for client in node.clients:
...
...
theano/gof/tests/test_op.py
浏览文件 @
feabe7f9
...
@@ -5,6 +5,7 @@ import numpy
...
@@ -5,6 +5,7 @@ import numpy
import
theano
import
theano
import
theano.gof.op
as
op
import
theano.gof.op
as
op
from
theano.compat.six
import
string_types
from
theano.compat.six.moves
import
xrange
from
theano.compat.six.moves
import
xrange
from
theano.gof.type
import
Type
,
Generic
from
theano.gof.type
import
Type
,
Generic
from
theano.gof.graph
import
Apply
,
Variable
from
theano.gof.graph
import
Apply
,
Variable
...
@@ -39,7 +40,7 @@ class MyType(Type):
...
@@ -39,7 +40,7 @@ class MyType(Type):
def
filter
(
self
,
x
,
strict
=
False
,
allow_downcast
=
None
):
def
filter
(
self
,
x
,
strict
=
False
,
allow_downcast
=
None
):
# Dummy filter: we want this type to represent strings that
# Dummy filter: we want this type to represent strings that
# start with `self.thingy`.
# start with `self.thingy`.
if
not
isinstance
(
x
,
basestring
):
if
not
isinstance
(
x
,
string_types
):
raise
TypeError
(
"Invalid type"
)
raise
TypeError
(
"Invalid type"
)
if
not
x
.
startswith
(
self
.
thingy
):
if
not
x
.
startswith
(
self
.
thingy
):
raise
ValueError
(
"Invalid value"
)
raise
ValueError
(
"Invalid value"
)
...
...
theano/gof/type.py
浏览文件 @
feabe7f9
"""WRITEME Defines the `Type` class."""
"""WRITEME Defines the `Type` class."""
from
theano.compat
import
PY3
from
theano.compat
import
PY3
from
theano.compat.six
import
string_types
from
theano.gof
import
utils
from
theano.gof
import
utils
from
theano.gof.utils
import
MethodNotDefined
,
object2
from
theano.gof.utils
import
MethodNotDefined
,
object2
...
@@ -540,10 +541,10 @@ class CDataType(Type):
...
@@ -540,10 +541,10 @@ class CDataType(Type):
function must have a `void` return and take a
function must have a `void` return and take a
single pointer argument.
single pointer argument.
"""
"""
assert
isinstance
(
ctype
,
basestring
)
assert
isinstance
(
ctype
,
string_types
)
self
.
ctype
=
ctype
self
.
ctype
=
ctype
if
freefunc
is
not
None
:
if
freefunc
is
not
None
:
assert
isinstance
(
freefunc
,
basestring
)
assert
isinstance
(
freefunc
,
string_types
)
self
.
freefunc
=
freefunc
self
.
freefunc
=
freefunc
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
...
...
theano/misc/ordered_set.py
浏览文件 @
feabe7f9
...
@@ -3,6 +3,8 @@ from collections import MutableSet
...
@@ -3,6 +3,8 @@ from collections import MutableSet
from
theano.compat
import
OrderedDict
from
theano.compat
import
OrderedDict
import
types
import
types
from
theano.compat.six
import
string_types
def
check_deterministic
(
iterable
):
def
check_deterministic
(
iterable
):
# Most places where OrderedSet is used, theano interprets any exception
# Most places where OrderedSet is used, theano interprets any exception
...
@@ -13,7 +15,7 @@ def check_deterministic(iterable):
...
@@ -13,7 +15,7 @@ def check_deterministic(iterable):
# theano to use exceptions correctly, so that this can be a TypeError.
# theano to use exceptions correctly, so that this can be a TypeError.
if
iterable
is
not
None
:
if
iterable
is
not
None
:
assert
isinstance
(
iterable
,
(
assert
isinstance
(
iterable
,
(
list
,
tuple
,
OrderedSet
,
types
.
GeneratorType
,
basestring
))
list
,
tuple
,
OrderedSet
,
types
.
GeneratorType
,
string_types
))
# Copyright (C) 2009 Raymond Hettinger
# Copyright (C) 2009 Raymond Hettinger
# Permission is hereby granted, free of charge, to any person obtaining a
# Permission is hereby granted, free of charge, to any person obtaining a
...
...
theano/misc/pycuda_example.py
浏览文件 @
feabe7f9
...
@@ -23,6 +23,7 @@ TheanoElementwiseKernel.
...
@@ -23,6 +23,7 @@ TheanoElementwiseKernel.
import
numpy
import
numpy
import
theano
import
theano
from
theano.compat.six
import
string_types
from
theano.compat.six.moves
import
xrange
from
theano.compat.six.moves
import
xrange
from
theano.gof
import
Op
,
Apply
,
local_optimizer
,
EquilibriumDB
from
theano.gof
import
Op
,
Apply
,
local_optimizer
,
EquilibriumDB
from
theano.sandbox.cuda
import
GpuElemwise
,
CudaNdarrayType
,
GpuOp
from
theano.sandbox.cuda
import
GpuElemwise
,
CudaNdarrayType
,
GpuOp
...
@@ -64,7 +65,7 @@ class TheanoElementwiseKernel(pycuda.elementwise.ElementwiseKernel):
...
@@ -64,7 +65,7 @@ class TheanoElementwiseKernel(pycuda.elementwise.ElementwiseKernel):
name="kernel", keep=False, options=None, **kwargs):
name="kernel", keep=False, options=None, **kwargs):
if options is None:
if options is None:
options = []
options = []
if isinstance(arguments,
basestring
):
if isinstance(arguments,
string_types
):
arguments = [theano_parse_c_arg(arg)
arguments = [theano_parse_c_arg(arg)
for arg in arguments.split(",")]
for arg in arguments.split(",")]
pycuda.elementwise.ElementwiseKernel.__init__(self, arguments,
pycuda.elementwise.ElementwiseKernel.__init__(self, arguments,
...
...
theano/printing.py
浏览文件 @
feabe7f9
...
@@ -13,6 +13,7 @@ import hashlib
...
@@ -13,6 +13,7 @@ import hashlib
import
numpy
as
np
import
numpy
as
np
import
collections
import
collections
from
theano.compat.six
import
string_types
try
:
try
:
import
pydot
as
pd
import
pydot
as
pd
...
@@ -345,7 +346,7 @@ class PatternPrinter:
...
@@ -345,7 +346,7 @@ class PatternPrinter:
def
__init__
(
self
,
*
patterns
):
def
__init__
(
self
,
*
patterns
):
self
.
patterns
=
[]
self
.
patterns
=
[]
for
pattern
in
patterns
:
for
pattern
in
patterns
:
if
isinstance
(
pattern
,
basestring
):
if
isinstance
(
pattern
,
string_types
):
self
.
patterns
.
append
((
pattern
,
()))
self
.
patterns
.
append
((
pattern
,
()))
else
:
else
:
self
.
patterns
.
append
((
pattern
[
0
],
pattern
[
1
:]))
self
.
patterns
.
append
((
pattern
[
0
],
pattern
[
1
:]))
...
...
theano/sandbox/gpuarray/basic_ops.py
浏览文件 @
feabe7f9
...
@@ -12,6 +12,7 @@ from theano.tensor.basic import Alloc, Join, Split
...
@@ -12,6 +12,7 @@ from theano.tensor.basic import Alloc, Join, Split
from
theano.gof
import
HideC
from
theano.gof
import
HideC
from
theano.gof.utils
import
MethodNotDefined
from
theano.gof.utils
import
MethodNotDefined
from
theano.compat
import
PY3
from
theano.compat
import
PY3
from
theano.compat.six
import
string_types
try
:
try
:
import
pygpu
import
pygpu
...
@@ -65,7 +66,7 @@ class Kernel(object):
...
@@ -65,7 +66,7 @@ class Kernel(object):
@staticmethod
@staticmethod
def
get_flags
(
*
types
):
def
get_flags
(
*
types
):
def
get_dtype
(
t
):
def
get_dtype
(
t
):
if
isinstance
(
t
,
(
str
,
unicode
)
):
if
isinstance
(
t
,
string_types
):
return
numpy
.
dtype
(
t
)
return
numpy
.
dtype
(
t
)
elif
isinstance
(
t
,
Type
):
elif
isinstance
(
t
,
Type
):
return
t
.
dtype
return
t
.
dtype
...
...
theano/sandbox/symbolic_module.py
浏览文件 @
feabe7f9
...
@@ -4,6 +4,7 @@ import theano
...
@@ -4,6 +4,7 @@ import theano
import
theano.tensor
as
T
import
theano.tensor
as
T
import
collections
import
collections
from
theano.compat.six
import
string_types
#import klass
#import klass
...
@@ -133,7 +134,7 @@ def compile(smod, initial_values=None):
...
@@ -133,7 +134,7 @@ def compile(smod, initial_values=None):
elif
issymbolicmodule
(
val
):
elif
issymbolicmodule
(
val
):
for
s
in
modwalker
(
val
.
__dict__
,
[
v
for
k
,
v
in
sym_items
(
val
)]):
for
s
in
modwalker
(
val
.
__dict__
,
[
v
for
k
,
v
in
sym_items
(
val
)]):
yield
s
yield
s
elif
isinstance
(
val
,
(
basestring
,
int
,
float
)):
elif
isinstance
(
val
,
(
string_types
,
int
,
float
)):
pass
pass
elif
isinstance
(
val
,
theano
.
Variable
):
elif
isinstance
(
val
,
theano
.
Variable
):
pass
pass
...
@@ -184,7 +185,7 @@ def compile(smod, initial_values=None):
...
@@ -184,7 +185,7 @@ def compile(smod, initial_values=None):
reflected
[
thing
]
=
cmod
reflected
[
thing
]
=
cmod
for
key
,
val
in
sym_items
(
thing
):
for
key
,
val
in
sym_items
(
thing
):
setattr
(
CMod
,
key
,
reflect
(
val
))
setattr
(
CMod
,
key
,
reflect
(
val
))
elif
isinstance
(
thing
,
(
basestring
,
int
,
float
)):
elif
isinstance
(
thing
,
(
string_types
,
int
,
float
)):
reflected
[
thing
]
=
thing
reflected
[
thing
]
=
thing
elif
isinstance
(
thing
,
theano
.
Variable
):
elif
isinstance
(
thing
,
theano
.
Variable
):
if
thing
.
owner
is
None
:
if
thing
.
owner
is
None
:
...
...
theano/scan_module/scan_op.py
浏览文件 @
feabe7f9
...
@@ -72,6 +72,7 @@ from theano.compat import OrderedDict
...
@@ -72,6 +72,7 @@ from theano.compat import OrderedDict
from
theano.tensor
import
TensorType
from
theano.tensor
import
TensorType
from
theano.tensor.opt
import
Shape_i
from
theano.tensor.opt
import
Shape_i
from
theano.gradient
import
grad_undefined
,
DisconnectedType
,
NullType
from
theano.gradient
import
grad_undefined
,
DisconnectedType
,
NullType
from
theano.compat.six
import
string_types
from
theano.compile.profiling
import
ScanProfileStats
from
theano.compile.profiling
import
ScanProfileStats
from
theano.scan_module
import
scan_utils
from
theano.scan_module
import
scan_utils
...
@@ -745,9 +746,9 @@ class Scan(PureOp):
...
@@ -745,9 +746,9 @@ class Scan(PureOp):
wrapped_outputs
+=
self
.
outputs
[
slices
:]
wrapped_outputs
+=
self
.
outputs
[
slices
:]
profile
=
None
profile
=
None
if
(
theano
.
config
.
profile
or
if
(
theano
.
config
.
profile
or
(
isinstance
(
self
.
profile
,
(
basestring
,
bool
,
int
))
(
isinstance
(
self
.
profile
,
(
string_types
,
bool
,
int
))
and
self
.
profile
)):
and
self
.
profile
)):
if
isinstance
(
self
.
profile
,
basestring
):
if
isinstance
(
self
.
profile
,
string_types
):
profile
=
ScanProfileStats
(
name
=
self
.
profile
)
profile
=
ScanProfileStats
(
name
=
self
.
profile
)
else
:
else
:
profile
=
ScanProfileStats
(
name
=
self
.
name
)
profile
=
ScanProfileStats
(
name
=
self
.
name
)
...
...
theano/scan_module/scan_utils.py
浏览文件 @
feabe7f9
...
@@ -21,6 +21,7 @@ from itertools import izip
...
@@ -21,6 +21,7 @@ from itertools import izip
import
numpy
import
numpy
import
theano
import
theano
from
theano.compat.six
import
string_types
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
...
@@ -367,7 +368,7 @@ def isNaN_or_Inf_or_None(x):
...
@@ -367,7 +368,7 @@ def isNaN_or_Inf_or_None(x):
try
:
try
:
isNaN
=
numpy
.
isnan
(
x
)
isNaN
=
numpy
.
isnan
(
x
)
isInf
=
numpy
.
isinf
(
x
)
isInf
=
numpy
.
isinf
(
x
)
isStr
=
isinstance
(
x
,
basestring
)
isStr
=
isinstance
(
x
,
string_types
)
except
Exception
:
except
Exception
:
isNaN
=
False
isNaN
=
False
isInf
=
False
isInf
=
False
...
@@ -380,7 +381,7 @@ def isNaN_or_Inf_or_None(x):
...
@@ -380,7 +381,7 @@ def isNaN_or_Inf_or_None(x):
except
Exception
:
except
Exception
:
isNaN
=
False
isNaN
=
False
isInf
=
False
isInf
=
False
if
isinstance
(
x
,
gof
.
Constant
)
and
isinstance
(
x
.
data
,
basestring
):
if
isinstance
(
x
,
gof
.
Constant
)
and
isinstance
(
x
.
data
,
string_types
):
isStr
=
True
isStr
=
True
else
:
else
:
isStr
=
False
isStr
=
False
...
...
theano/sparse/type.py
浏览文件 @
feabe7f9
...
@@ -7,6 +7,7 @@ except ImportError:
...
@@ -7,6 +7,7 @@ except ImportError:
import
theano
import
theano
from
theano
import
gof
from
theano
import
gof
from
theano.compat.six
import
string_types
def
_is_sparse
(
x
):
def
_is_sparse
(
x
):
...
@@ -61,7 +62,7 @@ class SparseType(gof.Type):
...
@@ -61,7 +62,7 @@ class SparseType(gof.Type):
raise
NotImplementedError
(
'unsupported dtype "
%
s" not in list'
%
raise
NotImplementedError
(
'unsupported dtype "
%
s" not in list'
%
dtype
,
list
(
self
.
dtype_set
))
dtype
,
list
(
self
.
dtype_set
))
assert
isinstance
(
format
,
basestring
)
assert
isinstance
(
format
,
string_types
)
if
format
in
self
.
format_cls
:
if
format
in
self
.
format_cls
:
self
.
format
=
format
self
.
format
=
format
else
:
else
:
...
...
theano/tensor/raw_random.py
浏览文件 @
feabe7f9
...
@@ -12,6 +12,7 @@ from theano.compat.six.moves import reduce
...
@@ -12,6 +12,7 @@ from theano.compat.six.moves import reduce
from
theano
import
tensor
from
theano
import
tensor
from
theano.tensor
import
opt
from
theano.tensor
import
opt
from
theano
import
gof
from
theano
import
gof
from
theano.compat.six
import
string_types
from
theano.compile
import
optdb
from
theano.compile
import
optdb
...
@@ -144,7 +145,7 @@ class RandomFunction(gof.Op):
...
@@ -144,7 +145,7 @@ class RandomFunction(gof.Op):
def
__setstate__
(
self
,
state
):
def
__setstate__
(
self
,
state
):
self
.
state
=
state
self
.
state
=
state
fn
,
outtype
,
inplace
,
ndim_added
=
state
fn
,
outtype
,
inplace
,
ndim_added
=
state
if
isinstance
(
fn
,
basestring
):
if
isinstance
(
fn
,
string_types
):
self
.
fn
=
getattr
(
numpy
.
random
.
RandomState
,
fn
)
self
.
fn
=
getattr
(
numpy
.
random
.
RandomState
,
fn
)
else
:
else
:
self
.
fn
=
fn
self
.
fn
=
fn
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论