Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
371048ea
提交
371048ea
authored
1月 11, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
1月 13, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make sure `Type` subclasses implement the clone method
上级
b920bd29
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
35 行增加
和
4 行删除
+35
-4
type.py
aesara/graph/type.py
+4
-0
basic.py
aesara/scalar/basic.py
+5
-0
type.py
aesara/sparse/type.py
+7
-0
type_other.py
aesara/tensor/type_other.py
+3
-0
test_types.py
tests/graph/test_types.py
+5
-0
test_type.py
tests/scalar/test_type.py
+6
-0
test_type.py
tests/sparse/test_type.py
+5
-4
没有找到文件。
aesara/graph/type.py
浏览文件 @
371048ea
...
...
@@ -212,6 +212,10 @@ class Type(MetaObject):
"""
return
self
.
Constant
(
type
=
self
,
data
=
value
,
name
=
name
)
def
clone
(
self
,
*
args
,
**
kwargs
):
"""Clone a copy of this type with the given arguments/keyword values, if any."""
return
type
(
self
)(
*
args
,
**
kwargs
)
def
__call__
(
self
,
name
:
Optional
[
Text
]
=
None
)
->
Variable
:
"""Return a new `Variable` instance of Type `self`.
...
...
aesara/scalar/basic.py
浏览文件 @
371048ea
...
...
@@ -345,6 +345,11 @@ class Scalar(CType):
self
.
dtype
=
dtype
self
.
dtype_specs
()
# error checking
def
clone
(
self
,
dtype
=
None
,
**
kwargs
):
if
dtype
is
None
:
dtype
=
self
.
dtype
return
type
(
self
)(
dtype
)
@staticmethod
def
may_share_memory
(
a
,
b
):
# This class represent basic c type, represented in python
...
...
aesara/sparse/type.py
浏览文件 @
371048ea
...
...
@@ -89,6 +89,13 @@ class SparseType(Type):
list
(
self
.
format_cls
.
keys
()),
)
def
clone
(
self
,
format
=
None
,
dtype
=
None
,
**
kwargs
):
if
format
is
None
:
format
=
self
.
format
if
dtype
is
None
:
dtype
=
self
.
dtype
return
type
(
self
)(
format
,
dtype
)
def
filter
(
self
,
value
,
strict
=
False
,
allow_downcast
=
None
):
if
(
isinstance
(
value
,
self
.
format_cls
[
self
.
format
])
...
...
aesara/tensor/type_other.py
浏览文件 @
371048ea
...
...
@@ -52,6 +52,9 @@ make_slice = MakeSlice()
class
SliceType
(
Type
):
def
clone
(
self
,
**
kwargs
):
return
type
(
self
)()
def
filter
(
self
,
x
,
strict
=
False
,
allow_downcast
=
None
):
if
isinstance
(
x
,
slice
):
return
x
...
...
tests/graph/test_types.py
浏览文件 @
371048ea
...
...
@@ -67,6 +67,11 @@ def test_convert_variable():
t1
.
convert_variable
(
v3
)
def
test_default_clone
():
mt
=
MyType
(
1
)
assert
isinstance
(
mt
.
clone
(
1
),
MyType
)
@pytest.mark.skipif
(
not
aesara
.
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
)
...
...
tests/scalar/test_type.py
浏览文件 @
371048ea
...
...
@@ -60,3 +60,9 @@ def test_filter_float_subclass():
with
config
.
change_flags
(
floatX
=
"float64"
):
filtered_nan
=
test_type
.
filter
(
nan
)
assert
isinstance
(
filtered_nan
,
np
.
floating
)
def
test_clone
():
st
=
Scalar
(
"int64"
)
assert
st
==
st
.
clone
()
assert
st
.
clone
(
"float64"
)
.
dtype
==
"float64"
tests/sparse/test_type.py
浏览文件 @
371048ea
def
test_sparse_type
():
import
aesara.sparse
from
aesara.sparse.type
import
SparseType
# They need to be available even if scipy is not available.
assert
hasattr
(
aesara
.
sparse
,
"SparseType"
)
def
test_clone
():
st
=
SparseType
(
"csr"
,
"float64"
)
assert
st
==
st
.
clone
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论