Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5b3d7c52
提交
5b3d7c52
authored
11月 01, 2020
作者:
George Ho
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove 'easy' references to theano.compat
上级
70ec78a1
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
62 行增加
和
126 行删除
+62
-126
test_function_module.py
tests/compile/test_function_module.py
+1
-1
test_multinomial.py
tests/gpuarray/test_multinomial.py
+0
-7
function.py
theano/compile/function.py
+3
-3
cc.py
theano/gof/cc.py
+7
-31
cmodule.py
theano/gof/cmodule.py
+19
-29
cutils.py
theano/gof/cutils.py
+20
-30
optdb.py
theano/gof/optdb.py
+1
-1
utils.py
theano/gof/utils.py
+9
-22
basic.py
theano/scalar/basic.py
+1
-1
updates.py
theano/updates.py
+1
-1
没有找到文件。
tests/compile/test_function_module.py
浏览文件 @
5b3d7c52
...
...
@@ -9,7 +9,7 @@ import theano
import
theano.gpuarray
import
theano.tensor
as
tt
from
theano
import
config
,
gof
from
theano.
compat
import
exc_message
from
theano.
utils
import
exc_message
from
theano.compile
import
UnusedInputError
,
function
from
theano.compile.io
import
In
,
Out
from
theano.gof
import
MissingInputError
...
...
tests/gpuarray/test_multinomial.py
浏览文件 @
5b3d7c52
...
...
@@ -8,7 +8,6 @@ import tests.unittest_tools as utt
import
theano
from
tests.gpuarray.config
import
mode_with_gpu
from
theano
import
config
,
function
,
tensor
from
theano.compat
import
PY3
from
theano.gpuarray.multinomial
import
(
GPUAChoiceFromUniform
,
GPUAMultinomialFromUniform
,
...
...
@@ -378,9 +377,3 @@ def test_gpu_opt_wor():
def
test_unpickle_legacy_op
():
testfile_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
fname
=
"test_gpuarray_multinomial_wo_replacement.pkl"
if
not
PY3
:
with
open
(
os
.
path
.
join
(
testfile_dir
,
fname
))
as
fp
:
u
=
Unpickler
(
fp
)
m
=
u
.
load
()
assert
isinstance
(
m
,
GPUAChoiceFromUniform
)
theano/compile/function.py
浏览文件 @
5b3d7c52
...
...
@@ -8,8 +8,8 @@ import logging
import
re
import
traceback
as
tb
import
warnings
from
collections
import
OrderedDict
from
theano
import
compat
from
theano.compile.function_module
import
orig_function
from
theano.compile.pfunc
import
pfunc
...
...
@@ -291,7 +291,7 @@ def function(
if
(
isinstance
(
updates
,
dict
)
and
not
isinstance
(
updates
,
compat
.
OrderedDict
)
and
not
isinstance
(
updates
,
OrderedDict
)
and
len
(
updates
)
>
1
):
warnings
.
warn
(
...
...
@@ -300,7 +300,7 @@ def function(
" got "
+
str
(
type
(
updates
))
+
". Using "
"a standard dictionary here results in "
"non-deterministic behavior. You should use an OrderedDict"
" if you are using Python 2.7 (
theano.compat
.OrderedDict"
" if you are using Python 2.7 (
collections
.OrderedDict"
" for older python), or use a list of (shared, update)"
" pairs. Do not just convert your dictionary to this type before"
" the call as the conversion will still be non-deterministic."
,
...
...
theano/gof/cc.py
浏览文件 @
5b3d7c52
...
...
@@ -12,7 +12,6 @@ from six.moves import StringIO
import
theano
from
theano
import
config
from
theano.compat
import
PY3
from
theano.gof
import
cmodule
,
graph
,
link
,
utils
from
theano.gof.callcache
import
CallCache
from
theano.gof.compilelock
import
get_lock
,
release_lock
...
...
@@ -1648,8 +1647,7 @@ class CLinker(link.Linker):
# Static methods that can run and destroy the struct built by
# instantiate.
if
PY3
:
static
=
"""
static
=
"""
static int {struct_name}_executor({struct_name} *self) {{
return self->run();
}}
...
...
@@ -1658,21 +1656,7 @@ class CLinker(link.Linker):
{struct_name} *self = ({struct_name} *)PyCapsule_GetContext(capsule);
delete self;
}}
"""
.
format
(
struct_name
=
self
.
struct_name
)
else
:
static
=
"""
static int
%(struct_name)
s_executor(
%(struct_name)
s* self) {
return self->run();
}
static void
%(struct_name)
s_destructor(void* executor, void* self) {
delete ((
%(struct_name)
s*)self);
}
"""
%
dict
(
struct_name
=
self
.
struct_name
)
"""
.
format
(
struct_name
=
self
.
struct_name
)
# We add all the support code, compile args, headers and libs we need.
for
support_code
in
self
.
support_code
()
+
self
.
c_support_code_apply
:
...
...
@@ -1769,9 +1753,7 @@ class CLinker(link.Linker):
print
(
" delete struct_ptr;"
,
file
=
code
)
print
(
" return NULL;"
,
file
=
code
)
print
(
" }"
,
file
=
code
)
if
PY3
:
print
(
"""
\
print
(
"""
\
PyObject* thunk = PyCapsule_New((void*)(&{struct_name}_executor), NULL, {struct_name}_destructor);
if (thunk != NULL && PyCapsule_SetContext(thunk, struct_ptr) != 0) {{
PyErr_Clear();
...
...
@@ -1779,16 +1761,10 @@ class CLinker(link.Linker):
thunk = NULL;
}}
"""
.
format
(
**
locals
()
),
file
=
code
,
)
else
:
print
(
" PyObject* thunk = PyCObject_FromVoidPtrAndDesc((void*)(&
%(struct_name)
s_executor), struct_ptr,
%(struct_name)
s_destructor);"
%
locals
(),
file
=
code
,
)
**
locals
()
),
file
=
code
,
)
print
(
" return thunk; }"
,
file
=
code
)
return
code
.
getvalue
()
...
...
theano/gof/cmodule.py
浏览文件 @
5b3d7c52
...
...
@@ -149,38 +149,28 @@ class DynamicModule:
print
(
"};"
,
file
=
stream
)
def
print_init
(
self
,
stream
):
if
PY3
:
print
(
"""
\
print
(
"""
\
static struct PyModuleDef moduledef = {{
PyModuleDef_HEAD_INIT,
"{name}",
NULL,
-1,
MyMethods,
PyModuleDef_HEAD_INIT,
"{name}",
NULL,
-1,
MyMethods,
}};
"""
.
format
(
name
=
self
.
hash_placeholder
),
file
=
stream
,
)
print
(
(
"PyMODINIT_FUNC PyInit_
%
s(void) {"
%
self
.
hash_placeholder
),
file
=
stream
,
)
for
block
in
self
.
init_blocks
:
print
(
" "
,
block
,
file
=
stream
)
print
(
" PyObject *m = PyModule_Create(&moduledef);"
,
file
=
stream
)
print
(
" return m;"
,
file
=
stream
)
else
:
print
((
"PyMODINIT_FUNC init
%
s(void){"
%
self
.
hash_placeholder
),
file
=
stream
)
for
block
in
self
.
init_blocks
:
print
(
" "
,
block
,
file
=
stream
)
print
(
" "
,
(
'(void) Py_InitModule("
%
s", MyMethods);'
%
self
.
hash_placeholder
),
file
=
stream
,
)
name
=
self
.
hash_placeholder
),
file
=
stream
,
)
print
(
(
"PyMODINIT_FUNC PyInit_
%
s(void) {"
%
self
.
hash_placeholder
),
file
=
stream
,
)
for
block
in
self
.
init_blocks
:
print
(
" "
,
block
,
file
=
stream
)
print
(
" PyObject *m = PyModule_Create(&moduledef);"
,
file
=
stream
)
print
(
" return m;"
,
file
=
stream
)
print
(
"}"
,
file
=
stream
)
def
add_include
(
self
,
str
):
...
...
theano/gof/cutils.py
浏览文件 @
5b3d7c52
...
...
@@ -3,7 +3,6 @@ import os
import
sys
from
theano
import
config
from
theano.compat
import
PY3
from
theano.gof.compilelock
import
get_lock
,
release_lock
from
.
import
cmodule
...
...
@@ -49,35 +48,26 @@ def compile_cutils():
"Run a theano cthunk."},
{NULL, NULL, 0, NULL} /* Sentinel */
};"""
if
PY3
:
# This is not the most efficient code, but it is written this way to
# highlight the changes needed to make 2.x code compile under python 3.
code
=
code
.
replace
(
"<Python.h>"
,
'"numpy/npy_3kcompat.h"'
,
1
)
code
=
code
.
replace
(
"PyCObject"
,
"NpyCapsule"
)
code
+=
"""
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"cutils_ext",
NULL,
-1,
CutilsExtMethods,
};
PyMODINIT_FUNC
PyInit_cutils_ext(void) {
return PyModule_Create(&moduledef);
}
}
"""
else
:
code
+=
"""
PyMODINIT_FUNC
initcutils_ext(void)
{
(void) Py_InitModule("cutils_ext", CutilsExtMethods);
}
} //extern C
"""
# This is not the most efficient code, but it is written this way to
# highlight the changes needed to make 2.x code compile under python 3.
code
=
code
.
replace
(
"<Python.h>"
,
'"numpy/npy_3kcompat.h"'
,
1
)
code
=
code
.
replace
(
"PyCObject"
,
"NpyCapsule"
)
code
+=
"""
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"cutils_ext",
NULL,
-1,
CutilsExtMethods,
};
PyMODINIT_FUNC
PyInit_cutils_ext(void) {
return PyModule_Create(&moduledef);
}
}
"""
loc
=
os
.
path
.
join
(
config
.
compiledir
,
"cutils_ext"
)
if
not
os
.
path
.
exists
(
loc
):
...
...
theano/gof/optdb.py
浏览文件 @
5b3d7c52
...
...
@@ -5,7 +5,7 @@ import sys
from
six
import
StringIO
from
theano
import
config
from
theano.
compat
import
DefaultOrderedDict
from
theano.
utils
import
DefaultOrderedDict
from
theano.gof
import
opt
from
theano.misc.ordered_set
import
OrderedSet
...
...
theano/gof/utils.py
浏览文件 @
5b3d7c52
...
...
@@ -6,7 +6,6 @@ import numpy as np
from
six.moves
import
StringIO
from
theano
import
config
from
theano.compat
import
PY3
def
simple_extract_stack
(
f
=
None
,
limit
=
None
,
skips
=
None
):
...
...
@@ -598,28 +597,16 @@ def remove(predicate, coll):
return
[
x
for
x
in
coll
if
not
predicate
(
x
)]
if
PY3
:
import
hashlib
import
hashlib
def
hash_from_code
(
msg
):
# hashlib.sha256() requires an object that supports buffer interface,
# but Python 3 (unicode) strings don't.
if
isinstance
(
msg
,
str
):
msg
=
msg
.
encode
()
# Python 3 does not like module names that start with
# a digit.
return
"m"
+
hashlib
.
sha256
(
msg
)
.
hexdigest
()
else
:
import
hashlib
def
hash_from_code
(
msg
):
try
:
return
hashlib
.
sha256
(
msg
)
.
hexdigest
()
except
TypeError
:
assert
isinstance
(
msg
,
np
.
ndarray
)
return
hashlib
.
sha256
(
np
.
getbuffer
(
msg
))
.
hexdigest
()
def
hash_from_code
(
msg
):
# hashlib.sha256() requires an object that supports buffer interface,
# but Python 3 (unicode) strings don't.
if
isinstance
(
msg
,
str
):
msg
=
msg
.
encode
()
# Python 3 does not like module names that start with
# a digit.
return
"m"
+
hashlib
.
sha256
(
msg
)
.
hexdigest
()
def
hash_from_file
(
file_path
):
...
...
theano/scalar/basic.py
浏览文件 @
5b3d7c52
...
...
@@ -16,12 +16,12 @@ from copy import copy
from
functools
import
partial
from
itertools
import
chain
from
textwrap
import
dedent
from
collections.abc
import
Callable
import
numpy
as
np
import
theano
from
theano
import
config
,
gof
,
printing
from
theano.compat
import
Callable
from
theano.gof
import
Apply
,
Constant
,
FunctionGraph
,
Op
,
Type
,
Variable
,
utils
from
theano.gradient
import
DisconnectedType
,
grad_undefined
from
theano.misc.safe_asarray
import
_asarray
...
...
theano/updates.py
浏览文件 @
5b3d7c52
...
...
@@ -40,7 +40,7 @@ class OrderedUpdates(OrderedDict):
"non-ordered dictionary with 2+ elements could "
"make your code non-deterministic. You can use "
"an OrderedDict that is available at "
"
theano.compat
.OrderedDict for python 2.6+."
"
collections
.OrderedDict for python 2.6+."
)
super
()
.
__init__
(
*
key
,
**
kwargs
)
for
key
in
self
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论