Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e42ffb27
提交
e42ffb27
authored
1月 25, 2012
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Indent C code to match Python indentation level.
Also use textwrap.dedent to avoid adding indentation to the final C code.
上级
dfb7afd2
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
72 行增加
和
71 行删除
+72
-71
basic.py
theano/scalar/basic.py
+72
-71
没有找到文件。
theano/scalar/basic.py
浏览文件 @
e42ffb27
...
...
@@ -16,6 +16,7 @@ import math
import
warnings
from
copy
import
copy
from
itertools
import
imap
from
textwrap
import
dedent
import
numpy
...
...
@@ -1350,21 +1351,21 @@ class IntDiv(BinaryScalarOp):
else
:
raise
NotImplementedError
(
'type not supported'
,
t
)
return
"""
if (
%(x)
s < 0) {
if (
%(y)
s < 0) {
%(z)
s =
%(x_div_y_mm)
s;
} else {
%(z)
s = -
%(x_div_y_mp)
s - ((
%(x_mod_y_mp)
s == 0) ? 0 : 1);
}
} else {
if (
%(y)
s < 0) {
%(z)
s = -
%(x_div_y_pm)
s - ((
%(x_mod_y_pm)
s == 0) ? 0 : 1);
} else {
%(z)
s =
%(x_div_y_mm)
s;
}
}
"""
%
locals
()
return
dedent
(
"""
if (
%(x)
s < 0) {
if (
%(y)
s < 0) {
%(z)
s =
%(x_div_y_mm)
s;
} else {
%(z)
s = -
%(x_div_y_mp)
s - ((
%(x_mod_y_mp)
s == 0) ? 0 : 1);
}
} else {
if (
%(y)
s < 0) {
%(z)
s = -
%(x_div_y_pm)
s - ((
%(x_mod_y_pm)
s == 0) ? 0 : 1);
} else {
%(z)
s =
%(x_div_y_mm)
s;
}
}
"""
)
%
locals
()
def
c_code_cache_version
(
self
):
return
(
1
,)
...
...
@@ -1441,19 +1442,19 @@ class Mod(BinaryScalarOp):
else
:
raise
NotImplementedError
(
'type not supported'
,
t
)
return
"""
if (
%(x)
s < 0){
if (
%(y)
s < 0){
%(z)
s = -(
%(x_mod_ymm)
s);
}else{
%(z)
s = -
%(x_mod_ymp)
s + (
%(x_mod_ymp)
s != 0 ?
%(y)
s : 0);
}
}else if (
%(y)
s < 0){
%(z)
s = (
%(x_mod_ypm)
s) + (
%(x_mod_ypm)
s != 0 ?
%(y)
s : 0);
}else{
%(z)
s =
%(x_mod_y)
s;
}
"""
%
locals
()
return
dedent
(
"""
if (
%(x)
s < 0){
if (
%(y)
s < 0){
%(z)
s = -(
%(x_mod_ymm)
s);
}else{
%(z)
s = -
%(x_mod_ymp)
s + (
%(x_mod_ymp)
s != 0 ?
%(y)
s : 0);
}
}else if (
%(y)
s < 0){
%(z)
s = (
%(x_mod_ypm)
s) + (
%(x_mod_ypm)
s != 0 ?
%(y)
s : 0);
}else{
%(z)
s =
%(x_mod_y)
s;
}
"""
)
%
locals
()
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
return
None
,
None
...
...
@@ -1716,51 +1717,51 @@ class RoundHalfToEven(UnaryScalarOp):
if
not
node
.
outputs
[
0
]
.
type
.
dtype
in
[
'float32'
,
'float64'
]:
Exception
(
"The output should be float32 or float64"
)
return
"""
#ifndef ROUNDING_EPSILON
#define ROUNDING_EPSILON 0.0000001
#endif
if (
%(x)
s < 0.0){
// We implement the else part like that: -else( -
%(x)
s);
%(typ)
s i;
std::modf( -
%(x)
s, &i );
// If
%(x)
s is exactly halfway between two integers
if ((-
%(x)
s -(i +0.5)) < epsilon){
// If 'i' is even then return 'i'
if (std::fmod( i, 2.0 ) < epsilon){
%(z)
s = - i;
}else{
// Else return the nearest even integer
%(z)
s = - ceil( i +0.5 );
}
}else{
// round to closest
%(z)
s = - round(
%(x)
s+5);
}
}else{
%(typ)
s i;
std::modf(
%(x)
s, &i );
// If
%(x)
s is exactly halfway between two integers
if ((
%(x)
s -(i +0.5)) < epsilon){
// If 'i' is even then return 'i'
if (std::fmod( i, 2.0 ) < epsilon){
%(z)
s = i;
}else{
// Else return the nearest even integer
%(z)
s = ceil( i +0.5 );
}
}else{
// round to closest
%(z)
s = round(
%(x)
s+5);
}
}
return
dedent
(
"""
#ifndef ROUNDING_EPSILON
#define ROUNDING_EPSILON 0.0000001
#endif
if (
%(x)
s < 0.0){
// We implement the else part like that: -else( -
%(x)
s);
%(typ)
s i;
std::modf( -
%(x)
s, &i );
// If
%(x)
s is exactly halfway between two integers
if ((-
%(x)
s -(i +0.5)) < epsilon){
// If 'i' is even then return 'i'
if (std::fmod( i, 2.0 ) < epsilon){
%(z)
s = - i;
}else{
// Else return the nearest even integer
%(z)
s = - ceil( i +0.5 );
}
}else{
// round to closest
%(z)
s = - round(
%(x)
s+5);
}
}else{
%(typ)
s i;
std::modf(
%(x)
s, &i );
// If
%(x)
s is exactly halfway between two integers
if ((
%(x)
s -(i +0.5)) < epsilon){
// If 'i' is even then return 'i'
if (std::fmod( i, 2.0 ) < epsilon){
%(z)
s = i;
}else{
// Else return the nearest even integer
%(z)
s = ceil( i +0.5 );
}
}else{
// round to closest
%(z)
s = round(
%(x)
s+5);
}
}
#undef ROUNDING_EPSILON
#undef ROUNDING_EPSILON
"""
"""
)
round_half_to_even
=
RoundHalfToEven
(
same_out_float_only
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论