Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8e9f3ff6
提交
8e9f3ff6
authored
12月 15, 2009
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename ReorderRowElements to PermuteRowElements, to better reflect the
implementation.
上级
d147486a
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
28 行增加
和
28 行删除
+28
-28
basic.py
theano/tensor/basic.py
+4
-4
randomstreams.py
theano/tensor/randomstreams.py
+2
-2
test_basic.py
theano/tensor/tests/test_basic.py
+22
-22
没有找到文件。
theano/tensor/basic.py
浏览文件 @
8e9f3ff6
...
@@ -2735,8 +2735,8 @@ class InversePermutation(Op):
...
@@ -2735,8 +2735,8 @@ class InversePermutation(Op):
inverse_permutation
=
InversePermutation
()
inverse_permutation
=
InversePermutation
()
class
Reorder
RowElements
(
Op
):
class
Permute
RowElements
(
Op
):
"""
Reorder each row (inner-most dim) of a tensor wrt a permutation
.
"""
Permute the elements of each row (inner-most dim) of a tensor
.
The permutation argument (y) will be broadcasted to fit x, then each
The permutation argument (y) will be broadcasted to fit x, then each
row (vector) of x will be reordered according to the corresponding row
row (vector) of x will be reordered according to the corresponding row
...
@@ -2784,10 +2784,10 @@ class ReorderRowElements(Op):
...
@@ -2784,10 +2784,10 @@ class ReorderRowElements(Op):
self
.
_rec_perform
(
node
,
x
,
y
,
outs
[
0
],
curdim
=
0
)
self
.
_rec_perform
(
node
,
x
,
y
,
outs
[
0
],
curdim
=
0
)
def
grad
(
self
,
(
x
,
y
),
(
gz
,)):
def
grad
(
self
,
(
x
,
y
),
(
gz
,)):
gx
=
reorder
_row_elements
(
gz
,
inverse_permutation
(
y
))
gx
=
permute
_row_elements
(
gz
,
inverse_permutation
(
y
))
return
[
gx
,
None
]
return
[
gx
,
None
]
reorder_row_elements
=
Reorder
RowElements
()
permute_row_elements
=
Permute
RowElements
()
#########################
#########################
...
...
theano/tensor/randomstreams.py
浏览文件 @
8e9f3ff6
...
@@ -6,7 +6,7 @@ import numpy
...
@@ -6,7 +6,7 @@ import numpy
from
theano.compile
import
module
,
In
,
Component
from
theano.compile
import
module
,
In
,
Component
from
theano.gof
import
Container
from
theano.gof
import
Container
from
theano.tensor
import
raw_random
,
reorder
_row_elements
from
theano.tensor
import
raw_random
,
permute
_row_elements
class
RandomStreamsInstance
(
object
):
class
RandomStreamsInstance
(
object
):
"""RandomStreamsInstance"""
"""RandomStreamsInstance"""
...
@@ -192,7 +192,7 @@ class RandomStreams(Component):
...
@@ -192,7 +192,7 @@ class RandomStreams(Component):
def
shuffle_row_elements
(
self
,
input
):
def
shuffle_row_elements
(
self
,
input
):
"""Return a variable with every row (rightmost index) shuffled"""
"""Return a variable with every row (rightmost index) shuffled"""
perm
=
self
.
permutation
(
input
.
ndim
-
1
,
input
.
shape
[:
-
1
],
input
.
shape
[
-
1
])
perm
=
self
.
permutation
(
input
.
ndim
-
1
,
input
.
shape
[:
-
1
],
input
.
shape
[
-
1
])
shuffled
=
reorder
_row_elements
(
input
,
perm
)
shuffled
=
permute
_row_elements
(
input
,
perm
)
return
shuffled
return
shuffled
theano/tensor/tests/test_basic.py
浏览文件 @
8e9f3ff6
...
@@ -1832,65 +1832,65 @@ class TestInversePermutation(unittest.TestCase):
...
@@ -1832,65 +1832,65 @@ class TestInversePermutation(unittest.TestCase):
assert
numpy
.
all
(
i_row
[
p_row
]
==
numpy
.
arange
(
10
))
assert
numpy
.
all
(
i_row
[
p_row
]
==
numpy
.
arange
(
10
))
class
Test
Reorder
RowElements
(
unittest
.
TestCase
):
class
Test
Permute
RowElements
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
utt
.
seed_rng
()
utt
.
seed_rng
()
def
test_1_1
(
self
):
def
test_1_1
(
self
):
"""Test
Reorder
RowElements(vector, vector)"""
"""Test
Permute
RowElements(vector, vector)"""
input
=
vector
()
input
=
vector
()
p
=
ivector
()
p
=
ivector
()
out
=
reorder
_row_elements
(
input
,
p
)
out
=
permute
_row_elements
(
input
,
p
)
reorder
=
function
([
input
,
p
],
out
)
permute
=
function
([
input
,
p
],
out
)
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
input_val
=
rng
.
uniform
(
size
=
(
5
,))
input_val
=
rng
.
uniform
(
size
=
(
5
,))
p_val
=
rng
.
permutation
(
5
)
p_val
=
rng
.
permutation
(
5
)
out_val
=
reorder
(
input_val
,
p_val
)
out_val
=
permute
(
input_val
,
p_val
)
# Should be equivalent to advanced indexing
# Should be equivalent to advanced indexing
out_bis
=
input_val
[
p_val
]
out_bis
=
input_val
[
p_val
]
assert
numpy
.
all
(
out_val
==
out_bis
)
assert
numpy
.
all
(
out_val
==
out_bis
)
# Verify gradient
# Verify gradient
def
reorder
_fixed
(
s_input
):
def
permute
_fixed
(
s_input
):
"""Auxiliary op defined to get rid of gradient wrt p_val"""
"""Auxiliary op defined to get rid of gradient wrt p_val"""
return
reorder
_row_elements
(
s_input
,
p_val
)
return
permute
_row_elements
(
s_input
,
p_val
)
utt
.
verify_grad
(
reorder
_fixed
,
[
input_val
])
utt
.
verify_grad
(
permute
_fixed
,
[
input_val
])
def
test_2_1
(
self
):
def
test_2_1
(
self
):
"""Test broadcasting in
Reorder
RowElements(matrix, vector)"""
"""Test broadcasting in
Permute
RowElements(matrix, vector)"""
input
=
matrix
()
input
=
matrix
()
p
=
ivector
()
p
=
ivector
()
out
=
reorder
_row_elements
(
input
,
p
)
out
=
permute
_row_elements
(
input
,
p
)
reorder
=
function
([
input
,
p
],
out
)
permute
=
function
([
input
,
p
],
out
)
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
input_val
=
rng
.
uniform
(
size
=
(
3
,
5
))
input_val
=
rng
.
uniform
(
size
=
(
3
,
5
))
p_val
=
rng
.
permutation
(
5
)
p_val
=
rng
.
permutation
(
5
)
out_val
=
reorder
(
input_val
,
p_val
)
out_val
=
permute
(
input_val
,
p_val
)
# The same permutation should be applied to every row of the input matrix.
# The same permutation should be applied to every row of the input matrix.
out_bis
=
numpy
.
asarray
([
row
[
p_val
]
for
row
in
input_val
])
out_bis
=
numpy
.
asarray
([
row
[
p_val
]
for
row
in
input_val
])
assert
numpy
.
all
(
out_val
==
out_bis
)
assert
numpy
.
all
(
out_val
==
out_bis
)
# Verify gradient
# Verify gradient
def
reorder
_fixed
(
s_input
):
def
permute
_fixed
(
s_input
):
"""Auxiliary op defined to get rid of gradient wrt p_val"""
"""Auxiliary op defined to get rid of gradient wrt p_val"""
return
reorder
_row_elements
(
s_input
,
p_val
)
return
permute
_row_elements
(
s_input
,
p_val
)
utt
.
verify_grad
(
reorder
_fixed
,
[
input_val
])
utt
.
verify_grad
(
permute
_fixed
,
[
input_val
])
def
test_2_2
(
self
):
def
test_2_2
(
self
):
"""Test
Reorder
RowElements(matrix, matrix)"""
"""Test
Permute
RowElements(matrix, matrix)"""
input
=
matrix
()
input
=
matrix
()
p
=
imatrix
()
p
=
imatrix
()
out
=
reorder
_row_elements
(
input
,
p
)
out
=
permute
_row_elements
(
input
,
p
)
reorder
=
function
([
input
,
p
],
out
)
permute
=
function
([
input
,
p
],
out
)
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
input_val
=
rng
.
uniform
(
size
=
(
3
,
5
))
input_val
=
rng
.
uniform
(
size
=
(
3
,
5
))
p_val
=
numpy
.
asarray
([
rng
.
permutation
(
5
)
for
i
in
range
(
3
)])
p_val
=
numpy
.
asarray
([
rng
.
permutation
(
5
)
for
i
in
range
(
3
)])
out_val
=
reorder
(
input_val
,
p_val
)
out_val
=
permute
(
input_val
,
p_val
)
# Each row of p contains a permutation to apply to the corresponding
# Each row of p contains a permutation to apply to the corresponding
# row of input
# row of input
...
@@ -1898,10 +1898,10 @@ class TestReorderRowElements(unittest.TestCase):
...
@@ -1898,10 +1898,10 @@ class TestReorderRowElements(unittest.TestCase):
assert
numpy
.
all
(
out_val
==
out_bis
)
assert
numpy
.
all
(
out_val
==
out_bis
)
# Verify gradient
# Verify gradient
def
reorder
_fixed
(
s_input
):
def
permute
_fixed
(
s_input
):
"""Auxiliary op defined to get rid of gradient wrt p_val"""
"""Auxiliary op defined to get rid of gradient wrt p_val"""
return
reorder
_row_elements
(
s_input
,
p_val
)
return
permute
_row_elements
(
s_input
,
p_val
)
utt
.
verify_grad
(
reorder
_fixed
,
[
input_val
])
utt
.
verify_grad
(
permute
_fixed
,
[
input_val
])
class
test_tensordot
(
unittest
.
TestCase
):
class
test_tensordot
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论