Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7ad266d6
提交
7ad266d6
authored
2月 18, 2026
作者:
Tomas Capretto
提交者:
Ricardo Vieira
2月 26, 2026
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement ColScaleCSC and RowScaleCSC sparse Ops in Numba backend
上级
4765cdad
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
67 行增加
和
0 行删除
+67
-0
basic.py
pytensor/link/numba/dispatch/sparse/basic.py
+45
-0
test_basic.py
tests/link/numba/sparse/test_basic.py
+22
-0
没有找到文件。
pytensor/link/numba/dispatch/sparse/basic.py
浏览文件 @
7ad266d6
...
@@ -14,9 +14,11 @@ from pytensor.link.numba.dispatch.sparse.variable import CSMatrixType
...
@@ -14,9 +14,11 @@ from pytensor.link.numba.dispatch.sparse.variable import CSMatrixType
from
pytensor.sparse
import
(
from
pytensor.sparse
import
(
CSM
,
CSM
,
Cast
,
Cast
,
ColScaleCSC
,
CSMProperties
,
CSMProperties
,
DenseFromSparse
,
DenseFromSparse
,
HStack
,
HStack
,
RowScaleCSC
,
SparseFromDense
,
SparseFromDense
,
Transpose
,
Transpose
,
VStack
,
VStack
,
...
@@ -238,3 +240,46 @@ def numba_funcify_VStack(op, node, **kwargs):
...
@@ -238,3 +240,46 @@ def numba_funcify_VStack(op, node, **kwargs):
return
vstack_csr
(
*
blocks
)
.
tocsc
()
return
vstack_csr
(
*
blocks
)
.
tocsc
()
return
vstack_csc
return
vstack_csc
@register_funcify_default_op_cache_key
(
ColScaleCSC
)
def
numba_funcify_ColScaleCSC
(
op
,
node
,
**
kwargs
):
@numba_basic.numba_njit
def
col_scale_csc
(
x
,
v
):
n_cols
=
x
.
shape
[
1
]
assert
v
.
shape
==
(
n_cols
,)
z
=
x
.
copy
()
z_data
=
z
.
data
z_indptr
=
z
.
indptr
.
view
(
np
.
uint32
)
for
col_idx
in
range
(
n_cols
):
scale
=
v
[
col_idx
]
# Could use slicing, but numba is usually faster with explicit loops.
for
idx
in
range
(
z_indptr
[
col_idx
],
z_indptr
[
col_idx
+
1
]):
z_data
[
idx
]
*=
scale
return
z
return
col_scale_csc
@register_funcify_default_op_cache_key
(
RowScaleCSC
)
def
numba_funcify_RowScaleCSC
(
op
,
node
,
**
kwargs
):
@numba_basic.numba_njit
def
row_scale_csc
(
x
,
v
):
n_rows
,
n_cols
=
x
.
shape
assert
v
.
shape
==
(
n_rows
,)
indices
=
x
.
indices
.
view
(
np
.
uint32
)
indptr
=
x
.
indptr
.
view
(
np
.
uint32
)
z_data
=
x
.
data
.
copy
()
for
col_idx
in
range
(
n_cols
):
for
idx
in
range
(
indptr
[
col_idx
],
indptr
[
col_idx
+
1
]):
z_data
[
idx
]
*=
v
[
indices
[
idx
]]
return
sp
.
sparse
.
csc_matrix
(
(
z_data
,
x
.
indices
.
copy
(),
x
.
indptr
.
copy
()),
shape
=
x
.
shape
)
return
row_scale_csc
tests/link/numba/sparse/test_basic.py
浏览文件 @
7ad266d6
...
@@ -432,3 +432,25 @@ def test_sparse_vstack_mismatched_cols_raises():
...
@@ -432,3 +432,25 @@ def test_sparse_vstack_mismatched_cols_raises():
with
pytest
.
raises
(
ValueError
,
match
=
"Mismatching dimensions along axis 1"
):
with
pytest
.
raises
(
ValueError
,
match
=
"Mismatching dimensions along axis 1"
):
fn
(
x_test
,
y_test
)
fn
(
x_test
,
y_test
)
@pytest.mark.parametrize
(
"format"
,
(
"csr"
,
"csc"
))
def
test_sparse_col_scale
(
format
):
x
=
ps
.
matrix
(
format
,
name
=
"x"
,
shape
=
(
8
,
10
),
dtype
=
config
.
floatX
)
v
=
pt
.
vector
(
name
=
"v"
,
shape
=
(
10
,),
dtype
=
config
.
floatX
)
z
=
ps
.
col_scale
(
x
,
v
)
x_test
=
sp
.
sparse
.
random
(
8
,
10
,
density
=
0.4
,
format
=
format
,
dtype
=
config
.
floatX
)
s_test
=
np
.
random
.
random
(
10
)
.
astype
(
config
.
floatX
)
compare_numba_and_py_sparse
([
x
,
v
],
z
,
[
x_test
,
s_test
])
@pytest.mark.parametrize
(
"format"
,
(
"csr"
,
"csc"
))
def
test_sparse_row_scale
(
format
):
x
=
ps
.
matrix
(
format
,
name
=
"x"
,
shape
=
(
7
,
10
),
dtype
=
config
.
floatX
)
v
=
pt
.
vector
(
name
=
"v"
,
shape
=
(
7
,),
dtype
=
config
.
floatX
)
z
=
ps
.
row_scale
(
x
,
v
)
x_test
=
sp
.
sparse
.
random
(
7
,
10
,
density
=
0.4
,
format
=
format
,
dtype
=
config
.
floatX
)
v_test
=
np
.
random
.
random
(
7
)
.
astype
(
config
.
floatX
)
compare_numba_and_py_sparse
([
x
,
v
],
z
,
[
x_test
,
v_test
])
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论