Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
042e4a67
提交
042e4a67
authored
4月 13, 2022
作者:
Larry Dong
提交者:
Brandon T. Willard
4月 22, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change at.diff to slicing + subtraction
上级
e5ebf260
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
17 行增加
和
3 行删除
+17
-3
extra_ops.py
aesara/tensor/extra_ops.py
+17
-3
没有找到文件。
aesara/tensor/extra_ops.py
浏览文件 @
042e4a67
...
@@ -3,6 +3,7 @@ from typing import Iterable, Tuple, Union
...
@@ -3,6 +3,7 @@ from typing import Iterable, Tuple, Union
import
numpy
as
np
import
numpy
as
np
import
numpy.core.numeric
import
numpy.core.numeric
from
numpy.core.multiarray
import
normalize_axis_index
import
aesara
import
aesara
from
aesara.gradient
import
(
from
aesara.gradient
import
(
...
@@ -483,7 +484,7 @@ class DiffOp(Op):
...
@@ -483,7 +484,7 @@ class DiffOp(Op):
def
make_node
(
self
,
x
):
def
make_node
(
self
,
x
):
x
=
at
.
as_tensor_variable
(
x
)
x
=
at
.
as_tensor_variable
(
x
)
axis
=
n
umpy
.
core
.
numeric
.
n
ormalize_axis_index
(
self
.
axis
,
x
.
ndim
)
axis
=
normalize_axis_index
(
self
.
axis
,
x
.
ndim
)
shape
=
[
None
]
*
x
.
type
.
ndim
shape
=
[
None
]
*
x
.
type
.
ndim
for
i
,
shape_i
in
enumerate
(
x
.
type
.
shape
):
for
i
,
shape_i
in
enumerate
(
x
.
type
.
shape
):
if
shape_i
is
None
:
if
shape_i
is
None
:
...
@@ -533,7 +534,7 @@ def diff(x, n=1, axis=-1):
...
@@ -533,7 +534,7 @@ def diff(x, n=1, axis=-1):
The first order difference is given by ``out[i] = a[i + 1] - a[i]``
The first order difference is given by ``out[i] = a[i + 1] - a[i]``
along the given `axis`, higher order differences are calculated by
along the given `axis`, higher order differences are calculated by
using `diff` recursively. This
wraps
``numpy.diff``.
using `diff` recursively. This
is heavily inspired by
``numpy.diff``.
Parameters
Parameters
----------
----------
...
@@ -548,7 +549,20 @@ def diff(x, n=1, axis=-1):
...
@@ -548,7 +549,20 @@ def diff(x, n=1, axis=-1):
.. versionadded:: 0.6
.. versionadded:: 0.6
"""
"""
return
DiffOp
(
n
=
n
,
axis
=
axis
)(
x
)
ndim
=
x
.
ndim
axis
=
normalize_axis_index
(
axis
,
ndim
)
slice1
=
[
slice
(
None
)]
*
ndim
slice2
=
[
slice
(
None
)]
*
ndim
slice1
[
axis
]
=
slice
(
1
,
None
)
slice2
[
axis
]
=
slice
(
None
,
-
1
)
slice1
=
tuple
(
slice1
)
slice2
=
tuple
(
slice2
)
for
_
in
range
(
n
):
x
=
x
[
slice1
]
-
x
[
slice2
]
return
x
def
bincount
(
x
,
weights
=
None
,
minlength
=
None
,
assert_nonneg
=
False
):
def
bincount
(
x
,
weights
=
None
,
minlength
=
None
,
assert_nonneg
=
False
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论