Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b87ac81a
提交
b87ac81a
authored
11月 23, 2008
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more misc bug fixes trying to help Joseph
上级
8f460289
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
46 行增加
和
10 行删除
+46
-10
opt.py
theano/gof/opt.py
+7
-0
blas.py
theano/tensor/blas.py
+4
-3
opt.py
theano/tensor/opt.py
+25
-4
test_blas.py
theano/tensor/tests/test_blas.py
+10
-3
没有找到文件。
theano/gof/opt.py
浏览文件 @
b87ac81a
...
@@ -635,6 +635,13 @@ class NavigatorOptimizer(Optimizer):
...
@@ -635,6 +635,13 @@ class NavigatorOptimizer(Optimizer):
except
Exception
,
e
:
except
Exception
,
e
:
if
self
.
failure_callback
is
not
None
:
if
self
.
failure_callback
is
not
None
:
self
.
failure_callback
(
e
,
self
,
repl_pairs
)
self
.
failure_callback
(
e
,
self
,
repl_pairs
)
#DEBUG DONT PUSH
#print lopt
#print dir(lopt)
#raise
#END
return
False
return
False
else
:
else
:
raise
raise
...
...
theano/tensor/blas.py
浏览文件 @
b87ac81a
...
@@ -361,7 +361,7 @@ class Dot22(GemmRelated):
...
@@ -361,7 +361,7 @@ class Dot22(GemmRelated):
def
make_node
(
self
,
x
,
y
):
def
make_node
(
self
,
x
,
y
):
assert
_is_real_matrix
(
x
)
assert
_is_real_matrix
(
x
)
assert
y
.
type
==
x
.
type
#makes sure y is a matrix
assert
y
.
type
==
x
.
type
#makes sure y is a matrix
bz
=
[
x
.
type
.
broadcastable
[
0
],
y
.
type
.
broadcastable
[
1
]
]
bz
=
[
False
,
False
]
outputs
=
[
T
.
tensor
(
x
.
type
.
dtype
,
bz
)]
outputs
=
[
T
.
tensor
(
x
.
type
.
dtype
,
bz
)]
return
Apply
(
self
,
[
x
,
y
],
outputs
)
return
Apply
(
self
,
[
x
,
y
],
outputs
)
...
@@ -435,8 +435,9 @@ def _as_scalar(res):
...
@@ -435,8 +435,9 @@ def _as_scalar(res):
return
None
return
None
def
_is_real_matrix
(
res
):
def
_is_real_matrix
(
res
):
return
res
.
type
in
T
.
float_matrix_types
\
return
res
.
type
in
T
.
float_matrix_types
\
and
res
.
broadcastable
==
(
False
,
False
)
and
res
.
broadcastable
[
0
]
==
False
\
and
res
.
broadcastable
[
1
]
==
False
#cope with tuple vs. list
def
_as_isolated_scalar_times_matrix
(
res
):
def
_as_isolated_scalar_times_matrix
(
res
):
if
_is_a
(
res
,
T
.
mul
,
1
):
if
_is_a
(
res
,
T
.
mul
,
1
):
...
...
theano/tensor/opt.py
浏览文件 @
b87ac81a
...
@@ -505,9 +505,30 @@ class Canonizer(gof.LocalOptimizer):
...
@@ -505,9 +505,30 @@ class Canonizer(gof.LocalOptimizer):
return
False
return
False
new
=
self
.
merge_num_denum
(
num
,
denum
)
new
=
self
.
merge_num_denum
(
num
,
denum
)
if
new
.
type
!=
out
.
type
:
if
new
.
dtype
!=
out
.
d
type
:
#new = T.fill(out, new)
#new = T.fill(out, new)
new
=
T
.
fill
(
out
,
T
.
Elemwise
(
scalar
.
Identity
(
scalar
.
specific_out
(
getattr
(
scalar
,
out
.
type
.
dtype
))))(
new
))
elem_op
=
T
.
Elemwise
(
scalar
.
Identity
(
scalar
.
specific_out
(
getattr
(
scalar
,
out
.
type
.
dtype
))))
new
=
T
.
fill
(
out
,
elem_op
(
new
))
if
new
.
broadcastable
!=
out
.
broadcastable
:
#this case is tricky... we need to provide exactly the same kind of broadcastable
#pattern, but only if legal...
dlen
=
len
(
new
.
broadcastable
)
-
len
(
out
.
broadcastable
)
if
dlen
>
0
:
#try to take the leading ranks of new.broadcastable, which should be broadcastable
# ranks
#if this means skipping over nonbroadcastable ranks, then DimShuffle will fail
dimshuffle_op
=
T
.
DimShuffle
(
new
.
broadcastable
,
range
(
dlen
,
len
(
new
.
broadcastable
)))
new
=
dimshuffle_op
(
new
)
elif
dlen
<
0
:
#we have to boost up a scalar or something
dimshuffle_op
=
T
.
DimShuffle
(
new
.
broadcastable
,
[
'x'
for
x
in
range
(
-
dlen
)]
+
range
(
0
,
len
(
new
.
broadcastable
)))
new
=
dimshuffle_op
(
new
)
# if our if's above worked, this should be true. OTW investigate.
assert
new
.
type
==
out
.
type
return
[
new
]
return
[
new
]
def
__str__
(
self
):
def
__str__
(
self
):
...
@@ -616,9 +637,9 @@ def local_mul_specialize(node):
...
@@ -616,9 +637,9 @@ def local_mul_specialize(node):
new_inputs
.
append
(
input
)
new_inputs
.
append
(
input
)
if
len
(
new_inputs
)
<
len
(
node
.
inputs
):
if
len
(
new_inputs
)
<
len
(
node
.
inputs
):
if
len
(
new_inputs
)
==
0
:
if
len
(
new_inputs
)
==
0
:
newval
=
-
1
if
neg
else
1
newval
=
-
y
.
flatten
()[
0
]
if
neg
else
y
.
flatten
()[
0
]
return
[
T
.
TensorConstant
(
T
.
Tensor
(
dtype
=
node
.
outputs
[
0
]
.
type
.
dtype
,
return
[
T
.
TensorConstant
(
T
.
Tensor
(
dtype
=
node
.
outputs
[
0
]
.
type
.
dtype
,
broadcastable
=
()
),
N
.
asarray
(
newval
))]
broadcastable
=
[
True
]
*
node
.
outputs
[
0
]
.
ndim
),
N
.
asarray
(
newval
))]
if
len
(
new_inputs
)
==
1
:
if
len
(
new_inputs
)
==
1
:
return
[
-
new_inputs
[
0
]]
if
neg
else
new_inputs
return
[
-
new_inputs
[
0
]]
if
neg
else
new_inputs
...
...
theano/tensor/tests/test_blas.py
浏览文件 @
b87ac81a
...
@@ -3,7 +3,7 @@ import theano.tensor as T
...
@@ -3,7 +3,7 @@ import theano.tensor as T
from
...gof
import
Env
from
...gof
import
Env
import
numpy
import
numpy
from
theano.tensor.blas
import
*
from
theano.tensor.blas
import
*
from
theano.tensor.blas
import
_as_scalar
,
_dot22
from
theano.tensor.blas
import
_as_scalar
,
_dot22
,
_is_real_matrix
from
unittest
import
TestCase
from
unittest
import
TestCase
from
copy
import
copy
from
copy
import
copy
...
@@ -222,6 +222,11 @@ class t_as_scalar(TestCase):
...
@@ -222,6 +222,11 @@ class t_as_scalar(TestCase):
self
.
failUnless
(
None
==
_as_scalar
(
a
))
self
.
failUnless
(
None
==
_as_scalar
(
a
))
self
.
failUnless
(
None
==
_as_scalar
(
T
.
DimShuffle
([
False
,
False
],
[
0
,
'x'
,
1
])(
a
)))
self
.
failUnless
(
None
==
_as_scalar
(
T
.
DimShuffle
([
False
,
False
],
[
0
,
'x'
,
1
])(
a
)))
class
T_real_matrix
(
TestCase
):
def
test0
(
self
):
self
.
failUnless
(
_is_real_matrix
(
T
.
DimShuffle
([
False
,
False
],
[
1
,
0
])(
T
.
dmatrix
())))
self
.
failUnless
(
not
_is_real_matrix
(
T
.
DimShuffle
([
False
],
[
'x'
,
0
])(
T
.
dvector
())))
class
T_gemm_opt
(
TestCase
):
class
T_gemm_opt
(
TestCase
):
"""This test suite ensures that Gemm is inserted where it belongs, and that the resulting
"""This test suite ensures that Gemm is inserted where it belongs, and that the resulting
functions compute the same things as the originals."""
functions compute the same things as the originals."""
...
@@ -298,6 +303,8 @@ class T_gemm_opt(TestCase):
...
@@ -298,6 +303,8 @@ class T_gemm_opt(TestCase):
u
,
v
=
T
.
dvector
(),
T
.
dvector
()
u
,
v
=
T
.
dvector
(),
T
.
dvector
()
f
=
function
([
a
,
u
,
v
],
a
+
T
.
dot
(
u
,
v
),
mode
=
'FAST_RUN'
)
f
=
function
([
a
,
u
,
v
],
a
+
T
.
dot
(
u
,
v
),
mode
=
'FAST_RUN'
)
self
.
failIf
(
gemm
in
[
n
.
op
for
n
in
f
.
maker
.
env
.
nodes
])
print
f
.
maker
.
env
.
nodes
f
=
function
([
a
,
u
,
X
,
Y
],
a
*
u
+
T
.
dot
(
X
,
Y
),
mode
=
'FAST_RUN'
)
self
.
failIf
(
gemm
in
[
n
.
op
for
n
in
f
.
maker
.
env
.
nodes
])
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论