Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
59204ff9
提交
59204ff9
authored
4月 19, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added Assert op c_code and test.
上级
ab17c207
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
18 行增加
和
10 行删除
+18
-10
opt.py
theano/tensor/opt.py
+10
-10
test_opt.py
theano/tensor/tests/test_opt.py
+8
-0
没有找到文件。
theano/tensor/opt.py
浏览文件 @
59204ff9
...
@@ -622,30 +622,32 @@ def local_alloc_unary(node):
...
@@ -622,30 +622,32 @@ def local_alloc_unary(node):
class
Assert
(
T
.
Op
):
class
Assert
(
T
.
Op
):
view_map
=
{
0
:[
0
]}
view_map
=
{
0
:[
0
]}
def
make_node
(
self
,
value
,
*
shape
):
def
make_node
(
self
,
value
,
*
conds
):
sh
=
[
T
.
as_tensor_variable
(
s
)
for
s
in
shape
]
cond
=
[
T
.
as_tensor_variable
(
c
)
for
c
in
conds
]
return
gof
.
Apply
(
self
,
[
value
]
+
sh
,
[
value
.
type
()])
assert
numpy
.
all
([
c
.
type
.
ndim
==
0
for
c
in
cond
])
return
gof
.
Apply
(
self
,
[
value
]
+
cond
,
[
value
.
type
()])
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
__class__
.
__name__
return
self
.
__class__
.
__name__
def
perform
(
self
,
node
,
inputs
,
(
out
,)):
def
perform
(
self
,
node
,
inputs
,
(
out
,)):
v
=
inputs
[
0
]
v
=
inputs
[
0
]
if
out
[
0
]
is
None
:
out
[
0
]
=
v
out
[
0
]
=
v
assert
all
(
inputs
[
1
:])
assert
numpy
.
all
(
inputs
[
1
:])
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
grad
(
self
,
input
,
output_gradients
):
def
grad
(
self
,
input
,
output_gradients
):
return
output_gradients
return
output_gradients
def
c_code
_old
(
self
,
node
,
name
,
inames
,
onames
,
sub
):
def
c_code
(
self
,
node
,
name
,
inames
,
onames
,
sub
):
value
=
inames
[
0
]
value
=
inames
[
0
]
out
=
onames
[
0
]
out
=
onames
[
0
]
check
=
[]
check
=
[]
fail
=
sub
[
'fail'
]
for
idx
in
range
(
len
(
inames
)
-
1
):
for
idx
in
range
(
len
(
inames
)
-
1
):
i
=
inames
[
idx
+
1
]
i
=
inames
[
idx
+
1
]
dtype
=
node
.
inputs
[
idx
+
1
]
.
dtype
dtype
=
node
.
inputs
[
idx
+
1
]
.
dtype
check
.
append
(
"assert((
%(out)
s->dimensions[
%(idx)
s]));//==(*((*npy_
%(dtype)
s)PyArray_DATA(
%(i)
s))));"
%
locals
())
check
.
append
(
'if(!((npy_
%(dtype)
s*)PyArray_DATA(
%(i)
s))[0]){PyErr_SetString(PyExc_AssertionError,"Theano Assert failed!");
%(fail)
s}'
%
locals
())
check
=
"
\n
"
.
join
(
check
)
check
=
"
\n
"
.
join
(
check
)
return
"""
return
"""
%(check)
s
%(check)
s
...
@@ -654,7 +656,7 @@ class Assert(T.Op):
...
@@ -654,7 +656,7 @@ class Assert(T.Op):
"""
%
locals
()
"""
%
locals
()
pass
pass
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
()
return
(
0
,
1
)
assert_
=
Assert
()
assert_
=
Assert
()
...
@@ -729,10 +731,8 @@ def local_alloc_elemwise(node):
...
@@ -729,10 +731,8 @@ def local_alloc_elemwise(node):
#TODO, T.eq if both input are the same, remove!
#TODO, T.eq if both input are the same, remove!
#TODO, op that check the condition are all true and remove the Assert. Also remove the constant condition.
#TODO, op that check the condition are all true and remove the Assert. Also remove the constant condition.
#TODO, create a test_case where the assert is needed and fail.
#TODO, global optimizer that lift the assert to the beginning of the graph.
#TODO, global optimizer that lift the assert to the beginning of the graph.
#TODO, var.tag.shape to propagate the shape and lower the overhead of this op
#TODO, var.tag.shape to propagate the shape and lower the overhead of this op
#TODO, Assert.c_code
#TODO, when all can be optimizer do all except one
#TODO, when all can be optimizer do all except one
theano
.
configparser
.
AddConfigVar
(
'experimental.local_alloc_elemwise'
,
theano
.
configparser
.
AddConfigVar
(
'experimental.local_alloc_elemwise'
,
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
59204ff9
...
@@ -1085,6 +1085,14 @@ class test_shapeoptimizer(unittest.TestCase):
...
@@ -1085,6 +1085,14 @@ class test_shapeoptimizer(unittest.TestCase):
assert
identity_noshape
not
in
h_ops
assert
identity_noshape
not
in
h_ops
assert
identity_shape
not
in
h_ops
assert
identity_shape
not
in
h_ops
class
test_assert
(
unittest
.
TestCase
):
def
test0
(
self
):
x
=
T
.
scalar
()
y
=
T
.
scalar
()
f
=
theano
.
function
([
x
,
y
],
theano
.
tensor
.
opt
.
assert_
(
x
,
T
.
eq
(
x
,
y
)))
f
(
1
,
1
)
self
.
failUnlessRaises
(
AssertionError
,
f
,
1
,
0
)
def
test_local_mul_specialize
():
def
test_local_mul_specialize
():
# test a few cases to make sure that the basics are covered
# test a few cases to make sure that the basics are covered
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论