Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8451a929
提交
8451a929
authored
8月 10, 2011
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adding scipy version of Ger
It's a little faster than the numpy implementation, but not much.
上级
e105f562
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
96 行增加
和
5 行删除
+96
-5
__init__.py
theano/tensor/__init__.py
+1
-0
blas.py
theano/tensor/blas.py
+6
-5
blas_scipy.py
theano/tensor/blas_scipy.py
+89
-0
没有找到文件。
theano/tensor/__init__.py
浏览文件 @
8451a929
...
@@ -6,6 +6,7 @@ from basic import *
...
@@ -6,6 +6,7 @@ from basic import *
import
opt
import
opt
import
opt_uncanonicalize
import
opt_uncanonicalize
import
blas
import
blas
import
blas_scipy
import
xlogx
import
xlogx
import
raw_random
,
randomstreams
import
raw_random
,
randomstreams
...
...
theano/tensor/blas.py
浏览文件 @
8451a929
...
@@ -238,9 +238,9 @@ class Ger(Op):
...
@@ -238,9 +238,9 @@ class Ger(Op):
def
__str__
(
self
):
def
__str__
(
self
):
if
self
.
destructive
:
if
self
.
destructive
:
return
'
Ger{destructive}'
return
'
%
s{destructive}'
%
self
.
__class__
.
__name__
else
:
else
:
return
'
Ger{non-destructive}'
return
'
%
s{non-destructive}'
%
self
.
__class__
.
__name__
def
make_node
(
self
,
A
,
alpha
,
x
,
y
):
def
make_node
(
self
,
A
,
alpha
,
x
,
y
):
A
=
T
.
as_tensor_variable
(
A
)
A
=
T
.
as_tensor_variable
(
A
)
...
@@ -1418,11 +1418,12 @@ blas_optdb.register('local_gemm_to_gemv',
...
@@ -1418,11 +1418,12 @@ blas_optdb.register('local_gemm_to_gemv',
# After destroyhandler is in but before we try to make elemwise things inplace
# After destroyhandler is in but before we try to make elemwise things inplace
# Try to make gemm inplace
# Try to make gemm inplace
# Also, need to make the gemm optimisation(step 70) happen before the fusion of elemwise(step 71)
# Also, need to make the gemm optimisation(step 70) happen before the fusion of elemwise(step 71)
optdb
.
register
(
'InplaceBlasOpt'
,
blas_opt_inplace
=
EquilibriumOptimizer
(
EquilibriumOptimizer
(
[
local_inplace_gemm
,
local_inplace_gemv
,
local_inplace_ger
],
[
local_inplace_gemm
,
local_inplace_gemv
,
local_inplace_ger
],
failure_callback
=
EquilibriumOptimizer
.
warn_inplace
,
failure_callback
=
EquilibriumOptimizer
.
warn_inplace
,
max_use_ratio
=
5
),
max_use_ratio
=
5
)
optdb
.
register
(
'InplaceBlasOpt'
,
blas_opt_inplace
,
70.0
,
'fast_run'
,
'inplace'
)
70.0
,
'fast_run'
,
'inplace'
)
class
Dot22Scalar
(
GemmRelated
):
class
Dot22Scalar
(
GemmRelated
):
...
...
theano/tensor/blas_scipy.py
0 → 100644
浏览文件 @
8451a929
"""
Implementations of BLAS Ops based on scipy's BLAS bindings.
"""
import
numpy
from
blas
import
Ger
,
ger
,
ger_destructive
from
blas
import
Gemv
from
blas
import
Gemm
from
blas
import
blas_optdb
,
optdb
,
local_optimizer
,
EquilibriumOptimizer
try
:
import
scipy.linalg.blas
have_fblas
=
True
_blas_gemv_fns
=
{
numpy
.
dtype
(
'float32'
):
scipy
.
linalg
.
blas
.
fblas
.
sgemv
,
numpy
.
dtype
(
'float64'
):
scipy
.
linalg
.
blas
.
fblas
.
dgemv
,
numpy
.
dtype
(
'complex64'
):
scipy
.
linalg
.
blas
.
fblas
.
cgemv
,
numpy
.
dtype
(
'complex128'
):
scipy
.
linalg
.
blas
.
fblas
.
zgemv
,
}
_blas_ger_fns
=
{
numpy
.
dtype
(
'float32'
):
scipy
.
linalg
.
blas
.
fblas
.
sger
,
numpy
.
dtype
(
'float64'
):
scipy
.
linalg
.
blas
.
fblas
.
dger
,
#numpy.dtype('complex64'):scipy.linalg.blas.fblas.cger,
#numpy.dtype('complex128'):scipy.linalg.blas.fblas.zger,
}
except
ImportError
,
e
:
have_fblas
=
False
class
ScipyGer
(
Ger
):
# keep everything else, but override the make_thunk
def
make_thunk
(
self
,
node
,
storage_map
,
compute_map
,
no_recycling
):
node_input_storage
=
[
storage_map
[
r
]
for
r
in
node
.
inputs
]
node_output_storage
=
[
storage_map
[
r
]
for
r
in
node
.
outputs
]
# get vars for containers
cA
,
calpha
,
cx
,
cy
=
node_input_storage
cZ
,
=
node_output_storage
local_ger
=
_blas_ger_fns
[
numpy
.
dtype
(
node
.
inputs
[
0
]
.
type
.
dtype
)]
def
rval
():
# N.B. some versions of scipy (e.g. mine) don't actually work
# in-place on a, even when I tell it to.
A
=
local_ger
(
calpha
[
0
],
cx
[
0
],
cy
[
0
],
a
=
cA
[
0
],
overwrite_a
=
int
(
self
.
destructive
))
cZ
[
0
]
=
A
#TODO: If this is currently an unofficial part of the thunk API,
# then maybe it should be documented and made official?
rval
.
inputs
=
node_input_storage
rval
.
outputs
=
node_output_storage
rval
.
lazy
=
False
return
rval
@local_optimizer
([
ger
,
ger_destructive
])
def
use_scipy_ger
(
node
):
if
node
.
op
==
ger
:
return
[
ScipyGer
(
False
)(
*
node
.
inputs
)]
@local_optimizer
([
ScipyGer
(
False
)])
def
make_ger_destructive
(
node
):
if
node
.
op
==
ScipyGer
(
False
):
return
[
ScipyGer
(
True
)(
*
node
.
inputs
)]
use_scipy_blas
=
EquilibriumOptimizer
(
[
use_scipy_ger
],
max_use_ratio
=
5
)
make_scipy_blas_destructive
=
EquilibriumOptimizer
(
[
make_ger_destructive
],
max_use_ratio
=
5
)
if
have_fblas
:
# scipy_blas is scheduled in the blas_optdb very late, because scipy sortof
# sucks, but it is almost always present.
# C implementations should be scheduled earlier than this, so that they take
# precedence. Once the original Ger is replaced, then these optimizations
# have no effect.
blas_optdb
.
register
(
'scipy_blas'
,
use_scipy_blas
,
100
,
'fast_run'
)
# this matches the InplaceBlasOpt defined in blas.py
optdb
.
register
(
'make_scipy_blas_destructive'
,
make_scipy_blas_destructive
,
70.0
,
'fast_run'
,
'inplace'
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论