Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e3b3ecc1
提交
e3b3ecc1
authored
5月 02, 2016
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do the same fix for all opt path and for prod.
上级
dd58fb00
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
33 行增加
和
27 行删除
+33
-27
opt.py
theano/tensor/opt.py
+8
-6
test_opt.py
theano/tensor/tests/test_opt.py
+25
-1
test_raise_on_float64.py
theano/tests/test_raise_on_float64.py
+0
-20
没有找到文件。
theano/tensor/opt.py
浏览文件 @
e3b3ecc1
...
@@ -5210,11 +5210,12 @@ def local_opt_alloc(node):
...
@@ -5210,11 +5210,12 @@ def local_opt_alloc(node):
val
=
get_scalar_constant_value
(
input
)
val
=
get_scalar_constant_value
(
input
)
assert
val
.
size
==
1
assert
val
.
size
==
1
# check which type of op
# check which type of op
casted
=
T
.
mul
(
*
shapes
)
.
astype
(
str
(
val
.
dtype
))
if
isinstance
(
node
.
op
,
T
.
Sum
):
if
isinstance
(
node
.
op
,
T
.
Sum
):
val
=
val
.
reshape
(
1
)[
0
]
*
T
.
mul
(
*
shapes
)
val
=
val
.
reshape
(
1
)[
0
]
*
casted
else
:
else
:
val
=
val
.
reshape
(
1
)[
0
]
**
T
.
mul
(
*
shapes
)
val
=
val
.
reshape
(
1
)[
0
]
**
casted
return
[
T
.
cast
(
val
,
dtype
=
node
.
outputs
[
0
]
.
dtype
)
]
return
[
val
]
except
NotScalarConstantError
:
except
NotScalarConstantError
:
pass
pass
...
@@ -5226,11 +5227,12 @@ def local_opt_alloc(node):
...
@@ -5226,11 +5227,12 @@ def local_opt_alloc(node):
to_prod
=
[
shapes
[
i
]
for
i
in
xrange
(
len
(
shapes
))
to_prod
=
[
shapes
[
i
]
for
i
in
xrange
(
len
(
shapes
))
if
i
in
node
.
op
.
axis
]
if
i
in
node
.
op
.
axis
]
if
to_prod
:
if
to_prod
:
casted
=
T
.
mul
(
*
to_prod
)
.
astype
(
str
(
val
.
dtype
))
if
isinstance
(
node
.
op
,
T
.
Sum
):
if
isinstance
(
node
.
op
,
T
.
Sum
):
val
*=
T
.
mul
(
*
to_prod
)
.
astype
(
str
(
val
.
dtype
))
val
*=
casted
else
:
else
:
val
=
val
**
T
.
mul
(
*
to_prod
)
val
=
val
**
casted
return
[
T
.
alloc
(
T
.
cast
(
val
,
dtype
=
node
.
outputs
[
0
]
.
dtype
)
,
return
[
T
.
alloc
(
val
,
*
[
shapes
[
i
]
for
i
in
xrange
(
len
(
shapes
))
*
[
shapes
[
i
]
for
i
in
xrange
(
len
(
shapes
))
if
i
not
in
node
.
op
.
axis
])]
if
i
not
in
node
.
op
.
axis
])]
except
NotScalarConstantError
:
except
NotScalarConstantError
:
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
e3b3ecc1
...
@@ -5271,8 +5271,8 @@ class T_local_sum_prod(unittest.TestCase):
...
@@ -5271,8 +5271,8 @@ class T_local_sum_prod(unittest.TestCase):
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
def
test_local_sum_prod_alloc
(
self
):
def
test_local_sum_prod_alloc
(
self
):
# test local_opt_alloc
a
=
T
.
dtensor3
()
a
=
T
.
dtensor3
()
input
=
numpy
.
asarray
(
numpy
.
arange
(
2
*
3
*
4
)
.
reshape
(
2
,
3
,
4
),
input
=
numpy
.
asarray
(
numpy
.
arange
(
2
*
3
*
4
)
.
reshape
(
2
,
3
,
4
),
dtype
=
'float64'
)
dtype
=
'float64'
)
...
@@ -5376,6 +5376,30 @@ class T_local_sum_prod(unittest.TestCase):
...
@@ -5376,6 +5376,30 @@ class T_local_sum_prod(unittest.TestCase):
config
.
on_opt_error
=
backup
config
.
on_opt_error
=
backup
class
T_local_opt_alloc
(
unittest
.
TestCase
):
def
test_sum_upcast
(
self
):
s
=
theano
.
tensor
.
lscalar
()
a
=
theano
.
tensor
.
alloc
(
numpy
.
asarray
(
5
,
dtype
=
'float32'
),
s
,
s
)
orig
=
theano
.
config
.
warn_float64
theano
.
config
.
warn_float64
=
"raise"
try
:
f
=
theano
.
function
([
s
],
a
.
sum
())
f
(
5
)
finally
:
theano
.
config
.
warn_float64
=
orig
def
test_prod_upcast
(
self
):
s
=
theano
.
tensor
.
lscalar
()
a
=
theano
.
tensor
.
alloc
(
numpy
.
asarray
(
5
,
dtype
=
'float32'
),
s
,
s
)
orig
=
theano
.
config
.
warn_float64
theano
.
config
.
warn_float64
=
"raise"
try
:
f
=
theano
.
function
([
s
],
a
.
prod
())
f
(
5
)
finally
:
theano
.
config
.
warn_float64
=
orig
class
T_local_reduce
(
unittest
.
TestCase
):
class
T_local_reduce
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
self
.
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
...
...
theano/tests/test_raise_on_float64.py
deleted
100644 → 0
浏览文件 @
dd58fb00
from
__future__
import
absolute_import
,
print_function
,
division
__author__
=
"deepworx"
__contact__
=
"deepworx@GitHub"
import
unittest
import
theano
,
numpy
class
RaiseOnFloat64
(
unittest
.
TestCase
):
s
=
theano
.
tensor
.
lscalar
()
a
=
theano
.
tensor
.
alloc
(
numpy
.
asarray
(
5
,
dtype
=
'float32'
),
s
,
s
)
orig
=
theano
.
config
.
warn_float64
theano
.
config
.
warn_float64
=
"raise"
try
:
f
=
theano
.
function
([
s
],
a
.
sum
())
theano
.
printing
.
debugprint
(
f
)
f
(
5
)
finally
:
theano
.
config
.
warn_float64
=
orig
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论