Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e31655fb
提交
e31655fb
authored
12月 07, 2022
作者:
Brandon T. Willard
提交者:
Ricardo Vieira
3月 22, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add np.shape and ndim overloads for sparse Numba types
上级
4317d0df
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
45 行增加
和
0 行删除
+45
-0
sparse.py
pytensor/link/numba/dispatch/sparse.py
+21
-0
test_sparse.py
tests/link/numba/test_sparse.py
+24
-0
没有找到文件。
pytensor/link/numba/dispatch/sparse.py
浏览文件 @
e31655fb
import
numpy
as
np
import
scipy
as
sp
import
scipy.sparse
from
numba.core
import
cgutils
,
types
...
...
@@ -6,6 +7,8 @@ from numba.extending import (
box
,
make_attribute_wrapper
,
models
,
overload
,
overload_attribute
,
register_model
,
typeof_impl
,
unbox
,
...
...
@@ -139,3 +142,21 @@ def box_matrix(typ, val, c):
c
.
pyapi
.
decref
(
shape_obj
)
return
obj
@overload
(
np
.
shape
)
def
overload_sparse_shape
(
x
):
if
isinstance
(
x
,
CSMatrixType
):
return
lambda
x
:
x
.
shape
@overload_attribute
(
CSMatrixType
,
"ndim"
)
def
overload_sparse_ndim
(
inst
):
if
not
isinstance
(
inst
,
CSMatrixType
):
return
def
ndim
(
inst
):
return
2
return
ndim
tests/link/numba/test_sparse.py
浏览文件 @
e31655fb
...
...
@@ -38,3 +38,27 @@ def test_sparse_boxing():
assert
np
.
array_equal
(
res_y_val
.
indices
,
y_val
.
indices
)
assert
np
.
array_equal
(
res_y_val
.
indptr
,
y_val
.
indptr
)
assert
res_y_val
.
shape
==
y_val
.
shape
def
test_sparse_shape
():
@numba.njit
def
test_fn
(
x
):
return
np
.
shape
(
x
)
x_val
=
sp
.
sparse
.
csr_matrix
(
np
.
eye
(
100
))
res
=
test_fn
(
x_val
)
assert
res
==
(
100
,
100
)
def
test_sparse_ndim
():
@numba.njit
def
test_fn
(
x
):
return
x
.
ndim
x_val
=
sp
.
sparse
.
csr_matrix
(
np
.
eye
(
100
))
res
=
test_fn
(
x_val
)
assert
res
==
2
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论