Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
df265150
提交
df265150
authored
12月 08, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
a better implementation of SparseType.may_share_memory. test it.
上级
db66b8e6
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
27 行增加
和
2 行删除
+27
-2
basic.py
theano/sparse/basic.py
+13
-2
test_basic.py
theano/sparse/tests/test_basic.py
+14
-0
没有找到文件。
theano/sparse/basic.py
浏览文件 @
df265150
...
...
@@ -190,7 +190,18 @@ class SparseType(gof.Type):
def
may_share_memory
(
a
,
b
):
# This is Fred suggestion for a quick and dirty way of checking
# aliasing .. this can potentially be further refined (ticket #374)
return
a
is
b
if
_is_sparse
(
a
)
and
_is_sparse
(
b
):
return
a
is
b
if
_is_sparse
(
b
)
and
isinstance
(
a
,
numpy
.
ndarray
):
a
,
b
=
b
,
a
if
_is_sparse
(
a
)
and
isinstance
(
b
,
numpy
.
ndarray
):
if
(
numpy
.
may_share_memory
(
a
.
data
,
b
)
or
numpy
.
may_share_memory
(
a
.
indices
,
b
)
or
numpy
.
may_share_memory
(
a
.
indptr
,
b
)):
#currently we can't share memory with a.shape as it is a tuple
return
True
return
False
def
make_variable
(
self
,
name
=
None
):
return
SparseVariable
(
self
,
name
=
name
)
...
...
@@ -250,7 +261,7 @@ class _sparse_py_operators:
def
__rdot__
(
right
,
left
):
return
structured_dot
(
left
,
right
)
#N.B. THIS IS COMMENTED OUT ON PURPOSE!!!
# Discussion with Fred & James (at least, and maybe others before)
# Discussion with Fred & James (at least, and maybe others before)
# we decided that casting from a sparse to dense should be explicit
# because it's usually something you want to be pretty careful about,
# and not to do by accident.
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
df265150
...
...
@@ -485,6 +485,20 @@ def test_shape():
assert
isinstance
(
topo
[
1
]
.
op
,
tensor
.
opt
.
Shape_i
)
assert
isinstance
(
topo
[
2
]
.
op
,
tensor
.
opt
.
MakeVector
)
def
test_may_share_memory
():
a
=
scipy
.
sparse
.
csc_matrix
(
scipy
.
sparse
.
eye
(
5
,
3
))
b
=
scipy
.
sparse
.
csc_matrix
(
scipy
.
sparse
.
eye
(
4
,
3
))
as_ar
=
lambda
a
:
theano
.
_asarray
(
a
,
dtype
=
'int32'
)
for
a_
,
b_
,
rep
in
[(
a
,
a
,
True
),(
b
,
b
,
True
),(
a
,
b
,
False
),
(
a
,
a
.
data
,
True
),(
a
,
a
.
indptr
,
True
),(
a
,
a
.
indices
,
True
),(
a
,
as_ar
(
a
.
shape
),
False
),
(
a
.
data
,
a
,
True
),(
a
.
indptr
,
a
,
True
),(
a
.
indices
,
a
,
True
),(
as_ar
(
a
.
shape
),
a
,
False
),
(
b
,
b
.
data
,
True
),(
b
,
b
.
indptr
,
True
),(
b
,
b
.
indices
,
True
),(
b
,
as_ar
(
b
.
shape
),
False
),
(
b
.
data
,
b
,
True
),(
b
.
indptr
,
b
,
True
),(
b
.
indices
,
b
,
True
),(
as_ar
(
b
.
shape
),
b
,
False
),
(
b
.
data
,
a
,
False
),(
b
.
indptr
,
a
,
False
),(
b
.
indices
,
a
,
False
),(
as_ar
(
b
.
shape
),
a
,
False
),
]:
assert
SparseType
.
may_share_memory
(
a_
,
b_
)
==
rep
import
theano.tensor.tests.test_sharedvar
test_shared_options
=
theano
.
tensor
.
tests
.
test_sharedvar
.
makeSharedTester
(
theano
.
sparse
.
shared
,
'float64'
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论