Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6a17990a
提交
6a17990a
authored
1月 30, 2026
作者:
ricardoV94
提交者:
Ricardo Vieira
1月 30, 2026
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Numba sparse: Allow no-op tocsc and tocsr
上级
23205754
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
39 行增加
和
2 行删除
+39
-2
variable.py
pytensor/link/numba/dispatch/sparse/variable.py
+16
-2
test_basic.py
tests/link/numba/sparse/test_basic.py
+23
-0
没有找到文件。
pytensor/link/numba/dispatch/sparse/variable.py
浏览文件 @
6a17990a
...
@@ -289,8 +289,15 @@ def overload_sparse_astype(matrix, dtype):
...
@@ -289,8 +289,15 @@ def overload_sparse_astype(matrix, dtype):
return
astype
return
astype
@overload_method
(
CS
C
MatrixType
,
"tocsr"
)
@overload_method
(
CSMatrixType
,
"tocsr"
)
def
overload_tocsr
(
matrix
):
def
overload_tocsr
(
matrix
):
if
isinstance
(
matrix
,
CSRMatrixType
):
def
to_csr
(
matrix
):
return
matrix
else
:
# CSCMatrix
def
to_csr
(
matrix
):
def
to_csr
(
matrix
):
n_row
,
n_col
=
matrix
.
shape
n_row
,
n_col
=
matrix
.
shape
csc_ptr
=
matrix
.
indptr
.
view
(
np
.
uint32
)
csc_ptr
=
matrix
.
indptr
.
view
(
np
.
uint32
)
...
@@ -337,8 +344,15 @@ def overload_tocsr(matrix):
...
@@ -337,8 +344,15 @@ def overload_tocsr(matrix):
return
to_csr
return
to_csr
@overload_method
(
CS
R
MatrixType
,
"tocsc"
)
@overload_method
(
CSMatrixType
,
"tocsc"
)
def
overload_tocsc
(
matrix
):
def
overload_tocsc
(
matrix
):
if
isinstance
(
matrix
,
CSCMatrixType
):
def
to_csc
(
matrix
):
return
matrix
else
:
# CSRMatrix
def
to_csc
(
matrix
):
def
to_csc
(
matrix
):
n_row
,
n_col
=
matrix
.
shape
n_row
,
n_col
=
matrix
.
shape
csr_ptr
=
matrix
.
indptr
.
view
(
np
.
uint32
)
csr_ptr
=
matrix
.
indptr
.
view
(
np
.
uint32
)
...
...
tests/link/numba/sparse/test_basic.py
浏览文件 @
6a17990a
...
@@ -276,3 +276,26 @@ def test_sparse_dense_from_sparse(format):
...
@@ -276,3 +276,26 @@ def test_sparse_dense_from_sparse(format):
x_test
=
sp
.
sparse
.
random
(
5
,
3
,
density
=
0.5
,
format
=
format
)
x_test
=
sp
.
sparse
.
random
(
5
,
3
,
density
=
0.5
,
format
=
format
)
y
=
ps
.
dense_from_sparse
(
x
)
y
=
ps
.
dense_from_sparse
(
x
)
compare_numba_and_py_sparse
([
x
],
y
,
[
x_test
])
compare_numba_and_py_sparse
([
x
],
y
,
[
x_test
])
def
test_sparse_conversion
():
@numba.njit
def
to_csr
(
matrix
):
return
matrix
.
tocsr
()
@numba.njit
def
to_csc
(
matrix
):
return
matrix
.
tocsc
()
x_csr
=
scipy
.
sparse
.
random
(
5
,
5
,
density
=
0.5
,
format
=
"csr"
)
x_csc
=
x_csr
.
tocsc
()
x_dense
=
x_csr
.
todense
()
for
x_inp
in
(
x_csr
,
x_csc
):
for
output_format
in
(
"csr"
,
"csc"
):
if
output_format
==
"csr"
:
res
=
to_csr
(
x_inp
)
else
:
res
=
to_csc
(
x_inp
)
assert
res
.
format
==
output_format
np
.
testing
.
assert_array_equal
(
res
.
todense
(),
x_dense
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论