Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b031dfe0
提交
b031dfe0
authored
2月 27, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
差异文件
merge
上级
f7a67132
4f79b6bc
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
50 行增加
和
14 行删除
+50
-14
debugmode.py
theano/compile/debugmode.py
+0
-0
link.py
theano/gof/link.py
+1
-1
opt.py
theano/gof/opt.py
+2
-6
type.py
theano/gof/type.py
+8
-0
basic.py
theano/scalar/basic.py
+8
-0
basic.py
theano/sparse/basic.py
+9
-0
basic.py
theano/tensor/basic.py
+11
-0
test_basic.py
theano/tensor/tests/test_basic.py
+7
-4
test_blas.py
theano/tensor/tests/test_blas.py
+4
-3
没有找到文件。
theano/compile/debugmode.py
浏览文件 @
b031dfe0
差异被折叠。
点击展开。
theano/gof/link.py
浏览文件 @
b031dfe0
...
@@ -163,7 +163,7 @@ class Container(object):
...
@@ -163,7 +163,7 @@ class Container(object):
def
map_storage
(
env
,
order
,
input_storage
,
output_storage
):
def
map_storage
(
env
,
order
,
input_storage
,
output_storage
):
"""Ensure there is storage for inputs, outputs, and interior nodes.
"""Ensure there is storage
(a length-1 list)
for inputs, outputs, and interior nodes.
:param env: The current env. This function uses the inputs and outputs attributes.
:param env: The current env. This function uses the inputs and outputs attributes.
:param order: an iterable over Apply instances (in program running order)
:param order: an iterable over Apply instances (in program running order)
...
...
theano/gof/opt.py
浏览文件 @
b031dfe0
...
@@ -431,7 +431,7 @@ class OpSub(LocalOptimizer):
...
@@ -431,7 +431,7 @@ class OpSub(LocalOptimizer):
new_output
.
tag
=
copy
(
output
.
tag
)
new_output
.
tag
=
copy
(
output
.
tag
)
return
repl
.
outputs
return
repl
.
outputs
def
str
(
self
):
def
__str__
(
self
):
return
"
%
s ->
%
s"
%
(
self
.
op1
,
self
.
op2
)
return
"
%
s ->
%
s"
%
(
self
.
op1
,
self
.
op2
)
...
@@ -444,10 +444,6 @@ class OpRemove(LocalOptimizer):
...
@@ -444,10 +444,6 @@ class OpRemove(LocalOptimizer):
reentrant
=
False
# no nodes are added at all
reentrant
=
False
# no nodes are added at all
def
__init__
(
self
,
op
):
def
__init__
(
self
,
op
):
"""
op1.make_node and op2.make_node must take the same number of
inputs and have the same number of outputs.
"""
self
.
op
=
op
self
.
op
=
op
def
op_key
(
self
):
def
op_key
(
self
):
...
@@ -461,7 +457,7 @@ class OpRemove(LocalOptimizer):
...
@@ -461,7 +457,7 @@ class OpRemove(LocalOptimizer):
return
False
return
False
return
node
.
inputs
return
node
.
inputs
def
str
(
self
):
def
__str__
(
self
):
return
"
%
s(x) -> x"
%
(
self
.
op
)
return
"
%
s(x) -> x"
%
(
self
.
op
)
...
...
theano/gof/type.py
浏览文件 @
b031dfe0
...
@@ -218,6 +218,10 @@ class PureType(object):
...
@@ -218,6 +218,10 @@ class PureType(object):
"""
"""
raise
AbstractFunctionError
()
raise
AbstractFunctionError
()
def
is_valid_value
(
self
,
a
):
"""Required: Return True for any python object `a` that would be a legal value for a Result of this Type"""
raise
AbstractFunctionError
()
def
make_result
(
self
,
name
=
None
):
def
make_result
(
self
,
name
=
None
):
"""Return a new `Result` instance of Type `self`.
"""Return a new `Result` instance of Type `self`.
...
@@ -325,6 +329,9 @@ class Generic(SingletonType):
...
@@ -325,6 +329,9 @@ class Generic(SingletonType):
def
filter
(
self
,
data
,
strict
=
False
):
def
filter
(
self
,
data
,
strict
=
False
):
return
data
return
data
def
is_valid_value
(
self
,
a
):
return
True
def
c_declare
(
self
,
name
,
sub
):
def
c_declare
(
self
,
name
,
sub
):
return
"""
return
"""
PyObject*
%(name)
s;
PyObject*
%(name)
s;
...
@@ -348,6 +355,7 @@ class Generic(SingletonType):
...
@@ -348,6 +355,7 @@ class Generic(SingletonType):
Py_XINCREF(py_
%(name)
s);
Py_XINCREF(py_
%(name)
s);
"""
%
locals
()
"""
%
locals
()
generic
=
Generic
()
generic
=
Generic
()
...
...
theano/scalar/basic.py
浏览文件 @
b031dfe0
...
@@ -52,6 +52,14 @@ class Scalar(Type):
...
@@ -52,6 +52,14 @@ class Scalar(Type):
except
Exception
,
e
:
except
Exception
,
e
:
raise
TypeError
(
"Could not convert
%
s (value=
%
s) to
%
s"
%
(
type
(
data
),
data
,
self
.
dtype
),
e
)
raise
TypeError
(
"Could not convert
%
s (value=
%
s) to
%
s"
%
(
type
(
data
),
data
,
self
.
dtype
),
e
)
def
values_eq_enough
(
self
,
a
,
b
):
return
abs
(
a
-
b
)
/
(
a
+
b
)
<
1e-4
def
is_valid_value
(
self
,
a
):
_a
=
numpy
.
asarray
(
a
)
rval
=
(
_a
.
ndim
==
0
)
and
(
str
(
_a
.
dtype
)
==
self
.
dtype
)
return
rval
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
and
other
.
dtype
==
self
.
dtype
return
type
(
self
)
==
type
(
other
)
and
other
.
dtype
==
self
.
dtype
...
...
theano/sparse/basic.py
浏览文件 @
b031dfe0
...
@@ -9,6 +9,7 @@ To read about different sparse formats, see U{http://www-users.cs.umn.edu/~saad/
...
@@ -9,6 +9,7 @@ To read about different sparse formats, see U{http://www-users.cs.umn.edu/~saad/
import
sys
,
operator
import
sys
,
operator
import
numpy
import
numpy
from
scipy
import
sparse
from
scipy
import
sparse
import
scipy.sparse
from
..
import
gof
from
..
import
gof
from
..
import
tensor
from
..
import
tensor
...
@@ -185,6 +186,14 @@ class Sparse(gof.Type):
...
@@ -185,6 +186,14 @@ class Sparse(gof.Type):
def
__repr__
(
self
):
def
__repr__
(
self
):
return
"Sparse[
%
s,
%
s]"
%
(
str
(
self
.
dtype
),
str
(
self
.
format
))
return
"Sparse[
%
s,
%
s]"
%
(
str
(
self
.
dtype
),
str
(
self
.
format
))
def
values_eq_enough
(
self
,
a
,
b
,
eps
=
1e-6
):
return
scipy
.
sparse
.
issparse
(
a
)
\
and
scipy
.
sparse
.
issparse
(
b
)
\
and
abs
(
a
-
b
)
.
sum
()
<
(
1e-6
*
a
.
nnz
)
def
is_valid_value
(
self
,
a
):
return
scipy
.
sparse
.
issparse
(
a
)
and
(
a
.
format
==
self
.
format
)
csc_matrix
=
Sparse
(
format
=
'csc'
)
csc_matrix
=
Sparse
(
format
=
'csc'
)
csr_matrix
=
Sparse
(
format
=
'csr'
)
csr_matrix
=
Sparse
(
format
=
'csr'
)
...
...
theano/tensor/basic.py
浏览文件 @
b031dfe0
...
@@ -226,6 +226,17 @@ class Tensor(Type):
...
@@ -226,6 +226,17 @@ class Tensor(Type):
return
type
(
a
)
is
numpy
.
ndarray
and
type
(
b
)
is
numpy
.
ndarray
\
return
type
(
a
)
is
numpy
.
ndarray
and
type
(
b
)
is
numpy
.
ndarray
\
and
(
a
.
shape
==
b
.
shape
)
and
numpy
.
allclose
(
a
,
b
)
and
(
a
.
shape
==
b
.
shape
)
and
numpy
.
allclose
(
a
,
b
)
def
is_valid_value
(
self
,
a
):
rval
=
(
type
(
a
)
is
numpy
.
ndarray
)
and
(
self
.
ndim
==
a
.
ndim
)
\
and
(
str
(
a
.
dtype
)
==
self
.
dtype
)
\
and
all
([((
si
==
1
)
or
not
bi
)
for
si
,
bi
in
zip
(
a
.
shape
,
self
.
broadcastable
)])
if
not
rval
:
print
type
(
a
),(
type
(
a
)
is
numpy
.
ndarray
)
print
a
.
ndim
,
(
self
.
ndim
==
a
.
ndim
)
print
a
.
dtype
,
(
str
(
a
.
dtype
)
==
self
.
dtype
)
print
a
.
shape
,
self
.
broadcastable
,
([(
shp_i
==
1
)
for
shp_i
in
a
.
shape
]
==
self
.
broadcastable
)
return
rval
def
__hash__
(
self
):
def
__hash__
(
self
):
"""Hash equal for same kinds of Tensor"""
"""Hash equal for same kinds of Tensor"""
return
hash
(
self
.
dtype
)
^
hash
(
self
.
broadcastable
)
return
hash
(
self
.
dtype
)
^
hash
(
self
.
broadcastable
)
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
b031dfe0
...
@@ -114,8 +114,8 @@ def make_restet(name, op, expected, checks = {}, good = {}, bad_build = {}, bad_
...
@@ -114,8 +114,8 @@ def make_restet(name, op, expected, checks = {}, good = {}, bad_build = {}, bad_
for
description
,
check
in
self
.
checks
.
items
():
for
description
,
check
in
self
.
checks
.
items
():
if
not
check
(
inputs
,
results
):
if
not
check
(
inputs
,
results
):
self
.
fail
(
"Test
%
s::
%
s: Failed check:
%
s (inputs were
%
s)"
self
.
fail
(
"Test
%
s::
%
s: Failed check:
%
s (inputs were
%
s
, outputs were
%
s
)"
%
(
self
.
op
,
testname
,
description
,
inputs
))
%
(
self
.
op
,
testname
,
description
,
inputs
,
results
))
def
test_bad_build
(
self
):
def
test_bad_build
(
self
):
for
testname
,
inputs
in
self
.
bad_build
.
items
():
for
testname
,
inputs
in
self
.
bad_build
.
items
():
...
@@ -195,8 +195,11 @@ def make_broadcast_restet(op, expected, checks = {}, **kwargs):
...
@@ -195,8 +195,11 @@ def make_broadcast_restet(op, expected, checks = {}, **kwargs):
if
kwargs
[
'inplace'
]:
if
kwargs
[
'inplace'
]:
_expected
=
expected
_expected
=
expected
expected
=
lambda
*
inputs
:
numpy
.
array
(
_expected
(
*
inputs
),
dtype
=
inputs
[
0
]
.
dtype
)
expected
=
lambda
*
inputs
:
numpy
.
array
(
_expected
(
*
inputs
),
dtype
=
inputs
[
0
]
.
dtype
)
checks
=
dict
(
checks
,
def
inplace_check
(
inputs
,
outputs
):
inplace_check
=
lambda
inputs
,
outputs
:
inputs
[
0
]
is
outputs
[
0
])
# this used to be inputs[0] is output[0]
# I changed it so that it was easier to satisfy by the DebugMode
return
numpy
.
all
(
inputs
[
0
]
==
outputs
[
0
])
checks
=
dict
(
checks
,
inplace_check
=
inplace_check
)
#lambda inputs, outputs: numpy.all(inputs[0] == outputs[0]))
del
kwargs
[
'inplace'
]
del
kwargs
[
'inplace'
]
return
make_restet
(
name
,
op
,
expected
,
checks
,
**
kwargs
)
return
make_restet
(
name
,
op
,
expected
,
checks
,
**
kwargs
)
...
...
theano/tensor/tests/test_blas.py
浏览文件 @
b031dfe0
...
@@ -141,9 +141,10 @@ class t_gemm(TestCase):
...
@@ -141,9 +141,10 @@ class t_gemm(TestCase):
"""test that dot args can be aliased"""
"""test that dot args can be aliased"""
Z
=
value
(
self
.
rand
(
2
,
2
))
Z
=
value
(
self
.
rand
(
2
,
2
))
A
=
value
(
self
.
rand
(
2
,
2
))
A
=
value
(
self
.
rand
(
2
,
2
))
eval_outputs
([
gemm
(
Z
,
1.0
,
A
,
A
,
1.0
)])
f
=
inplace_func
([
A
,
Z
],
gemm
(
Z
,
1.0
,
A
,
A
,
1.0
))
eval_outputs
([
gemm
(
Z
,
1.0
,
A
,
A
.
T
,
1.0
)])
f
(
A
.
data
,
Z
.
data
)
f
=
inplace_func
([
A
,
Z
],
gemm
(
Z
,
1.0
,
A
,
A
.
T
,
1.0
))
f
(
A
.
data
,
Z
.
data
)
def
test_transposes
(
self
):
def
test_transposes
(
self
):
# three square matrices which are not contiguous
# three square matrices which are not contiguous
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论