Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ff9bc957
提交
ff9bc957
authored
10月 09, 2016
作者:
sentient07
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removed hash_from_dict and a fix for _c_code
上级
9a3d3ef1
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
19 行增加
和
71 行删除
+19
-71
test_utils.py
theano/gof/tests/test_utils.py
+1
-18
utils.py
theano/gof/utils.py
+0
-34
frozendict.py
theano/misc/frozendict.py
+1
-0
pycuda_example.py
theano/misc/pycuda_example.py
+5
-18
basic.py
theano/scalar/basic.py
+1
-1
elemwise.py
theano/tensor/elemwise.py
+11
-0
没有找到文件。
theano/gof/tests/test_utils.py
浏览文件 @
ff9bc957
from
__future__
import
absolute_import
,
print_function
,
division
from
collections
import
OrderedDict
import
theano
from
theano.gof.utils
import
(
give_variables_names
,
hash_from_dict
,
remove
,
unique
)
give_variables_names
,
remove
,
unique
)
def
test_give_variables_names
():
...
...
@@ -49,22 +48,6 @@ def test_remove():
assert
list
(
remove
(
even
,
range
(
5
)))
==
list
(
filter
(
odd
,
range
(
5
)))
def
test_hash_from_dict
():
dicts
=
[{},
{
0
:
0
},
{
0
:
1
},
{
1
:
0
},
{
1
:
1
},
{
0
:
(
0
,)},
{
0
:
[
1
]},
{
0
:
(
0
,
1
)},
{
0
:
[
1
,
0
]}]
for
elem
in
dicts
[:]:
dicts
.
append
(
OrderedDict
(
elem
))
hashs
=
[]
for
idx
,
d
in
enumerate
(
dicts
):
h
=
hash_from_dict
(
d
)
assert
h
not
in
hashs
hashs
.
append
(
h
)
# List are not hashable. So they are transformed into tuple.
assert
hash_from_dict
({
0
:
(
0
,)})
==
hash_from_dict
({
0
:
[
0
]})
def
test_stack_trace
():
orig
=
theano
.
config
.
traceback
.
limit
try
:
...
...
theano/gof/utils.py
浏览文件 @
ff9bc957
from
__future__
import
absolute_import
,
print_function
,
division
from
collections
import
OrderedDict
import
linecache
import
sys
import
traceback
...
...
@@ -570,36 +569,3 @@ def hash_from_file(file_path):
"""
return
hash_from_code
(
open
(
file_path
,
'rb'
)
.
read
())
def
hash_from_dict
(
d
):
"""
Work around the fact that dict are not hashable in python.
This request that all object have a sorted order that depend only
on the key of the object. We support only integer/float/string keys.
Also, we transform values that are list into tuple as list are not
hashable.
Notes
-----
Special case for OrderedDict, it use the order of the dict,
so the key don't need to be sortable.
"""
if
isinstance
(
d
,
OrderedDict
):
items
=
list
(
iteritems
(
d
))
else
:
items
=
list
(
d
.
items
())
items
.
sort
()
first_part
=
[
k
for
k
,
v
in
items
]
second_part
=
[]
for
k
,
v
in
items
:
assert
isinstance
(
k
,
(
string_types
,
integer_types
,
float
))
if
isinstance
(
v
,
(
tuple
,
list
)):
second_part
+=
[
tuple
(
v
)]
else
:
second_part
+=
[
v
]
tuple_items
=
tuple
(
first_part
+
second_part
+
[
d
.
__class__
])
return
hash
(
tuple_items
)
theano/misc/frozendict.py
浏览文件 @
ff9bc957
# License : https://github.com/slezica/python-frozendict/blob/master/LICENSE.txt
from
__future__
import
absolute_import
,
print_function
,
division
import
collections
import
operator
import
functools
...
...
theano/misc/pycuda_example.py
浏览文件 @
ff9bc957
...
...
@@ -28,11 +28,11 @@ import theano
from
six.moves
import
xrange
from
theano.compat
import
izip
from
theano.gof
import
Op
,
Apply
,
local_optimizer
,
EquilibriumDB
from
theano.gof.utils
import
hash_from_dict
from
theano.sandbox.cuda
import
GpuElemwise
,
CudaNdarrayType
,
GpuOp
from
theano.sandbox.cuda.basic_ops
import
(
as_cuda_ndarray_variable
,
gpu_contiguous
)
from
theano.sandbox.cuda.opt
import
gpu_seqopt
from
theano.misc.frozendict
import
frozendict
import
pycuda
from
pycuda.compiler
import
SourceModule
...
...
@@ -183,13 +183,14 @@ class PycudaElemwiseKernelOp(GpuOp):
class
PycudaElemwiseSourceModuleOp
(
GpuOp
):
nin
=
property
(
lambda
self
:
self
.
scalar_op
.
nin
)
nout
=
property
(
lambda
self
:
self
.
scalar_op
.
nout
)
__props__
=
(
"scalar_op"
,
"inplace_pattern"
,
"name"
)
def
__init__
(
self
,
scalar_op
,
inplace_pattern
=
None
,
name
=
None
):
if
inplace_pattern
is
None
:
inplace_pattern
=
{}
inplace_pattern
=
frozendict
({})
self
.
name
=
name
self
.
scalar_op
=
scalar_op
self
.
inplace_pattern
=
inplace_pattern
self
.
inplace_pattern
=
frozendict
(
inplace_pattern
)
def
__str__
(
self
):
if
self
.
name
is
None
:
...
...
@@ -203,15 +204,6 @@ class PycudaElemwiseSourceModuleOp(GpuOp):
else
:
return
self
.
name
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
)
and
self
.
scalar_op
==
other
.
scalar_op
and
self
.
inplace_pattern
==
other
.
inplace_pattern
)
def
__hash__
(
self
):
return
(
hash
(
type
(
self
))
^
hash
(
self
.
scalar_op
)
^
hash_from_dict
(
self
.
inplace_pattern
))
def
make_node
(
self
,
*
inputs
):
_inputs
=
[
gpu_contiguous
(
as_cuda_ndarray_variable
(
i
))
for
i
in
inputs
]
if
self
.
nin
>
0
and
len
(
_inputs
)
!=
self
.
nin
:
...
...
@@ -284,12 +276,7 @@ class PycudaElemwiseSourceModuleMakeThunkOp(Op):
inplace_pattern
=
{}
self
.
name
=
name
self
.
scalar_op
=
scalar_op
self
.
inplace_pattern
=
inplace_pattern
# As we have a dict in props, we need to implement __hash__
def
__hash__
(
self
):
return
hash
((
type
(
self
),
hash
(
self
.
scalar_op
),
hash_from_dict
(
self
.
inplace_pattern
)))
self
.
inplace_pattern
=
frozendict
(
inplace_pattern
)
def
__str__
(
self
):
if
self
.
name
is
None
:
...
...
theano/scalar/basic.py
浏览文件 @
ff9bc957
...
...
@@ -3853,7 +3853,7 @@ class Composite(ScalarOp):
self
.
nin
=
len
(
inputs
)
self
.
nout
=
len
(
outputs
)
self
.
init_fgraph
()
# self.fgraph
self
.
init_c_code
()
# Postpone the creation in case it isn't needed.
# self.init_name() # self.name
self
.
name
=
None
...
...
theano/tensor/elemwise.py
浏览文件 @
ff9bc957
...
...
@@ -581,6 +581,17 @@ second dimension
out_broadcastables
)]
return
Apply
(
self
,
inputs
,
outputs
)
def
__str__
(
self
):
if
self
.
name
is
None
:
if
self
.
inplace_pattern
:
items
=
list
(
self
.
inplace_pattern
.
items
())
items
.
sort
()
return
"Elemwise{
%
s}
%
s"
%
(
self
.
scalar_op
,
str
(
items
))
else
:
return
"Elemwise{
%
s}"
%
(
self
.
scalar_op
)
else
:
return
self
.
name
def
R_op
(
self
,
inputs
,
eval_points
):
outs
=
self
(
*
inputs
,
**
dict
(
return_list
=
True
))
rval
=
[
None
for
x
in
outs
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论