Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5b50d27d
提交
5b50d27d
authored
6月 30, 2023
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
7月 11, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow inlined Infinity / Nan constants in Composite
上级
6d5cc513
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
23 行增加
和
5 行删除
+23
-5
basic.py
pytensor/scalar/basic.py
+6
-0
test_basic.py
tests/scalar/test_basic.py
+17
-5
没有找到文件。
pytensor/scalar/basic.py
浏览文件 @
5b50d27d
...
...
@@ -432,6 +432,12 @@ class ScalarType(CType, HasDataType, HasShape):
return
None
if
self
.
dtype
==
"bool"
:
return
"1"
if
data
else
"0"
if
data
==
np
.
inf
:
return
"INFINITY"
if
data
==
-
np
.
inf
:
return
"-INFINITY"
if
np
.
isnan
(
data
):
return
"NAN"
return
str
(
data
)
def
c_declare
(
self
,
name
,
sub
,
check_input
=
True
):
...
...
tests/scalar/test_basic.py
浏览文件 @
5b50d27d
...
...
@@ -128,21 +128,33 @@ class TestComposite:
# We don't flatten that case.
assert
isinstance
(
CC
.
outputs
[
0
]
.
owner
.
op
,
Composite
)
def
test_with_constants
(
self
):
@pytest.mark.parametrize
(
"literal_value"
,
(
70.0
,
-
np
.
inf
,
np
.
float32
(
"nan"
)))
def
test_with_constants
(
self
,
literal_value
):
x
,
y
,
z
=
floats
(
"xyz"
)
e
=
mul
(
add
(
70.0
,
y
),
true_div
(
x
,
y
))
e
=
mul
(
add
(
literal_value
,
y
),
true_div
(
x
,
y
))
comp_op
=
Composite
([
x
,
y
],
[
e
])
comp_node
=
comp_op
.
make_node
(
x
,
y
)
c_code
=
comp_node
.
op
.
c_code
(
comp_node
,
"dummy"
,
[
"x"
,
"y"
],
[
"z"
],
dict
(
id
=
0
))
assert
"70.0"
in
c_code
assert
constant
(
literal_value
)
.
type
.
c_literal
(
literal_value
)
in
c_code
# Make sure caching of the c_code template works
assert
hasattr
(
comp_node
.
op
,
"_c_code"
)
g
=
FunctionGraph
([
x
,
y
],
[
comp_node
.
out
])
fn
=
make_function
(
DualLinker
()
.
accept
(
g
))
assert
fn
(
1.0
,
2.0
)
==
36.0
# Default checker does not allow `nan`
def
checker
(
x
,
y
):
np
.
testing
.
assert_equal
(
x
,
y
)
fn
=
make_function
(
DualLinker
(
checker
=
checker
)
.
accept
(
g
))
test_x
=
1.0
test_y
=
2.0
np
.
testing
.
assert_equal
(
fn
(
test_x
,
test_y
),
(
literal_value
+
test_y
)
*
(
test_x
/
test_y
),
)
def
test_many_outputs
(
self
):
x
,
y
,
z
=
floats
(
"xyz"
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论