Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
783834f2
提交
783834f2
authored
9月 30, 2011
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make dot22scalar work in python with complex.
上级
db8bf96d
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
65 行增加
和
29 行删除
+65
-29
blas.py
theano/tensor/blas.py
+11
-2
test_blas.py
theano/tensor/tests/test_blas.py
+54
-27
没有找到文件。
theano/tensor/blas.py
浏览文件 @
783834f2
...
@@ -1503,6 +1503,9 @@ class Dot22Scalar(GemmRelated):
...
@@ -1503,6 +1503,9 @@ class Dot22Scalar(GemmRelated):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
#DEBUG
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
#DEBUG
_x
,
_y
,
_a
=
inp
_x
,
_y
,
_a
=
inp
_zout
,
=
out
_zout
,
=
out
if
node
.
inputs
[
0
]
.
type
.
dtype
.
startswith
(
'complex'
):
raise
utils
.
MethodNotDefined
(
'
%
s.c_code'
\
%
self
.
__class__
.
__name__
)
if
len
(
self
.
c_libraries
())
<=
0
:
if
len
(
self
.
c_libraries
())
<=
0
:
return
super
(
Dot22Scalar
,
self
)
.
c_code
(
node
,
name
,
(
_x
,
_y
),
(
_zout
,
),
sub
)
return
super
(
Dot22Scalar
,
self
)
.
c_code
(
node
,
name
,
(
_x
,
_y
),
(
_zout
,
),
sub
)
full_code
=
self
.
build_gemm_call
()
%
dict
(
locals
(),
**
sub
)
full_code
=
self
.
build_gemm_call
()
%
dict
(
locals
(),
**
sub
)
...
@@ -1551,12 +1554,18 @@ def local_dot22_to_dot22scalar(node):
...
@@ -1551,12 +1554,18 @@ def local_dot22_to_dot22scalar(node):
m
=
node
.
inputs
[
mul_idx
]
m
=
node
.
inputs
[
mul_idx
]
if
len
(
m
.
owner
.
inputs
)
==
2
and
any
([
_as_scalar
(
x
)
for
x
in
m
.
owner
.
inputs
]):
if
len
(
m
.
owner
.
inputs
)
==
2
and
any
([
_as_scalar
(
x
)
for
x
in
m
.
owner
.
inputs
]):
scalar_idx
=
0
scalar_idx
=
-
1
for
i
,
x
in
enumerate
(
m
.
owner
.
inputs
):
for
i
,
x
in
enumerate
(
m
.
owner
.
inputs
):
if
_as_scalar
(
x
):
if
_as_scalar
(
x
)
and
(
theano
.
scalar
.
upcast
(
x
.
type
.
dtype
,
d
.
type
.
dtype
)
==
d
.
type
.
dtype
):
scalar_idx
=
i
scalar_idx
=
i
break
break
if
scalar_idx
<
0
:
_logger
.
info
(
'Not optimizing dot22 with inputs
%
s
%
s, as the type '
'of the scalar cannot be upcasted to the matrix type'
,
node
.
inputs
,
[
x
.
type
for
x
in
node
.
inputs
])
return
False
a
=
T
.
cast
(
_as_scalar
(
m
.
owner
.
inputs
[
scalar_idx
]),
d
.
type
.
dtype
)
a
=
T
.
cast
(
_as_scalar
(
m
.
owner
.
inputs
[
scalar_idx
]),
d
.
type
.
dtype
)
assert
not
a
.
type
.
ndim
assert
not
a
.
type
.
ndim
dot
=
_dot22scalar
(
d
.
owner
.
inputs
[
0
],
d
.
owner
.
inputs
[
1
],
a
)
dot
=
_dot22scalar
(
d
.
owner
.
inputs
[
0
],
d
.
owner
.
inputs
[
1
],
a
)
...
...
theano/tensor/tests/test_blas.py
浏览文件 @
783834f2
...
@@ -704,53 +704,81 @@ def test_dot22scalar():
...
@@ -704,53 +704,81 @@ def test_dot22scalar():
## TODO: exclude other optimizations in BlasOpt?
## TODO: exclude other optimizations in BlasOpt?
#m = theano.compile.get_default_mode().including('local_dot_to_dot22','local_dot22_to_dot22scalar','specialize')
#m = theano.compile.get_default_mode().including('local_dot_to_dot22','local_dot22_to_dot22scalar','specialize')
#m = theano.compile.get_default_mode().including('BlasOpt', 'specialize')
#m = theano.compile.get_default_mode().including('BlasOpt', 'specialize')
a
=
T
.
matrix
()
b
=
T
.
matrix
()
c
=
T
.
matrix
()
rng
=
numpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
for
dtype1
in
[
'complex64'
,
'complex128'
]:
a
=
T
.
matrix
(
'a'
,
dtype
=
dtype1
)
for
dtype2
in
[
'complex64'
,
'complex128'
]:
b
=
T
.
matrix
(
'b'
,
dtype
=
dtype2
)
for
dtype3
in
[
'complex64'
,
'complex128'
]:
c
=
T
.
matrix
(
'c'
,
dtype
=
dtype3
)
for
dtype4
in
[
'complex64'
,
'complex128'
]:
cst
=
theano
.
tensor
.
basic
.
constant
(
.
2
,
dtype
=
dtype4
)
cst2
=
theano
.
tensor
.
basic
.
constant
(
.
1
,
dtype
=
dtype4
)
def
check_dot22scalar
(
func
,
len_topo_scalar
=-
1
):
topo
=
func
.
maker
.
env
.
toposort
()
ops
=
[
x
.
op
for
x
in
topo
]
dtype4_upcast
=
theano
.
scalar
.
upcast
(
dtype4
,
dtype1
,
dtype2
)
if
dtype1
==
dtype2
==
dtype3
==
dtype4_upcast
:
if
len_topo_scalar
>
0
:
assert
len
(
topo
)
==
len_topo_scalar
assert
_dot22scalar
in
ops
,
(
dtype1
,
dtype2
,
dtype3
,
dtype4
)
elif
dtype1
==
dtype2
==
dtype4_upcast
:
if
not
(
len_topo_scalar
>
0
):
assert
len
(
topo
)
==
len_topo_scalar
assert
_dot22scalar
in
ops
,
(
dtype1
,
dtype2
,
dtype3
,
dtype4
)
else
:
# Currently there is a problem of optimization order
# The constant get upcasted to float64 before we try to merge it
# with the dot22 of float32. So this prevent the merge.
assert
_dot22scalar
in
ops
or
_dot22
in
ops
,
(
dtype1
,
dtype2
,
dtype3
,
dtype4
)
elif
dtype1
==
dtype2
:
assert
_dot22
in
ops
,
(
dtype1
,
dtype2
,
dtype3
,
dtype4
)
else
:
assert
T
.
dot
in
ops
,
(
dtype1
,
dtype2
,
dtype3
,
dtype4
)
def
cmp
(
a_shp
,
b_shp
,
c_shp
,
sqr_shp
=
(
5
,
5
)):
def
cmp
(
a_shp
,
b_shp
,
c_shp
,
sqr_shp
=
(
5
,
5
)):
av
=
rng
.
uniform
(
size
=
a_shp
)
.
astype
(
config
.
floatX
)
av
=
rng
.
uniform
(
size
=
a_shp
)
.
astype
(
dtype1
)
bv
=
rng
.
uniform
(
size
=
b_shp
)
.
astype
(
config
.
floatX
)
bv
=
rng
.
uniform
(
size
=
b_shp
)
.
astype
(
dtype2
)
cv
=
rng
.
uniform
(
size
=
c_shp
)
.
astype
(
config
.
floatX
)
cv
=
rng
.
uniform
(
size
=
c_shp
)
.
astype
(
dtype3
)
sv
=
rng
.
uniform
(
size
=
sqr_shp
)
.
astype
(
config
.
floatX
)
sv
=
rng
.
uniform
(
size
=
sqr_shp
)
.
astype
(
dtype1
)
if
Tru
e
:
if
Fals
e
:
f
=
theano
.
function
([
a
,
b
],
0.2
*
T
.
dot
(
a
,
b
),
mode
=
mode_blas_opt
)
f
=
theano
.
function
([
a
,
b
],
cst
*
T
.
dot
(
a
,
b
),
mode
=
mode_blas_opt
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
_dot22scalar
in
[
x
.
op
for
x
in
topo
]
check_dot22scalar
(
f
,
1
)
assert
len
(
topo
)
==
1
f
(
av
,
bv
)
f
(
av
,
bv
)
if
True
:
if
True
:
f
=
theano
.
function
([
a
,
b
,
c
],
0.2
*
c
*
T
.
dot
(
a
,
b
),
mode
=
mode_blas_opt
)
f
=
theano
.
function
([
a
,
b
,
c
],
cst
*
c
*
T
.
dot
(
a
,
b
),
mode
=
mode_blas_opt
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
_dot22scalar
in
[
x
.
op
for
x
in
topo
]
check_dot22scalar
(
f
,
2
)
assert
len
(
topo
)
==
2
f
(
av
,
bv
,
cv
)
f
(
av
,
bv
,
cv
)
f
=
theano
.
function
([
a
,
b
,
c
],
c
*
0.2
*
T
.
dot
(
a
,
b
),
mode
=
mode_blas_opt
)
f
=
theano
.
function
([
a
,
b
,
c
],
c
*
cst
*
T
.
dot
(
a
,
b
),
mode
=
mode_blas_opt
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
_dot22scalar
in
[
x
.
op
for
x
in
topo
]
check_dot22scalar
(
f
,
2
)
assert
len
(
topo
)
==
2
f
(
av
,
bv
,
cv
)
f
(
av
,
bv
,
cv
)
## Here, canonicalize also seems needed
## Here, canonicalize also seems needed
## TODO: add only the optimizations needed?
## TODO: add only the optimizations needed?
m2
=
mode_blas_opt
.
including
(
'canonicalize'
)
m2
=
mode_blas_opt
.
including
(
'canonicalize'
)
f
=
theano
.
function
([
a
,
b
,
c
],
0.1
*
c
*
0.2
*
T
.
dot
(
a
,
b
),
mode
=
m2
)
f
=
theano
.
function
([
a
,
b
,
c
],
cst2
*
c
*
cst
*
T
.
dot
(
a
,
b
),
mode
=
m2
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
_dot22scalar
in
[
x
.
op
for
x
in
topo
]
check_dot22scalar
(
f
,
2
)
assert
len
(
topo
)
==
2
f
(
av
,
bv
,
cv
)
f
(
av
,
bv
,
cv
)
f
=
theano
.
function
([
a
,
b
,
c
],
c
*
0.2
*
a
*
T
.
dot
(
a
,
b
),
mode
=
m2
)
if
dtype1
==
dtype2
==
dtype3
:
f
=
theano
.
function
([
a
,
b
,
c
],
c
*
cst
*
a
*
T
.
dot
(
a
,
b
),
mode
=
m2
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
_dot22scalar
in
[
x
.
op
for
x
in
topo
]
check_dot22scalar
(
f
,
2
)
assert
len
(
topo
)
==
2
f
(
sv
,
sv
,
sv
)
f
(
sv
,
sv
,
sv
)
f
=
theano
.
function
([
a
,
b
,
c
],
0.2
*
c
*
a
*
T
.
dot
(
a
,
b
),
mode
=
mode_blas_opt
)
f
=
theano
.
function
([
a
,
b
,
c
],
cst
*
c
*
a
*
T
.
dot
(
a
,
b
),
mode
=
mode_blas_opt
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
#currently the canonizer don't always merge all Mul together...
#currently the canonizer don't always merge all Mul together...
# dot22scalar optimizer does not do a recursive search
# dot22scalar optimizer does not do a recursive search
...
@@ -761,10 +789,9 @@ def test_dot22scalar():
...
@@ -761,10 +789,9 @@ def test_dot22scalar():
# assert len(topo)==2
# assert len(topo)==2
f
(
sv
,
sv
,
sv
)
f
(
sv
,
sv
,
sv
)
f
=
theano
.
function
([
a
,
b
,
c
],
c
*
a
*
0.2
*
T
.
dot
(
a
,
b
),
mode
=
m2
)
f
=
theano
.
function
([
a
,
b
,
c
],
c
*
a
*
cst
*
T
.
dot
(
a
,
b
),
mode
=
m2
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
_dot22scalar
in
[
x
.
op
for
x
in
topo
]
check_dot22scalar
(
f
,
2
)
assert
len
(
topo
)
==
2
f
(
sv
,
sv
,
sv
)
f
(
sv
,
sv
,
sv
)
cmp
((
3
,
4
),(
4
,
5
),(
3
,
5
))
cmp
((
3
,
4
),(
4
,
5
),(
3
,
5
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论