Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2c177e38
提交
2c177e38
authored
3月 24, 2017
作者:
amrithasuresh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1. Added import numpy as np
2. Updated numpy as np
上级
5835a7e7
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
178 行增加
和
178 行删除
+178
-178
test_blas.py
theano/tensor/tests/test_blas.py
+178
-178
没有找到文件。
theano/tensor/tests/test_blas.py
浏览文件 @
2c177e38
...
@@ -3,7 +3,7 @@ from copy import copy
...
@@ -3,7 +3,7 @@ from copy import copy
from
itertools
import
product
as
itertools_product
from
itertools
import
product
as
itertools_product
from
unittest
import
TestCase
from
unittest
import
TestCase
import
numpy
import
numpy
as
np
from
numpy
import
(
arange
,
array
,
common_type
,
complex64
,
complex128
,
float32
,
from
numpy
import
(
arange
,
array
,
common_type
,
complex64
,
complex128
,
float32
,
float64
,
newaxis
,
shape
,
transpose
,
zeros
)
float64
,
newaxis
,
shape
,
transpose
,
zeros
)
from
numpy.testing
import
assert_array_almost_equal
from
numpy.testing
import
assert_array_almost_equal
...
@@ -42,7 +42,7 @@ def test_dot_eq():
...
@@ -42,7 +42,7 @@ def test_dot_eq():
def
sharedX
(
x
,
name
):
def
sharedX
(
x
,
name
):
return
theano
.
shared
(
n
umpy
.
asarray
(
x
,
config
.
floatX
),
name
=
name
)
return
theano
.
shared
(
n
p
.
asarray
(
x
,
config
.
floatX
),
name
=
name
)
class
t_gemm
(
TestCase
):
class
t_gemm
(
TestCase
):
...
@@ -58,22 +58,22 @@ class t_gemm(TestCase):
...
@@ -58,22 +58,22 @@ class t_gemm(TestCase):
def
_gemm
(
z
,
a
,
x
,
y
,
b
):
def
_gemm
(
z
,
a
,
x
,
y
,
b
):
assert
a
.
shape
==
()
assert
a
.
shape
==
()
assert
b
.
shape
==
()
assert
b
.
shape
==
()
return
b
*
z
+
a
*
n
umpy
.
dot
(
x
,
y
)
return
b
*
z
+
a
*
n
p
.
dot
(
x
,
y
)
@staticmethod
@staticmethod
def
rand
(
*
args
):
def
rand
(
*
args
):
return
n
umpy
.
random
.
rand
(
*
args
)
return
n
p
.
random
.
rand
(
*
args
)
def
cmp
(
self
,
z_
,
a_
,
x_
,
y_
,
b_
):
def
cmp
(
self
,
z_
,
a_
,
x_
,
y_
,
b_
):
for
dtype
in
[
'float32'
,
'float64'
,
'complex64'
,
'complex128'
]:
for
dtype
in
[
'float32'
,
'float64'
,
'complex64'
,
'complex128'
]:
z
=
n
umpy
.
asarray
(
z_
,
dtype
=
dtype
)
z
=
n
p
.
asarray
(
z_
,
dtype
=
dtype
)
a
=
n
umpy
.
asarray
(
a_
,
dtype
=
dtype
)
a
=
n
p
.
asarray
(
a_
,
dtype
=
dtype
)
x
=
n
umpy
.
asarray
(
x_
,
dtype
=
dtype
)
x
=
n
p
.
asarray
(
x_
,
dtype
=
dtype
)
y
=
n
umpy
.
asarray
(
y_
,
dtype
=
dtype
)
y
=
n
p
.
asarray
(
y_
,
dtype
=
dtype
)
b
=
n
umpy
.
asarray
(
b_
,
dtype
=
dtype
)
b
=
n
p
.
asarray
(
b_
,
dtype
=
dtype
)
def
cmp_linker
(
z
,
a
,
x
,
y
,
b
,
l
):
def
cmp_linker
(
z
,
a
,
x
,
y
,
b
,
l
):
z
,
a
,
x
,
y
,
b
=
[
n
umpy
.
asarray
(
p
)
for
p
in
(
z
,
a
,
x
,
y
,
b
)]
z
,
a
,
x
,
y
,
b
=
[
n
p
.
asarray
(
p
)
for
p
in
(
z
,
a
,
x
,
y
,
b
)]
z_orig
=
z
.
copy
()
z_orig
=
z
.
copy
()
tz
,
ta
,
tx
,
ty
,
tb
=
[
as_tensor_variable
(
p
)
.
type
()
tz
,
ta
,
tx
,
ty
,
tb
=
[
as_tensor_variable
(
p
)
.
type
()
for
p
in
(
z
,
a
,
x
,
y
,
b
)]
for
p
in
(
z
,
a
,
x
,
y
,
b
)]
...
@@ -91,7 +91,7 @@ class t_gemm(TestCase):
...
@@ -91,7 +91,7 @@ class t_gemm(TestCase):
elif
z_orig
.
size
==
0
:
elif
z_orig
.
size
==
0
:
self
.
assertTrue
(
z
.
size
==
0
)
self
.
assertTrue
(
z
.
size
==
0
)
else
:
else
:
self
.
assertFalse
(
n
umpy
.
all
(
z_orig
==
z
))
self
.
assertFalse
(
n
p
.
all
(
z_orig
==
z
))
cmp_linker
(
copy
(
z
),
a
,
x
,
y
,
b
,
'c|py'
)
cmp_linker
(
copy
(
z
),
a
,
x
,
y
,
b
,
'c|py'
)
cmp_linker
(
copy
(
z
),
a
,
x
,
y
,
b
,
'py'
)
cmp_linker
(
copy
(
z
),
a
,
x
,
y
,
b
,
'py'
)
...
@@ -172,7 +172,7 @@ class t_gemm(TestCase):
...
@@ -172,7 +172,7 @@ class t_gemm(TestCase):
a
=
T
.
matrix
()
a
=
T
.
matrix
()
b
=
T
.
matrix
()
b
=
T
.
matrix
()
c
=
T
.
matrix
()
c
=
T
.
matrix
()
s
=
theano
.
shared
(
n
umpy
.
zeros
((
5
,
5
))
.
astype
(
config
.
floatX
))
s
=
theano
.
shared
(
n
p
.
zeros
((
5
,
5
))
.
astype
(
config
.
floatX
))
lr1
=
T
.
constant
(
0.01
)
.
astype
(
config
.
floatX
)
lr1
=
T
.
constant
(
0.01
)
.
astype
(
config
.
floatX
)
lr2
=
T
.
constant
(
2
)
.
astype
(
config
.
floatX
)
lr2
=
T
.
constant
(
2
)
.
astype
(
config
.
floatX
)
...
@@ -331,7 +331,7 @@ class t_gemm(TestCase):
...
@@ -331,7 +331,7 @@ class t_gemm(TestCase):
z
,
a
,
x
,
y
,
b
=
[
theano
.
_asarray
(
p
,
dtype
=
dt
)
z
,
a
,
x
,
y
,
b
=
[
theano
.
_asarray
(
p
,
dtype
=
dt
)
for
p
in
(
z
,
a
,
x
,
y
,
b
)]
for
p
in
(
z
,
a
,
x
,
y
,
b
)]
z_orig
=
z
.
copy
()
z_orig
=
z
.
copy
()
z_after
=
n
umpy
.
zeros_like
(
z_orig
)
z_after
=
n
p
.
zeros_like
(
z_orig
)
for
i
in
xrange
(
3
):
for
i
in
xrange
(
3
):
z_after
[:,
:,
i
]
=
self
.
_gemm
(
z
[:,
:,
i
],
a
,
z_after
[:,
:,
i
]
=
self
.
_gemm
(
z
[:,
:,
i
],
a
,
x
[:,
:,
i
],
y
[:,
:,
i
],
b
)
x
[:,
:,
i
],
y
[:,
:,
i
],
b
)
...
@@ -388,7 +388,7 @@ class t_as_scalar(TestCase):
...
@@ -388,7 +388,7 @@ class t_as_scalar(TestCase):
def
test0
(
self
):
def
test0
(
self
):
"""Test that it works on scalar constants"""
"""Test that it works on scalar constants"""
a
=
T
.
constant
(
2.5
)
a
=
T
.
constant
(
2.5
)
b
=
T
.
constant
(
n
umpy
.
asarray
([[[
0.5
]]]))
b
=
T
.
constant
(
n
p
.
asarray
([[[
0.5
]]]))
b2
=
b
.
dimshuffle
()
b2
=
b
.
dimshuffle
()
assert
b2
.
ndim
==
0
assert
b2
.
ndim
==
0
d_a
=
T
.
DimShuffle
([],
[])(
a
)
d_a
=
T
.
DimShuffle
([],
[])(
a
)
...
@@ -403,7 +403,7 @@ class t_as_scalar(TestCase):
...
@@ -403,7 +403,7 @@ class t_as_scalar(TestCase):
def
test1
(
self
):
def
test1
(
self
):
"""Test that it fails on nonscalar constants"""
"""Test that it fails on nonscalar constants"""
a
=
T
.
constant
(
n
umpy
.
ones
(
5
))
a
=
T
.
constant
(
n
p
.
ones
(
5
))
self
.
assertTrue
(
None
==
_as_scalar
(
a
))
self
.
assertTrue
(
None
==
_as_scalar
(
a
))
self
.
assertTrue
(
None
==
_as_scalar
(
T
.
DimShuffle
([
False
],
[
0
,
'x'
])(
a
)))
self
.
assertTrue
(
None
==
_as_scalar
(
T
.
DimShuffle
([
False
],
[
0
,
'x'
])(
a
)))
...
@@ -482,13 +482,13 @@ def just_gemm(i, o, ishapes=[(4, 3), (3, 5), (4, 5), (), ()],
...
@@ -482,13 +482,13 @@ def just_gemm(i, o, ishapes=[(4, 3), (3, 5), (4, 5), (), ()],
# theano.printing.debugprint(f)
# theano.printing.debugprint(f)
assert
False
,
'graphlen=
%
i>
%
i'
%
(
graphlen
,
max_graphlen
)
assert
False
,
'graphlen=
%
i>
%
i'
%
(
graphlen
,
max_graphlen
)
rng
=
n
umpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
(
234
))
rng
=
n
p
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
(
234
))
r0
=
f
(
*
[
n
umpy
.
asarray
(
rng
.
randn
(
*
sh
),
config
.
floatX
)
r0
=
f
(
*
[
n
p
.
asarray
(
rng
.
randn
(
*
sh
),
config
.
floatX
)
for
sh
in
ishapes
])
for
sh
in
ishapes
])
rng
=
n
umpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
(
234
))
rng
=
n
p
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
(
234
))
r1
=
g
(
*
[
n
umpy
.
asarray
(
rng
.
randn
(
*
sh
),
config
.
floatX
)
r1
=
g
(
*
[
n
p
.
asarray
(
rng
.
randn
(
*
sh
),
config
.
floatX
)
for
sh
in
ishapes
])
for
sh
in
ishapes
])
max_abs_err
=
n
umpy
.
max
(
numpy
.
abs
(
r0
[
0
]
-
r1
[
0
]))
max_abs_err
=
n
p
.
max
(
np
.
abs
(
r0
[
0
]
-
r1
[
0
]))
eps
=
1.0e-8
eps
=
1.0e-8
if
config
.
floatX
==
'float32'
:
if
config
.
floatX
==
'float32'
:
eps
=
1.0e-6
eps
=
1.0e-6
...
@@ -556,13 +556,13 @@ def test_gemm_opt_double_gemm():
...
@@ -556,13 +556,13 @@ def test_gemm_opt_double_gemm():
# for node in g.maker.fgraph.apply_nodes:
# for node in g.maker.fgraph.apply_nodes:
# if node.op == gemm_inplace: raise Failure('gemm_inplace in graph')
# if node.op == gemm_inplace: raise Failure('gemm_inplace in graph')
rng
=
n
umpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
(
234
))
rng
=
n
p
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
(
234
))
r0
=
f
(
*
[
n
umpy
.
asarray
(
rng
.
randn
(
*
sh
),
config
.
floatX
)
r0
=
f
(
*
[
n
p
.
asarray
(
rng
.
randn
(
*
sh
),
config
.
floatX
)
for
sh
in
ishapes
])
for
sh
in
ishapes
])
rng
=
n
umpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
(
234
))
rng
=
n
p
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
(
234
))
r1
=
g
(
*
[
n
umpy
.
asarray
(
rng
.
randn
(
*
sh
),
config
.
floatX
)
r1
=
g
(
*
[
n
p
.
asarray
(
rng
.
randn
(
*
sh
),
config
.
floatX
)
for
sh
in
ishapes
])
for
sh
in
ishapes
])
max_abs_err
=
n
umpy
.
max
(
numpy
.
abs
(
r0
[
0
]
-
r1
[
0
]))
max_abs_err
=
n
p
.
max
(
np
.
abs
(
r0
[
0
]
-
r1
[
0
]))
eps
=
1.0e-8
eps
=
1.0e-8
if
config
.
floatX
==
'float32'
:
if
config
.
floatX
==
'float32'
:
eps
=
1.0e-6
eps
=
1.0e-6
...
@@ -652,7 +652,7 @@ def test_upcasting_scalar_nogemm():
...
@@ -652,7 +652,7 @@ def test_upcasting_scalar_nogemm():
f
=
theano
.
function
([
w
,
v
,
t
,
alpha
],
rval
)
f
=
theano
.
function
([
w
,
v
,
t
,
alpha
],
rval
)
t
=
f
.
maker
.
fgraph
.
toposort
()
t
=
f
.
maker
.
fgraph
.
toposort
()
assert
n
umpy
.
sum
([
isinstance
(
n
.
op
,
Gemm
)
for
n
in
t
])
==
0
assert
n
p
.
sum
([
isinstance
(
n
.
op
,
Gemm
)
for
n
in
t
])
==
0
#theano.printing.debugprint(f, print_type=True)
#theano.printing.debugprint(f, print_type=True)
v
=
T
.
fmatrix
(
'v'
)
v
=
T
.
fmatrix
(
'v'
)
...
@@ -669,7 +669,7 @@ def test_upcasting_scalar_nogemm():
...
@@ -669,7 +669,7 @@ def test_upcasting_scalar_nogemm():
config
.
on_opt_error
=
on_opt_error
config
.
on_opt_error
=
on_opt_error
t
=
f
.
maker
.
fgraph
.
toposort
()
t
=
f
.
maker
.
fgraph
.
toposort
()
assert
n
umpy
.
sum
([
isinstance
(
n
.
op
,
Gemm
)
for
n
in
t
])
==
0
assert
n
p
.
sum
([
isinstance
(
n
.
op
,
Gemm
)
for
n
in
t
])
==
0
#theano.printing.debugprint(f, print_type=True)
#theano.printing.debugprint(f, print_type=True)
...
@@ -763,13 +763,13 @@ def test_gemm_unrolled():
...
@@ -763,13 +763,13 @@ def test_gemm_unrolled():
"""
"""
batch_size
=
100
batch_size
=
100
rep_size
=
40
rep_size
=
40
rng
=
n
umpy
.
random
.
RandomState
([
1
,
2
,
3
])
rng
=
n
p
.
random
.
RandomState
([
1
,
2
,
3
])
for
num_rounds
in
range
(
1
,
10
):
for
num_rounds
in
range
(
1
,
10
):
W
=
sharedX
(
rng
.
randn
(
rep_size
,
rep_size
),
name
=
'W'
)
W
=
sharedX
(
rng
.
randn
(
rep_size
,
rep_size
),
name
=
'W'
)
V
=
sharedX
(
n
umpy
.
zeros
((
batch_size
,
rep_size
)),
name
=
'V'
)
V
=
sharedX
(
n
p
.
zeros
((
batch_size
,
rep_size
)),
name
=
'V'
)
H
=
sharedX
(
n
umpy
.
zeros
((
batch_size
,
rep_size
)),
name
=
'H'
)
H
=
sharedX
(
n
p
.
zeros
((
batch_size
,
rep_size
)),
name
=
'H'
)
G
=
sharedX
(
n
umpy
.
zeros
((
batch_size
,
rep_size
)),
name
=
'G'
)
G
=
sharedX
(
n
p
.
zeros
((
batch_size
,
rep_size
)),
name
=
'G'
)
init_V
=
sharedX
(
rng
.
uniform
(
0
,
1
,
(
batch_size
,
rep_size
)),
name
=
'init_V'
)
init_V
=
sharedX
(
rng
.
uniform
(
0
,
1
,
(
batch_size
,
rep_size
)),
name
=
'init_V'
)
init_H
=
sharedX
(
rng
.
uniform
(
0
,
1
,
(
batch_size
,
rep_size
)),
name
=
'init_H'
)
init_H
=
sharedX
(
rng
.
uniform
(
0
,
1
,
(
batch_size
,
rep_size
)),
name
=
'init_H'
)
...
@@ -844,7 +844,7 @@ def test_dot22():
...
@@ -844,7 +844,7 @@ def test_dot22():
else
:
else
:
check
=
[
isinstance
(
x
.
op
,
T
.
Dot
)
for
x
in
topo
]
check
=
[
isinstance
(
x
.
op
,
T
.
Dot
)
for
x
in
topo
]
assert
any
(
check
),
(
dtype1
,
dtype2
)
assert
any
(
check
),
(
dtype1
,
dtype2
)
rng
=
n
umpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
def
cmp
(
a_shp
,
b_shp
):
def
cmp
(
a_shp
,
b_shp
):
av
=
rng
.
uniform
(
size
=
a_shp
)
.
astype
(
dtype1
)
av
=
rng
.
uniform
(
size
=
a_shp
)
.
astype
(
dtype1
)
...
@@ -867,7 +867,7 @@ def test_dot22scalar():
...
@@ -867,7 +867,7 @@ def test_dot22scalar():
# m = theano.compile.get_default_mode().including('local_dot_to_dot22',
# m = theano.compile.get_default_mode().including('local_dot_to_dot22',
# 'local_dot22_to_dot22scalar','specialize')
# 'local_dot22_to_dot22scalar','specialize')
#m = theano.compile.get_default_mode().including('BlasOpt', 'specialize')
#m = theano.compile.get_default_mode().including('BlasOpt', 'specialize')
rng
=
n
umpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
for
dtype1
in
[
'complex64'
,
'complex128'
]:
for
dtype1
in
[
'complex64'
,
'complex128'
]:
a
=
T
.
matrix
(
'a'
,
dtype
=
dtype1
)
a
=
T
.
matrix
(
'a'
,
dtype
=
dtype1
)
for
dtype2
in
[
'complex64'
,
'complex128'
]:
for
dtype2
in
[
'complex64'
,
'complex128'
]:
...
@@ -1069,7 +1069,7 @@ def test_dot_w_self():
...
@@ -1069,7 +1069,7 @@ def test_dot_w_self():
# normally be a gemm must not be because the output is aliased to
# normally be a gemm must not be because the output is aliased to
# one of the inputs.
# one of the inputs.
A
=
shared
(
value
=
n
umpy
.
ones
((
2
,
2
)))
A
=
shared
(
value
=
n
p
.
ones
((
2
,
2
)))
B
=
T
.
matrix
()
B
=
T
.
matrix
()
p
=
T
.
dot
(
A
,
A
)
*
B
p
=
T
.
dot
(
A
,
A
)
*
B
...
@@ -1078,7 +1078,7 @@ def test_dot_w_self():
...
@@ -1078,7 +1078,7 @@ def test_dot_w_self():
f
=
theano
.
function
([
B
],
p
,
updates
=
[(
A
,
A
-
grad
)])
f
=
theano
.
function
([
B
],
p
,
updates
=
[(
A
,
A
-
grad
)])
# tests correctness in debugmode
# tests correctness in debugmode
f
(
n
umpy
.
asarray
([[
0
,
1
],
[
2
,
3
]],
dtype
=
config
.
floatX
))
f
(
n
p
.
asarray
([[
0
,
1
],
[
2
,
3
]],
dtype
=
config
.
floatX
))
###############################################################################
###############################################################################
...
@@ -1088,9 +1088,9 @@ def test_dot_w_self():
...
@@ -1088,9 +1088,9 @@ def test_dot_w_self():
class
TestGemv
(
TestCase
,
unittest_tools
.
TestOptimizationMixin
):
class
TestGemv
(
TestCase
,
unittest_tools
.
TestOptimizationMixin
):
def
test_dot_vv
(
self
):
def
test_dot_vv
(
self
):
''' Currently we generate a gemv for that case'''
''' Currently we generate a gemv for that case'''
rng
=
n
umpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
v
=
theano
.
shared
(
n
umpy
.
array
(
rng
.
uniform
(
size
=
(
2
,)),
dtype
=
'float32'
))
v
=
theano
.
shared
(
n
p
.
array
(
rng
.
uniform
(
size
=
(
2
,)),
dtype
=
'float32'
))
w
=
theano
.
shared
(
n
umpy
.
array
(
rng
.
uniform
(
size
=
(
2
,)),
dtype
=
'float32'
))
w
=
theano
.
shared
(
n
p
.
array
(
rng
.
uniform
(
size
=
(
2
,)),
dtype
=
'float32'
))
f
=
theano
.
function
([],
theano
.
dot
(
v
,
w
),
mode
=
mode_blas_opt
)
f
=
theano
.
function
([],
theano
.
dot
(
v
,
w
),
mode
=
mode_blas_opt
)
# Assert that the dot was optimized somehow
# Assert that the dot was optimized somehow
...
@@ -1098,13 +1098,13 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
...
@@ -1098,13 +1098,13 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
self
.
assertFunctionContains1
(
f
,
Gemv
(
True
))
self
.
assertFunctionContains1
(
f
,
Gemv
(
True
))
# Assert they produce the same output
# Assert they produce the same output
assert
n
umpy
.
allclose
(
f
(),
numpy
.
dot
(
v
.
get_value
(),
w
.
get_value
()))
assert
n
p
.
allclose
(
f
(),
np
.
dot
(
v
.
get_value
(),
w
.
get_value
()))
def
test_dot_vm
(
self
):
def
test_dot_vm
(
self
):
''' Test vector dot matrix '''
''' Test vector dot matrix '''
rng
=
n
umpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
v
=
theano
.
shared
(
n
umpy
.
array
(
rng
.
uniform
(
size
=
(
2
,)),
dtype
=
'float32'
))
v
=
theano
.
shared
(
n
p
.
array
(
rng
.
uniform
(
size
=
(
2
,)),
dtype
=
'float32'
))
m
=
theano
.
shared
(
n
umpy
.
array
(
rng
.
uniform
(
size
=
(
2
,
3
)),
m
=
theano
.
shared
(
n
p
.
array
(
rng
.
uniform
(
size
=
(
2
,
3
)),
dtype
=
'float32'
))
dtype
=
'float32'
))
f
=
theano
.
function
([],
theano
.
dot
(
v
,
m
),
mode
=
mode_blas_opt
)
f
=
theano
.
function
([],
theano
.
dot
(
v
,
m
),
mode
=
mode_blas_opt
)
...
@@ -1113,18 +1113,18 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
...
@@ -1113,18 +1113,18 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
self
.
assertFunctionContains1
(
f
,
Gemv
(
True
))
self
.
assertFunctionContains1
(
f
,
Gemv
(
True
))
# Assert they produce the same output
# Assert they produce the same output
assert
n
umpy
.
allclose
(
f
(),
numpy
.
dot
(
v
.
get_value
(),
m
.
get_value
()))
assert
n
p
.
allclose
(
f
(),
np
.
dot
(
v
.
get_value
(),
m
.
get_value
()))
# Assert it works when m has no contiguous dimension
# Assert it works when m has no contiguous dimension
m
.
set_value
(
m
.
set_value
(
m
.
get_value
(
borrow
=
True
)[::
-
1
,
::
-
1
],
m
.
get_value
(
borrow
=
True
)[::
-
1
,
::
-
1
],
borrow
=
True
)
borrow
=
True
)
assert
n
umpy
.
allclose
(
f
(),
numpy
.
dot
(
v
.
get_value
(),
m
.
get_value
()))
assert
n
p
.
allclose
(
f
(),
np
.
dot
(
v
.
get_value
(),
m
.
get_value
()))
def
test_dot_mv
(
self
):
def
test_dot_mv
(
self
):
''' Test matrix dot vector '''
''' Test matrix dot vector '''
rng
=
n
umpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
v
=
theano
.
shared
(
n
umpy
.
array
(
rng
.
uniform
(
size
=
(
2
,)),
dtype
=
'float32'
))
v
=
theano
.
shared
(
n
p
.
array
(
rng
.
uniform
(
size
=
(
2
,)),
dtype
=
'float32'
))
m
=
theano
.
shared
(
n
umpy
.
array
(
rng
.
uniform
(
size
=
(
3
,
2
)),
m
=
theano
.
shared
(
n
p
.
array
(
rng
.
uniform
(
size
=
(
3
,
2
)),
dtype
=
'float32'
))
dtype
=
'float32'
))
f
=
theano
.
function
([],
theano
.
dot
(
m
,
v
),
mode
=
mode_blas_opt
)
f
=
theano
.
function
([],
theano
.
dot
(
m
,
v
),
mode
=
mode_blas_opt
)
...
@@ -1133,29 +1133,29 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
...
@@ -1133,29 +1133,29 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
self
.
assertFunctionContains1
(
f
,
Gemv
(
True
))
self
.
assertFunctionContains1
(
f
,
Gemv
(
True
))
# Assert they produce the same output
# Assert they produce the same output
assert
n
umpy
.
allclose
(
f
(),
numpy
.
dot
(
m
.
get_value
(),
v
.
get_value
()))
assert
n
p
.
allclose
(
f
(),
np
.
dot
(
m
.
get_value
(),
v
.
get_value
()))
# Assert it works when m has no contiguous dimension
# Assert it works when m has no contiguous dimension
m
.
set_value
(
m
.
set_value
(
m
.
get_value
(
borrow
=
True
)[::
-
1
,
::
-
1
],
m
.
get_value
(
borrow
=
True
)[::
-
1
,
::
-
1
],
borrow
=
True
)
borrow
=
True
)
assert
n
umpy
.
allclose
(
f
(),
numpy
.
dot
(
m
.
get_value
(),
v
.
get_value
()))
assert
n
p
.
allclose
(
f
(),
np
.
dot
(
m
.
get_value
(),
v
.
get_value
()))
@staticmethod
@staticmethod
def
t_gemv1
(
m_shp
):
def
t_gemv1
(
m_shp
):
''' test vector2+dot(matrix,vector1) '''
''' test vector2+dot(matrix,vector1) '''
rng
=
n
umpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
v1
=
theano
.
shared
(
n
umpy
.
array
(
rng
.
uniform
(
size
=
(
m_shp
[
1
],)
v1
=
theano
.
shared
(
n
p
.
array
(
rng
.
uniform
(
size
=
(
m_shp
[
1
],)
),
dtype
=
'float32'
))
),
dtype
=
'float32'
))
v2_orig
=
n
umpy
.
array
(
rng
.
uniform
(
size
=
(
m_shp
[
0
],)),
dtype
=
'float32'
)
v2_orig
=
n
p
.
array
(
rng
.
uniform
(
size
=
(
m_shp
[
0
],)),
dtype
=
'float32'
)
v2
=
theano
.
shared
(
v2_orig
)
v2
=
theano
.
shared
(
v2_orig
)
m
=
theano
.
shared
(
n
umpy
.
array
(
rng
.
uniform
(
size
=
m_shp
),
m
=
theano
.
shared
(
n
p
.
array
(
rng
.
uniform
(
size
=
m_shp
),
dtype
=
'float32'
))
dtype
=
'float32'
))
f
=
theano
.
function
([],
v2
+
theano
.
dot
(
m
,
v1
),
mode
=
mode_blas_opt
)
f
=
theano
.
function
([],
v2
+
theano
.
dot
(
m
,
v1
),
mode
=
mode_blas_opt
)
# Assert they produce the same output
# Assert they produce the same output
assert
n
umpy
.
allclose
(
f
(),
assert
n
p
.
allclose
(
f
(),
n
umpy
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
v2_orig
)
n
p
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
v2_orig
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
,
Gemv
)
assert
isinstance
(
topo
[
0
]
.
op
,
Gemv
)
...
@@ -1167,8 +1167,8 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
...
@@ -1167,8 +1167,8 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
# Assert they produce the same output
# Assert they produce the same output
g
()
g
()
assert
n
umpy
.
allclose
(
v2
.
get_value
(),
assert
n
p
.
allclose
(
v2
.
get_value
(),
n
umpy
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
v2_orig
)
n
p
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
v2_orig
)
topo
=
g
.
maker
.
fgraph
.
toposort
()
topo
=
g
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
,
Gemv
)
assert
isinstance
(
topo
[
0
]
.
op
,
Gemv
)
...
@@ -1180,11 +1180,11 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
...
@@ -1180,11 +1180,11 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
m
.
get_value
(
borrow
=
True
)[::
-
1
,
::
-
1
],
m
.
get_value
(
borrow
=
True
)[::
-
1
,
::
-
1
],
borrow
=
True
)
borrow
=
True
)
v2
.
set_value
(
v2_orig
)
v2
.
set_value
(
v2_orig
)
assert
n
umpy
.
allclose
(
f
(),
assert
n
p
.
allclose
(
f
(),
n
umpy
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
v2_orig
)
n
p
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
v2_orig
)
g
()
g
()
assert
n
umpy
.
allclose
(
v2
.
get_value
(),
assert
n
p
.
allclose
(
v2
.
get_value
(),
n
umpy
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
v2_orig
)
n
p
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
v2_orig
)
@attr
(
'slow'
)
@attr
(
'slow'
)
def
test_gemv1
(
self
):
def
test_gemv1
(
self
):
...
@@ -1195,19 +1195,19 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
...
@@ -1195,19 +1195,19 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
def
test_gemv2
(
self
):
def
test_gemv2
(
self
):
''' test vector2+dot(vector1,matrix) '''
''' test vector2+dot(vector1,matrix) '''
rng
=
n
umpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
v1
=
theano
.
shared
(
n
umpy
.
array
(
rng
.
uniform
(
size
=
(
2
,)),
v1
=
theano
.
shared
(
n
p
.
array
(
rng
.
uniform
(
size
=
(
2
,)),
dtype
=
'float32'
))
dtype
=
'float32'
))
v2_orig
=
n
umpy
.
array
(
rng
.
uniform
(
size
=
(
3
,)),
dtype
=
'float32'
)
v2_orig
=
n
p
.
array
(
rng
.
uniform
(
size
=
(
3
,)),
dtype
=
'float32'
)
v2
=
theano
.
shared
(
v2_orig
)
v2
=
theano
.
shared
(
v2_orig
)
m
=
theano
.
shared
(
n
umpy
.
array
(
rng
.
uniform
(
size
=
(
2
,
3
)),
m
=
theano
.
shared
(
n
p
.
array
(
rng
.
uniform
(
size
=
(
2
,
3
)),
dtype
=
'float32'
))
dtype
=
'float32'
))
f
=
theano
.
function
([],
v2
+
theano
.
dot
(
v1
,
m
),
mode
=
mode_blas_opt
)
f
=
theano
.
function
([],
v2
+
theano
.
dot
(
v1
,
m
),
mode
=
mode_blas_opt
)
# Assert they produce the same output
# Assert they produce the same output
assert
n
umpy
.
allclose
(
f
(),
assert
n
p
.
allclose
(
f
(),
n
umpy
.
dot
(
v1
.
get_value
(),
m
.
get_value
())
+
v2
.
get_value
())
n
p
.
dot
(
v1
.
get_value
(),
m
.
get_value
())
+
v2
.
get_value
())
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
sum
(
isinstance
(
node
.
op
,
Gemv
)
for
node
in
topo
)
==
1
assert
sum
(
isinstance
(
node
.
op
,
Gemv
)
for
node
in
topo
)
==
1
assert
topo
[
-
1
]
.
op
.
inplace
==
False
assert
topo
[
-
1
]
.
op
.
inplace
==
False
...
@@ -1218,8 +1218,8 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
...
@@ -1218,8 +1218,8 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
# Assert they produce the same output
# Assert they produce the same output
g
()
g
()
assert
n
umpy
.
allclose
(
v2
.
get_value
(),
assert
n
p
.
allclose
(
v2
.
get_value
(),
n
umpy
.
dot
(
v1
.
get_value
(),
m
.
get_value
())
+
v2_orig
)
n
p
.
dot
(
v1
.
get_value
(),
m
.
get_value
())
+
v2_orig
)
topo
=
g
.
maker
.
fgraph
.
toposort
()
topo
=
g
.
maker
.
fgraph
.
toposort
()
assert
sum
(
isinstance
(
node
.
op
,
Gemv
)
for
node
in
topo
)
==
1
assert
sum
(
isinstance
(
node
.
op
,
Gemv
)
for
node
in
topo
)
==
1
if
config
.
mode
!=
'FAST_COMPILE'
:
if
config
.
mode
!=
'FAST_COMPILE'
:
...
@@ -1230,38 +1230,38 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
...
@@ -1230,38 +1230,38 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
m
.
get_value
(
borrow
=
True
)[::
-
1
,
::
-
1
],
m
.
get_value
(
borrow
=
True
)[::
-
1
,
::
-
1
],
borrow
=
True
)
borrow
=
True
)
v2
.
set_value
(
v2_orig
)
v2
.
set_value
(
v2_orig
)
assert
n
umpy
.
allclose
(
f
(),
assert
n
p
.
allclose
(
f
(),
n
umpy
.
dot
(
v1
.
get_value
(),
m
.
get_value
())
+
v2
.
get_value
())
n
p
.
dot
(
v1
.
get_value
(),
m
.
get_value
())
+
v2
.
get_value
())
g
()
g
()
assert
n
umpy
.
allclose
(
v2
.
get_value
(),
assert
n
p
.
allclose
(
v2
.
get_value
(),
n
umpy
.
dot
(
v1
.
get_value
(),
m
.
get_value
())
+
v2_orig
)
n
p
.
dot
(
v1
.
get_value
(),
m
.
get_value
())
+
v2_orig
)
def
test_gemv_broadcast
(
self
):
def
test_gemv_broadcast
(
self
):
''' test gemv with some broadcasted input '''
''' test gemv with some broadcasted input '''
rng
=
n
umpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
v1
=
theano
.
shared
(
n
umpy
.
array
(
rng
.
uniform
(
size
=
(
2
,)),
v1
=
theano
.
shared
(
n
p
.
array
(
rng
.
uniform
(
size
=
(
2
,)),
dtype
=
'float32'
))
dtype
=
'float32'
))
v2_orig
=
n
umpy
.
array
(
rng
.
uniform
(
size
=
(
1
,)),
dtype
=
'float32'
)
v2_orig
=
n
p
.
array
(
rng
.
uniform
(
size
=
(
1
,)),
dtype
=
'float32'
)
v2
=
theano
.
shared
(
v2_orig
)
v2
=
theano
.
shared
(
v2_orig
)
m
=
theano
.
shared
(
n
umpy
.
array
(
rng
.
uniform
(
size
=
(
1
,
2
)),
m
=
theano
.
shared
(
n
p
.
array
(
rng
.
uniform
(
size
=
(
1
,
2
)),
dtype
=
'float32'
),
dtype
=
'float32'
),
broadcastable
=
(
True
,
False
))
broadcastable
=
(
True
,
False
))
o
=
theano
.
dot
(
m
,
v1
)
o
=
theano
.
dot
(
m
,
v1
)
f
=
theano
.
function
([],
o
+
v2
,
mode
=
mode_blas_opt
)
f
=
theano
.
function
([],
o
+
v2
,
mode
=
mode_blas_opt
)
# Assert they produce the same output
# Assert they produce the same output
assert
n
umpy
.
allclose
(
assert
n
p
.
allclose
(
f
(),
f
(),
n
umpy
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
v2
.
get_value
())
n
p
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
v2
.
get_value
())
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
sum
(
isinstance
(
node
.
op
,
Gemv
)
for
node
in
topo
)
==
1
assert
sum
(
isinstance
(
node
.
op
,
Gemv
)
for
node
in
topo
)
==
1
# call gemv directly for mixed broadcast pattern.
# call gemv directly for mixed broadcast pattern.
o
=
theano
.
tensor
.
blas
.
gemv_no_inplace
(
v2
,
0.5
,
m
,
v1
,
0.25
)
o
=
theano
.
tensor
.
blas
.
gemv_no_inplace
(
v2
,
0.5
,
m
,
v1
,
0.25
)
f
=
theano
.
function
([],
o
,
mode
=
mode_blas_opt
)
f
=
theano
.
function
([],
o
,
mode
=
mode_blas_opt
)
assert
n
umpy
.
allclose
(
assert
n
p
.
allclose
(
f
(),
f
(),
0.5
*
n
umpy
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
0.25
*
v2
.
get_value
())
0.5
*
n
p
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
0.25
*
v2
.
get_value
())
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
sum
(
isinstance
(
node
.
op
,
Gemv
)
for
node
in
topo
)
==
1
assert
sum
(
isinstance
(
node
.
op
,
Gemv
)
for
node
in
topo
)
==
1
...
@@ -1277,12 +1277,12 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
...
@@ -1277,12 +1277,12 @@ class TestGemv(TestCase, unittest_tools.TestOptimizationMixin):
f
=
theano
.
function
([
A
,
x
,
y
],
z
)
f
=
theano
.
function
([
A
,
x
,
y
],
z
)
# Matrix value
# Matrix value
A_val
=
n
umpy
.
ones
((
5
,
3
),
dtype
=
config
.
floatX
)
A_val
=
n
p
.
ones
((
5
,
3
),
dtype
=
config
.
floatX
)
# Different vector length
# Different vector length
ones_3
=
n
umpy
.
ones
(
3
,
dtype
=
config
.
floatX
)
ones_3
=
n
p
.
ones
(
3
,
dtype
=
config
.
floatX
)
ones_4
=
n
umpy
.
ones
(
4
,
dtype
=
config
.
floatX
)
ones_4
=
n
p
.
ones
(
4
,
dtype
=
config
.
floatX
)
ones_5
=
n
umpy
.
ones
(
5
,
dtype
=
config
.
floatX
)
ones_5
=
n
p
.
ones
(
5
,
dtype
=
config
.
floatX
)
ones_6
=
n
umpy
.
ones
(
6
,
dtype
=
config
.
floatX
)
ones_6
=
n
p
.
ones
(
6
,
dtype
=
config
.
floatX
)
f
(
A_val
,
ones_3
,
ones_5
)
f
(
A_val
,
ones_3
,
ones_5
)
f
(
A_val
[::
-
1
,
::
-
1
],
ones_3
,
ones_5
)
f
(
A_val
[::
-
1
,
::
-
1
],
ones_3
,
ones_5
)
...
@@ -1322,7 +1322,7 @@ class BaseGemv(object):
...
@@ -1322,7 +1322,7 @@ class BaseGemv(object):
shared
=
staticmethod
(
theano
.
shared
)
shared
=
staticmethod
(
theano
.
shared
)
def
get_data
(
self
,
x_stride
=
1
,
y_stride
=
1
):
def
get_data
(
self
,
x_stride
=
1
,
y_stride
=
1
):
rng
=
n
umpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
mult
=
array
(
1
,
dtype
=
self
.
dtype
)
mult
=
array
(
1
,
dtype
=
self
.
dtype
)
if
self
.
dtype
in
[
complex64
,
complex128
]:
if
self
.
dtype
in
[
complex64
,
complex128
]:
mult
=
array
(
1
+
1
j
,
dtype
=
self
.
dtype
)
mult
=
array
(
1
+
1
j
,
dtype
=
self
.
dtype
)
...
@@ -1652,7 +1652,7 @@ class TestGer(TestCase, unittest_tools.TestOptimizationMixin):
...
@@ -1652,7 +1652,7 @@ class TestGer(TestCase, unittest_tools.TestOptimizationMixin):
return
theano
.
function
(
inputs
,
outputs
,
self
.
mode
,
updates
=
updates
)
return
theano
.
function
(
inputs
,
outputs
,
self
.
mode
,
updates
=
updates
)
def
b
(
self
,
bval
):
def
b
(
self
,
bval
):
return
T
.
as_tensor_variable
(
n
umpy
.
asarray
(
bval
,
dtype
=
self
.
dtype
))
return
T
.
as_tensor_variable
(
n
p
.
asarray
(
bval
,
dtype
=
self
.
dtype
))
def
test_b_0_triggers_ger
(
self
):
def
test_b_0_triggers_ger
(
self
):
""" test local_gemm_to_ger opt"""
""" test local_gemm_to_ger opt"""
...
@@ -1685,45 +1685,45 @@ class TestGer(TestCase, unittest_tools.TestOptimizationMixin):
...
@@ -1685,45 +1685,45 @@ class TestGer(TestCase, unittest_tools.TestOptimizationMixin):
def
test_outer
(
self
):
def
test_outer
(
self
):
f
=
self
.
function
([
self
.
x
,
self
.
y
],
T
.
outer
(
self
.
x
,
self
.
y
))
f
=
self
.
function
([
self
.
x
,
self
.
y
],
T
.
outer
(
self
.
x
,
self
.
y
))
self
.
assertFunctionContains
(
f
,
self
.
ger_destructive
)
self
.
assertFunctionContains
(
f
,
self
.
ger_destructive
)
f
(
n
umpy
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
),
f
(
n
p
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
),
n
umpy
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
))
n
p
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
))
def
test_A_plus_outer
(
self
):
def
test_A_plus_outer
(
self
):
f
=
self
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
f
=
self
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
self
.
A
+
T
.
outer
(
self
.
x
,
self
.
y
))
self
.
A
+
T
.
outer
(
self
.
x
,
self
.
y
))
self
.
assertFunctionContains
(
f
,
self
.
ger
)
self
.
assertFunctionContains
(
f
,
self
.
ger
)
f
(
n
umpy
.
random
.
rand
(
5
,
4
)
.
astype
(
self
.
dtype
),
f
(
n
p
.
random
.
rand
(
5
,
4
)
.
astype
(
self
.
dtype
),
n
umpy
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
),
n
p
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
),
n
umpy
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
))
n
p
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
))
f
(
n
umpy
.
random
.
rand
(
5
,
4
)
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
f
(
n
p
.
random
.
rand
(
5
,
4
)
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
n
umpy
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
),
n
p
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
),
n
umpy
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
))
n
p
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
))
def
test_A_plus_scaled_outer
(
self
):
def
test_A_plus_scaled_outer
(
self
):
f
=
self
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
f
=
self
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
self
.
A
+
0.1
*
T
.
outer
(
self
.
x
,
self
.
y
))
self
.
A
+
0.1
*
T
.
outer
(
self
.
x
,
self
.
y
))
self
.
assertFunctionContains
(
f
,
self
.
ger
)
self
.
assertFunctionContains
(
f
,
self
.
ger
)
f
(
n
umpy
.
random
.
rand
(
5
,
4
)
.
astype
(
self
.
dtype
),
f
(
n
p
.
random
.
rand
(
5
,
4
)
.
astype
(
self
.
dtype
),
n
umpy
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
),
n
p
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
),
n
umpy
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
))
n
p
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
))
f
(
n
umpy
.
random
.
rand
(
5
,
4
)
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
f
(
n
p
.
random
.
rand
(
5
,
4
)
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
n
umpy
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
),
n
p
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
),
n
umpy
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
))
n
p
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
))
def
test_scaled_A_plus_scaled_outer
(
self
):
def
test_scaled_A_plus_scaled_outer
(
self
):
f
=
self
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
f
=
self
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
n
umpy
.
asarray
(
0.2
,
self
.
dtype
)
*
self
.
A
+
n
p
.
asarray
(
0.2
,
self
.
dtype
)
*
self
.
A
+
n
umpy
.
asarray
(
0.1
,
self
.
dtype
)
*
T
.
outer
(
n
p
.
asarray
(
0.1
,
self
.
dtype
)
*
T
.
outer
(
self
.
x
,
self
.
y
))
self
.
x
,
self
.
y
))
# Why gemm? This make the graph simpler did we test that it
# Why gemm? This make the graph simpler did we test that it
# make it faster?
# make it faster?
self
.
assertFunctionContains
(
f
,
self
.
gemm
)
self
.
assertFunctionContains
(
f
,
self
.
gemm
)
f
(
n
umpy
.
random
.
rand
(
5
,
4
)
.
astype
(
self
.
dtype
),
f
(
n
p
.
random
.
rand
(
5
,
4
)
.
astype
(
self
.
dtype
),
n
umpy
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
),
n
p
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
),
n
umpy
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
))
n
p
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
))
f
(
n
umpy
.
random
.
rand
(
5
,
4
)
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
f
(
n
p
.
random
.
rand
(
5
,
4
)
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
n
umpy
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
),
n
p
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
),
n
umpy
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
))
n
p
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
))
def
given_dtype
(
self
,
dtype
,
M
,
N
):
def
given_dtype
(
self
,
dtype
,
M
,
N
):
""" test corner case shape and dtype"""
""" test corner case shape and dtype"""
...
@@ -1731,12 +1731,12 @@ class TestGer(TestCase, unittest_tools.TestOptimizationMixin):
...
@@ -1731,12 +1731,12 @@ class TestGer(TestCase, unittest_tools.TestOptimizationMixin):
f
=
self
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
f
=
self
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
self
.
A
+
0.1
*
T
.
outer
(
self
.
x
,
self
.
y
))
self
.
A
+
0.1
*
T
.
outer
(
self
.
x
,
self
.
y
))
self
.
assertFunctionContains
(
f
,
self
.
ger
)
self
.
assertFunctionContains
(
f
,
self
.
ger
)
f
(
n
umpy
.
random
.
rand
(
M
,
N
)
.
astype
(
self
.
dtype
),
f
(
n
p
.
random
.
rand
(
M
,
N
)
.
astype
(
self
.
dtype
),
n
umpy
.
random
.
rand
(
M
)
.
astype
(
self
.
dtype
),
n
p
.
random
.
rand
(
M
)
.
astype
(
self
.
dtype
),
n
umpy
.
random
.
rand
(
N
)
.
astype
(
self
.
dtype
))
n
p
.
random
.
rand
(
N
)
.
astype
(
self
.
dtype
))
f
(
n
umpy
.
random
.
rand
(
M
,
N
)
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
f
(
n
p
.
random
.
rand
(
M
,
N
)
.
astype
(
self
.
dtype
)[::
-
1
,
::
-
1
],
n
umpy
.
random
.
rand
(
M
)
.
astype
(
self
.
dtype
),
n
p
.
random
.
rand
(
M
)
.
astype
(
self
.
dtype
),
n
umpy
.
random
.
rand
(
N
)
.
astype
(
self
.
dtype
))
n
p
.
random
.
rand
(
N
)
.
astype
(
self
.
dtype
))
def
test_f32_0_0
(
self
):
def
test_f32_0_0
(
self
):
return
self
.
given_dtype
(
'float32'
,
0
,
0
)
return
self
.
given_dtype
(
'float32'
,
0
,
0
)
...
@@ -1769,19 +1769,19 @@ class TestGer(TestCase, unittest_tools.TestOptimizationMixin):
...
@@ -1769,19 +1769,19 @@ class TestGer(TestCase, unittest_tools.TestOptimizationMixin):
return
self
.
given_dtype
(
'complex128'
,
1
,
9
)
return
self
.
given_dtype
(
'complex128'
,
1
,
9
)
def
test_inplace
(
self
):
def
test_inplace
(
self
):
A
=
self
.
shared
(
n
umpy
.
random
.
rand
(
4
,
5
)
.
astype
(
self
.
dtype
))
A
=
self
.
shared
(
n
p
.
random
.
rand
(
4
,
5
)
.
astype
(
self
.
dtype
))
f
=
self
.
function
([
self
.
x
,
self
.
y
],
[],
f
=
self
.
function
([
self
.
x
,
self
.
y
],
[],
updates
=
[(
A
,
A
+
T
.
constant
(
0.1
,
dtype
=
self
.
dtype
)
*
updates
=
[(
A
,
A
+
T
.
constant
(
0.1
,
dtype
=
self
.
dtype
)
*
T
.
outer
(
self
.
x
,
self
.
y
))])
T
.
outer
(
self
.
x
,
self
.
y
))])
self
.
assertFunctionContains
(
f
,
self
.
ger_destructive
)
self
.
assertFunctionContains
(
f
,
self
.
ger_destructive
)
f
(
n
umpy
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
),
f
(
n
p
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
),
n
umpy
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
))
n
p
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
))
A
.
set_value
(
A
.
set_value
(
A
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)[::
-
1
,
::
-
1
],
A
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)[::
-
1
,
::
-
1
],
borrow
=
True
)
borrow
=
True
)
f
(
n
umpy
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
),
f
(
n
p
.
random
.
rand
(
4
)
.
astype
(
self
.
dtype
),
n
umpy
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
))
n
p
.
random
.
rand
(
5
)
.
astype
(
self
.
dtype
))
class
TestBlasStrides
(
TestCase
):
class
TestBlasStrides
(
TestCase
):
...
@@ -1789,13 +1789,13 @@ class TestBlasStrides(TestCase):
...
@@ -1789,13 +1789,13 @@ class TestBlasStrides(TestCase):
shared
=
staticmethod
(
tensor
.
_shared
)
shared
=
staticmethod
(
tensor
.
_shared
)
mode
=
theano
.
compile
.
get_default_mode
()
mode
=
theano
.
compile
.
get_default_mode
()
mode
=
mode
.
including
(
'fast_run'
)
.
excluding
(
'gpu'
,
'c_blas'
,
'scipy_blas'
)
mode
=
mode
.
including
(
'fast_run'
)
.
excluding
(
'gpu'
,
'c_blas'
,
'scipy_blas'
)
rng
=
n
umpy
.
random
.
RandomState
(
seed
=
unittest_tools
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
seed
=
unittest_tools
.
fetch_seed
())
def
rand
(
self
,
*
shape
):
def
rand
(
self
,
*
shape
):
return
theano
.
_asarray
(
self
.
rng
.
rand
(
*
shape
),
dtype
=
self
.
dtype
)
return
theano
.
_asarray
(
self
.
rng
.
rand
(
*
shape
),
dtype
=
self
.
dtype
)
def
cmp_dot22
(
self
,
b_shp
,
c_shp
):
def
cmp_dot22
(
self
,
b_shp
,
c_shp
):
av
=
n
umpy
.
zeros
((
0
,
0
),
dtype
=
self
.
dtype
)
av
=
n
p
.
zeros
((
0
,
0
),
dtype
=
self
.
dtype
)
bv
=
self
.
rand
(
*
b_shp
)
bv
=
self
.
rand
(
*
b_shp
)
cv
=
self
.
rand
(
*
c_shp
)
cv
=
self
.
rand
(
*
c_shp
)
...
@@ -1834,20 +1834,20 @@ class TestBlasStrides(TestCase):
...
@@ -1834,20 +1834,20 @@ class TestBlasStrides(TestCase):
c_t
.
set_value
(
ct_dev
.
copy
()[::
c_step2
,
::
c_step1
],
borrow
=
True
)
c_t
.
set_value
(
ct_dev
.
copy
()[::
c_step2
,
::
c_step1
],
borrow
=
True
)
# Numpy result
# Numpy result
a_n
=
n
umpy
.
dot
(
bv
[::
b_step1
,
::
b_step2
],
a_n
=
n
p
.
dot
(
bv
[::
b_step1
,
::
b_step2
],
cv
[::
c_step1
,
::
c_step2
])
cv
[::
c_step1
,
::
c_step2
])
f_nn
()
f_nn
()
assert
n
umpy
.
allclose
(
a
.
get_value
(),
a_n
)
assert
n
p
.
allclose
(
a
.
get_value
(),
a_n
)
f_nt
()
f_nt
()
assert
n
umpy
.
allclose
(
a
.
get_value
(),
a_n
)
assert
n
p
.
allclose
(
a
.
get_value
(),
a_n
)
f_tn
()
f_tn
()
assert
n
umpy
.
allclose
(
a
.
get_value
(),
a_n
)
assert
n
p
.
allclose
(
a
.
get_value
(),
a_n
)
f_tt
()
f_tt
()
assert
n
umpy
.
allclose
(
a
.
get_value
(),
a_n
)
assert
n
p
.
allclose
(
a
.
get_value
(),
a_n
)
def
test_dot22
(
self
):
def
test_dot22
(
self
):
self
.
cmp_dot22
((
3
,
4
),
(
4
,
5
))
self
.
cmp_dot22
((
3
,
4
),
(
4
,
5
))
...
@@ -1865,10 +1865,10 @@ class TestBlasStrides(TestCase):
...
@@ -1865,10 +1865,10 @@ class TestBlasStrides(TestCase):
self
.
cmp_dot22
((
0
,
0
),
(
0
,
0
))
self
.
cmp_dot22
((
0
,
0
),
(
0
,
0
))
def
cmp_dot22scalar
(
self
,
b_shp
,
c_shp
):
def
cmp_dot22scalar
(
self
,
b_shp
,
c_shp
):
av
=
n
umpy
.
zeros
((
0
,
0
),
dtype
=
self
.
dtype
)
av
=
n
p
.
zeros
((
0
,
0
),
dtype
=
self
.
dtype
)
bv
=
self
.
rand
(
*
b_shp
)
bv
=
self
.
rand
(
*
b_shp
)
cv
=
self
.
rand
(
*
c_shp
)
cv
=
self
.
rand
(
*
c_shp
)
l
=
n
umpy
.
float32
(
0.2
)
l
=
n
p
.
float32
(
0.2
)
a
=
self
.
shared
(
av
,
'a'
)
a
=
self
.
shared
(
av
,
'a'
)
b
=
self
.
shared
(
bv
,
'b'
)
b
=
self
.
shared
(
bv
,
'b'
)
...
@@ -1904,20 +1904,20 @@ class TestBlasStrides(TestCase):
...
@@ -1904,20 +1904,20 @@ class TestBlasStrides(TestCase):
c_t
.
set_value
(
ct_dev
.
copy
()[::
c_step2
,
::
c_step1
],
borrow
=
True
)
c_t
.
set_value
(
ct_dev
.
copy
()[::
c_step2
,
::
c_step1
],
borrow
=
True
)
# Numpy result
# Numpy result
a_n
=
l
*
n
umpy
.
dot
(
bv
[::
b_step1
,
::
b_step2
],
a_n
=
l
*
n
p
.
dot
(
bv
[::
b_step1
,
::
b_step2
],
cv
[::
c_step1
,
::
c_step2
])
cv
[::
c_step1
,
::
c_step2
])
f_nn
()
f_nn
()
assert
n
umpy
.
allclose
(
a
.
get_value
(),
a_n
)
assert
n
p
.
allclose
(
a
.
get_value
(),
a_n
)
f_nt
()
f_nt
()
assert
n
umpy
.
allclose
(
a
.
get_value
(),
a_n
)
assert
n
p
.
allclose
(
a
.
get_value
(),
a_n
)
f_tn
()
f_tn
()
assert
n
umpy
.
allclose
(
a
.
get_value
(),
a_n
)
assert
n
p
.
allclose
(
a
.
get_value
(),
a_n
)
f_tt
()
f_tt
()
assert
n
umpy
.
allclose
(
a
.
get_value
(),
a_n
)
assert
n
p
.
allclose
(
a
.
get_value
(),
a_n
)
def
test_dot22scalar
(
self
):
def
test_dot22scalar
(
self
):
self
.
cmp_dot22scalar
((
3
,
4
),
(
4
,
5
))
self
.
cmp_dot22scalar
((
3
,
4
),
(
4
,
5
))
...
@@ -1938,7 +1938,7 @@ class TestBlasStrides(TestCase):
...
@@ -1938,7 +1938,7 @@ class TestBlasStrides(TestCase):
av
=
self
.
rand
(
*
a_shp
)
av
=
self
.
rand
(
*
a_shp
)
bv
=
self
.
rand
(
*
b_shp
)
bv
=
self
.
rand
(
*
b_shp
)
cv
=
self
.
rand
(
*
c_shp
)
cv
=
self
.
rand
(
*
c_shp
)
l
=
n
umpy
.
float32
(
0.2
)
l
=
n
p
.
float32
(
0.2
)
a
=
self
.
shared
(
av
,
'a'
)
a
=
self
.
shared
(
av
,
'a'
)
b
=
self
.
shared
(
bv
,
'b'
)
b
=
self
.
shared
(
bv
,
'b'
)
...
@@ -1992,48 +1992,48 @@ class TestBlasStrides(TestCase):
...
@@ -1992,48 +1992,48 @@ class TestBlasStrides(TestCase):
# Numpy results
# Numpy results
a_n
=
(
l
*
av
[::
a_step1
,
::
a_step2
]
a_n
=
(
l
*
av
[::
a_step1
,
::
a_step2
]
+
n
umpy
.
dot
(
bv
[::
b_step1
,
::
b_step2
],
+
n
p
.
dot
(
bv
[::
b_step1
,
::
b_step2
],
cv
[::
c_step1
,
::
c_step2
]))
cv
[::
c_step1
,
::
c_step2
]))
at_n
=
(
l
*
av
[::
a_step1
,
::
a_step2
]
.
T
at_n
=
(
l
*
av
[::
a_step1
,
::
a_step2
]
.
T
+
n
umpy
.
dot
(
bv
[::
b_step1
,
::
b_step2
],
+
n
p
.
dot
(
bv
[::
b_step1
,
::
b_step2
],
cv
[::
c_step1
,
::
c_step2
])
.
T
)
cv
[::
c_step1
,
::
c_step2
])
.
T
)
# a's value is updated, so we need to reinitialize it each time
# a's value is updated, so we need to reinitialize it each time
a
.
set_value
(
a_dev
.
copy
()[::
a_step1
,
::
a_step2
],
borrow
=
True
)
a
.
set_value
(
a_dev
.
copy
()[::
a_step1
,
::
a_step2
],
borrow
=
True
)
f_nnn
()
f_nnn
()
assert
n
umpy
.
allclose
(
a
.
get_value
(),
a_n
)
assert
n
p
.
allclose
(
a
.
get_value
(),
a_n
)
a
.
set_value
(
a_dev
.
copy
()[::
a_step1
,
::
a_step2
],
borrow
=
True
)
a
.
set_value
(
a_dev
.
copy
()[::
a_step1
,
::
a_step2
],
borrow
=
True
)
f_nnt
()
f_nnt
()
assert
n
umpy
.
allclose
(
a
.
get_value
(),
a_n
)
assert
n
p
.
allclose
(
a
.
get_value
(),
a_n
)
a
.
set_value
(
a_dev
.
copy
()[::
a_step1
,
::
a_step2
],
borrow
=
True
)
a
.
set_value
(
a_dev
.
copy
()[::
a_step1
,
::
a_step2
],
borrow
=
True
)
f_ntn
()
f_ntn
()
assert
n
umpy
.
allclose
(
a
.
get_value
(),
a_n
)
assert
n
p
.
allclose
(
a
.
get_value
(),
a_n
)
a
.
set_value
(
a_dev
.
copy
()[::
a_step1
,
::
a_step2
],
borrow
=
True
)
a
.
set_value
(
a_dev
.
copy
()[::
a_step1
,
::
a_step2
],
borrow
=
True
)
f_ntt
()
f_ntt
()
assert
n
umpy
.
allclose
(
a
.
get_value
(),
a_n
)
assert
n
p
.
allclose
(
a
.
get_value
(),
a_n
)
a_t
.
set_value
(
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
a_t
.
set_value
(
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
)
borrow
=
True
)
f_tnn
()
f_tnn
()
assert
n
umpy
.
allclose
(
a_t
.
get_value
(),
at_n
)
assert
n
p
.
allclose
(
a_t
.
get_value
(),
at_n
)
a_t
.
set_value
(
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
a_t
.
set_value
(
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
)
borrow
=
True
)
f_tnt
()
f_tnt
()
assert
n
umpy
.
allclose
(
a_t
.
get_value
(),
at_n
)
assert
n
p
.
allclose
(
a_t
.
get_value
(),
at_n
)
a_t
.
set_value
(
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
a_t
.
set_value
(
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
)
borrow
=
True
)
f_ttn
()
f_ttn
()
assert
n
umpy
.
allclose
(
a_t
.
get_value
(),
at_n
)
assert
n
p
.
allclose
(
a_t
.
get_value
(),
at_n
)
a_t
.
set_value
(
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
a_t
.
set_value
(
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
)
borrow
=
True
)
f_ttt
()
f_ttt
()
assert
n
umpy
.
allclose
(
a_t
.
get_value
(),
at_n
)
assert
n
p
.
allclose
(
a_t
.
get_value
(),
at_n
)
def
test_gemm
(
self
):
def
test_gemm
(
self
):
self
.
cmp_gemm
((
3
,
5
),
(
3
,
4
),
(
4
,
5
))
self
.
cmp_gemm
((
3
,
5
),
(
3
,
4
),
(
4
,
5
))
...
@@ -2054,7 +2054,7 @@ class TestBlasStrides(TestCase):
...
@@ -2054,7 +2054,7 @@ class TestBlasStrides(TestCase):
av
=
self
.
rand
(
a_shp
)
av
=
self
.
rand
(
a_shp
)
bv
=
self
.
rand
(
*
b_shp
)
bv
=
self
.
rand
(
*
b_shp
)
cv
=
self
.
rand
(
c_shp
)
cv
=
self
.
rand
(
c_shp
)
l
=
n
umpy
.
float32
(
0.2
)
l
=
n
p
.
float32
(
0.2
)
a
=
self
.
shared
(
av
,
'a'
)
a
=
self
.
shared
(
av
,
'a'
)
b
=
self
.
shared
(
bv
,
'b'
)
b
=
self
.
shared
(
bv
,
'b'
)
...
@@ -2086,14 +2086,14 @@ class TestBlasStrides(TestCase):
...
@@ -2086,14 +2086,14 @@ class TestBlasStrides(TestCase):
c
.
set_value
(
c_dev
.
copy
()[::
c_step
],
borrow
=
True
)
c
.
set_value
(
c_dev
.
copy
()[::
c_step
],
borrow
=
True
)
a_n
=
(
av
[::
a_step
]
a_n
=
(
av
[::
a_step
]
+
l
*
n
umpy
.
dot
(
bv
[::
b_step1
,
::
b_step2
],
+
l
*
n
p
.
dot
(
bv
[::
b_step1
,
::
b_step2
],
cv
[::
c_step
]))
cv
[::
c_step
]))
f_n
()
f_n
()
assert
n
umpy
.
allclose
(
a
.
get_value
(),
a_n
),
(
a
.
get_value
(),
a_n
)
assert
n
p
.
allclose
(
a
.
get_value
(),
a_n
),
(
a
.
get_value
(),
a_n
)
a
.
set_value
(
a_dev
.
copy
()[::
a_step
],
borrow
=
True
)
a
.
set_value
(
a_dev
.
copy
()[::
a_step
],
borrow
=
True
)
f_t
()
f_t
()
assert
n
umpy
.
allclose
(
a
.
get_value
(),
a_n
),
(
a
.
get_value
(),
a_n
)
assert
n
p
.
allclose
(
a
.
get_value
(),
a_n
),
(
a
.
get_value
(),
a_n
)
def
test_gemv
(
self
):
def
test_gemv
(
self
):
self
.
cmp_gemv
(
3
,
(
3
,
5
),
5
)
self
.
cmp_gemv
(
3
,
(
3
,
5
),
5
)
...
@@ -2109,7 +2109,7 @@ class TestBlasStrides(TestCase):
...
@@ -2109,7 +2109,7 @@ class TestBlasStrides(TestCase):
av
=
self
.
rand
(
*
a_shp
)
av
=
self
.
rand
(
*
a_shp
)
bv
=
self
.
rand
(
b_shp
)
bv
=
self
.
rand
(
b_shp
)
cv
=
self
.
rand
(
c_shp
)
cv
=
self
.
rand
(
c_shp
)
l
=
n
umpy
.
float32
(
0.2
)
l
=
n
p
.
float32
(
0.2
)
a
=
self
.
shared
(
av
,
'a'
)
a
=
self
.
shared
(
av
,
'a'
)
b
=
self
.
shared
(
bv
,
'b'
)
b
=
self
.
shared
(
bv
,
'b'
)
...
@@ -2142,13 +2142,13 @@ class TestBlasStrides(TestCase):
...
@@ -2142,13 +2142,13 @@ class TestBlasStrides(TestCase):
f_n
()
f_n
()
n_n
=
(
av
[::
a_step1
,
::
a_step2
]
n_n
=
(
av
[::
a_step1
,
::
a_step2
]
+
l
*
n
umpy
.
outer
(
bv
[::
b_step
],
cv
[::
c_step
]))
+
l
*
n
p
.
outer
(
bv
[::
b_step
],
cv
[::
c_step
]))
assert
n
umpy
.
allclose
(
a
.
get_value
(),
n_n
),
(
a
.
get_value
(),
n_n
)
assert
n
p
.
allclose
(
a
.
get_value
(),
n_n
),
(
a
.
get_value
(),
n_n
)
f_t
()
f_t
()
n_t
=
(
av
.
T
[::
a_step1
,
::
a_step2
]
n_t
=
(
av
.
T
[::
a_step1
,
::
a_step2
]
+
l
*
n
umpy
.
outer
(
bv
[::
b_step
],
cv
[::
c_step
])
.
T
)
+
l
*
n
p
.
outer
(
bv
[::
b_step
],
cv
[::
c_step
])
.
T
)
assert
n
umpy
.
allclose
(
a_t
.
get_value
(),
n_t
),
\
assert
n
p
.
allclose
(
a_t
.
get_value
(),
n_t
),
\
(
a_t
.
get_value
(),
n_t
)
(
a_t
.
get_value
(),
n_t
)
def
test_ger_strides
(
self
):
def
test_ger_strides
(
self
):
...
@@ -2163,9 +2163,9 @@ class TestBlasStrides(TestCase):
...
@@ -2163,9 +2163,9 @@ class TestBlasStrides(TestCase):
def
test_gemm_non_contiguous
(
self
):
def
test_gemm_non_contiguous
(
self
):
"""test_gemm_non_contiguous: Test if GEMM works well with non-contiguous matrices."""
"""test_gemm_non_contiguous: Test if GEMM works well with non-contiguous matrices."""
aval
=
n
umpy
.
ones
((
6
,
2
))
aval
=
n
p
.
ones
((
6
,
2
))
bval
=
n
umpy
.
ones
((
2
,
7
))
bval
=
n
p
.
ones
((
2
,
7
))
cval
=
n
umpy
.
arange
(
7
)
+
numpy
.
arange
(
0
,
.
6
,
.
1
)[:,
numpy
.
newaxis
]
cval
=
n
p
.
arange
(
7
)
+
np
.
arange
(
0
,
.
6
,
.
1
)[:,
np
.
newaxis
]
a
=
theano
.
shared
(
aval
[:
3
],
borrow
=
True
)
a
=
theano
.
shared
(
aval
[:
3
],
borrow
=
True
)
b
=
theano
.
shared
(
bval
[:,
:
5
],
borrow
=
True
)
b
=
theano
.
shared
(
bval
[:,
:
5
],
borrow
=
True
)
...
@@ -2176,7 +2176,7 @@ class TestBlasStrides(TestCase):
...
@@ -2176,7 +2176,7 @@ class TestBlasStrides(TestCase):
f
=
theano
.
function
([
s
],
[],
updates
=
{
c
:
upd_c
})
f
=
theano
.
function
([
s
],
[],
updates
=
{
c
:
upd_c
})
f
(
0
)
f
(
0
)
ref_output
=
n
umpy
.
ones
((
3
,
5
))
*
2
ref_output
=
n
p
.
ones
((
3
,
5
))
*
2
unittest_tools
.
assert_allclose
(
c
.
get_value
(),
ref_output
)
unittest_tools
.
assert_allclose
(
c
.
get_value
(),
ref_output
)
...
@@ -2185,8 +2185,8 @@ class test_infer_shape(unittest_tools.InferShapeTester):
...
@@ -2185,8 +2185,8 @@ class test_infer_shape(unittest_tools.InferShapeTester):
x
,
y
=
T
.
matrices
(
'xy'
)
x
,
y
=
T
.
matrices
(
'xy'
)
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
x
,
y
],
[
T
.
blas
.
_dot22
(
x
,
y
)],
[
x
,
y
],
[
T
.
blas
.
_dot22
(
x
,
y
)],
[
n
umpy
.
random
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
[
n
p
.
random
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
n
umpy
.
random
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
)],
n
p
.
random
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
)],
T
.
blas
.
Dot22
)
T
.
blas
.
Dot22
)
def
test_dot22scalar
(
self
):
def
test_dot22scalar
(
self
):
...
@@ -2194,9 +2194,9 @@ class test_infer_shape(unittest_tools.InferShapeTester):
...
@@ -2194,9 +2194,9 @@ class test_infer_shape(unittest_tools.InferShapeTester):
a
=
T
.
scalar
(
'a'
)
a
=
T
.
scalar
(
'a'
)
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
x
,
y
,
a
],
[
T
.
blas
.
_dot22scalar
(
x
,
y
,
a
)],
[
x
,
y
,
a
],
[
T
.
blas
.
_dot22scalar
(
x
,
y
,
a
)],
[
n
umpy
.
random
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
[
n
p
.
random
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
n
umpy
.
random
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
),
n
p
.
random
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
),
n
umpy
.
asarray
(
0.5
,
dtype
=
config
.
floatX
)],
n
p
.
asarray
(
0.5
,
dtype
=
config
.
floatX
)],
T
.
blas
.
Dot22Scalar
)
T
.
blas
.
Dot22Scalar
)
def
test_gemm
(
self
):
def
test_gemm
(
self
):
...
@@ -2205,11 +2205,11 @@ class test_infer_shape(unittest_tools.InferShapeTester):
...
@@ -2205,11 +2205,11 @@ class test_infer_shape(unittest_tools.InferShapeTester):
b
=
T
.
scalar
(
'b'
)
b
=
T
.
scalar
(
'b'
)
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
x
,
y
,
a
,
z
,
b
],
[
T
.
blas
.
gemm
(
z
,
a
,
x
,
y
,
b
)],
[
x
,
y
,
a
,
z
,
b
],
[
T
.
blas
.
gemm
(
z
,
a
,
x
,
y
,
b
)],
[
n
umpy
.
random
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
[
n
p
.
random
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
n
umpy
.
random
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
),
n
p
.
random
.
random
((
3
,
4
))
.
astype
(
config
.
floatX
),
n
umpy
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
n
p
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
n
umpy
.
random
.
random
((
2
,
4
))
.
astype
(
config
.
floatX
),
n
p
.
random
.
random
((
2
,
4
))
.
astype
(
config
.
floatX
),
n
umpy
.
asarray
(
0.5
,
dtype
=
config
.
floatX
)],
n
p
.
asarray
(
0.5
,
dtype
=
config
.
floatX
)],
T
.
blas
.
Gemm
)
T
.
blas
.
Gemm
)
def
test_gemv
(
self
):
def
test_gemv
(
self
):
...
@@ -2219,11 +2219,11 @@ class test_infer_shape(unittest_tools.InferShapeTester):
...
@@ -2219,11 +2219,11 @@ class test_infer_shape(unittest_tools.InferShapeTester):
b
=
T
.
scalar
(
'b'
)
b
=
T
.
scalar
(
'b'
)
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
y
,
a
,
A
,
x
,
b
],
[
T
.
blas
.
gemv
(
y
,
a
,
A
,
x
,
b
)],
[
y
,
a
,
A
,
x
,
b
],
[
T
.
blas
.
gemv
(
y
,
a
,
A
,
x
,
b
)],
[
n
umpy
.
random
.
random
((
2
,))
.
astype
(
config
.
floatX
),
[
n
p
.
random
.
random
((
2
,))
.
astype
(
config
.
floatX
),
n
umpy
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
n
p
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
n
umpy
.
random
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
n
p
.
random
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
n
umpy
.
random
.
random
((
3
,))
.
astype
(
config
.
floatX
),
n
p
.
random
.
random
((
3
,))
.
astype
(
config
.
floatX
),
n
umpy
.
asarray
(
0.5
,
dtype
=
config
.
floatX
)],
n
p
.
asarray
(
0.5
,
dtype
=
config
.
floatX
)],
T
.
blas
.
Gemv
)
T
.
blas
.
Gemv
)
def
test_ger
(
self
):
def
test_ger
(
self
):
...
@@ -2232,8 +2232,8 @@ class test_infer_shape(unittest_tools.InferShapeTester):
...
@@ -2232,8 +2232,8 @@ class test_infer_shape(unittest_tools.InferShapeTester):
a
=
T
.
scalar
(
'a'
)
a
=
T
.
scalar
(
'a'
)
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
A
,
a
,
x
,
y
],
[
T
.
blas
.
ger
(
A
,
a
,
x
,
y
)],
[
A
,
a
,
x
,
y
],
[
T
.
blas
.
ger
(
A
,
a
,
x
,
y
)],
[
n
umpy
.
random
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
[
n
p
.
random
.
random
((
2
,
3
))
.
astype
(
config
.
floatX
),
n
umpy
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
n
p
.
asarray
(
0.5
,
dtype
=
config
.
floatX
),
n
umpy
.
random
.
random
((
2
,))
.
astype
(
config
.
floatX
),
n
p
.
random
.
random
((
2
,))
.
astype
(
config
.
floatX
),
n
umpy
.
random
.
random
((
3
,))
.
astype
(
config
.
floatX
)],
n
p
.
random
.
random
((
3
,))
.
astype
(
config
.
floatX
)],
T
.
blas
.
Ger
)
T
.
blas
.
Ger
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论