Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5c05a90c
提交
5c05a90c
authored
1月 07, 2009
作者:
james@X40
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sparse tests pass
上级
8e620d7b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
48 行增加
和
15 行删除
+48
-15
basic.py
theano/sparse/basic.py
+46
-14
test_basic.py
theano/sparse/tests/test_basic.py
+2
-1
没有找到文件。
theano/sparse/basic.py
浏览文件 @
5c05a90c
...
@@ -6,6 +6,7 @@ To read about different sparse formats, see U{http://www-users.cs.umn.edu/~saad/
...
@@ -6,6 +6,7 @@ To read about different sparse formats, see U{http://www-users.cs.umn.edu/~saad/
@todo: Automatic methods for determining best sparse format?
@todo: Automatic methods for determining best sparse format?
"""
"""
import
sys
import
numpy
import
numpy
from
scipy
import
sparse
from
scipy
import
sparse
...
@@ -211,12 +212,13 @@ class CSMProperties(gof.Op):
...
@@ -211,12 +212,13 @@ class CSMProperties(gof.Op):
[
data
,
tensor
.
ivector
(),
tensor
.
ivector
(),
tensor
.
ivector
()])
[
data
,
tensor
.
ivector
(),
tensor
.
ivector
(),
tensor
.
ivector
()])
def
perform
(
self
,
node
,
(
csm
,),
out
):
def
perform
(
self
,
node
,
(
csm
,),
out
):
print
'******* sp:CSMProperties:perform *******'
if
0
:
print
'self.map = '
,
self
.
map
print
'******* sp:CSMProperties:perform *******'
print
'csm.data = '
,
csm
.
data
print
'self.map = '
,
self
.
map
print
'size(csm.data) = '
,
numpy
.
size
(
csm
.
data
)
print
'csm.data = '
,
csm
.
data
print
'csm.todense.shape = '
,
csm
.
todense
()
.
shape
print
'size(csm.data) = '
,
numpy
.
size
(
csm
.
data
)
print
'type(csm) = '
,
type
(
csm
)
print
'csm.todense.shape = '
,
csm
.
todense
()
.
shape
print
'type(csm) = '
,
type
(
csm
)
out
[
0
][
0
]
=
csm
.
data
if
self
.
map
is
None
else
csm
.
data
[
self
.
map
]
out
[
0
][
0
]
=
csm
.
data
if
self
.
map
is
None
else
csm
.
data
[
self
.
map
]
out
[
1
][
0
]
=
numpy
.
asarray
(
csm
.
indices
,
dtype
=
'int32'
)
out
[
1
][
0
]
=
numpy
.
asarray
(
csm
.
indices
,
dtype
=
'int32'
)
out
[
2
][
0
]
=
numpy
.
asarray
(
csm
.
indptr
,
dtype
=
'int32'
)
out
[
2
][
0
]
=
numpy
.
asarray
(
csm
.
indptr
,
dtype
=
'int32'
)
...
@@ -295,12 +297,14 @@ class CSM(gof.Op):
...
@@ -295,12 +297,14 @@ class CSM(gof.Op):
"""Build a csc_matrix"""
"""Build a csc_matrix"""
#assert len(data.flatten()) == len(indices.flatten())
#assert len(data.flatten()) == len(indices.flatten())
print
'********** sp:CSM:perform ***********'
if
0
:
print
'data ='
,
data
.
__repr__
()
print
'********** sp:CSM:perform ***********'
print
'size(data) = '
,
numpy
.
size
(
data
)
print
'data ='
,
data
.
__repr__
()
print
'kmap ='
,
self
.
map
.
__repr__
()
print
'size(data) = '
,
numpy
.
size
(
data
)
print
'kmap ='
,
self
.
map
.
__repr__
()
data
=
data
[
self
.
map
]
if
self
.
map
!=
None
else
data
data
=
data
[
self
.
map
]
if
self
.
map
!=
None
else
data
print
'data[kmap] ='
,
data
.
__repr__
()
if
0
:
print
'data[kmap] ='
,
data
.
__repr__
()
if
len
(
shape
)
!=
2
:
if
len
(
shape
)
!=
2
:
raise
ValueError
(
'Shape should be an array of length 2'
)
raise
ValueError
(
'Shape should be an array of length 2'
)
...
@@ -502,7 +506,37 @@ class MulSD(gof.op.Op):
...
@@ -502,7 +506,37 @@ class MulSD(gof.op.Op):
elif
len
(
y
.
shape
)
==
2
:
elif
len
(
y
.
shape
)
==
2
:
#if we have enough memory to fit y, maybe we can fit x.asarray() too?
#if we have enough memory to fit y, maybe we can fit x.asarray() too?
#TODO: change runtime from O(M*N) to O(nonzeros)
#TODO: change runtime from O(M*N) to O(nonzeros)
out
[
0
]
=
type
(
x
)(
x
.
toarray
()
*
y
)
M
,
N
=
x
.
shape
assert
x
.
shape
==
y
.
shape
if
x
.
format
==
'csc'
:
x_data
=
x
.
data
indices
=
x
.
indices
indptr
=
x
.
indptr
z
=
x
.
copy
()
z_data
=
z
.
data
for
j
in
xrange
(
0
,
N
):
for
i_idx
in
xrange
(
indptr
[
j
],
indptr
[
j
+
1
]):
i
=
indices
[
i_idx
]
z_data
[
i_idx
]
*=
y
[
i
,
j
]
out
[
0
]
=
z
elif
x
.
format
==
'csr'
:
x_data
=
x
.
data
indices
=
x
.
indices
indptr
=
x
.
indptr
z
=
x
.
copy
()
z_data
=
z
.
data
for
i
in
xrange
(
0
,
M
):
for
j_idx
in
xrange
(
indptr
[
i
],
indptr
[
i
+
1
]):
j
=
indices
[
j_idx
]
z_data
[
j_idx
]
*=
y
[
i
,
j
]
out
[
0
]
=
z
else
:
print
>>
sys
.
stderr
,
"WARNING: crappy implementation of MulSD"
,
x
.
format
out
[
0
]
=
type
(
x
)(
x
.
toarray
()
*
y
)
def
grad
(
self
,
(
x
,
y
),
(
gz
,)):
def
grad
(
self
,
(
x
,
y
),
(
gz
,)):
assert
_is_sparse_result
(
x
)
and
_is_dense_result
(
y
)
assert
_is_sparse_result
(
x
)
and
_is_dense_result
(
y
)
assert
_is_sparse_result
(
gz
)
assert
_is_sparse_result
(
gz
)
...
@@ -563,8 +597,6 @@ class Dot(gof.op.Op):
...
@@ -563,8 +597,6 @@ class Dot(gof.op.Op):
@todo: Verify that output is sufficiently sparse, and raise a warning if it is not
@todo: Verify that output is sufficiently sparse, and raise a warning if it is not
@todo: Also determine that we are storing the output in the best storage format?
@todo: Also determine that we are storing the output in the best storage format?
"""
"""
print
'x type is'
,
type
(
x
)
print
'y type is'
,
type
(
y
)
out
[
0
]
=
x
.
dot
(
y
)
out
[
0
]
=
x
.
dot
(
y
)
def
grad
(
self
,
(
x
,
y
),
(
gz
,)):
def
grad
(
self
,
(
x
,
y
),
(
gz
,)):
assert
_is_sparse_result
(
gz
)
assert
_is_sparse_result
(
gz
)
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
5c05a90c
...
@@ -274,9 +274,10 @@ class test_dot(unittest.TestCase):
...
@@ -274,9 +274,10 @@ class test_dot(unittest.TestCase):
for
epoch
in
xrange
(
50
):
for
epoch
in
xrange
(
50
):
y
,
loss
,
gw
=
trainfn
(
x
,
w
)
y
,
loss
,
gw
=
trainfn
(
x
,
w
)
w
=
w
-
(
lr
*
gw
)
w
=
w
-
(
lr
*
gw
)
print
loss
self
.
failUnless
(
origloss
>
loss
)
self
.
failUnless
(
origloss
>
loss
)
self
.
failUnless
(
'1.05
4317228
5'
==
str
(
loss
))
self
.
failUnless
(
'1.05
19124111
5'
==
str
(
loss
))
def
test_graph_bprop_rand
(
self
):
def
test_graph_bprop_rand
(
self
):
for
i
in
range
(
10
):
for
i
in
range
(
10
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论