Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1944353c
提交
1944353c
authored
5月 30, 2023
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
6月 08, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify string expression for Constant Variables
上级
66934167
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
18 行增加
和
26 行删除
+18
-26
basic.py
pytensor/graph/basic.py
+14
-7
var.py
pytensor/tensor/var.py
+0
-15
test_basic.py
tests/graph/rewriting/test_basic.py
+1
-1
test_printing.py
tests/scan/test_printing.py
+0
-0
test_var.py
tests/tensor/test_var.py
+1
-1
test_printing.py
tests/test_printing.py
+2
-2
没有找到文件。
pytensor/graph/basic.py
浏览文件 @
1944353c
...
@@ -763,13 +763,20 @@ class Constant(AtomicVariable[_TypeType]):
...
@@ -763,13 +763,20 @@ class Constant(AtomicVariable[_TypeType]):
return
(
self
.
type
,
self
.
data
)
return
(
self
.
type
,
self
.
data
)
def
__str__
(
self
):
def
__str__
(
self
):
if
self
.
name
is
not
None
:
data_str
=
str
(
self
.
data
)
return
self
.
name
if
len
(
data_str
)
>
20
:
else
:
data_str
=
data_str
[:
10
]
.
strip
()
+
" ... "
+
data_str
[
-
10
:]
.
strip
()
name
=
str
(
self
.
data
)
if
len
(
name
)
>
20
:
if
self
.
name
is
None
:
name
=
name
[:
10
]
+
"..."
+
name
[
-
10
:]
return
data_str
return
f
"{type(self).__name__}{{{name}}}"
return
f
"{self.name}{{{data_str}}}"
def
__repr__
(
self
):
data_str
=
repr
(
self
.
data
)
if
len
(
data_str
)
>
20
:
data_str
=
data_str
[:
10
]
.
strip
()
+
" ... "
+
data_str
[
-
10
:]
.
strip
()
return
f
"{type(self).__name__}({repr(self.type)}, data={data_str})"
def
clone
(
self
,
**
kwargs
):
def
clone
(
self
,
**
kwargs
):
return
self
return
self
...
...
pytensor/tensor/var.py
浏览文件 @
1944353c
...
@@ -1023,21 +1023,6 @@ class TensorConstant(TensorVariable, Constant[_TensorTypeType]):
...
@@ -1023,21 +1023,6 @@ class TensorConstant(TensorVariable, Constant[_TensorTypeType]):
Constant
.
__init__
(
self
,
new_type
,
data
,
name
)
Constant
.
__init__
(
self
,
new_type
,
data
,
name
)
def
__str__
(
self
):
unique_val
=
get_unique_value
(
self
)
if
unique_val
is
not
None
:
val
=
f
"{self.data.shape} of {unique_val}"
else
:
val
=
f
"{self.data}"
if
len
(
val
)
>
20
:
val
=
val
[:
10
]
.
strip
()
+
" ... "
+
val
[
-
10
:]
.
strip
()
if
self
.
name
is
not
None
:
name
=
self
.
name
else
:
name
=
"TensorConstant"
return
f
"{name}{{{val}}}"
def
signature
(
self
):
def
signature
(
self
):
return
TensorConstantSignature
((
self
.
type
,
self
.
data
))
return
TensorConstantSignature
((
self
.
type
,
self
.
data
))
...
...
tests/graph/rewriting/test_basic.py
浏览文件 @
1944353c
...
@@ -166,7 +166,7 @@ class TestPatternNodeRewriter:
...
@@ -166,7 +166,7 @@ class TestPatternNodeRewriter:
e
=
op1
(
op1
(
x
,
y
),
y
)
e
=
op1
(
op1
(
x
,
y
),
y
)
g
=
FunctionGraph
([
y
],
[
e
])
g
=
FunctionGraph
([
y
],
[
e
])
OpKeyPatternNodeRewriter
((
op1
,
z
,
"1"
),
(
op2
,
"1"
,
z
))
.
rewrite
(
g
)
OpKeyPatternNodeRewriter
((
op1
,
z
,
"1"
),
(
op2
,
"1"
,
z
))
.
rewrite
(
g
)
assert
str
(
g
)
==
"FunctionGraph(Op1(Op2(y, z), y))"
assert
str
(
g
)
==
"FunctionGraph(Op1(Op2(y, z
{2}
), y))"
def
test_constraints
(
self
):
def
test_constraints
(
self
):
x
,
y
,
z
=
MyVariable
(
"x"
),
MyVariable
(
"y"
),
MyVariable
(
"z"
)
x
,
y
,
z
=
MyVariable
(
"x"
),
MyVariable
(
"y"
),
MyVariable
(
"z"
)
...
...
tests/scan/test_printing.py
浏览文件 @
1944353c
差异被折叠。
点击展开。
tests/tensor/test_var.py
浏览文件 @
1944353c
...
@@ -213,7 +213,7 @@ def test_print_constant():
...
@@ -213,7 +213,7 @@ def test_print_constant():
c
=
pytensor
.
tensor
.
constant
(
1
,
name
=
"const"
)
c
=
pytensor
.
tensor
.
constant
(
1
,
name
=
"const"
)
assert
str
(
c
)
==
"const{1}"
assert
str
(
c
)
==
"const{1}"
d
=
pytensor
.
tensor
.
constant
(
1
)
d
=
pytensor
.
tensor
.
constant
(
1
)
assert
str
(
d
)
==
"
TensorConstant{1}
"
assert
str
(
d
)
==
"
1
"
@pytest.mark.parametrize
(
@pytest.mark.parametrize
(
...
...
tests/test_printing.py
浏览文件 @
1944353c
...
@@ -280,10 +280,10 @@ def test_debugprint():
...
@@ -280,10 +280,10 @@ def test_debugprint():
│ ├─ AllocEmpty{dtype='float64'} 1
│ ├─ AllocEmpty{dtype='float64'} 1
│ │ └─ Shape_i{0} 0
│ │ └─ Shape_i{0} 0
│ │ └─ B
│ │ └─ B
│ ├─
TensorConstant{1.0}
│ ├─
1.0
│ ├─ B
│ ├─ B
│ ├─ <Vector(float64, shape=(?,))>
│ ├─ <Vector(float64, shape=(?,))>
│ └─
TensorConstant{0.0}
│ └─
0.0
├─ D
├─ D
└─ A
└─ A
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论