Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
51c892be
提交
51c892be
authored
12月 09, 2009
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cast to/from floatX that are not needed as they don't change the type will not…
cast to/from floatX that are not needed as they don't change the type will not generate an OP. Added test for this.
上级
be54333b
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
61 行增加
和
0 行删除
+61
-0
basic.py
theano/scalar/basic.py
+2
-0
basic.py
theano/tensor/basic.py
+2
-0
test_basic.py
theano/tensor/tests/test_basic.py
+57
-0
没有找到文件。
theano/scalar/basic.py
浏览文件 @
51c892be
...
@@ -957,6 +957,8 @@ _cast_mapping = {
...
@@ -957,6 +957,8 @@ _cast_mapping = {
'complex128'
:
convert_to_complex128
}
'complex128'
:
convert_to_complex128
}
def
cast
(
x
,
dtype
):
def
cast
(
x
,
dtype
):
"""Symbolically cast `x` to a Scalar of given `dtype`."""
"""Symbolically cast `x` to a Scalar of given `dtype`."""
if
dtype
==
'floatX'
:
dtype
=
config
.
config
.
get
(
'scalar.floatX'
)
_x
=
as_scalar
(
x
)
_x
=
as_scalar
(
x
)
if
_x
.
type
.
dtype
==
dtype
:
if
_x
.
type
.
dtype
==
dtype
:
return
_x
return
_x
...
...
theano/tensor/basic.py
浏览文件 @
51c892be
...
@@ -1128,6 +1128,8 @@ _cast_mapping = {
...
@@ -1128,6 +1128,8 @@ _cast_mapping = {
@constructor
@constructor
def
cast
(
x
,
dtype
):
def
cast
(
x
,
dtype
):
"""Symbolically cast `x` to a Tensor of type `dtype`."""
"""Symbolically cast `x` to a Tensor of type `dtype`."""
if
dtype
==
'floatX'
:
dtype
=
config
.
config
.
get
(
'scalar.floatX'
)
_x
=
as_tensor_variable
(
x
)
_x
=
as_tensor_variable
(
x
)
if
_x
.
type
.
dtype
==
dtype
:
if
_x
.
type
.
dtype
==
dtype
:
return
_x
return
_x
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
51c892be
...
@@ -1929,6 +1929,63 @@ def test_default_state():
...
@@ -1929,6 +1929,63 @@ def test_default_state():
assert
f
(
1
)
==
4.8
assert
f
(
1
)
==
4.8
assert
f
(
2.2
)
==
7
assert
f
(
2.2
)
==
7
def
test_cast_floatX
():
floatx
=
config
.
config
.
get
(
'scalar.floatX'
)
#float64 cast to float64 should not generate an op
x
=
dvector
(
'x'
)
f
=
function
([
x
],[
cast
(
x
,
'float64'
)])
# print f.maker.env.toposort()
assert
len
(
f
.
maker
.
env
.
toposort
())
==
0
#float32 cast to float32 should not generate an op
x
=
fvector
(
'x'
)
f
=
function
([
x
],[
cast
(
x
,
'float32'
)])
# print f.maker.env.toposort()
assert
len
(
f
.
maker
.
env
.
toposort
())
==
0
#floatX cast to float64
x
=
xvector
(
'x'
)
f
=
function
([
x
],[
cast
(
x
,
'float64'
)])
# print f.maker.env.toposort()
if
floatx
==
'float64'
:
assert
len
(
f
.
maker
.
env
.
toposort
())
==
0
else
:
assert
len
(
f
.
maker
.
env
.
toposort
())
==
1
#floatX cast to float32
x
=
xvector
(
'x'
)
f
=
function
([
x
],[
cast
(
x
,
'float32'
)])
# print f.maker.env.toposort()
if
floatx
==
'float32'
:
assert
len
(
f
.
maker
.
env
.
toposort
())
==
0
else
:
assert
len
(
f
.
maker
.
env
.
toposort
())
==
1
#float64 cast to floatX
x
=
dvector
(
'x'
)
f
=
function
([
x
],[
cast
(
x
,
'floatX'
)])
# print f.maker.env.toposort()
if
floatx
==
'float64'
:
assert
len
(
f
.
maker
.
env
.
toposort
())
==
0
else
:
assert
len
(
f
.
maker
.
env
.
toposort
())
==
1
#float32 cast to floatX
x
=
fvector
(
'x'
)
f
=
function
([
x
],[
cast
(
x
,
'floatX'
)])
# print f.maker.env.toposort()
if
floatx
==
'float32'
:
assert
len
(
f
.
maker
.
env
.
toposort
())
==
0
else
:
assert
len
(
f
.
maker
.
env
.
toposort
())
==
1
#floatX cast to floatX
x
=
xvector
(
'x'
)
f
=
function
([
x
],[
cast
(
x
,
'floatX'
)])
# print f.maker.env.toposort()
assert
len
(
f
.
maker
.
env
.
toposort
())
==
0
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
if
len
(
sys
.
argv
)
>=
2
and
sys
.
argv
[
1
]
==
'OPT'
:
if
len
(
sys
.
argv
)
>=
2
and
sys
.
argv
[
1
]
==
'OPT'
:
default_mode
=
compile
.
Mode
(
linker
=
'c&py'
,
default_mode
=
compile
.
Mode
(
linker
=
'c&py'
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论