Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e108fab5
提交
e108fab5
authored
12月 12, 2022
作者:
Rémi Louf
提交者:
Ricardo Vieira
2月 07, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the JAX implementation of `SpecifyShape`
上级
8cf3b20f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
17 行增加
和
22 行删除
+17
-22
shape.py
pytensor/link/jax/dispatch/shape.py
+2
-2
test_shape.py
tests/link/jax/test_shape.py
+15
-20
没有找到文件。
pytensor/link/jax/dispatch/shape.py
浏览文件 @
e108fab5
...
@@ -94,10 +94,10 @@ def jax_funcify_Shape_i(op, **kwargs):
...
@@ -94,10 +94,10 @@ def jax_funcify_Shape_i(op, **kwargs):
@jax_funcify.register
(
SpecifyShape
)
@jax_funcify.register
(
SpecifyShape
)
def
jax_funcify_SpecifyShape
(
op
,
**
kwargs
):
def
jax_funcify_SpecifyShape
(
op
,
node
,
**
kwargs
):
def
specifyshape
(
x
,
*
shape
):
def
specifyshape
(
x
,
*
shape
):
assert
x
.
ndim
==
len
(
shape
)
assert
x
.
ndim
==
len
(
shape
)
assert
jnp
.
all
(
x
.
shape
==
tuple
(
shape
)
),
(
assert
x
.
shape
==
tuple
(
shape
),
(
"got shape"
,
"got shape"
,
x
.
shape
,
x
.
shape
,
"expected"
,
"expected"
,
...
...
tests/link/jax/test_shape.py
浏览文件 @
e108fab5
import
jax
import
numpy
as
np
import
numpy
as
np
import
pytest
import
pytest
from
packaging.version
import
parse
as
version_parse
import
pytensor.tensor
as
at
import
pytensor.tensor
as
at
from
pytensor.compile.ops
import
DeepCopyOp
,
ViewOp
from
pytensor.compile.ops
import
DeepCopyOp
,
ViewOp
from
pytensor.configdefaults
import
config
from
pytensor.configdefaults
import
config
from
pytensor.graph.fg
import
FunctionGraph
from
pytensor.graph.fg
import
FunctionGraph
from
pytensor.tensor.shape
import
Shape
,
Shape_i
,
SpecifyShape
,
Unbroadcast
,
reshape
from
pytensor.tensor.shape
import
Shape
,
Shape_i
,
Unbroadcast
,
reshape
from
pytensor.tensor.type
import
iscalar
,
vector
from
pytensor.tensor.type
import
iscalar
,
vector
from
tests.link.jax.test_basic
import
compare_jax_and_py
from
tests.link.jax.test_basic
import
compare_jax_and_py
...
@@ -25,24 +23,21 @@ def test_jax_shape_ops():
...
@@ -25,24 +23,21 @@ def test_jax_shape_ops():
compare_jax_and_py
(
x_fg
,
[],
must_be_device_array
=
False
)
compare_jax_and_py
(
x_fg
,
[],
must_be_device_array
=
False
)
@pytest.mark.xfail
(
version_parse
(
jax
.
__version__
)
>=
version_parse
(
"0.2.12"
),
reason
=
"Omnistaging cannot be disabled"
,
)
def
test_jax_specify_shape
():
def
test_jax_specify_shape
():
x_np
=
np
.
zeros
((
20
,
3
))
in_at
=
at
.
matrix
(
"in"
)
x
=
SpecifyShape
()(
at
.
as_tensor_variable
(
x_np
),
(
20
,
3
))
x
=
at
.
specify_shape
(
in_at
,
(
4
,
5
))
x_fg
=
FunctionGraph
([],
[
x
])
x_fg
=
FunctionGraph
([
in_at
],
[
x
])
compare_jax_and_py
(
x_fg
,
[
np
.
ones
((
4
,
5
))
.
astype
(
config
.
floatX
)])
compare_jax_and_py
(
x_fg
,
[])
# When used to assert two arrays have similar shapes
with
config
.
change_flags
(
compute_test_value
=
"off"
):
in_at
=
at
.
matrix
(
"in"
)
shape_at
=
at
.
matrix
(
"shape"
)
x
=
SpecifyShape
()(
at
.
as_tensor_variable
(
x_np
),
*
(
2
,
3
))
x
=
at
.
specify_shape
(
in_at
,
shape_at
.
shape
)
x_fg
=
FunctionGraph
([],
[
x
])
x_fg
=
FunctionGraph
([
in_at
,
shape_at
],
[
x
])
compare_jax_and_py
(
with
pytest
.
raises
(
AssertionError
):
x_fg
,
compare_jax_and_py
(
x_fg
,
[])
[
np
.
ones
((
4
,
5
))
.
astype
(
config
.
floatX
),
np
.
ones
((
4
,
5
))
.
astype
(
config
.
floatX
)],
)
def
test_jax_Reshape_constant
():
def
test_jax_Reshape_constant
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论