Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6157b651
提交
6157b651
authored
11月 02, 2021
作者:
unknown
提交者:
Brandon T. Willard
11月 28, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace TensorConstant.tag.unique_value with a get_unique_value function
上级
b3f686f7
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
29 行增加
和
16 行删除
+29
-16
opt.py
aesara/scan/opt.py
+2
-2
basic.py
aesara/tensor/basic.py
+4
-3
math_opt.py
aesara/tensor/math_opt.py
+4
-3
var.py
aesara/tensor/var.py
+19
-8
没有找到文件。
aesara/scan/opt.py
浏览文件 @
6157b651
...
...
@@ -52,7 +52,7 @@ from aesara.tensor.subtensor import (
get_idx_list
,
set_subtensor
,
)
from
aesara.tensor.var
import
TensorConstant
from
aesara.tensor.var
import
TensorConstant
,
get_unique_value
_logger
=
logging
.
getLogger
(
"aesara.scan.opt"
)
...
...
@@ -118,7 +118,7 @@ def remove_constants_and_unused_inputs_scan(fgraph, node):
node_inp
=
node
.
inputs
[
idx
+
1
]
if
(
isinstance
(
node_inp
,
TensorConstant
)
and
node_inp
.
tag
.
unique_value
is
not
None
and
get_unique_value
(
node_inp
)
is
not
None
):
try
:
# This works if input is a constant that has all entries
...
...
aesara/tensor/basic.py
浏览文件 @
6157b651
...
...
@@ -60,7 +60,7 @@ from aesara.tensor.type import (
uint_dtypes
,
values_eq_approx_always_true
,
)
from
aesara.tensor.var
import
TensorConstant
,
TensorVariable
from
aesara.tensor.var
import
TensorConstant
,
TensorVariable
,
get_unique_value
_logger
=
logging
.
getLogger
(
"aesara.tensor.basic"
)
...
...
@@ -323,8 +323,9 @@ def get_scalar_constant_value(
raise
NotScalarConstantError
()
if
isinstance
(
v
,
Constant
):
if
getattr
(
v
.
tag
,
"unique_value"
,
None
)
is
not
None
:
data
=
v
.
tag
.
unique_value
unique_value
=
get_unique_value
(
v
)
if
unique_value
is
not
None
:
data
=
unique_value
else
:
data
=
v
.
data
...
...
aesara/tensor/math_opt.py
浏览文件 @
6157b651
...
...
@@ -92,7 +92,7 @@ from aesara.tensor.type import (
values_eq_approx_remove_inf_nan
,
values_eq_approx_remove_nan
,
)
from
aesara.tensor.var
import
TensorConstant
from
aesara.tensor.var
import
TensorConstant
,
get_unique_value
from
aesara.utils
import
NoDuplicateOptWarningFilter
...
...
@@ -129,8 +129,9 @@ def get_constant(v):
"""
if
isinstance
(
v
,
Constant
):
if
getattr
(
v
.
tag
,
"unique_value"
,
None
)
is
not
None
:
data
=
v
.
tag
.
unique_value
unique_value
=
get_unique_value
(
v
)
if
unique_value
is
not
None
:
data
=
unique_value
else
:
data
=
v
.
data
if
data
.
ndim
==
0
:
...
...
aesara/tensor/var.py
浏览文件 @
6157b651
...
...
@@ -2,6 +2,8 @@ import copy
import
traceback
as
tb
import
warnings
from
collections.abc
import
Iterable
from
numbers
import
Number
from
typing
import
Optional
import
numpy
as
np
...
...
@@ -957,6 +959,20 @@ class TensorConstantSignature(tuple):
no_nan
=
property
(
_get_no_nan
)
def
get_unique_value
(
x
:
TensorVariable
)
->
Optional
[
Number
]:
"""Return the unique value of a tensor, if there is one"""
if
isinstance
(
x
,
Constant
):
data
=
x
.
data
if
isinstance
(
data
,
np
.
ndarray
)
and
data
.
ndim
>
0
:
flat_data
=
data
.
ravel
()
if
flat_data
.
shape
[
0
]:
if
(
flat_data
==
flat_data
[
0
])
.
all
():
return
flat_data
[
0
]
return
None
class
TensorConstant
(
TensorVariable
,
Constant
):
"""Subclass to add the tensor operators to the basic `Constant` class.
...
...
@@ -966,16 +982,11 @@ class TensorConstant(TensorVariable, Constant):
def
__init__
(
self
,
type
,
data
,
name
=
None
):
Constant
.
__init__
(
self
,
type
,
data
,
name
)
self
.
tag
.
unique_value
=
None
if
isinstance
(
data
,
np
.
ndarray
)
and
data
.
ndim
>
0
:
flat_data
=
data
.
ravel
()
if
flat_data
.
shape
[
0
]:
if
(
flat_data
==
flat_data
[
0
])
.
all
():
self
.
tag
.
unique_value
=
flat_data
[
0
]
def
__str__
(
self
):
if
self
.
tag
.
unique_value
is
not
None
:
name
=
f
"{self.data.shape} of {self.tag.unique_value}"
unique_val
=
get_unique_value
(
self
)
if
unique_val
is
not
None
:
name
=
f
"{self.data.shape} of {unique_val}"
else
:
name
=
f
"{self.data}"
if
len
(
name
)
>
20
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论