Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6c3e7578
提交
6c3e7578
authored
8月 24, 2023
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
8月 24, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix numba implementation of CumOp when axis is None
上级
9a5deee0
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
25 行增加
和
7 行删除
+25
-7
extra_ops.py
pytensor/link/numba/dispatch/extra_ops.py
+8
-4
extra_ops.py
pytensor/tensor/extra_ops.py
+2
-2
var.py
pytensor/tensor/var.py
+1
-1
test_extra_ops.py
tests/link/numba/test_extra_ops.py
+14
-0
没有找到文件。
pytensor/link/numba/dispatch/extra_ops.py
浏览文件 @
6c3e7578
import
warnings
import
warnings
from
typing
import
cast
import
numba
import
numba
import
numpy
as
np
import
numpy
as
np
from
pytensor
import
config
from
pytensor
import
config
from
pytensor.graph
import
Apply
from
pytensor.link.numba.dispatch
import
basic
as
numba_basic
from
pytensor.link.numba.dispatch
import
basic
as
numba_basic
from
pytensor.link.numba.dispatch.basic
import
get_numba_type
,
numba_funcify
from
pytensor.link.numba.dispatch.basic
import
get_numba_type
,
numba_funcify
from
pytensor.raise_op
import
CheckAndRaise
from
pytensor.raise_op
import
CheckAndRaise
from
pytensor.tensor
import
TensorVariable
from
pytensor.tensor.extra_ops
import
(
from
pytensor.tensor.extra_ops
import
(
Bartlett
,
Bartlett
,
CumOp
,
CumOp
,
...
@@ -30,11 +33,12 @@ def numba_funcify_Bartlett(op, **kwargs):
...
@@ -30,11 +33,12 @@ def numba_funcify_Bartlett(op, **kwargs):
@numba_funcify.register
(
CumOp
)
@numba_funcify.register
(
CumOp
)
def
numba_funcify_CumOp
(
op
,
node
,
**
kwargs
):
def
numba_funcify_CumOp
(
op
:
CumOp
,
node
:
Apply
,
**
kwargs
):
axis
=
op
.
axis
axis
=
op
.
axis
mode
=
op
.
mode
mode
=
op
.
mode
ndim
=
node
.
outputs
[
0
]
.
ndim
ndim
=
cast
(
TensorVariable
,
node
.
outputs
[
0
])
.
ndim
if
axis
is
not
None
:
if
axis
<
0
:
if
axis
<
0
:
axis
=
ndim
+
axis
axis
=
ndim
+
axis
if
axis
<
0
or
axis
>=
ndim
:
if
axis
<
0
or
axis
>=
ndim
:
...
@@ -44,7 +48,7 @@ def numba_funcify_CumOp(op, node, **kwargs):
...
@@ -44,7 +48,7 @@ def numba_funcify_CumOp(op, node, **kwargs):
reaxis_first_inv
=
tuple
(
np
.
argsort
(
reaxis_first
))
reaxis_first_inv
=
tuple
(
np
.
argsort
(
reaxis_first
))
if
mode
==
"add"
:
if
mode
==
"add"
:
if
ndim
==
1
:
if
axis
is
None
or
ndim
==
1
:
@numba_basic.numba_njit
(
fastmath
=
config
.
numba__fastmath
)
@numba_basic.numba_njit
(
fastmath
=
config
.
numba__fastmath
)
def
cumop
(
x
):
def
cumop
(
x
):
...
@@ -68,7 +72,7 @@ def numba_funcify_CumOp(op, node, **kwargs):
...
@@ -68,7 +72,7 @@ def numba_funcify_CumOp(op, node, **kwargs):
return
res
.
transpose
(
reaxis_first_inv
)
return
res
.
transpose
(
reaxis_first_inv
)
else
:
else
:
if
ndim
==
1
:
if
axis
is
None
or
ndim
==
1
:
@numba_basic.numba_njit
(
fastmath
=
config
.
numba__fastmath
)
@numba_basic.numba_njit
(
fastmath
=
config
.
numba__fastmath
)
def
cumop
(
x
):
def
cumop
(
x
):
...
...
pytensor/tensor/extra_ops.py
浏览文件 @
6c3e7578
from
collections.abc
import
Collection
from
collections.abc
import
Collection
from
typing
import
Iterable
,
Set
,
Tuple
,
Union
from
typing
import
Iterable
,
Optional
,
Set
,
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
...
@@ -291,7 +291,7 @@ class CumOp(COp):
...
@@ -291,7 +291,7 @@ class CumOp(COp):
c_axis
=
int_t
,
mode
=
EnumList
((
"MODE_ADD"
,
"add"
),
(
"MODE_MUL"
,
"mul"
))
c_axis
=
int_t
,
mode
=
EnumList
((
"MODE_ADD"
,
"add"
),
(
"MODE_MUL"
,
"mul"
))
)
)
def
__init__
(
self
,
axis
=
None
,
mode
=
"add"
):
def
__init__
(
self
,
axis
:
Optional
[
int
]
=
None
,
mode
=
"add"
):
if
mode
not
in
(
"add"
,
"mul"
):
if
mode
not
in
(
"add"
,
"mul"
):
raise
ValueError
(
f
'{type(self).__name__}: Unknown mode "{mode}"'
)
raise
ValueError
(
f
'{type(self).__name__}: Unknown mode "{mode}"'
)
self
.
axis
=
axis
self
.
axis
=
axis
...
...
pytensor/tensor/var.py
浏览文件 @
6c3e7578
...
@@ -619,7 +619,7 @@ class _tensor_py_operators:
...
@@ -619,7 +619,7 @@ class _tensor_py_operators:
)
)
@property
@property
def
ndim
(
self
):
def
ndim
(
self
)
->
int
:
"""The rank of this tensor."""
"""The rank of this tensor."""
return
self
.
type
.
ndim
return
self
.
type
.
ndim
...
...
tests/link/numba/test_extra_ops.py
浏览文件 @
6c3e7578
...
@@ -67,6 +67,13 @@ def test_Bartlett(val):
...
@@ -67,6 +67,13 @@ def test_Bartlett(val):
1
,
1
,
"add"
,
"add"
,
),
),
(
set_test_value
(
at
.
matrix
(),
np
.
arange
(
6
,
dtype
=
config
.
floatX
)
.
reshape
((
3
,
2
))
),
None
,
"add"
,
),
(
(
set_test_value
(
set_test_value
(
at
.
matrix
(),
np
.
arange
(
6
,
dtype
=
config
.
floatX
)
.
reshape
((
3
,
2
))
at
.
matrix
(),
np
.
arange
(
6
,
dtype
=
config
.
floatX
)
.
reshape
((
3
,
2
))
...
@@ -81,6 +88,13 @@ def test_Bartlett(val):
...
@@ -81,6 +88,13 @@ def test_Bartlett(val):
1
,
1
,
"mul"
,
"mul"
,
),
),
(
set_test_value
(
at
.
matrix
(),
np
.
arange
(
6
,
dtype
=
config
.
floatX
)
.
reshape
((
3
,
2
))
),
None
,
"mul"
,
),
],
],
)
)
def
test_CumOp
(
val
,
axis
,
mode
):
def
test_CumOp
(
val
,
axis
,
mode
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论