Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
599bdad6
提交
599bdad6
authored
11月 01, 2011
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #172 from nouiz/fix_assert_import
Fix assert import
上级
b3cf9269
ffd586a6
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
76 行增加
和
9 行删除
+76
-9
mode.py
theano/compile/mode.py
+22
-6
type.py
theano/sandbox/cuda/type.py
+6
-0
basic.py
theano/sparse/basic.py
+5
-0
basic.py
theano/tensor/basic.py
+28
-3
opt.py
theano/tensor/opt.py
+0
-0
raw_random.py
theano/tensor/raw_random.py
+4
-0
test_basic.py
theano/tensor/tests/test_basic.py
+11
-0
没有找到文件。
theano/compile/mode.py
浏览文件 @
599bdad6
...
@@ -100,9 +100,30 @@ def register_optimizer(name, opt):
...
@@ -100,9 +100,30 @@ def register_optimizer(name, opt):
raise
ValueError
(
'Optimizer name already taken:
%
s'
%
name
)
raise
ValueError
(
'Optimizer name already taken:
%
s'
%
name
)
predefined_optimizers
[
name
]
=
opt
predefined_optimizers
[
name
]
=
opt
def
register_OutputGuard_c_code
(
type
):
OutputGuard
.
c_code_types
.
append
(
type
)
class
OutputGuard
(
gof
.
Op
):
class
OutputGuard
(
gof
.
Op
):
"""
This op is used only internally by Theano.
Only the AddDestroyHandler optimizer tries to insert them in the graph.
This Op is declared as destructive while it is not destroying
anything. It returns a view. This is used to prevent destruction of
the output variables of a Theano function.
There is a mechanism in Theano that should prevent this, but the use
of OutputGuard adds a safeguard: it may be possible for some optimization
run before the add_destroy_handler phase to bypass this mechanism, by
making in-place optimizations.
TODO: find a current full explanation.
"""
destroy_map
=
{
0
:[
0
]}
destroy_map
=
{
0
:[
0
]}
view_map
=
{
0
:[
0
]}
view_map
=
{
0
:[
0
]}
c_code_types
=
[]
def
make_node
(
self
,
x
):
def
make_node
(
self
,
x
):
return
gof
.
Apply
(
self
,
[
x
],
[
x
.
type
()])
return
gof
.
Apply
(
self
,
[
x
],
[
x
.
type
()])
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
...
@@ -124,12 +145,7 @@ class OutputGuard(gof.Op):
...
@@ -124,12 +145,7 @@ class OutputGuard(gof.Op):
return
"""
return
"""
%(z)
s =
%(x)
s;
%(z)
s =
%(x)
s;
"""
%
locals
()
"""
%
locals
()
elif
(
isinstance
(
node
.
inputs
[
0
]
.
type
,
elif
(
isinstance
(
node
.
inputs
[
0
]
.
type
,
tuple
(
self
.
c_code_types
))):
(
theano
.
tensor
.
TensorType
,
theano
.
sandbox
.
cuda
.
CudaNdarrayType
,
theano
.
tensor
.
raw_random
.
RandomStateType
))
or
node
.
inputs
[
0
]
.
type
.
__class__
.
__name__
==
'SparseType'
):
# These are Python object types
# These are Python object types
return
"""
return
"""
Py_XDECREF(
%(z)
s);
Py_XDECREF(
%(z)
s);
...
...
theano/sandbox/cuda/type.py
浏览文件 @
599bdad6
...
@@ -351,6 +351,12 @@ class CudaNdarrayType(Type):
...
@@ -351,6 +351,12 @@ class CudaNdarrayType(Type):
ret
.
append
(
'-use_fast_math'
)
ret
.
append
(
'-use_fast_math'
)
return
ret
return
ret
# Register CudaNdarrayType to the OutputGuard list of known types
# to have OutputGuard generate C code for this type.
theano
.
compile
.
mode
.
register_OutputGuard_c_code
(
CudaNdarrayType
)
# THIS WORKS
# THIS WORKS
# But CudaNdarray instances don't compare equal to one another, and what about __hash__ ?
# But CudaNdarray instances don't compare equal to one another, and what about __hash__ ?
# So the unpickled version doesn't equal the pickled version, and the cmodule cache is not
# So the unpickled version doesn't equal the pickled version, and the cmodule cache is not
...
...
theano/sparse/basic.py
浏览文件 @
599bdad6
...
@@ -326,6 +326,11 @@ class SparseType(gof.Type):
...
@@ -326,6 +326,11 @@ class SparseType(gof.Type):
def
is_valid_value
(
self
,
a
):
def
is_valid_value
(
self
,
a
):
return
scipy
.
sparse
.
issparse
(
a
)
and
(
a
.
format
==
self
.
format
)
return
scipy
.
sparse
.
issparse
(
a
)
and
(
a
.
format
==
self
.
format
)
# Register CudaNdarrayType to the OutputGuard list of known types
# to have OutputGuard generate C code for this type.
theano
.
compile
.
mode
.
register_OutputGuard_c_code
(
SparseType
)
# for more dtypes, call SparseType(format, dtype)
# for more dtypes, call SparseType(format, dtype)
def
matrix
(
format
,
name
=
None
,
dtype
=
None
):
def
matrix
(
format
,
name
=
None
,
dtype
=
None
):
if
dtype
is
None
:
if
dtype
is
None
:
...
...
theano/tensor/basic.py
浏览文件 @
599bdad6
...
@@ -910,6 +910,10 @@ class TensorType(Type):
...
@@ -910,6 +910,10 @@ class TensorType(Type):
else
:
else
:
return
()
return
()
# Register CudaNdarrayType to the OutputGuard list of known types
# to have OutputGuard generate C code for this type.
theano
.
compile
.
mode
.
register_OutputGuard_c_code
(
TensorType
)
# Easy constructors
# Easy constructors
def
tensor
(
*
args
,
**
kwargs
):
def
tensor
(
*
args
,
**
kwargs
):
...
@@ -3307,8 +3311,25 @@ class Subtensor(Op):
...
@@ -3307,8 +3311,25 @@ class Subtensor(Op):
{
{
%(fail)
s;
%(fail)
s;
}
}
assert (xview->dimensions !=
%(x)
s->dimensions);
assert (xview->strides !=
%(x)
s->strides);
if ((xview->dimensions ==
%(x)
s->dimensions)
&& (
%(x)
s->dimensions != NULL))
{
PyErr_Format(PyExc_ValueError, "x and xview"
"(with
%%
d dims) have the same dimensions"
" pointers:
%%
p and
%%
p",
%(x)
s->nd, xview->dimensions,
%(x)
s->dimensions);
%(fail)
s;
}
if (xview->strides ==
%(x)
s->strides
&& (
%(x)
s->dimensions != NULL))
{
PyErr_Format(PyExc_ValueError, "x and xview"
"(with
%%
d dims) have the same strides"
" pointers:
%%
p and
%%
p",
%(x)
s->nd, xview->strides,
%(x)
s->strides);
%(fail)
s;
}
for (; outer_ii <
%(len_is_slice)
s; ++outer_ii)
for (; outer_ii <
%(len_is_slice)
s; ++outer_ii)
{
{
...
@@ -3425,7 +3446,7 @@ class Subtensor(Op):
...
@@ -3425,7 +3446,7 @@ class Subtensor(Op):
@staticmethod
@staticmethod
def
helper_c_code_cache_version
():
def
helper_c_code_cache_version
():
return
(
2
,)
return
(
3
,)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
#DEBUG
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
#DEBUG
part0
=
self
.
helper_c_code
(
node
,
name
,
inputs
,
outputs
,
sub
,
part0
=
self
.
helper_c_code
(
node
,
name
,
inputs
,
outputs
,
sub
,
...
@@ -3446,6 +3467,10 @@ class Subtensor(Op):
...
@@ -3446,6 +3467,10 @@ class Subtensor(Op):
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
hv
=
self
.
helper_c_code_cache_version
()
hv
=
self
.
helper_c_code_cache_version
()
# If `helper_c_code_cache_version` is not versioned we do not want to
# have a versioned version of this op's C code.
if
len
(
hv
)
==
0
:
return
()
return
(
1
,
hv
)
return
(
1
,
hv
)
def
R_op
(
self
,
inputs
,
eval_points
):
def
R_op
(
self
,
inputs
,
eval_points
):
...
...
theano/tensor/opt.py
浏览文件 @
599bdad6
This source diff could not be displayed because it is too large. You can
view the blob
instead.
theano/tensor/raw_random.py
浏览文件 @
599bdad6
...
@@ -53,6 +53,10 @@ class RandomStateType(gof.Type):
...
@@ -53,6 +53,10 @@ class RandomStateType(gof.Type):
return
False
return
False
return
True
return
True
# Register CudaNdarrayType to the OutputGuard list of known types
# to have OutputGuard generate C code for this type.
theano
.
compile
.
mode
.
register_OutputGuard_c_code
(
RandomStateType
)
random_state_type
=
RandomStateType
()
random_state_type
=
RandomStateType
()
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
599bdad6
...
@@ -1957,6 +1957,17 @@ class T_subtensor(unittest.TestCase):
...
@@ -1957,6 +1957,17 @@ class T_subtensor(unittest.TestCase):
self
.
assertTrue
(
tval
.
shape
==
(
2
,))
self
.
assertTrue
(
tval
.
shape
==
(
2
,))
self
.
assertTrue
(
numpy
.
allclose
(
tval
,
n
.
get_value
()[
idx
]))
self
.
assertTrue
(
numpy
.
allclose
(
tval
,
n
.
get_value
()[
idx
]))
def
test1_0_dims
(
self
):
n
=
self
.
shared
(
numpy
.
ones
((),
dtype
=
self
.
dtype
))
t
=
theano
.
tensor
.
Subtensor
([])(
n
)
self
.
assertTrue
(
isinstance
(
t
.
owner
.
op
,
Subtensor
))
mode
=
self
.
mode
self
.
mode
=
mode
.
excluding
(
"local_useless_subtensor"
)
try
:
self
.
eval_output_and_check
(
t
)
finally
:
self
.
mode
=
mode
def
test1_err_invalid
(
self
):
def
test1_err_invalid
(
self
):
n
=
self
.
shared
(
numpy
.
ones
(
1
,
dtype
=
self
.
dtype
))
n
=
self
.
shared
(
numpy
.
ones
(
1
,
dtype
=
self
.
dtype
))
try
:
try
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论