Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5b604a49
提交
5b604a49
authored
7月 05, 2015
作者:
AdeB
提交者:
Xavier Bouthillier
8月 21, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix a few pep8 errors
上级
1e0da364
隐藏空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
48 行增加
和
58 行删除
+48
-58
__init__.py
theano/sandbox/__init__.py
+1
-0
blocksparse.py
theano/sandbox/blocksparse.py
+5
-5
nnet.py
theano/sandbox/cuda/nnet.py
+4
-2
test_blocksparse.py
theano/sandbox/cuda/tests/test_blocksparse.py
+2
-2
test_opt.py
theano/sandbox/cuda/tests/test_opt.py
+3
-6
opt.py
theano/sandbox/opt.py
+1
-1
test_blocksparse.py
theano/sandbox/tests/test_blocksparse.py
+17
-30
test_multinomial.py
theano/sandbox/tests/test_multinomial.py
+1
-1
test_opt.py
theano/sandbox/tests/test_opt.py
+6
-4
test_scan.py
theano/sandbox/tests/test_scan.py
+1
-1
test_theano_object.py
theano/sandbox/tests/test_theano_object.py
+1
-1
test_flake8.py
theano/tests/test_flake8.py
+6
-5
没有找到文件。
theano/sandbox/__init__.py
浏览文件 @
5b604a49
from
.
import
opt
theano/sandbox/blocksparse.py
浏览文件 @
5b604a49
...
...
@@ -16,6 +16,7 @@ class SparseBlockGemv(Op):
for i in range(h.shape[1]):
o[b, j, :] += numpy.dot(h[b, i], W[iIdx[b, i], oIdx[b, j]])
where b, h, W, o iIdx, oIdx are defined in the docstring of make_node.
.. image:: ../../images/blocksparse.png
"""
...
...
@@ -29,7 +30,7 @@ class SparseBlockGemv(Op):
def
make_node
(
self
,
o
,
W
,
h
,
inputIdx
,
outputIdx
):
"""
Compute the dot product of the specified pieces of vectors
and matrices.
and matrices.
Parameters
----------
...
...
@@ -76,7 +77,7 @@ class SparseBlockGemv(Op):
assert
outputIdx
.
type
.
dtype
in
discrete_dtypes
output
=
o
.
type
.
__class__
(
dtype
=
o
.
type
.
dtype
,
broadcastable
=
(
False
,)
*
o
.
ndim
)()
broadcastable
=
(
False
,)
*
o
.
ndim
)()
return
Apply
(
self
,
[
o
,
W
,
h
,
inputIdx
,
outputIdx
],
[
output
])
...
...
@@ -100,7 +101,6 @@ class SparseBlockGemv(Op):
"grad of outputIdx makes no sense"
)]
class
SparseBlockOuter
(
Op
):
"""
This computes the outer product of two sets of pieces of vectors
...
...
@@ -121,7 +121,7 @@ class SparseBlockOuter(Op):
"""
Compute the dot product of the specified pieces of vectors
and matrices.
and matrices.
Parameters
----------
...
...
@@ -154,7 +154,7 @@ class SparseBlockOuter(Op):
alpha
=
one
output
=
o
.
type
.
__class__
(
dtype
=
o
.
type
.
dtype
,
broadcastable
=
(
False
,)
*
o
.
ndim
)()
broadcastable
=
(
False
,)
*
o
.
ndim
)()
return
Apply
(
self
,
[
o
,
x
,
y
,
xIdx
,
yIdx
,
alpha
],
[
output
])
...
...
theano/sandbox/cuda/nnet.py
浏览文件 @
5b604a49
...
...
@@ -220,7 +220,8 @@ class GpuCrossentropySoftmaxArgmax1HotWithBias(GpuOp):
# return ()
return
(
4
,)
gpu_crossentropy_softmax_argmax_1hot_with_bias
=
GpuCrossentropySoftmaxArgmax1HotWithBias
()
gpu_crossentropy_softmax_argmax_1hot_with_bias
=
\
GpuCrossentropySoftmaxArgmax1HotWithBias
()
class
GpuCrossentropySoftmax1HotWithBiasDx
(
GpuOp
):
...
...
@@ -391,7 +392,8 @@ class GpuCrossentropySoftmax1HotWithBiasDx(GpuOp):
}
"""
%
locals
()
gpu_crossentropy_softmax_1hot_with_bias_dx
=
GpuCrossentropySoftmax1HotWithBiasDx
()
gpu_crossentropy_softmax_1hot_with_bias_dx
=
\
GpuCrossentropySoftmax1HotWithBiasDx
()
class
GpuSoftmax
(
GpuOp
):
...
...
theano/sandbox/cuda/tests/test_blocksparse.py
浏览文件 @
5b604a49
...
...
@@ -7,13 +7,13 @@ import theano.tests.unittest_tools as utt
import
theano.sandbox.tests.test_blocksparse
import
theano.sandbox.cuda
as
cuda_ndarray
if
not
cuda_ndarray
.
cuda_available
:
raise
SkipTest
(
'Optional package cuda disabled'
)
from
theano.sandbox.cuda.blocksparse
import
(
GpuSparseBlockOuter
,
gpu_sparse_block_gemv
,
gpu_sparse_block_outer
)
from
theano.sandbox.cuda.var
import
float32_shared_constructor
if
not
cuda_ndarray
.
cuda_available
:
raise
SkipTest
(
'Optional package cuda disabled'
)
if
theano
.
config
.
mode
==
'FAST_COMPILE'
:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
including
(
'gpu'
)
...
...
theano/sandbox/cuda/tests/test_opt.py
浏览文件 @
5b604a49
...
...
@@ -766,11 +766,10 @@ def test_blocksparse_gpu_outer_opt():
o
=
sparse_block_dot
(
W
,
h
,
iIdx
,
b
,
oIdx
)
theano
.
printing
.
debugprint
(
tensor
.
grad
(
o
.
sum
(),
wrt
=
W
))
f
=
theano
.
function
([
W
,
h
,
iIdx
,
b
,
oIdx
],
[
o
,
tensor
.
grad
(
o
.
sum
(),
wrt
=
W
)],
f
=
theano
.
function
([
W
,
h
,
iIdx
,
b
,
oIdx
],
[
o
,
tensor
.
grad
(
o
.
sum
(),
wrt
=
W
)],
mode
=
mode_with_gpu
)
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
-
2
]
.
op
,
GpuSparseBlockOuter
)
...
...
@@ -785,10 +784,8 @@ class test_diag(theano.tensor.tests.test_nlinalg.test_diag):
self
)
.
__init__
(
name
)
if
__name__
==
'__main__'
:
test_gpualloc
()
test_opt_gpujoin_onlyajoin
()
test_opt_gpujoin_joinvectors_elemwise_then_minusone
()
test_opt_gpujoin_joinvectors_negativeaxes
()
theano/sandbox/opt.py
浏览文件 @
5b604a49
...
...
@@ -126,7 +126,7 @@ def register_meta_opt(op_class, db_name, position, *args):
idx
=
bisect
.
bisect_left
((
positions
,
local_meta_opt
),
op_class
.
registered_opts
)
op_class
.
registered_opts
.
insert
(
idx
,
(
positions
,
local_meta_opt
.
__name__
))
(
positions
,
local_meta_opt
.
__name__
))
return
local_meta_opt
...
...
theano/sandbox/tests/test_blocksparse.py
浏览文件 @
5b604a49
...
...
@@ -2,7 +2,6 @@
Tests for block sparse dot
"""
import
unittest
import
time
import
numpy
from
numpy.random
import
randn
...
...
@@ -11,8 +10,8 @@ import theano
from
theano
import
tensor
import
theano.tests.unittest_tools
as
utt
from
theano.sandbox.blocksparse
import
sparse_block_dot
,
cpu_sparse_block_gemv
,
\
cpu_sparse_block_outer
from
theano.sandbox.blocksparse
import
sparse_block_dot
,
\
cpu_sparse_block_
gemv
,
cpu_sparse_block_
outer
class
BlockSparse_Gemv_and_Outer
(
unittest
.
TestCase
):
...
...
@@ -94,6 +93,9 @@ class BlockSparse_Gemv_and_Outer(unittest.TestCase):
@staticmethod
def
gemv_numpy2
(
o
,
W
,
h
,
iIdx
,
oIdx
):
"""
Other implementation
"""
from
numpy
import
ix_
for
b
in
range
(
o
.
shape
[
0
]):
w
=
W
[
ix_
(
iIdx
[
b
],
oIdx
[
b
])]
.
swapaxes
(
1
,
2
)
...
...
@@ -103,9 +105,14 @@ class BlockSparse_Gemv_and_Outer(unittest.TestCase):
@staticmethod
def
gemv_numpy3
(
o
,
W
,
h
,
iIdx
,
oIdx
):
"""
Other implementation
"""
from
numpy
import
ix_
for
b
in
range
(
o
.
shape
[
0
]):
w
=
W
[
ix_
(
iIdx
[
b
],
oIdx
[
b
])]
# The next three lines do the same operation. The last one is the
# fastest
# o[b] += (h[b][:, None, :, None] * w).sum(axis=(0, 2))
# o[b] += numpy.tensordot(h[b], w, [(0,1),(0,2)])
o
[
b
]
+=
numpy
.
einsum
(
'ik,ijkl'
,
h
[
b
],
w
)
...
...
@@ -135,27 +142,6 @@ class BlockSparse_Gemv_and_Outer(unittest.TestCase):
return
weight
,
input
,
inputIndice
,
bias
,
outputIndice
@staticmethod
def
compare
():
W_val
,
h_val
,
iIdx_val
,
b_val
,
oIdx_val
=
\
BlockSparse_Gemv_and_Outer
.
gemv_data2
()
start
=
time
.
clock
()
ref_out
=
BlockSparse_Gemv_and_Outer
.
gemv_numpy
(
b_val
.
take
(
oIdx_val
,
axis
=
0
),
W_val
,
h_val
,
iIdx_val
,
oIdx_val
)
v1
=
time
.
clock
()
ref_out_2
=
BlockSparse_Gemv_and_Outer
.
gemv_numpy2
(
b_val
.
take
(
oIdx_val
,
axis
=
0
),
W_val
,
h_val
,
iIdx_val
,
oIdx_val
)
v2
=
time
.
clock
()
ref_out_3
=
BlockSparse_Gemv_and_Outer
.
gemv_numpy3
(
b_val
.
take
(
oIdx_val
,
axis
=
0
),
W_val
,
h_val
,
iIdx_val
,
oIdx_val
)
v3
=
time
.
clock
()
print
v1
-
start
print
v2
-
v1
print
v3
-
v2
# utt.assert_allclose(ref_out, ref_out_2)
@staticmethod
def
outer_numpy
(
o
,
x
,
y
,
xIdx
,
yIdx
):
for
b
in
range
(
x
.
shape
[
0
]):
...
...
@@ -185,7 +171,7 @@ class BlockSparse_Gemv_and_Outer(unittest.TestCase):
th_out
=
f
(
W_val
,
h_val
,
iIdx_val
,
b_val
,
oIdx_val
)
ref_out
=
BlockSparse_Gemv_and_Outer
.
gemv_numpy
(
b_val
.
take
(
oIdx_val
,
axis
=
0
),
W_val
,
h_val
,
iIdx_val
,
oIdx_val
)
b_val
.
take
(
oIdx_val
,
axis
=
0
),
W_val
,
h_val
,
iIdx_val
,
oIdx_val
)
utt
.
assert_allclose
(
ref_out
,
th_out
)
...
...
@@ -208,7 +194,7 @@ class BlockSparse_Gemv_and_Outer(unittest.TestCase):
th_out
=
f
(
W_val
,
h_val
,
iIdx_val
,
b_val
,
oIdx_val
)
ref_out
=
BlockSparse_Gemv_and_Outer
.
gemv_numpy
(
b_val
.
take
(
oIdx_val
,
axis
=
0
),
W_val
,
h_val
,
iIdx_val
,
oIdx_val
)
b_val
.
take
(
oIdx_val
,
axis
=
0
),
W_val
,
h_val
,
iIdx_val
,
oIdx_val
)
utt
.
assert_allclose
(
ref_out
,
th_out
)
...
...
@@ -224,9 +210,10 @@ class BlockSparse_Gemv_and_Outer(unittest.TestCase):
oIdx
=
tensor
.
imatrix
()
o
=
self
.
gemv_op
(
b
.
take
(
oIdx
,
axis
=
0
),
tensor
.
DimShuffle
((
False
,
False
,
False
,
False
),
(
0
,
1
,
3
,
2
))(
tensor
.
as_tensor_variable
(
W
)),
h
,
iIdx
,
oIdx
)
tensor
.
DimShuffle
((
False
,
False
,
False
,
False
),
(
0
,
1
,
3
,
2
))
(
tensor
.
as_tensor_variable
(
W
)),
h
,
iIdx
,
oIdx
)
f
=
theano
.
function
([
W
,
h
,
iIdx
,
b
,
oIdx
],
o
,
mode
=
self
.
mode
)
...
...
@@ -236,7 +223,7 @@ class BlockSparse_Gemv_and_Outer(unittest.TestCase):
th_out
=
f
(
numpy
.
swapaxes
(
W_val
,
2
,
3
),
h_val
,
iIdx_val
,
b_val
,
oIdx_val
)
ref_out
=
BlockSparse_Gemv_and_Outer
.
gemv_numpy
(
b_val
.
take
(
oIdx_val
,
axis
=
0
),
W_val
,
h_val
,
iIdx_val
,
oIdx_val
)
b_val
.
take
(
oIdx_val
,
axis
=
0
),
W_val
,
h_val
,
iIdx_val
,
oIdx_val
)
utt
.
assert_allclose
(
ref_out
,
th_out
)
...
...
theano/sandbox/tests/test_multinomial.py
浏览文件 @
5b604a49
...
...
@@ -4,7 +4,7 @@ import numpy
import
theano
from
theano
import
config
,
function
,
tensor
from
.
import
multinomial
from
theano.sandbox
import
multinomial
from
theano.compile.mode
import
get_default_mode
,
predefined_linkers
import
theano.sandbox.cuda
as
cuda
...
...
theano/sandbox/tests/test_opt.py
浏览文件 @
5b604a49
import
theano
from
theano
import
tensor
from
theano.sandbox.blocksparse
import
CpuSparseBlockGemv
,
CpuSparseBlockOuter
,
sparse_block_dot
from
theano.sandbox.blocksparse
import
CpuSparseBlockGemv
,
\
CpuSparseBlockOuter
,
sparse_block_dot
def
test_blocksparse_cpu_gemv_opt
():
...
...
@@ -26,8 +27,9 @@ def test_blocksparse_cpu_outer_opt():
o
=
sparse_block_dot
(
W
,
h
,
iIdx
,
b
,
oIdx
)
theano
.
printing
.
debugprint
(
tensor
.
grad
(
o
.
sum
(),
wrt
=
W
))
theano
.
printing
.
debugprint
(
tensor
.
grad
(
o
.
sum
(),
wrt
=
W
))
f
=
theano
.
function
([
W
,
h
,
iIdx
,
b
,
oIdx
],
[
o
,
tensor
.
grad
(
o
.
sum
(),
wrt
=
W
)])
f
=
theano
.
function
([
W
,
h
,
iIdx
,
b
,
oIdx
],
[
o
,
tensor
.
grad
(
o
.
sum
(),
wrt
=
W
)])
assert
isinstance
(
f
.
maker
.
fgraph
.
toposort
()[
-
1
]
.
op
,
CpuSparseBlockOuter
)
theano/sandbox/tests/test_scan.py
浏览文件 @
5b604a49
import
theano
import
numpy
from
.
import
scan
from
theano.sandbox
import
scan
def
test_001
():
...
...
theano/sandbox/tests/test_theano_object.py
浏览文件 @
5b604a49
from
__future__
import
print_function
from
.theano_object
import
*
from
theano.sandbox
.theano_object
import
*
RUN_TESTS
=
False
...
...
theano/tests/test_flake8.py
浏览文件 @
5b604a49
...
...
@@ -98,14 +98,15 @@ whitelist_flake8 = [
"tensor/nnet/tests/test_sigm.py"
,
"scalar/__init__.py"
,
"scalar/tests/test_basic.py"
,
"sandbox/test_theano_object.py"
,
"sandbox/test_scan.py"
,
"sandbox/tests/test_theano_object.py"
,
"sandbox/tests/test_scan.py"
,
"sandbox/tests/test_rng_mrg.py"
,
"sandbox/tests/test_neighbourhoods.py"
,
"sandbox/tests/test_multinomial.py"
,
"sandbox/tests/__init__.py"
"sandbox/rng_mrg.py"
,
"sandbox/theano_object.py"
,
"sandbox/scan.py"
,
"sandbox/test_multinomial.py"
,
"sandbox/test_rng_mrg.py"
,
"sandbox/test_neighbourhoods.py"
,
"sandbox/symbolic_module.py"
,
"sandbox/conv.py"
,
"sandbox/debug.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论