Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0933d203
提交
0933d203
authored
11月 15, 2022
作者:
Adrian Seyboldt
提交者:
Adrian Seyboldt
12月 02, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Normalize negative axes
上级
ee9a6ff2
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
22 行增加
和
0 行删除
+22
-0
elemwise.py
pytensor/link/numba/dispatch/elemwise.py
+22
-0
没有找到文件。
pytensor/link/numba/dispatch/elemwise.py
浏览文件 @
0933d203
...
@@ -164,6 +164,18 @@ def create_vectorize_func(
...
@@ -164,6 +164,18 @@ def create_vectorize_func(
return
elemwise_fn
return
elemwise_fn
def
normalize_axis
(
axis
,
ndim
):
if
axis
is
None
:
return
axis
if
axis
<
0
:
axis
=
ndim
+
axis
if
axis
<
0
or
axis
>=
ndim
:
raise
np
.
AxisError
(
ndim
=
ndim
,
axis
=
axis
)
return
axis
def
create_axis_reducer
(
def
create_axis_reducer
(
scalar_op
:
Op
,
scalar_op
:
Op
,
identity
:
Union
[
np
.
ndarray
,
Number
],
identity
:
Union
[
np
.
ndarray
,
Number
],
...
@@ -218,6 +230,8 @@ def create_axis_reducer(
...
@@ -218,6 +230,8 @@ def create_axis_reducer(
"""
"""
axis
=
normalize_axis
(
axis
,
ndim
)
reduce_elemwise_fn_name
=
"careduce_axis"
reduce_elemwise_fn_name
=
"careduce_axis"
identity
=
str
(
identity
)
identity
=
str
(
identity
)
...
@@ -340,6 +354,8 @@ def create_multiaxis_reducer(
...
@@ -340,6 +354,8 @@ def create_multiaxis_reducer(
if
len
(
axes
)
==
1
:
if
len
(
axes
)
==
1
:
return
create_axis_reducer
(
scalar_op
,
identity
,
axes
[
0
],
ndim
,
dtype
)
return
create_axis_reducer
(
scalar_op
,
identity
,
axes
[
0
],
ndim
,
dtype
)
axes
=
[
normalize_axis
(
axis
,
ndim
)
for
axis
in
axes
]
careduce_fn_name
=
f
"careduce_{scalar_op}"
careduce_fn_name
=
f
"careduce_{scalar_op}"
global_env
=
{}
global_env
=
{}
to_reduce
=
reversed
(
sorted
(
axes
))
to_reduce
=
reversed
(
sorted
(
axes
))
...
@@ -409,6 +425,8 @@ def jit_compile_reducer(node, fn, **kwds):
...
@@ -409,6 +425,8 @@ def jit_compile_reducer(node, fn, **kwds):
def
create_axis_apply_fn
(
fn
,
axis
,
ndim
,
dtype
):
def
create_axis_apply_fn
(
fn
,
axis
,
ndim
,
dtype
):
axis
=
normalize_axis
(
axis
,
ndim
)
reaxis_first
=
tuple
(
i
for
i
in
range
(
ndim
)
if
i
!=
axis
)
+
(
axis
,)
reaxis_first
=
tuple
(
i
for
i
in
range
(
ndim
)
if
i
!=
axis
)
+
(
axis
,)
@numba_basic.numba_njit
(
boundscheck
=
False
)
@numba_basic.numba_njit
(
boundscheck
=
False
)
...
@@ -609,6 +627,8 @@ def numba_funcify_Softmax(op, node, **kwargs):
...
@@ -609,6 +627,8 @@ def numba_funcify_Softmax(op, node, **kwargs):
x_dtype
=
numba
.
np
.
numpy_support
.
from_dtype
(
x_dtype
)
x_dtype
=
numba
.
np
.
numpy_support
.
from_dtype
(
x_dtype
)
axis
=
op
.
axis
axis
=
op
.
axis
axis
=
normalize_axis
(
axis
,
x_at
.
ndim
)
if
axis
is
not
None
:
if
axis
is
not
None
:
reduce_max_py
=
create_axis_reducer
(
reduce_max_py
=
create_axis_reducer
(
scalar_maximum
,
-
np
.
inf
,
axis
,
x_at
.
ndim
,
x_dtype
,
keepdims
=
True
scalar_maximum
,
-
np
.
inf
,
axis
,
x_at
.
ndim
,
x_dtype
,
keepdims
=
True
...
@@ -646,6 +666,7 @@ def numba_funcify_SoftmaxGrad(op, node, **kwargs):
...
@@ -646,6 +666,7 @@ def numba_funcify_SoftmaxGrad(op, node, **kwargs):
sm_dtype
=
numba
.
np
.
numpy_support
.
from_dtype
(
sm_dtype
)
sm_dtype
=
numba
.
np
.
numpy_support
.
from_dtype
(
sm_dtype
)
axis
=
op
.
axis
axis
=
op
.
axis
axis
=
normalize_axis
(
axis
,
sm_at
.
ndim
)
if
axis
is
not
None
:
if
axis
is
not
None
:
reduce_sum_py
=
create_axis_reducer
(
reduce_sum_py
=
create_axis_reducer
(
add_as
,
0.0
,
axis
,
sm_at
.
ndim
,
sm_dtype
,
keepdims
=
True
add_as
,
0.0
,
axis
,
sm_at
.
ndim
,
sm_dtype
,
keepdims
=
True
...
@@ -676,6 +697,7 @@ def numba_funcify_LogSoftmax(op, node, **kwargs):
...
@@ -676,6 +697,7 @@ def numba_funcify_LogSoftmax(op, node, **kwargs):
x_dtype
=
x_at
.
type
.
numpy_dtype
x_dtype
=
x_at
.
type
.
numpy_dtype
x_dtype
=
numba
.
np
.
numpy_support
.
from_dtype
(
x_dtype
)
x_dtype
=
numba
.
np
.
numpy_support
.
from_dtype
(
x_dtype
)
axis
=
op
.
axis
axis
=
op
.
axis
axis
=
normalize_axis
(
axis
,
x_at
.
ndim
)
if
axis
is
not
None
:
if
axis
is
not
None
:
reduce_max_py
=
create_axis_reducer
(
reduce_max_py
=
create_axis_reducer
(
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论