Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
220442a2
提交
220442a2
authored
12月 08, 2022
作者:
Brandon T. Willard
提交者:
Ricardo Vieira
3月 22, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement a copy method for Numba sparse types
上级
eb6fc66e
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
51 行增加
和
0 行删除
+51
-0
sparse.py
pytensor/link/numba/dispatch/sparse.py
+38
-0
test_sparse.py
tests/link/numba/test_sparse.py
+13
-0
没有找到文件。
pytensor/link/numba/dispatch/sparse.py
浏览文件 @
220442a2
...
...
@@ -2,13 +2,16 @@ import numpy as np
import
scipy
as
sp
import
scipy.sparse
from
numba.core
import
cgutils
,
types
from
numba.core.imputils
import
impl_ret_borrowed
from
numba.extending
import
(
NativeValue
,
box
,
intrinsic
,
make_attribute_wrapper
,
models
,
overload
,
overload_attribute
,
overload_method
,
register_model
,
typeof_impl
,
unbox
,
...
...
@@ -166,3 +169,38 @@ def overload_sparse_ndim(inst):
return
2
return
ndim
@intrinsic
def
_sparse_copy
(
typingctx
,
inst
,
data
,
indices
,
indptr
,
shape
):
def
_construct
(
context
,
builder
,
sig
,
args
):
typ
=
sig
.
return_type
struct
=
cgutils
.
create_struct_proxy
(
typ
)(
context
,
builder
)
_
,
data
,
indices
,
indptr
,
shape
=
args
struct
.
data
=
data
struct
.
indices
=
indices
struct
.
indptr
=
indptr
struct
.
shape
=
shape
return
impl_ret_borrowed
(
context
,
builder
,
sig
.
return_type
,
struct
.
_getvalue
(),
)
sig
=
inst
(
inst
,
inst
.
data
,
inst
.
indices
,
inst
.
indptr
,
inst
.
shape
)
return
sig
,
_construct
@overload_method
(
CSMatrixType
,
"copy"
)
def
overload_sparse_copy
(
inst
):
if
not
isinstance
(
inst
,
CSMatrixType
):
return
def
copy
(
inst
):
return
_sparse_copy
(
inst
,
inst
.
data
.
copy
(),
inst
.
indices
.
copy
(),
inst
.
indptr
.
copy
(),
inst
.
shape
)
return
copy
tests/link/numba/test_sparse.py
浏览文件 @
220442a2
...
...
@@ -71,6 +71,19 @@ def test_sparse_ndim():
assert
res
==
2
def
test_sparse_copy
():
@numba.njit
def
test_fn
(
x
):
y
=
x
.
copy
()
return
(
y
is
not
x
and
np
.
all
(
x
.
data
==
y
.
data
)
and
np
.
all
(
x
.
indices
==
y
.
indices
)
)
x_val
=
sp
.
sparse
.
csr_matrix
(
np
.
eye
(
100
))
assert
test_fn
(
x_val
)
def
test_sparse_objmode
():
x
=
SparseTensorType
(
"csc"
,
dtype
=
config
.
floatX
)()
y
=
SparseTensorType
(
"csc"
,
dtype
=
config
.
floatX
)()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论