Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b128827c
提交
b128827c
authored
7月 03, 2023
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
7月 11, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't introduce Second in AlegrabicCanonizer because of shape specialization…
Don't introduce Second in AlegrabicCanonizer because of shape specialization (only for broadcasting)
上级
5b50d27d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
28 行增加
和
4 行删除
+28
-4
math.py
pytensor/tensor/rewriting/math.py
+4
-2
test_math.py
tests/tensor/rewriting/test_math.py
+24
-2
没有找到文件。
pytensor/tensor/rewriting/math.py
浏览文件 @
b128827c
...
@@ -1135,10 +1135,12 @@ class AlgebraicCanonizer(NodeRewriter):
...
@@ -1135,10 +1135,12 @@ class AlgebraicCanonizer(NodeRewriter):
if
new
.
type
.
dtype
!=
out
.
type
.
dtype
:
if
new
.
type
.
dtype
!=
out
.
type
.
dtype
:
new
=
cast
(
new
,
out
.
type
.
dtype
)
new
=
cast
(
new
,
out
.
type
.
dtype
)
if
new
.
type
!=
out
.
typ
e
:
if
new
.
type
.
broadcastable
!=
out
.
type
.
broadcastabl
e
:
new
=
fill_chain
(
new
,
node
.
inputs
)[
0
]
new
=
fill_chain
(
new
,
node
.
inputs
)[
0
]
if
new
.
type
==
out
.
type
:
if
(
new
.
type
.
dtype
==
out
.
type
.
dtype
)
and
(
new
.
type
.
broadcastable
==
out
.
type
.
broadcastable
):
new
.
tag
.
values_eq_approx
=
values_eq_approx_remove_inf_nan
new
.
tag
.
values_eq_approx
=
values_eq_approx_remove_inf_nan
copy_stack_trace
(
out
,
new
)
copy_stack_trace
(
out
,
new
)
return
[
new
]
return
[
new
]
...
...
tests/tensor/rewriting/test_math.py
浏览文件 @
b128827c
...
@@ -30,7 +30,7 @@ from pytensor.graph.rewriting.utils import is_same_graph, rewrite_graph
...
@@ -30,7 +30,7 @@ from pytensor.graph.rewriting.utils import is_same_graph, rewrite_graph
from
pytensor.misc.safe_asarray
import
_asarray
from
pytensor.misc.safe_asarray
import
_asarray
from
pytensor.printing
import
debugprint
from
pytensor.printing
import
debugprint
from
pytensor.tensor
import
inplace
from
pytensor.tensor
import
inplace
from
pytensor.tensor.basic
import
Alloc
,
join
,
switch
from
pytensor.tensor.basic
import
Alloc
,
join
,
s
econd
,
s
witch
from
pytensor.tensor.blas
import
Dot22
,
Gemv
from
pytensor.tensor.blas
import
Dot22
,
Gemv
from
pytensor.tensor.blas_c
import
CGemv
from
pytensor.tensor.blas_c
import
CGemv
from
pytensor.tensor.elemwise
import
CAReduce
,
DimShuffle
,
Elemwise
from
pytensor.tensor.elemwise
import
CAReduce
,
DimShuffle
,
Elemwise
...
@@ -96,7 +96,7 @@ from pytensor.tensor.rewriting.math import (
...
@@ -96,7 +96,7 @@ from pytensor.tensor.rewriting.math import (
perform_sigm_times_exp
,
perform_sigm_times_exp
,
simplify_mul
,
simplify_mul
,
)
)
from
pytensor.tensor.shape
import
Reshape
,
Shape_i
,
SpecifyShape
from
pytensor.tensor.shape
import
Reshape
,
Shape_i
,
SpecifyShape
,
specify_shape
from
pytensor.tensor.type
import
(
from
pytensor.tensor.type
import
(
TensorType
,
TensorType
,
cmatrix
,
cmatrix
,
...
@@ -979,6 +979,28 @@ class TestAlgebraicCanonizer:
...
@@ -979,6 +979,28 @@ class TestAlgebraicCanonizer:
# No rewrite was applied
# No rewrite was applied
assert
z_rewritten
is
z
assert
z_rewritten
is
z
def
test_shape_specified_by_constant
(
self
):
x
=
vector
(
"x"
)
const
=
np
.
full
(
shape
=
(
5
,),
fill_value
=
2.0
)
.
astype
(
config
.
floatX
)
out
=
x
*
const
new_out
=
rewrite_graph
(
out
,
custom_rewrite
=
in2out
(
local_mul_canonizer
,
name
=
"test"
)
)
expected_out
=
np
.
array
([
2.0
])
.
astype
(
config
.
floatX
)
*
specify_shape
(
x
,
(
5
,))
assert
equal_computations
([
new_out
],
[
expected_out
])
def
test_broadcasted_by_constant
(
self
):
x
=
vector
(
"x"
)
const
=
np
.
full
(
shape
=
(
3
,
5
),
fill_value
=
2.0
)
.
astype
(
config
.
floatX
)
out
=
x
*
const
new_out
=
rewrite_graph
(
out
,
custom_rewrite
=
in2out
(
local_mul_canonizer
,
name
=
"test"
)
)
expected_out
=
second
(
const
,
np
.
array
([[
2.0
]],
dtype
=
config
.
floatX
)
*
x
)
assert
equal_computations
([
new_out
],
[
expected_out
])
def
test_local_merge_abs
():
def
test_local_merge_abs
():
x
,
y
,
z
=
matrices
(
"xyz"
)
x
,
y
,
z
=
matrices
(
"xyz"
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论