Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e51e8787
提交
e51e8787
authored
10月 01, 2021
作者:
Brandon T. Willard
提交者:
Thomas Wiecki
10月 01, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add an empty_like implementation
上级
61c3e37b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
29 行增加
和
2 行删除
+29
-2
basic.py
aesara/tensor/basic.py
+23
-1
test_basic.py
tests/tensor/test_basic.py
+6
-1
没有找到文件。
aesara/tensor/basic.py
浏览文件 @
e51e8787
...
@@ -12,7 +12,7 @@ from collections import OrderedDict
...
@@ -12,7 +12,7 @@ from collections import OrderedDict
from
collections.abc
import
Sequence
from
collections.abc
import
Sequence
from
functools
import
partial
from
functools
import
partial
from
numbers
import
Number
from
numbers
import
Number
from
typing
import
Dict
,
Tuple
,
Union
from
typing
import
Dict
,
Optional
,
Tuple
,
Union
import
numpy
as
np
import
numpy
as
np
from
numpy.core.multiarray
import
normalize_axis_index
from
numpy.core.multiarray
import
normalize_axis_index
...
@@ -4299,6 +4299,27 @@ def empty(shape, dtype=None):
...
@@ -4299,6 +4299,27 @@ def empty(shape, dtype=None):
return
AllocEmpty
(
dtype
)(
*
shape
)
return
AllocEmpty
(
dtype
)(
*
shape
)
def
empty_like
(
prototype
:
TensorVariable
,
dtype
:
Optional
[
Union
[
str
,
np
.
generic
,
np
.
dtype
]]
=
None
)
->
TensorVariable
:
"""Return a new array with the same shape and type as a given array.
See ``numpy.empty_like``.
Parameters
----------
prototype
The shape and data-type of `prototype` define these same attributes
of the returned array.
dtype : data-type, optional
Overrides the data type of the result.
"""
if
dtype
is
None
:
dtype
=
prototype
.
dtype
return
empty
(
shape
(
prototype
),
dtype
)
def
atleast_Nd
(
def
atleast_Nd
(
*
arys
:
Union
[
np
.
ndarray
,
TensorVariable
],
n
:
int
=
1
,
left
:
bool
=
True
*
arys
:
Union
[
np
.
ndarray
,
TensorVariable
],
n
:
int
=
1
,
left
:
bool
=
True
)
->
TensorVariable
:
)
->
TensorVariable
:
...
@@ -4462,4 +4483,5 @@ __all__ = [
...
@@ -4462,4 +4483,5 @@ __all__ = [
"extract_diag"
,
"extract_diag"
,
"full"
,
"full"
,
"empty"
,
"empty"
,
"empty_like"
,
]
]
tests/tensor/test_basic.py
浏览文件 @
e51e8787
...
@@ -4104,7 +4104,7 @@ class TestChoose(utt.InferShapeTester):
...
@@ -4104,7 +4104,7 @@ class TestChoose(utt.InferShapeTester):
)
)
def
test_
alloc
empty
():
def
test_empty
():
# Test that we allocated correctly
# Test that we allocated correctly
f
=
aesara
.
function
([],
AllocEmpty
(
"float32"
)(
2
,
3
))
f
=
aesara
.
function
([],
AllocEmpty
(
"float32"
)(
2
,
3
))
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
...
@@ -4122,6 +4122,11 @@ def test_allocempty():
...
@@ -4122,6 +4122,11 @@ def test_allocempty():
assert
res
.
shape
==
(
2
,
3
)
assert
res
.
shape
==
(
2
,
3
)
assert
res
.
dtype
==
"int64"
assert
res
.
dtype
==
"int64"
empty_at
=
aet
.
empty_like
(
empty_at
)
res
=
aesara
.
function
([],
empty_at
)()
assert
res
.
shape
==
(
2
,
3
)
assert
res
.
dtype
==
"int64"
def
test_atleast_Nd
():
def
test_atleast_Nd
():
ary1
=
dscalar
()
ary1
=
dscalar
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论