Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e8bd0d7d
提交
e8bd0d7d
authored
7月 11, 2023
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
7月 11, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bug in JAX implementation of Second
上级
5e6b356d
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
22 行增加
和
1 行删除
+22
-1
scalar.py
pytensor/link/jax/dispatch/scalar.py
+2
-1
test_scalar.py
tests/link/jax/test_scalar.py
+20
-0
没有找到文件。
pytensor/link/jax/dispatch/scalar.py
浏览文件 @
e8bd0d7d
...
@@ -181,7 +181,8 @@ def jax_funcify_Composite(op, node, vectorize=True, **kwargs):
...
@@ -181,7 +181,8 @@ def jax_funcify_Composite(op, node, vectorize=True, **kwargs):
@jax_funcify.register
(
Second
)
@jax_funcify.register
(
Second
)
def
jax_funcify_Second
(
op
,
**
kwargs
):
def
jax_funcify_Second
(
op
,
**
kwargs
):
def
second
(
x
,
y
):
def
second
(
x
,
y
):
return
jnp
.
broadcast_to
(
y
,
x
.
shape
)
_
,
y
=
jnp
.
broadcast_arrays
(
x
,
y
)
return
y
return
second
return
second
...
...
tests/link/jax/test_scalar.py
浏览文件 @
e8bd0d7d
...
@@ -25,6 +25,7 @@ from tests.link.jax.test_basic import compare_jax_and_py
...
@@ -25,6 +25,7 @@ from tests.link.jax.test_basic import compare_jax_and_py
jax
=
pytest
.
importorskip
(
"jax"
)
jax
=
pytest
.
importorskip
(
"jax"
)
from
pytensor.link.jax.dispatch
import
jax_funcify
def
test_second
():
def
test_second
():
...
@@ -40,6 +41,25 @@ def test_second():
...
@@ -40,6 +41,25 @@ def test_second():
fgraph
=
FunctionGraph
([
a1
,
b
],
[
out
])
fgraph
=
FunctionGraph
([
a1
,
b
],
[
out
])
compare_jax_and_py
(
fgraph
,
[
np
.
zeros
([
5
],
dtype
=
config
.
floatX
),
5.0
])
compare_jax_and_py
(
fgraph
,
[
np
.
zeros
([
5
],
dtype
=
config
.
floatX
),
5.0
])
a2
=
matrix
(
"a2"
,
shape
=
(
1
,
None
),
dtype
=
"float64"
)
b2
=
matrix
(
"b2"
,
shape
=
(
None
,
1
),
dtype
=
"int32"
)
out
=
at
.
second
(
a2
,
b2
)
fgraph
=
FunctionGraph
([
a2
,
b2
],
[
out
])
compare_jax_and_py
(
fgraph
,
[
np
.
zeros
((
1
,
3
),
dtype
=
"float64"
),
np
.
ones
((
5
,
1
),
dtype
=
"int32"
)]
)
def
test_second_constant_scalar
():
b
=
scalar
(
"b"
,
dtype
=
"int"
)
out
=
at
.
second
(
0.0
,
b
)
fgraph
=
FunctionGraph
([
b
],
[
out
])
# Test dispatch directly as useless second is removed during compilation
fn
=
jax_funcify
(
fgraph
)
[
res
]
=
fn
(
1
)
assert
res
==
1
assert
res
.
dtype
==
out
.
dtype
def
test_identity
():
def
test_identity
():
a
=
scalar
(
"a"
)
a
=
scalar
(
"a"
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论