Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
04b21e34
提交
04b21e34
authored
3月 25, 2017
作者:
amrithasuresh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reverted np as numpy
上级
cc6a5c7b
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
29 行增加
和
29 行删除
+29
-29
blas.py
theano/tensor/blas.py
+29
-29
没有找到文件。
theano/tensor/blas.py
浏览文件 @
04b21e34
...
@@ -130,7 +130,7 @@ import logging
...
@@ -130,7 +130,7 @@ import logging
import
os
import
os
import
time
import
time
import
numpy
as
np
import
numpy
import
numpy.distutils
import
numpy.distutils
try
:
try
:
import
numpy.distutils.__config__
import
numpy.distutils.__config__
...
@@ -166,10 +166,10 @@ try:
...
@@ -166,10 +166,10 @@ try:
# `scipy.linalg.blas.fblas` with `scipy.linalg.blas`.
# `scipy.linalg.blas.fblas` with `scipy.linalg.blas`.
# See http://github.com/scipy/scipy/pull/358
# See http://github.com/scipy/scipy/pull/358
fblas
=
scipy
.
linalg
.
blas
fblas
=
scipy
.
linalg
.
blas
_blas_gemv_fns
=
{
n
p
.
dtype
(
'float32'
):
fblas
.
sgemv
,
_blas_gemv_fns
=
{
n
umpy
.
dtype
(
'float32'
):
fblas
.
sgemv
,
n
p
.
dtype
(
'float64'
):
fblas
.
dgemv
,
n
umpy
.
dtype
(
'float64'
):
fblas
.
dgemv
,
n
p
.
dtype
(
'complex64'
):
fblas
.
cgemv
,
n
umpy
.
dtype
(
'complex64'
):
fblas
.
cgemv
,
n
p
.
dtype
(
'complex128'
):
fblas
.
zgemv
}
n
umpy
.
dtype
(
'complex128'
):
fblas
.
zgemv
}
except
ImportError
as
e
:
except
ImportError
as
e
:
have_fblas
=
False
have_fblas
=
False
# This is used in Gemv and ScipyGer. We use CGemv and CGer
# This is used in Gemv and ScipyGer. We use CGemv and CGer
...
@@ -190,12 +190,12 @@ def check_init_y():
...
@@ -190,12 +190,12 @@ def check_init_y():
if
not
have_fblas
:
if
not
have_fblas
:
check_init_y
.
_result
=
False
check_init_y
.
_result
=
False
y
=
float
(
'NaN'
)
*
n
p
.
ones
((
2
,))
y
=
float
(
'NaN'
)
*
n
umpy
.
ones
((
2
,))
x
=
n
p
.
ones
((
2
,))
x
=
n
umpy
.
ones
((
2
,))
A
=
n
p
.
ones
((
2
,
2
))
A
=
n
umpy
.
ones
((
2
,
2
))
gemv
=
_blas_gemv_fns
[
y
.
dtype
]
gemv
=
_blas_gemv_fns
[
y
.
dtype
]
gemv
(
1.0
,
A
.
T
,
x
,
0.0
,
y
,
overwrite_y
=
True
,
trans
=
True
)
gemv
(
1.0
,
A
.
T
,
x
,
0.0
,
y
,
overwrite_y
=
True
,
trans
=
True
)
check_init_y
.
_result
=
n
p
.
isnan
(
y
)
.
any
()
check_init_y
.
_result
=
n
umpy
.
isnan
(
y
)
.
any
()
return
check_init_y
.
_result
return
check_init_y
.
_result
...
@@ -269,7 +269,7 @@ class Gemv(Op):
...
@@ -269,7 +269,7 @@ class Gemv(Op):
out_storage
[
0
][
0
]
=
gemv
(
alpha
,
A
.
T
,
x
,
beta
,
y
,
out_storage
[
0
][
0
]
=
gemv
(
alpha
,
A
.
T
,
x
,
beta
,
y
,
overwrite_y
=
self
.
inplace
,
trans
=
True
)
overwrite_y
=
self
.
inplace
,
trans
=
True
)
else
:
else
:
out
=
n
p
.
dot
(
A
,
x
)
out
=
n
umpy
.
dot
(
A
,
x
)
if
alpha
!=
1
:
if
alpha
!=
1
:
out
*=
alpha
out
*=
alpha
if
beta
!=
0
:
if
beta
!=
0
:
...
@@ -277,7 +277,7 @@ class Gemv(Op):
...
@@ -277,7 +277,7 @@ class Gemv(Op):
out
+=
beta
*
y
out
+=
beta
*
y
else
:
else
:
out
+=
y
out
+=
y
out_storage
[
0
][
0
]
=
n
p
.
asarray
(
out
,
dtype
=
y
.
dtype
)
out_storage
[
0
][
0
]
=
n
umpy
.
asarray
(
out
,
dtype
=
y
.
dtype
)
def
infer_shape
(
self
,
node
,
input_shapes
):
def
infer_shape
(
self
,
node
,
input_shapes
):
return
[
input_shapes
[
0
]]
return
[
input_shapes
[
0
]]
...
@@ -341,9 +341,9 @@ class Ger(Op):
...
@@ -341,9 +341,9 @@ class Ger(Op):
else
:
else
:
A
=
cA
.
copy
()
A
=
cA
.
copy
()
if
calpha
!=
1
:
if
calpha
!=
1
:
A
+=
calpha
*
n
p
.
outer
(
cx
,
cy
)
A
+=
calpha
*
n
umpy
.
outer
(
cx
,
cy
)
else
:
else
:
A
+=
n
p
.
outer
(
cx
,
cy
)
A
+=
n
umpy
.
outer
(
cx
,
cy
)
cZ
[
0
]
=
A
cZ
[
0
]
=
A
def
infer_shape
(
self
,
node
,
input_shapes
):
def
infer_shape
(
self
,
node
,
input_shapes
):
...
@@ -902,26 +902,26 @@ class Gemm(GemmRelated):
...
@@ -902,26 +902,26 @@ class Gemm(GemmRelated):
if
not
self
.
inplace
:
if
not
self
.
inplace
:
z
=
z
.
copy
()
# the original z will not be changed
z
=
z
.
copy
()
# the original z will not be changed
if
z
.
shape
==
():
if
z
.
shape
==
():
z
.
itemset
(
z
*
a
+
b
*
n
p
.
dot
(
x
,
y
))
z
.
itemset
(
z
*
a
+
b
*
n
umpy
.
dot
(
x
,
y
))
zout
[
0
]
=
z
zout
[
0
]
=
z
else
:
else
:
if
b
==
0.0
:
if
b
==
0.0
:
if
a
==
1.0
:
if
a
==
1.0
:
z
[:]
=
n
p
.
dot
(
x
,
y
)
z
[:]
=
n
umpy
.
dot
(
x
,
y
)
elif
a
==
-
1.0
:
elif
a
==
-
1.0
:
z
[:]
=
-
n
p
.
dot
(
x
,
y
)
z
[:]
=
-
n
umpy
.
dot
(
x
,
y
)
else
:
else
:
z
[:]
=
a
*
n
p
.
dot
(
x
,
y
)
z
[:]
=
a
*
n
umpy
.
dot
(
x
,
y
)
elif
b
==
1.0
:
elif
b
==
1.0
:
if
a
==
1.0
:
if
a
==
1.0
:
z
+=
n
p
.
dot
(
x
,
y
)
z
+=
n
umpy
.
dot
(
x
,
y
)
elif
a
==
-
1.0
:
elif
a
==
-
1.0
:
z
-=
n
p
.
dot
(
x
,
y
)
z
-=
n
umpy
.
dot
(
x
,
y
)
else
:
else
:
z
+=
a
*
n
p
.
dot
(
x
,
y
)
z
+=
a
*
n
umpy
.
dot
(
x
,
y
)
else
:
else
:
z
*=
b
z
*=
b
z
+=
a
*
n
p
.
dot
(
x
,
y
)
z
+=
a
*
n
umpy
.
dot
(
x
,
y
)
zout
[
0
]
=
z
zout
[
0
]
=
z
def
infer_shape
(
self
,
node
,
input_shapes
):
def
infer_shape
(
self
,
node
,
input_shapes
):
...
@@ -1068,7 +1068,7 @@ def _as_scalar(res, dtype=None):
...
@@ -1068,7 +1068,7 @@ def _as_scalar(res, dtype=None):
"""Return None or a TensorVariable whose type is in T.float_scalar_types"""
"""Return None or a TensorVariable whose type is in T.float_scalar_types"""
if
dtype
is
None
:
if
dtype
is
None
:
dtype
=
config
.
floatX
dtype
=
config
.
floatX
if
n
p
.
all
(
res
.
type
.
broadcastable
):
if
n
umpy
.
all
(
res
.
type
.
broadcastable
):
while
res
.
owner
and
isinstance
(
res
.
owner
.
op
,
T
.
DimShuffle
):
while
res
.
owner
and
isinstance
(
res
.
owner
.
op
,
T
.
DimShuffle
):
res
=
res
.
owner
.
inputs
[
0
]
res
=
res
.
owner
.
inputs
[
0
]
# may still have some number of True's
# may still have some number of True's
...
@@ -1218,7 +1218,7 @@ def _gemm_canonicalize(r, scale, rval, maxclients):
...
@@ -1218,7 +1218,7 @@ def _gemm_canonicalize(r, scale, rval, maxclients):
vectors
=
[]
vectors
=
[]
matrices
=
[]
matrices
=
[]
for
i
in
r
.
owner
.
inputs
:
for
i
in
r
.
owner
.
inputs
:
if
n
p
.
all
(
i
.
type
.
broadcastable
):
if
n
umpy
.
all
(
i
.
type
.
broadcastable
):
while
i
.
owner
and
isinstance
(
i
.
owner
.
op
,
T
.
DimShuffle
):
while
i
.
owner
and
isinstance
(
i
.
owner
.
op
,
T
.
DimShuffle
):
i
=
i
.
owner
.
inputs
[
0
]
i
=
i
.
owner
.
inputs
[
0
]
if
i
.
type
.
broadcastable
:
if
i
.
type
.
broadcastable
:
...
@@ -1541,7 +1541,7 @@ class Dot22(GemmRelated):
...
@@ -1541,7 +1541,7 @@ class Dot22(GemmRelated):
x
,
y
=
inp
x
,
y
=
inp
z
,
=
out
z
,
=
out
try
:
try
:
z
[
0
]
=
n
p
.
asarray
(
np
.
dot
(
x
,
y
))
z
[
0
]
=
n
umpy
.
asarray
(
numpy
.
dot
(
x
,
y
))
except
ValueError
as
e
:
except
ValueError
as
e
:
# The error raised by numpy has no shape information, we mean to
# The error raised by numpy has no shape information, we mean to
# add that
# add that
...
@@ -1706,8 +1706,8 @@ def local_dot22_to_ger_or_gemv(node):
...
@@ -1706,8 +1706,8 @@ def local_dot22_to_ger_or_gemv(node):
x
,
y
=
node
.
inputs
x
,
y
=
node
.
inputs
xb
=
x
.
broadcastable
xb
=
x
.
broadcastable
yb
=
y
.
broadcastable
yb
=
y
.
broadcastable
one
=
T
.
as_tensor_variable
(
n
p
.
asarray
(
1
,
dtype
=
x
.
dtype
))
one
=
T
.
as_tensor_variable
(
n
umpy
.
asarray
(
1
,
dtype
=
x
.
dtype
))
zero
=
T
.
as_tensor_variable
(
n
p
.
asarray
(
0
,
dtype
=
x
.
dtype
))
zero
=
T
.
as_tensor_variable
(
n
umpy
.
asarray
(
0
,
dtype
=
x
.
dtype
))
if
xb
[
1
]
and
yb
[
0
]:
if
xb
[
1
]
and
yb
[
0
]:
# x and y are both vectors so this might qualifies for a GER
# x and y are both vectors so this might qualifies for a GER
xv
=
x
.
dimshuffle
(
0
)
xv
=
x
.
dimshuffle
(
0
)
...
@@ -1812,7 +1812,7 @@ class Dot22Scalar(GemmRelated):
...
@@ -1812,7 +1812,7 @@ class Dot22Scalar(GemmRelated):
x
,
y
,
scalar
=
inp
x
,
y
,
scalar
=
inp
z
,
=
out
z
,
=
out
try
:
try
:
z
[
0
]
=
n
p
.
asarray
(
scalar
*
np
.
dot
(
x
,
y
))
z
[
0
]
=
n
umpy
.
asarray
(
scalar
*
numpy
.
dot
(
x
,
y
))
except
ValueError
as
e
:
except
ValueError
as
e
:
# The error raised by numpy has no shape information, we
# The error raised by numpy has no shape information, we
# mean to add that
# mean to add that
...
@@ -2036,9 +2036,9 @@ class BatchedDot(Op):
...
@@ -2036,9 +2036,9 @@ class BatchedDot(Op):
shape
=
self
.
infer_shape
(
node
,
[
i
.
shape
for
i
in
inp
])[
0
]
shape
=
self
.
infer_shape
(
node
,
[
i
.
shape
for
i
in
inp
])[
0
]
dtype
=
node
.
outputs
[
0
]
.
dtype
dtype
=
node
.
outputs
[
0
]
.
dtype
z0
=
z
[
0
]
=
n
p
.
empty
(
shape
,
dtype
=
dtype
)
z0
=
z
[
0
]
=
n
umpy
.
empty
(
shape
,
dtype
=
dtype
)
for
i
in
xrange
(
z0
.
shape
[
0
]):
for
i
in
xrange
(
z0
.
shape
[
0
]):
z0
[
i
]
=
n
p
.
dot
(
x
[
i
],
y
[
i
])
z0
[
i
]
=
n
umpy
.
dot
(
x
[
i
],
y
[
i
])
def
c_support_code
(
self
):
def
c_support_code
(
self
):
batch_gemm_defn
=
"""
batch_gemm_defn
=
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论