Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
77a2fd51
提交
77a2fd51
authored
6月 27, 2017
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add params to Gemm op.
上级
9db9d791
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
16 行增加
和
11 行删除
+16
-11
blas.py
theano/tensor/blas.py
+16
-11
没有找到文件。
theano/tensor/blas.py
浏览文件 @
77a2fd51
...
...
@@ -145,9 +145,11 @@ from theano.gof import (utils, Op, view_roots,
InconsistencyError
,
toolbox
,
SequenceDB
,
EquilibriumOptimizer
,
Apply
,
ReplacementDidntRemovedError
)
from
theano.gof.params_type
import
ParamsType
from
theano.printing
import
pprint
,
FunctionPrinter
,
debugprint
from
theano.compile.mode
import
optdb
import
theano.scalar
from
theano.scalar
import
bool
as
bool_t
from
theano.tensor
import
basic
as
T
from
theano.tensor.blas_headers
import
blas_header_text
from
theano.tensor.blas_headers
import
blas_header_version
...
...
@@ -522,7 +524,11 @@ class GemmRelated(Op):
int sx_0, sx_1, sy_0, sy_1, sz_0, sz_1;
"""
# implement if you don't have an inplace props
# setup_z_Nz_Sz = None
# otherwise implement
# setup_z_Nz_Sz_inplace = None
# setup_z_Nz_Sz_outplace = None
check_xyz_rank2
=
"""
if (PyArray_NDIM(
%(_x)
s) != 2) {
...
...
@@ -755,11 +761,16 @@ class GemmRelated(Op):
"""
def
build_gemm_call
(
self
):
if
hasattr
(
self
,
'inplace'
):
setup_z_Nz_Sz
=
"if(
%%(params)
s->inplace){
%
s}else{
%
s}"
%
(
self
.
setup_z_Nz_Sz_inplace
,
self
.
setup_z_Nz_Sz_outplace
)
else
:
setup_z_Nz_Sz
=
self
.
setup_z_Nz_Sz
return
reduce
(
str
.
__add__
,
(
self
.
declare_NS
,
self
.
check_xyz_rank2
,
se
lf
.
se
tup_z_Nz_Sz
,
setup_z_Nz_Sz
,
self
.
check_xyz_double_or_float
,
self
.
check_ab_double_or_float
,
self
.
check_dims
,
...
...
@@ -809,14 +820,12 @@ class Gemm(GemmRelated):
E_float
=
'gemm requires floating-point dtypes'
__props__
=
(
'inplace'
,)
params_type
=
ParamsType
(
inplace
=
bool_t
,)
def
__init__
(
self
,
inplace
):
self
.
inplace
=
inplace
if
self
.
inplace
:
self
.
destroy_map
=
{
0
:
[
0
]}
self
.
setup_z_Nz_Sz
=
self
.
setup_z_Nz_Sz_inplace
else
:
self
.
setup_z_Nz_Sz
=
self
.
setup_z_Nz_Sz_outplace
def
__str__
(
self
):
if
self
.
inplace
:
...
...
@@ -827,10 +836,6 @@ class Gemm(GemmRelated):
def
__setstate__
(
self
,
dct
):
self
.
__dict__
.
update
(
dct
)
if
self
.
inplace
:
self
.
setup_z_Nz_Sz
=
self
.
setup_z_Nz_Sz_inplace
else
:
self
.
setup_z_Nz_Sz
=
self
.
setup_z_Nz_Sz_outplace
# Correctly reload older pickles where destroy_map were not
# saved
...
...
@@ -841,7 +846,7 @@ class Gemm(GemmRelated):
rval
=
self
.
__dict__
.
copy
()
# Do not serialize the setup code, it will be restored in __setstate__
# depending on the value of 'inplace'
rval
.
pop
(
'setup_z_Nz_Sz'
)
rval
.
pop
(
'setup_z_Nz_Sz'
,
None
)
return
rval
def
make_node
(
self
,
*
inputs
):
...
...
@@ -892,12 +897,12 @@ class Gemm(GemmRelated):
output
=
z
.
type
()
return
Apply
(
self
,
inputs
,
[
output
])
def
perform
(
self
,
node
,
inp
,
out
):
def
perform
(
self
,
node
,
inp
,
out
,
params
):
z
,
a
,
x
,
y
,
b
=
inp
zout
,
=
out
assert
a
.
shape
==
()
assert
b
.
shape
==
()
if
not
self
.
inplace
:
if
not
params
.
inplace
:
z
=
z
.
copy
()
# the original z will not be changed
if
z
.
shape
==
():
z
.
itemset
(
z
*
a
+
b
*
np
.
dot
(
x
,
y
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论