Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
986c6dc6
提交
986c6dc6
authored
12月 22, 2016
作者:
Frédéric Bastien
提交者:
GitHub
12月 22, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5359 from notoraptor/fix-batched-dot
Fix issue #4476 related to BatchedDot.
上级
9bff4ddc
265980e2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
35 行增加
和
3 行删除
+35
-3
blas.py
theano/tensor/blas.py
+5
-3
test_basic.py
theano/tensor/tests/test_basic.py
+30
-0
没有找到文件。
theano/tensor/blas.py
浏览文件 @
986c6dc6
...
@@ -2151,11 +2151,13 @@ class BatchedDot(Op):
...
@@ -2151,11 +2151,13 @@ class BatchedDot(Op):
# generate contiguity condition
# generate contiguity condition
def
contiguous
(
var
,
ndim
):
def
contiguous
(
var
,
ndim
):
strides
=
"PyArray_STRIDES(
%
s)"
%
var
strides
=
"PyArray_STRIDES(
%
s)"
%
var
if
ndim
==
1
:
return
"{strides}[0] == type_size"
.
format
(
strides
=
strides
)
return
" && "
.
join
([
return
" && "
.
join
([
" && "
.
join
(
"{strides}[{i}] > 0 && {strides}[{i}]
%
type_size == 0"
" && "
.
join
(
"{strides}[{i}] > 0 && {strides}[{i}]
%
type_size == 0"
.
format
(
strides
=
strides
,
i
=
i
)
for
i
in
range
(
ndim
)),
.
format
(
strides
=
strides
,
i
=
i
)
for
i
in
range
(
1
,
ndim
)),
"(
%
s)"
%
" || "
.
join
(
"{strides}[{i}] == type_size"
"(
%
s)"
%
" || "
.
join
(
"{strides}[{i}] == type_size"
.
format
(
strides
=
strides
,
i
=
i
)
for
i
in
range
(
ndim
)),
.
format
(
strides
=
strides
,
i
=
i
)
for
i
in
range
(
1
,
ndim
)),
])
])
x_ndim
,
y_ndim
,
z_ndim
=
node
.
inputs
[
0
]
.
ndim
,
node
.
inputs
[
1
]
.
ndim
,
node
.
outputs
[
0
]
.
ndim
x_ndim
,
y_ndim
,
z_ndim
=
node
.
inputs
[
0
]
.
ndim
,
node
.
inputs
[
1
]
.
ndim
,
node
.
outputs
[
0
]
.
ndim
...
@@ -2309,7 +2311,7 @@ class BatchedDot(Op):
...
@@ -2309,7 +2311,7 @@ class BatchedDot(Op):
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
from
theano.tensor.blas_headers
import
blas_header_version
from
theano.tensor.blas_headers
import
blas_header_version
return
(
1
,
blas_header_version
())
return
(
3
,
blas_header_version
())
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
x
,
y
=
inp
x
,
y
=
inp
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
986c6dc6
...
@@ -2771,6 +2771,36 @@ def test_batched_dot():
...
@@ -2771,6 +2771,36 @@ def test_batched_dot():
assert
result
.
shape
[
0
]
==
first_mat_val
.
shape
[
0
]
assert
result
.
shape
[
0
]
==
first_mat_val
.
shape
[
0
]
def
test_batched_dot_not_contiguous
():
def
np_genarray
(
*
_shape
):
size
=
1
for
dimsize
in
_shape
:
size
*=
dimsize
return
numpy
.
arange
(
size
,
dtype
=
floatX
)
.
reshape
(
_shape
)
X
=
tensor3
()
W
=
tensor3
()
Z
=
batched_dot
(
X
,
W
)
f
=
function
([
X
,
W
],
Z
)
w
=
np_genarray
(
30
,
10
,
5
)
reversed_x_container
=
np_genarray
(
20
,
40
,
30
)
x_container
=
reversed_x_container
.
T
def
check_first_dim
(
inverted
):
direction
=
-
1
if
inverted
else
1
x
=
x_container
[::
direction
,
::
2
,
::
2
]
assert
x
.
shape
==
(
30
,
20
,
10
)
assert
x
.
strides
[
0
]
==
direction
*
numpy
.
dtype
(
floatX
)
.
itemsize
assert
not
(
x
.
flags
[
'C_CONTIGUOUS'
]
or
x
.
flags
[
'F_CONTIGUOUS'
])
result
=
f
(
x
,
w
)
ref_result
=
numpy
.
asarray
(
list
(
numpy
.
dot
(
u
,
v
)
for
u
,
v
in
zip
(
x
,
w
)))
utt
.
assert_allclose
(
ref_result
,
result
)
for
inverted
in
(
0
,
1
):
yield
(
check_first_dim
,
inverted
)
def
test_batched_tensordot
():
def
test_batched_tensordot
():
first
=
theano
.
tensor
.
tensor4
(
"first"
)
first
=
theano
.
tensor
.
tensor4
(
"first"
)
second
=
theano
.
tensor
.
tensor4
(
"second"
)
second
=
theano
.
tensor
.
tensor4
(
"second"
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论