Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9f85a888
提交
9f85a888
authored
1月 21, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
差异文件
merge
上级
599630e7
23ef03cb
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
63 行增加
和
7 行删除
+63
-7
basic.py
theano/sparse/basic.py
+0
-0
test_basic.py
theano/sparse/tests/test_basic.py
+59
-3
blas.py
theano/tensor/blas.py
+3
-3
opt.py
theano/tensor/opt.py
+1
-1
没有找到文件。
theano/sparse/basic.py
浏览文件 @
9f85a888
差异被折叠。
点击展开。
theano/sparse/tests/test_basic.py
浏览文件 @
9f85a888
from
theano.sparse
import
*
from
theano.sparse
import
*
import
random
import
unittest
import
unittest
import
theano
from
theano
import
compile
from
theano
import
compile
from
theano
import
gradient
from
theano
import
gradient
from
theano
import
gof
from
theano.sparse.basic
import
_is_dense
,
_is_sparse
,
_is_dense_result
,
_is_sparse_result
from
theano.sparse.basic
import
_is_dense
,
_is_sparse
,
_is_dense_result
,
_is_sparse_result
from
theano.sparse.basic
import
_mtypes
,
_mtype_to_str
from
theano.sparse.basic
import
_mtypes
,
_mtype_to_str
import
random
from
theano
import
gof
def
eval_outputs
(
outputs
):
def
eval_outputs
(
outputs
):
return
compile
.
function
([],
outputs
)()[
0
]
return
compile
.
function
([],
outputs
)()[
0
]
...
@@ -228,7 +230,7 @@ class test_true_dot(unittest.TestCase):
...
@@ -228,7 +230,7 @@ class test_true_dot(unittest.TestCase):
x
.
data
=
x
.
data
.
T
x
.
data
=
x
.
data
.
T
y
.
data
=
y
.
data
.
T
y
.
data
=
y
.
data
.
T
#
zop = true_dot(y, x)
zop
=
true_dot
(
y
,
x
)
zop
=
transpose
(
true_dot
(
y
,
x
))
zop
=
transpose
(
true_dot
(
y
,
x
))
self
.
failUnless
(
_is_sparse_result
(
zop
))
self
.
failUnless
(
_is_sparse_result
(
zop
))
z
=
eval_outputs
([
zop
])
z
=
eval_outputs
([
zop
])
...
@@ -304,5 +306,59 @@ class test_true_dot(unittest.TestCase):
...
@@ -304,5 +306,59 @@ class test_true_dot(unittest.TestCase):
self
.
failUnless
(
origloss
>
loss
)
self
.
failUnless
(
origloss
>
loss
)
import
scipy.sparse
as
sp
class
test_structureddot
(
unittest
.
TestCase
):
def
test_structuredot
(
self
):
#bsize = 5
#spmat = sp.csc_matrix((8,15))
#spmat[1,2] = 3
#spmat[4,7] = 6
#spmat[2,7] = 72
#spmat[1,9] = 2
#spmat[7,12] = 1
#spmat[4,2] = 7
bsize
=
2
spmat
=
sp
.
csc_matrix
((
5
,
5
))
spmat
[
1
,
2
]
=
1
spmat
[
0
,
1
]
=
2
spmat
[
0
,
2
]
=
3
kerns
=
tensor
.
dvector
()
images
=
tensor
.
dmatrix
()
def
buildgraphCSC
(
kerns
,
images
):
csc
=
CSC
(
kerns
,
spmat
.
indices
[:
spmat
.
size
],
spmat
.
indptr
,
spmat
.
shape
)
return
structured_dot
(
csc
,
images
.
T
)
out
=
buildgraphCSC
(
kerns
,
images
)
for
mode
in
'FAST_COMPILE'
,
'FAST_RUN'
:
f
=
theano
.
function
([
kerns
,
images
],
out
,
mode
=
mode
)
kernvals
=
spmat
.
data
[:
spmat
.
size
]
imvals
=
1.0
*
numpy
.
arange
(
bsize
*
spmat
.
shape
[
1
])
.
reshape
(
bsize
,
spmat
.
shape
[
1
])
outvals
=
f
(
kernvals
,
imvals
)
assert
numpy
.
all
(
outvals
==
spmat
.
dot
(
imvals
.
T
)
.
todense
())
tensor
.
verify_grad
(
None
,
buildgraphCSC
,
[
kernvals
,
imvals
],
mode
=
mode
)
spmat
=
spmat
.
tocsr
()
def
buildgraphCSR
(
kerns
,
images
):
csr
=
CSR
(
kerns
,
spmat
.
indices
[:
spmat
.
size
],
spmat
.
indptr
,
spmat
.
shape
)
return
structured_dot
(
csr
,
images
.
T
)
out
=
buildgraphCSR
(
kerns
,
images
)
for
mode
in
'FAST_COMPILE'
,
'FAST_RUN'
:
f
=
theano
.
function
([
kerns
,
images
],
out
,
mode
=
mode
)
kernvals
=
spmat
.
data
[:
spmat
.
size
]
imvals
=
1.0
*
numpy
.
arange
(
bsize
*
spmat
.
shape
[
1
])
.
reshape
(
bsize
,
spmat
.
shape
[
1
])
outvals
=
f
(
kernvals
,
imvals
)
assert
numpy
.
all
(
outvals
==
spmat
.
dot
(
imvals
.
T
)
.
todense
())
tensor
.
verify_grad
(
None
,
buildgraphCSR
,
[
kernvals
,
imvals
],
mode
=
mode
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
theano/tensor/blas.py
浏览文件 @
9f85a888
...
@@ -543,11 +543,11 @@ class GemmLocalOptimizer(LocalOptimizer):
...
@@ -543,11 +543,11 @@ class GemmLocalOptimizer(LocalOptimizer):
# TODO: This could be an equilibriumOptmizer, but I don't know how to combine an OpKeyOptimizer and
# TODO: This could be an equilibriumOptmizer, but I don't know how to combine an OpKeyOptimizer and
# an EquilibriumOptimizer.
# an EquilibriumOptimizer.
compile
.
optdb
.
register
(
'inplace_gemm_0'
,
OpKeyOptimizer
(
GemmLocalOptimizer
(),
compile
.
optdb
.
register
(
'inplace_gemm_0'
,
OpKeyOptimizer
(
GemmLocalOptimizer
(),
failure_callback
=
GemmLocalOptimizer
.
failure_callback
),
70.00
,
'fast_run'
,
'inplace'
)
failure_callback
=
GemmLocalOptimizer
.
failure_callback
),
70.00
,
'fast_run'
,
'inplace'
,
'gemm'
)
compile
.
optdb
.
register
(
'inplace_gemm_1'
,
OpKeyOptimizer
(
GemmLocalOptimizer
(),
compile
.
optdb
.
register
(
'inplace_gemm_1'
,
OpKeyOptimizer
(
GemmLocalOptimizer
(),
failure_callback
=
GemmLocalOptimizer
.
failure_callback
),
70.01
,
'fast_run'
,
'inplace'
)
failure_callback
=
GemmLocalOptimizer
.
failure_callback
),
70.01
,
'fast_run'
,
'inplace'
,
'gemm'
)
compile
.
optdb
.
register
(
'inplace_gemm_2'
,
OpKeyOptimizer
(
GemmLocalOptimizer
(),
compile
.
optdb
.
register
(
'inplace_gemm_2'
,
OpKeyOptimizer
(
GemmLocalOptimizer
(),
failure_callback
=
GemmLocalOptimizer
.
failure_callback
),
70.02
,
'fast_run'
,
'inplace'
)
failure_callback
=
GemmLocalOptimizer
.
failure_callback
),
70.02
,
'fast_run'
,
'inplace'
,
'gemm'
)
class
Dot22
(
GemmRelated
):
class
Dot22
(
GemmRelated
):
"""Compute a matrix-matrix product.
"""Compute a matrix-matrix product.
...
...
theano/tensor/opt.py
浏览文件 @
9f85a888
...
@@ -588,6 +588,7 @@ def mul_calculate(num, denum, aslist = False):
...
@@ -588,6 +588,7 @@ def mul_calculate(num, denum, aslist = False):
return
v
return
v
local_mul_canonizer
=
Canonizer
(
T
.
mul
,
T
.
div
,
T
.
inv
,
mul_calculate
,
False
)
local_mul_canonizer
=
Canonizer
(
T
.
mul
,
T
.
div
,
T
.
inv
,
mul_calculate
,
False
)
register_canonicalize
(
local_mul_canonizer
,
name
=
'local_mul_canonizer'
)
@gof.local_optimizer
([
T
.
neg
])
@gof.local_optimizer
([
T
.
neg
])
def
local_neg_to_mul
(
node
):
def
local_neg_to_mul
(
node
):
...
@@ -693,7 +694,6 @@ def local_mul_specialize(node):
...
@@ -693,7 +694,6 @@ def local_mul_specialize(node):
return
False
return
False
register_specialize
(
local_mul_specialize
)
register_specialize
(
local_mul_specialize
)
register_canonicalize
(
local_mul_canonizer
,
name
=
'local_mul_canonizer'
)
# neg_to_mul = out2in(gof.LocalOptGroup(local_neg_to_mul))
# neg_to_mul = out2in(gof.LocalOptGroup(local_neg_to_mul))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论