Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
55b96ed6
提交
55b96ed6
authored
4月 28, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added tensor.round fct and associated test.
上级
025fb494
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
34 行增加
和
0 行删除
+34
-0
basic.py
theano/scalar/basic.py
+17
-0
basic.py
theano/tensor/basic.py
+4
-0
inplace.py
theano/tensor/inplace.py
+4
-0
test_basic.py
theano/tensor/tests/test_basic.py
+9
-0
没有找到文件。
theano/scalar/basic.py
浏览文件 @
55b96ed6
...
@@ -398,6 +398,11 @@ def upcast_out(*types):
...
@@ -398,6 +398,11 @@ def upcast_out(*types):
return
Scalar
(
dtype
=
Scalar
.
upcast
(
*
types
)),
return
Scalar
(
dtype
=
Scalar
.
upcast
(
*
types
)),
def
same_out
(
type
):
def
same_out
(
type
):
return
type
,
return
type
,
def
same_out_float_only
(
type
):
if
type
not
in
float_types
:
raise
TypeError
(
'only float type are supported'
)
return
type
,
class
transfer_type
(
gof
.
utils
.
object2
):
class
transfer_type
(
gof
.
utils
.
object2
):
def
__init__
(
self
,
*
transfer
):
def
__init__
(
self
,
*
transfer
):
assert
all
(
type
(
x
)
==
int
for
x
in
transfer
)
assert
all
(
type
(
x
)
==
int
for
x
in
transfer
)
...
@@ -1147,6 +1152,18 @@ class IRound(UnaryScalarOp):
...
@@ -1147,6 +1152,18 @@ class IRound(UnaryScalarOp):
return
"
%(z)
s = round(
%(x)
s);"
%
locals
()
return
"
%(z)
s = round(
%(x)
s);"
%
locals
()
iround
=
IRound
(
int_out_nocomplex
)
iround
=
IRound
(
int_out_nocomplex
)
class
Round
(
UnaryScalarOp
):
def
impl
(
self
,
x
):
return
theano
.
_asarray
(
numpy
.
round
(
x
),
dtype
=
'int64'
)
def
c_code
(
self
,
node
,
name
,
(
x
,
),
(
z
,
),
sub
):
if
node
.
outputs
[
0
]
.
type
.
dtype
==
'float32'
:
return
"
%(z)
s = fround(
%(x)
s);"
%
locals
()
elif
node
.
outputs
[
0
]
.
type
.
dtype
==
'float64'
:
return
"
%(z)
s = round(
%(x)
s);"
%
locals
()
else
:
Exception
(
"The output should be float32 or float64"
)
round
=
Round
(
same_out_float_only
)
class
Neg
(
UnaryScalarOp
):
class
Neg
(
UnaryScalarOp
):
def
impl
(
self
,
x
):
def
impl
(
self
,
x
):
return
-
x
return
-
x
...
...
theano/tensor/basic.py
浏览文件 @
55b96ed6
...
@@ -1578,6 +1578,10 @@ def floor(a):
...
@@ -1578,6 +1578,10 @@ def floor(a):
def
iround
(
a
):
def
iround
(
a
):
"""int(round(a))"""
"""int(round(a))"""
@_scal_elemwise
def
round
(
a
):
"""round(a)"""
@_scal_elemwise
@_scal_elemwise
def
sqr
(
a
):
def
sqr
(
a
):
"""square of a"""
"""square of a"""
...
...
theano/tensor/inplace.py
浏览文件 @
55b96ed6
...
@@ -128,6 +128,10 @@ def floor_inplace(a):
...
@@ -128,6 +128,10 @@ def floor_inplace(a):
def
iround_inplace
(
a
):
def
iround_inplace
(
a
):
"""int(round(a)) (inplace on `a`)"""
"""int(round(a)) (inplace on `a`)"""
@_scal_inplace
def
round_inplace
(
a
):
"""round(a) (inplace on `a`)"""
@_scal_inplace
@_scal_inplace
def
sqr_inplace
(
a
):
def
sqr_inplace
(
a
):
"""square of `a` (inplace on `a`)"""
"""square of `a` (inplace on `a`)"""
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
55b96ed6
...
@@ -448,6 +448,15 @@ IRoundInplaceTester = makeBroadcastTester(op = inplace.iround_inplace,
...
@@ -448,6 +448,15 @@ IRoundInplaceTester = makeBroadcastTester(op = inplace.iround_inplace,
good
=
_good_broadcast_unary_normal
,
good
=
_good_broadcast_unary_normal
,
inplace
=
True
)
inplace
=
True
)
RoundTester
=
makeBroadcastTester
(
op
=
round
,
expected
=
numpy
.
round
,
good
=
_good_broadcast_unary_normal_float
)
RoundInplaceTester
=
makeBroadcastTester
(
op
=
inplace
.
round_inplace
,
expected
=
numpy
.
round
,
good
=
_good_broadcast_unary_normal_float
,
inplace
=
True
)
SqrTester
=
makeBroadcastTester
(
op
=
sqr
,
SqrTester
=
makeBroadcastTester
(
op
=
sqr
,
expected
=
numpy
.
square
,
expected
=
numpy
.
square
,
good
=
_good_broadcast_unary_normal
,
good
=
_good_broadcast_unary_normal
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论