Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5cfd9da9
提交
5cfd9da9
authored
2月 05, 2024
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
2月 06, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Deprecate ScalarSharedVariable
上级
1091b441
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
20 行增加
和
7 行删除
+20
-7
sharedvar.py
pytensor/tensor/sharedvar.py
+13
-5
test_sharedvar.py
tests/tensor/test_sharedvar.py
+7
-2
没有找到文件。
pytensor/tensor/sharedvar.py
浏览文件 @
5cfd9da9
...
...
@@ -9,6 +9,18 @@ from pytensor.tensor.type import TensorType
from
pytensor.tensor.variable
import
_tensor_py_operators
def
__getattr__
(
name
):
if
name
==
"ScalarSharedVariable"
:
warnings
.
warn
(
"The class `ScalarSharedVariable` has been deprecated. "
"Use `TensorSharedVariable` instead and check for `ndim==0`."
,
FutureWarning
,
)
return
TensorSharedVariable
raise
AttributeError
(
f
"module {__name__!r} has no attribute {name!r}"
)
def
load_shared_variable
(
val
):
"""
This function is only here to keep some pickles loading
...
...
@@ -94,10 +106,6 @@ def tensor_constructor(
)
class
ScalarSharedVariable
(
TensorSharedVariable
):
pass
@shared_constructor.register
(
np
.
number
)
@shared_constructor.register
(
float
)
@shared_constructor.register
(
int
)
...
...
@@ -132,7 +140,7 @@ def scalar_constructor(
# Do not pass the dtype to asarray because we want this to fail if
# strict is True and the types do not match.
rval
=
Scala
rSharedVariable
(
rval
=
Tenso
rSharedVariable
(
type
=
tensor_type
,
value
=
np
.
array
(
value
,
copy
=
True
),
name
=
name
,
...
...
tests/tensor/test_sharedvar.py
浏览文件 @
5cfd9da9
...
...
@@ -10,7 +10,7 @@ from pytensor.misc.may_share_memory import may_share_memory
from
pytensor.tensor
import
get_vector_length
from
pytensor.tensor.basic
import
MakeVector
from
pytensor.tensor.shape
import
Shape_i
,
specify_shape
from
pytensor.tensor.sharedvar
import
ScalarSharedVariable
,
TensorSharedVariable
from
pytensor.tensor.sharedvar
import
TensorSharedVariable
from
tests
import
unittest_tools
as
utt
...
...
@@ -679,12 +679,17 @@ def test_tensor_shared_zero():
def
test_scalar_shared_options
():
res
=
pytensor
.
shared
(
value
=
np
.
float32
(
0.0
),
name
=
"lk"
,
borrow
=
True
)
assert
isinstance
(
res
,
ScalarSharedVariable
)
assert
isinstance
(
res
,
TensorSharedVariable
)
and
res
.
type
.
ndim
==
0
assert
res
.
type
.
dtype
==
"float32"
assert
res
.
name
==
"lk"
assert
res
.
type
.
shape
==
()
def
test_scalar_shared_deprecated
():
with
pytest
.
warns
(
FutureWarning
,
match
=
".*deprecated.*"
):
pytensor
.
tensor
.
sharedvar
.
ScalarSharedVariable
def
test_get_vector_length
():
x
=
pytensor
.
shared
(
np
.
array
((
2
,
3
,
4
,
5
)))
assert
get_vector_length
(
x
)
==
4
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论