Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d09e222b
提交
d09e222b
authored
6月 28, 2022
作者:
Tommy Guy
提交者:
Ricardo Vieira
6月 30, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add dtype option to identity_like
Resolves #816
上级
7393b744
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
29 行增加
和
4 行删除
+29
-4
basic.py
aesara/tensor/basic.py
+16
-2
basic.rst
doc/library/tensor/basic.rst
+3
-2
test_basic.py
tests/tensor/test_basic.py
+10
-0
没有找到文件。
aesara/tensor/basic.py
浏览文件 @
d09e222b
...
@@ -1422,8 +1422,22 @@ def eye(n, m=None, k=0, dtype=None):
...
@@ -1422,8 +1422,22 @@ def eye(n, m=None, k=0, dtype=None):
return
localop
(
n
,
m
,
k
)
return
localop
(
n
,
m
,
k
)
def
identity_like
(
x
):
def
identity_like
(
x
,
dtype
:
Optional
[
Union
[
str
,
np
.
generic
,
np
.
dtype
]]
=
None
):
return
eye
(
x
.
shape
[
0
],
x
.
shape
[
1
],
k
=
0
,
dtype
=
x
.
dtype
)
"""Create a tensor with ones on main diagonal and zeroes elsewhere.
Parameters
----------
x : tensor
dtype : data-type, optional
Returns
-------
tensor
tensor the shape of x with ones on main diagonal and zeroes elsewhere of type of dtype.
"""
if
dtype
is
None
:
dtype
=
x
.
dtype
return
eye
(
x
.
shape
[
0
],
x
.
shape
[
1
],
k
=
0
,
dtype
=
dtype
)
def
infer_broadcastable
(
shape
):
def
infer_broadcastable
(
shape
):
...
...
doc/library/tensor/basic.rst
浏览文件 @
d09e222b
...
@@ -777,12 +777,13 @@ Creating Tensors
...
@@ -777,12 +777,13 @@ Creating Tensors
:returns: An array where all elements are equal to zero, except for the `k`-th
:returns: An array where all elements are equal to zero, except for the `k`-th
diagonal, whose values are equal to one.
diagonal, whose values are equal to one.
.. function:: identity_like(x)
.. function:: identity_like(x
, dtype=None
)
:param x: tensor
:param x: tensor
:param dtype: The dtype of the returned tensor. If `None`, default to dtype of `x`
:returns: A tensor of same shape as `x` that is filled with zeros everywhere
:returns: A tensor of same shape as `x` that is filled with zeros everywhere
except for the main diagonal, whose values are equal to one. The output
except for the main diagonal, whose values are equal to one. The output
will have same dtype as `x`.
will have same dtype as `x`
unless overridden in `dtype`
.
.. function:: stack(tensors, axis=0)
.. function:: stack(tensors, axis=0)
...
...
tests/tensor/test_basic.py
浏览文件 @
d09e222b
...
@@ -59,6 +59,7 @@ from aesara.tensor.basic import (
...
@@ -59,6 +59,7 @@ from aesara.tensor.basic import (
get_scalar_constant_value
,
get_scalar_constant_value
,
get_vector_length
,
get_vector_length
,
horizontal_stack
,
horizontal_stack
,
identity_like
,
infer_broadcastable
,
infer_broadcastable
,
inverse_permutation
,
inverse_permutation
,
join
,
join
,
...
@@ -4392,6 +4393,15 @@ def test_empty():
...
@@ -4392,6 +4393,15 @@ def test_empty():
assert
res
.
dtype
==
"int64"
assert
res
.
dtype
==
"int64"
def
test_identity_like_dtype
():
# Test that we allocate eye correctly via identity_like
m
=
matrix
(
dtype
=
"int64"
)
m_out
=
identity_like
(
m
)
assert
m_out
.
dtype
==
m
.
dtype
m_out_float
=
identity_like
(
m
,
dtype
=
np
.
float64
)
assert
m_out_float
.
dtype
==
"float64"
def
test_atleast_Nd
():
def
test_atleast_Nd
():
ary1
=
dscalar
()
ary1
=
dscalar
()
res_ary1
=
atleast_Nd
(
ary1
,
n
=
1
)
res_ary1
=
atleast_Nd
(
ary1
,
n
=
1
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论