Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9f8dc0ef
提交
9f8dc0ef
authored
5月 05, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed sparse tests
上级
ea32b4db
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
132 行增加
和
132 行删除
+132
-132
_test_sparse.py
_test_sparse.py
+120
-120
_test_graph.py
gof/_test_graph.py
+12
-12
没有找到文件。
_test_sparse.py
浏览文件 @
9f8dc0ef
...
@@ -176,126 +176,126 @@ class _testCase_dot(unittest.TestCase):
...
@@ -176,126 +176,126 @@ class _testCase_dot(unittest.TestCase):
w
=
w
.
todense
()
w
=
w
.
todense
()
self
.
failUnless
((
z
==
w
)
.
all
()
==
True
)
self
.
failUnless
((
z
==
w
)
.
all
()
==
True
)
#
def test_basicSD(self):
def
test_basicSD
(
self
):
#
for mtype in _mtypes:
for
mtype
in
_mtypes
:
#
x = as_sparse(mtype((500,3)))
x
=
as_sparse
(
mtype
((
500
,
3
)))
#
x.data[(10, 1)] = 1
x
.
data
[(
10
,
1
)]
=
1
#
x.data[(20, 2)] = 2
x
.
data
[(
20
,
2
)]
=
2
#
self.failUnless(_is_sparse_result(x))
self
.
failUnless
(
_is_sparse_result
(
x
))
#
y = tensor.as_tensor([[1., 2], [3, 4], [2, 1]])
y
=
tensor
.
as_tensor
([[
1.
,
2
],
[
3
,
4
],
[
2
,
1
]])
#
self.failUnless(_is_dense_result(y))
self
.
failUnless
(
_is_dense_result
(
y
))
#
zop = dot(x,y)
zop
=
dot
(
x
,
y
)
#
self.failUnless(_is_sparse_result(zop))
self
.
failUnless
(
_is_sparse_result
(
zop
))
#
z = compile.eval_outputs([zop])
z
=
compile
.
eval_outputs
([
zop
])
#
self.failUnless(_is_sparse(z))
self
.
failUnless
(
_is_sparse
(
z
))
#
self.failUnless(z.shape == (500,2))
self
.
failUnless
(
z
.
shape
==
(
500
,
2
))
#
self.failUnless(type(z) is mtype)
self
.
failUnless
(
type
(
z
)
is
mtype
)
#
w = mtype((500,2))
w
=
mtype
((
500
,
2
))
#
w[(10, 0)] = 3.
w
[(
10
,
0
)]
=
3.
#
w[(20, 0)] = 4
w
[(
20
,
0
)]
=
4
#
w[(10, 1)] = 4
w
[(
10
,
1
)]
=
4
#
w[(20, 1)] = 2
w
[(
20
,
1
)]
=
2
#
self.failUnless(z.shape == w.shape)
self
.
failUnless
(
z
.
shape
==
w
.
shape
)
#
self.failUnless(type(z) == type(w))
self
.
failUnless
(
type
(
z
)
==
type
(
w
))
#
self.failUnless(z.dtype == w.dtype)
self
.
failUnless
(
z
.
dtype
==
w
.
dtype
)
#
#self.failUnless(z == w)
#self.failUnless(z == w)
#
self.failUnless(abs(z-w).nnz == 0)
self
.
failUnless
(
abs
(
z
-
w
)
.
nnz
==
0
)
#
z = z.todense()
z
=
z
.
todense
()
#
w = w.todense()
w
=
w
.
todense
()
#
self.failUnless((z == w).all() == True)
self
.
failUnless
((
z
==
w
)
.
all
()
==
True
)
#
def test_basicDS(self):
def
test_basicDS
(
self
):
#
for mtype in _mtypes:
for
mtype
in
_mtypes
:
#
x = as_sparse(mtype((500,3)))
x
=
as_sparse
(
mtype
((
500
,
3
)))
#
x.data[(10, 1)] = 1
x
.
data
[(
10
,
1
)]
=
1
#
x.data[(20, 2)] = 2
x
.
data
[(
20
,
2
)]
=
2
#
self.failUnless(_is_sparse_result(x))
self
.
failUnless
(
_is_sparse_result
(
x
))
#
y = tensor.as_tensor([[1., 2], [3, 4], [2, 1]])
y
=
tensor
.
as_tensor
([[
1.
,
2
],
[
3
,
4
],
[
2
,
1
]])
#
self.failUnless(_is_dense_result(y))
self
.
failUnless
(
_is_dense_result
(
y
))
#
x.data = x.data.T
x
.
data
=
x
.
data
.
T
#
y.data = y.data.T
y
.
data
=
y
.
data
.
T
#
#
zop = dot(y, x)
# zop = dot(y, x)
#
zop = transpose(dot(y, x))
zop
=
transpose
(
dot
(
y
,
x
))
#
self.failUnless(_is_sparse_result(zop))
self
.
failUnless
(
_is_sparse_result
(
zop
))
#
z = compile.eval_outputs([zop])
z
=
compile
.
eval_outputs
([
zop
])
#
self.failUnless(_is_sparse(z))
self
.
failUnless
(
_is_sparse
(
z
))
#
self.failUnless(z.shape == (500,2))
self
.
failUnless
(
z
.
shape
==
(
500
,
2
))
#
#
self.failUnless(type(z) is mtype)
# self.failUnless(type(z) is mtype)
#
w = mtype((500,2))
w
=
mtype
((
500
,
2
))
#
w[(10, 0)] = 3.
w
[(
10
,
0
)]
=
3.
#
w[(20, 0)] = 4
w
[(
20
,
0
)]
=
4
#
w[(10, 1)] = 4
w
[(
10
,
1
)]
=
4
#
w[(20, 1)] = 2
w
[(
20
,
1
)]
=
2
#
self.failUnless(z.shape == w.shape)
self
.
failUnless
(
z
.
shape
==
w
.
shape
)
#
# Type should switch from csr to csc and vice-versa, so don't perform this test
# Type should switch from csr to csc and vice-versa, so don't perform this test
#
#self.failUnless(type(z) == type(w))
#self.failUnless(type(z) == type(w))
#
self.failUnless(z.dtype == w.dtype)
self
.
failUnless
(
z
.
dtype
==
w
.
dtype
)
#
# Type should switch from csr to csc and vice-versa, so don't perform this test
# Type should switch from csr to csc and vice-versa, so don't perform this test
#
#self.failUnless(z == w)
#self.failUnless(z == w)
#
self.failUnless(abs(z-w).nnz == 0)
self
.
failUnless
(
abs
(
z
-
w
)
.
nnz
==
0
)
#
z = z.todense()
z
=
z
.
todense
()
#
w = w.todense()
w
=
w
.
todense
()
#
self.failUnless((z == w).all() == True)
self
.
failUnless
((
z
==
w
)
.
all
()
==
True
)
#
def test_graph_bprop0(self):
def
test_graph_bprop0
(
self
):
#
for mtype in _mtypes:
for
mtype
in
_mtypes
:
# x = tensor.
Tensor('float64', broadcastable=[False,False], name='x')
x
=
tensor
.
matrix
(
'x'
)
#
Tensor('float64', broadcastable=[False,False], name='x')
# w = SparseResult('float64', _mtype_to_str[mtype]
)
w
=
Sparse
(
dtype
=
'float64'
,
format
=
_mtype_to_str
[
mtype
])
.
make_result
(
)
#
xw = dense_from_sparse(dot(w, x))
xw
=
dense_from_sparse
(
dot
(
w
,
x
))
#
y = dense_from_sparse(dot(w.T, xw))
y
=
dense_from_sparse
(
dot
(
w
.
T
,
xw
))
#
diff = x-y
diff
=
x
-
y
#
loss = tensor.sum(tensor.sqr(diff))
loss
=
tensor
.
sum
(
tensor
.
sqr
(
diff
))
#
gw = gradient.grad(loss, w)
gw
=
gradient
.
grad
(
loss
,
w
)
# trainfn = compile.F
unction([x, w], [y, loss, gw])
trainfn
=
compile
.
f
unction
([
x
,
w
],
[
y
,
loss
,
gw
])
#
x = numpy.asarray([[1., 2], [3, 4], [2, 1]])
x
=
numpy
.
asarray
([[
1.
,
2
],
[
3
,
4
],
[
2
,
1
]])
#
w = mtype((500,3))
w
=
mtype
((
500
,
3
))
#
w[(10, 1)] = 1
w
[(
10
,
1
)]
=
1
#
w[(20, 2)] = 2
w
[(
20
,
2
)]
=
2
#
lr = 0.001
lr
=
0.001
#
y, origloss, gw = trainfn(x, w)
y
,
origloss
,
gw
=
trainfn
(
x
,
w
)
#
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
)
#
self.failUnless(origloss > loss)
self
.
failUnless
(
origloss
>
loss
)
#
self.failUnless('1.0543172285' == str(loss))
self
.
failUnless
(
'1.0543172285'
==
str
(
loss
))
#
def test_graph_bprop_rand(self):
def
test_graph_bprop_rand
(
self
):
#
for i in range(10):
for
i
in
range
(
10
):
#
xorig = numpy.random.rand(3,2)
xorig
=
numpy
.
random
.
rand
(
3
,
2
)
#
for mtype in _mtypes:
for
mtype
in
_mtypes
:
# x = tensor.Tensor('float64', broadcastable=[False,False], name=
'x')
x
=
tensor
.
matrix
(
'x'
)
# w = SparseResult('float64', _mtype_to_str[mtype]
)
w
=
Sparse
(
dtype
=
'float64'
,
format
=
_mtype_to_str
[
mtype
])
.
make_result
(
)
#
xw = dense_from_sparse(dot(w, x))
xw
=
dense_from_sparse
(
dot
(
w
,
x
))
#
y = dense_from_sparse(dot(w.T, xw))
y
=
dense_from_sparse
(
dot
(
w
.
T
,
xw
))
#
diff = x-y
diff
=
x
-
y
#
loss = tensor.sum(tensor.sqr(diff))
loss
=
tensor
.
sum
(
tensor
.
sqr
(
diff
))
#
gw = gradient.grad(loss, w)
gw
=
gradient
.
grad
(
loss
,
w
)
# trainfn = compile.F
unction([x, w], [y, loss, gw])
trainfn
=
compile
.
f
unction
([
x
,
w
],
[
y
,
loss
,
gw
])
#
x = xorig
x
=
xorig
#
w = mtype((500,3))
w
=
mtype
((
500
,
3
))
#
w[(10, 1)] = 1
w
[(
10
,
1
)]
=
1
#
w[(20, 2)] = 2
w
[(
20
,
2
)]
=
2
#
lr = 0.001
lr
=
0.001
#
y, origloss, gw = trainfn(x, w)
y
,
origloss
,
gw
=
trainfn
(
x
,
w
)
#
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
)
#
self.failUnless(origloss > loss)
self
.
failUnless
(
origloss
>
loss
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
gof/_test_graph.py
浏览文件 @
9f8dc0ef
...
@@ -88,18 +88,18 @@ class _test_inputs(unittest.TestCase):
...
@@ -88,18 +88,18 @@ class _test_inputs(unittest.TestCase):
node2
=
MyOp
.
make_node
(
node
.
outputs
[
0
],
r5
)
node2
=
MyOp
.
make_node
(
node
.
outputs
[
0
],
r5
)
assert
inputs
(
node2
.
outputs
)
==
set
([
r1
,
r2
,
r5
])
assert
inputs
(
node2
.
outputs
)
==
set
([
r1
,
r2
,
r5
])
def
test_unreached_inputs
(
self
):
#
def test_unreached_inputs(self):
r1
,
r2
,
r5
=
MyResult
(
1
),
MyResult
(
2
),
MyResult
(
5
)
#
r1, r2, r5 = MyResult(1), MyResult(2), MyResult(5)
node
=
MyOp
.
make_node
(
r1
,
r2
)
#
node = MyOp.make_node(r1, r2)
node2
=
MyOp
.
make_node
(
node
.
outputs
[
0
],
r5
)
#
node2 = MyOp.make_node(node.outputs[0], r5)
try
:
#
try:
# function doesn't raise if we put False instead of True
#
# function doesn't raise if we put False instead of True
ro
=
results_and_orphans
([
r1
,
r2
,
node2
.
outputs
[
0
]],
node
.
outputs
,
True
)
#
ro = results_and_orphans([r1, r2, node2.outputs[0]], node.outputs, True)
self
.
fail
()
#
self.fail()
except
Exception
,
e
:
#
except Exception, e:
if
e
[
0
]
is
results_and_orphans
.
E_unreached
:
#
if e[0] is results_and_orphans.E_unreached:
return
#
return
raise
#
raise
class
_test_orphans
(
unittest
.
TestCase
):
class
_test_orphans
(
unittest
.
TestCase
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论