Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fb013254
提交
fb013254
authored
3月 23, 2008
作者:
james@mackie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
scalar ->sandbox, created _test_sparse
上级
eaf79124
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
100 行增加
和
97 行删除
+100
-97
_test_sparse.py
_test_sparse.py
+100
-0
scalar.py
sandbox/scalar.py
+0
-0
scalar_ops.py
sandbox/scalar_ops.py
+0
-0
sparse.py
sparse.py
+0
-97
没有找到文件。
_test_sparse.py
0 → 100644
浏览文件 @
fb013254
from
sparse
import
*
import
unittest
class
_testCase_transpose
(
unittest
.
TestCase
):
def
setUp
(
self
):
core
.
build_eval_mode
()
numpy
.
random
.
seed
(
44
)
def
tearDown
(
self
):
core
.
pop_mode
()
def
test_transpose
(
self
):
a
=
SparseR
(
sparse
.
csr_matrix
(
sparse
.
speye
(
5
,
3
)))
self
.
failUnless
(
a
.
data
.
shape
==
(
5
,
3
))
ta
=
transpose
(
a
)
self
.
failUnless
(
ta
.
data
.
shape
==
(
3
,
5
))
class
_testCase_dot
(
unittest
.
TestCase
):
def
setUp
(
self
):
core
.
build_eval_mode
()
numpy
.
random
.
seed
(
44
)
def
tearDown
(
self
):
core
.
pop_mode
()
def
test_basic0
(
self
):
for
mtype
in
[
sparse
.
csc_matrix
,
sparse
.
csr_matrix
]:
x
=
SparseR
(
mtype
(
sparse
.
speye
(
5
,
3
)))
y
=
core
.
wrap
(
numpy
.
random
.
rand
(
3
,
2
))
z
=
dot
(
x
,
y
)
self
.
failUnless
(
z
.
data
.
shape
==
(
5
,
2
))
self
.
failUnless
(
type
(
z
.
data
)
is
mtype
)
def
test_basic1
(
self
):
"""dot: sparse left"""
a
=
numpy
.
asarray
([[
1
,
0
,
3
,
0
,
5
],
[
0
,
0
,
-
2
,
0
,
0
]],
dtype
=
'float64'
)
b
=
numpy
.
random
.
rand
(
5
,
3
)
for
mtype
in
[
sparse
.
csr_matrix
,
sparse
.
csc_matrix
,
sparse
.
dok_matrix
,
sparse
.
lil_matrix
]:
#, sparse.coo_matrix]:
#print type(a), mtype
m
=
mtype
(
a
)
ab
=
m
.
dot
(
b
)
try
:
z
=
dot
(
SparseR
(
m
),
core
.
ResultBase
(
data
=
b
))
self
.
failUnless
(
z
.
data
.
shape
==
ab
.
shape
)
self
.
failUnless
(
type
(
z
.
data
)
==
type
(
ab
))
except
Exception
,
e
:
print
'cccc'
,
mtype
,
e
,
str
(
e
)
raise
def
test_basic2
(
self
):
"""dot: sparse right"""
a
=
numpy
.
random
.
rand
(
2
,
5
)
b
=
numpy
.
asarray
([[
1
,
0
,
3
,
0
,
5
],
[
0
,
0
,
-
2
,
0
,
0
]],
dtype
=
'float64'
)
.
transpose
()
for
mtype
in
[
sparse
.
csr_matrix
,
sparse
.
csc_matrix
,
sparse
.
dok_matrix
,
sparse
.
lil_matrix
]:
#, sparse.coo_matrix]:
m
=
mtype
(
b
)
ab
=
m
.
transpose
()
.
dot
(
a
.
transpose
())
.
transpose
()
z
=
dot
(
core
.
ResultBase
(
data
=
a
),
SparseR
(
mtype
(
b
)))
self
.
failUnless
(
z
.
data
.
shape
==
ab
.
shape
)
self
.
failUnless
(
type
(
z
.
data
)
==
type
(
ab
))
def
test_graph_bprop0
(
self
):
x
=
core
.
wrap
(
numpy
.
random
.
rand
(
10
,
2
))
w
=
SparseR
(
sparse
.
csr_matrix
(
numpy
.
asarray
([[
1
,
0
,
3
,
0
,
5
],
[
0
,
0
,
-
2
,
0
,
0
]],
dtype
=
'float64'
)))
for
epoch
in
xrange
(
50
):
xw
=
sparse2dense
(
dot
(
x
,
w
))
y
=
sparse2dense
(
dot
(
xw
,
transpose
(
w
)))
loss
=
core
.
sum
(
core
.
sqr
(
x
-
y
))
gy
=
y
-
x
g
=
grad
.
Grad
({
y
:
gy
})
g
.
bprop
()
lr
=
0.002
g
(
w
)
.
data
[
1
,
0
]
=
0
g
(
w
)
.
data
[
1
,
4
]
=
0
w
.
data
=
-
lr
*
g
(
w
)
.
data
+
w
.
data
self
.
failUnless
(
'3.08560636025'
==
str
(
loss
.
data
))
def
test_graph_bprop1
(
self
):
x
=
core
.
wrap
(
numpy
.
random
.
rand
(
10
,
2
))
w
=
SparseR
(
sparse
.
csr_matrix
(
numpy
.
asarray
([[
1
,
0
,
3
,
0
,
5
],
[
0
,
0
,
-
2
,
0
,
0
]],
dtype
=
'float64'
)))
for
epoch
in
xrange
(
50
):
xw
=
sparse2dense
(
dot
(
x
,
w
))
y
=
sparse2dense
(
dot
(
xw
,
transpose
(
w
)))
loss
=
core
.
sum
(
core
.
sqr
(
x
-
y
))
g
=
grad
.
grad
(
loss
)
lr
=
0.001
g
(
w
)
.
data
[
1
,
0
]
=
0
g
(
w
)
.
data
[
1
,
4
]
=
0
w
.
data
=
-
lr
*
g
(
w
)
.
data
+
w
.
data
self
.
failUnless
(
'3.08560636025'
==
str
(
loss
.
data
))
if
__name__
==
'__main__'
:
unittest
.
main
()
scalar.py
→
s
andbox/s
calar.py
浏览文件 @
fb013254
File moved
scalar_ops.py
→
s
andbox/s
calar_ops.py
浏览文件 @
fb013254
File moved
sparse.py
浏览文件 @
fb013254
import
unittest
import
numpy
import
numpy
from
scipy
import
sparse
from
scipy
import
sparse
...
@@ -111,18 +110,6 @@ class transpose(op):
...
@@ -111,18 +110,6 @@ class transpose(op):
def
impl
(
x
):
return
x
.
transpose
()
def
impl
(
x
):
return
x
.
transpose
()
def
grad
(
self
,
x
,
gz
):
return
transpose
(
gz
)
def
grad
(
self
,
x
,
gz
):
return
transpose
(
gz
)
class
_testCase_transpose
(
unittest
.
TestCase
):
def
setUp
(
self
):
core
.
build_eval_mode
()
numpy
.
random
.
seed
(
44
)
def
tearDown
(
self
):
core
.
pop_mode
()
def
test_transpose
(
self
):
a
=
SparseR
(
sparse
.
csr_matrix
(
sparse
.
speye
(
5
,
3
)))
self
.
failUnless
(
a
.
data
.
shape
==
(
5
,
3
))
ta
=
transpose
(
a
)
self
.
failUnless
(
ta
.
data
.
shape
==
(
3
,
5
))
class
dot
(
op
):
class
dot
(
op
):
"""
"""
Attributes:
Attributes:
...
@@ -155,87 +142,3 @@ class dot(op):
...
@@ -155,87 +142,3 @@ class dot(op):
rval
[
i
]
=
sparse2dense
(
rval
[
i
])
rval
[
i
]
=
sparse2dense
(
rval
[
i
])
return
rval
return
rval
class
_testCase_dot
(
unittest
.
TestCase
):
def
setUp
(
self
):
core
.
build_eval_mode
()
numpy
.
random
.
seed
(
44
)
def
tearDown
(
self
):
core
.
pop_mode
()
def
test_basic0
(
self
):
for
mtype
in
[
sparse
.
csc_matrix
,
sparse
.
csr_matrix
]:
x
=
SparseR
(
mtype
(
sparse
.
speye
(
5
,
3
)))
y
=
core
.
wrap
(
numpy
.
random
.
rand
(
3
,
2
))
z
=
dot
(
x
,
y
)
self
.
failUnless
(
z
.
data
.
shape
==
(
5
,
2
))
self
.
failUnless
(
type
(
z
.
data
)
is
mtype
)
def
test_basic1
(
self
):
"""dot: sparse left"""
a
=
numpy
.
asarray
([[
1
,
0
,
3
,
0
,
5
],
[
0
,
0
,
-
2
,
0
,
0
]],
dtype
=
'float64'
)
b
=
numpy
.
random
.
rand
(
5
,
3
)
for
mtype
in
[
sparse
.
csr_matrix
,
sparse
.
csc_matrix
,
sparse
.
dok_matrix
,
sparse
.
lil_matrix
]:
#, sparse.coo_matrix]:
#print type(a), mtype
m
=
mtype
(
a
)
ab
=
m
.
dot
(
b
)
try
:
z
=
dot
(
SparseR
(
m
),
core
.
ResultBase
(
data
=
b
))
self
.
failUnless
(
z
.
data
.
shape
==
ab
.
shape
)
self
.
failUnless
(
type
(
z
.
data
)
==
type
(
ab
))
except
Exception
,
e
:
print
'cccc'
,
mtype
,
e
,
str
(
e
)
raise
def
test_basic2
(
self
):
"""dot: sparse right"""
a
=
numpy
.
random
.
rand
(
2
,
5
)
b
=
numpy
.
asarray
([[
1
,
0
,
3
,
0
,
5
],
[
0
,
0
,
-
2
,
0
,
0
]],
dtype
=
'float64'
)
.
transpose
()
for
mtype
in
[
sparse
.
csr_matrix
,
sparse
.
csc_matrix
,
sparse
.
dok_matrix
,
sparse
.
lil_matrix
]:
#, sparse.coo_matrix]:
m
=
mtype
(
b
)
ab
=
m
.
transpose
()
.
dot
(
a
.
transpose
())
.
transpose
()
z
=
dot
(
core
.
ResultBase
(
data
=
a
),
SparseR
(
mtype
(
b
)))
self
.
failUnless
(
z
.
data
.
shape
==
ab
.
shape
)
self
.
failUnless
(
type
(
z
.
data
)
==
type
(
ab
))
def
test_graph_bprop0
(
self
):
x
=
core
.
wrap
(
numpy
.
random
.
rand
(
10
,
2
))
w
=
SparseR
(
sparse
.
csr_matrix
(
numpy
.
asarray
([[
1
,
0
,
3
,
0
,
5
],
[
0
,
0
,
-
2
,
0
,
0
]],
dtype
=
'float64'
)))
for
epoch
in
xrange
(
50
):
xw
=
sparse2dense
(
dot
(
x
,
w
))
y
=
sparse2dense
(
dot
(
xw
,
transpose
(
w
)))
loss
=
core
.
sum
(
core
.
sqr
(
x
-
y
))
gy
=
y
-
x
g
=
grad
.
Grad
({
y
:
gy
})
g
.
bprop
()
lr
=
0.002
g
(
w
)
.
data
[
1
,
0
]
=
0
g
(
w
)
.
data
[
1
,
4
]
=
0
w
.
data
=
-
lr
*
g
(
w
)
.
data
+
w
.
data
self
.
failUnless
(
'3.08560636025'
==
str
(
loss
.
data
))
def
test_graph_bprop1
(
self
):
x
=
core
.
wrap
(
numpy
.
random
.
rand
(
10
,
2
))
w
=
SparseR
(
sparse
.
csr_matrix
(
numpy
.
asarray
([[
1
,
0
,
3
,
0
,
5
],
[
0
,
0
,
-
2
,
0
,
0
]],
dtype
=
'float64'
)))
for
epoch
in
xrange
(
50
):
xw
=
sparse2dense
(
dot
(
x
,
w
))
y
=
sparse2dense
(
dot
(
xw
,
transpose
(
w
)))
loss
=
core
.
sum
(
core
.
sqr
(
x
-
y
))
g
=
grad
.
grad
(
loss
)
lr
=
0.001
g
(
w
)
.
data
[
1
,
0
]
=
0
g
(
w
)
.
data
[
1
,
4
]
=
0
w
.
data
=
-
lr
*
g
(
w
)
.
data
+
w
.
data
self
.
failUnless
(
'3.08560636025'
==
str
(
loss
.
data
))
if
__name__
==
'__main__'
:
unittest
.
main
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论