Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
29ee997f
提交
29ee997f
authored
10月 25, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1020 from caglar/batched_dot22
Batched dot22
上级
3bf101b0
b1b432b6
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
42 行增加
和
0 行删除
+42
-0
basic.py
theano/tensor/basic.py
+21
-0
test_basic.py
theano/tensor/tests/test_basic.py
+21
-0
没有找到文件。
theano/tensor/basic.py
浏览文件 @
29ee997f
...
...
@@ -4370,6 +4370,27 @@ def set_subtensor(x, y, inplace=False,
return
inc_subtensor
(
x
,
y
,
inplace
,
set_instead_of_inc
=
True
,
tolerate_inplace_aliasing
=
tolerate_inplace_aliasing
)
def
batched_dot
(
x
,
y
):
"""
:param x: A Tensor with sizes e.g.: for 3D (dim1, dim3, dim2)
:param y: A Tensor with sizes e.g.: for 3D (dim1, dim2, dim4)
This function computes the dot product between the two tensors, by iterating
over the first dimension using scan.
Returns a tensor of size e.g. if it is 3D: (dim1, dim3, dim4)
Example:
>>> first = T.tensor3('first')
>>> second = T.tensor3('second')
>>> result = batched_dot(first, second)
:note: This is a subset of numpy.einsum, but we do not provide it for now.
But numpy einsum is slower then dot or tensordot:
http://mail.scipy.org/pipermail/numpy-discussion/2012-October/064259.html
"""
result
,
updates
=
theano
.
scan
(
fn
=
lambda
x_mat
,
y_mat
:
theano
.
tensor
.
dot
(
x_mat
,
y_mat
),
outputs_info
=
None
,
sequences
=
[
x
,
y
],
non_sequences
=
None
)
return
result
def
inc_subtensor
(
x
,
y
,
inplace
=
False
,
set_instead_of_inc
=
False
,
tolerate_inplace_aliasing
=
False
):
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
29ee997f
...
...
@@ -1893,6 +1893,27 @@ def _approx_eq(a, b, eps=1.0e-4):
return
True
_approx_eq
.
debug
=
0
def
test_batched_dot
():
first
=
theano
.
tensor
.
tensor3
(
"first"
)
second
=
theano
.
tensor
.
tensor3
(
"second"
)
output
=
theano
.
tensor
.
basic
.
batched_dot
(
first
,
second
)
first_val
=
numpy
.
random
.
rand
(
10
,
10
,
20
)
second_val
=
numpy
.
random
.
rand
(
10
,
20
,
5
)
result_fn
=
theano
.
function
([
first
,
second
],
output
)
result
=
result_fn
(
first_val
,
second_val
)
assert
result
.
shape
[
0
]
==
first_val
.
shape
[
0
]
assert
result
.
shape
[
1
]
==
first_val
.
shape
[
1
]
assert
result
.
shape
[
2
]
==
second_val
.
shape
[
2
]
first_mat
=
theano
.
tensor
.
dmatrix
(
"first"
)
second_mat
=
theano
.
tensor
.
dmatrix
(
"second"
)
output
=
theano
.
tensor
.
basic
.
batched_dot
(
first_mat
,
second_mat
)
first_mat_val
=
numpy
.
random
.
rand
(
10
,
10
)
second_mat_val
=
numpy
.
random
.
rand
(
10
,
10
)
result_fn
=
theano
.
function
([
first_mat
,
second_mat
],
output
)
result
=
result_fn
(
first_mat_val
,
second_mat_val
)
assert
result
.
shape
[
0
]
==
first_val
.
shape
[
0
]
def
test_tensor_values_eq_approx
():
#test, inf, -inf and nan equal themself
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论