Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
90c3833e
提交
90c3833e
authored
12月 02, 2011
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #242 from nouiz/max_default
change the default of theano.{max,min,argmax,argmin,max_and_argmax} to t...
上级
c08a6f31
586c0e3c
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
77 行增加
和
124 行删除
+77
-124
sharedvalue.py
theano/compile/sharedvalue.py
+0
-30
basic.py
theano/tensor/basic.py
+0
-0
opt_uncanonicalize.py
theano/tensor/opt_uncanonicalize.py
+1
-1
test_basic.py
theano/tensor/tests/test_basic.py
+0
-0
test_opt_uncanonicalize.py
theano/tensor/tests/test_opt_uncanonicalize.py
+76
-72
test_sharedvar.py
theano/tensor/tests/test_sharedvar.py
+0
-21
没有找到文件。
theano/compile/sharedvalue.py
浏览文件 @
90c3833e
...
@@ -18,13 +18,6 @@ from theano.gof import Container, Variable, generic
...
@@ -18,13 +18,6 @@ from theano.gof import Container, Variable, generic
_logger
=
logging
.
getLogger
(
'theano.compile.sharedvalue'
)
_logger
=
logging
.
getLogger
(
'theano.compile.sharedvalue'
)
AddConfigVar
(
'shared.value_borrows'
,
(
"DEPRECATED. You should not use the 'value' property of shared"
" variables, but use the .get_value() and .set_value() methods."
" False: shared variables 'value' property is guaranteed to not"
" alias theano-managed memory. True: no guarantee, but faster."
),
BoolParam
(
True
),
in_c_key
=
False
)
class
SharedVariable
(
Variable
):
class
SharedVariable
(
Variable
):
"""
"""
...
@@ -125,29 +118,6 @@ class SharedVariable(Variable):
...
@@ -125,29 +118,6 @@ class SharedVariable(Variable):
cp
.
tag
=
copy
.
copy
(
self
.
tag
)
cp
.
tag
=
copy
.
copy
(
self
.
tag
)
return
cp
return
cp
def
_value_get
(
self
):
warnings
.
warn
((
"The .value property of shared variables is deprecated."
" You should use the .get_value() method instead."
),
stacklevel
=
2
)
return
self
.
get_value
(
borrow
=
config
.
shared
.
value_borrows
,
return_internal_type
=
False
)
def
_value_set
(
self
,
new_value
):
warnings
.
warn
((
"The .value property of shared variables is deprecated."
" You should use the .set_value() method instead."
),
stacklevel
=
2
)
return
self
.
set_value
(
new_value
,
borrow
=
config
.
shared
.
value_borrows
)
#TODO: USE A CONFIG VARIABLE TO set these get/set methods to the non-borrowing versions
# Semantically things are clearer when using non-borrow versions. That should be the
# default. The default support transparently (if slowly) when the 'raw' value is in a
# different memory space (e.g. GPU or other machine).
value
=
property
(
_value_get
,
_value_set
,
doc
=
(
"DEPRECATED. Shortcut for self.get_value() and "
"self.set_value(). "
"The `borrow` argument to these methods is read from "
"`theano.config.shared.value_borrows`. "
"You should call get_value() and set_value() directly."
))
def
filter_update
(
self
,
update
):
def
filter_update
(
self
,
update
):
"""
"""
When this shared variable is updated by a pfunc, the update value will be run through this function.
When this shared variable is updated by a pfunc, the update value will be run through this function.
...
...
theano/tensor/basic.py
浏览文件 @
90c3833e
差异被折叠。
点击展开。
theano/tensor/opt_uncanonicalize.py
浏览文件 @
90c3833e
...
@@ -57,7 +57,7 @@ class MaxAndArgmaxOptimizer(Optimizer):
...
@@ -57,7 +57,7 @@ class MaxAndArgmaxOptimizer(Optimizer):
if
len
(
node
.
outputs
[
1
]
.
clients
)
==
0
:
if
len
(
node
.
outputs
[
1
]
.
clients
)
==
0
:
try
:
try
:
axis
=
get_constant_value
(
node
.
inputs
[
1
])
axis
=
get_constant_value
(
node
.
inputs
[
1
])
except
ValueError
:
except
(
ValueError
,
TypeError
),
e
:
return
False
return
False
new
=
CAReduce
(
scal
.
maximum
,
axis
)(
node
.
inputs
[
0
])
new
=
CAReduce
(
scal
.
maximum
,
axis
)(
node
.
inputs
[
0
])
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
90c3833e
差异被折叠。
点击展开。
theano/tensor/tests/test_opt_uncanonicalize.py
浏览文件 @
90c3833e
...
@@ -13,91 +13,95 @@ from theano.tests import unittest_tools as utt
...
@@ -13,91 +13,95 @@ from theano.tests import unittest_tools as utt
class
T_max_and_argmax
(
unittest
.
TestCase
):
class
T_max_and_argmax
(
unittest
.
TestCase
):
def
test_optimization
(
self
):
def
test_optimization
(
self
):
#If we use only the max output, we should replace this op with a faster one.
#If we use only the max output, we should replace this op with
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'canonicalize'
,
'fast_run'
)
#a faster one.
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'canonicalize'
,
'fast_run'
)
data
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
2
,
3
),
dtype
=
config
.
floatX
)
for
axis
in
[
0
,
1
,
-
1
]:
n
=
tensor
.
matrix
()
data
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
2
,
3
),
dtype
=
config
.
floatX
)
n
=
tensor
.
matrix
()
f
=
function
([
n
],
tensor
.
max_and_argmax
(
n
,
0
)[
0
],
mode
=
mode
)
f
=
function
([
n
],
tensor
.
max_and_argmax
(
n
,
axis
)[
0
],
mode
=
mode
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
,
CAReduce
)
assert
isinstance
(
topo
[
0
]
.
op
,
CAReduce
)
f
=
function
([
n
],
tensor
.
max_and_argmax
(
n
,
0
),
mode
=
mode
)
f
=
function
([
n
],
tensor
.
max_and_argmax
(
n
,
axis
),
mode
=
mode
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
,
tensor
.
MaxAndArgmax
)
assert
isinstance
(
topo
[
0
]
.
op
,
tensor
.
MaxAndArgmax
)
class
T_min_max
(
unittest
.
TestCase
):
class
T_min_max
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
utt
.
seed_rng
()
utt
.
seed_rng
()
self
.
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'canonicalize'
,
'fast_run'
)
self
.
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'canonicalize'
,
'fast_run'
)
def
test_optimization_max
(
self
):
def
test_optimization_max
(
self
):
data
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
2
,
3
),
dtype
=
config
.
floatX
)
data
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
2
,
3
),
dtype
=
config
.
floatX
)
n
=
tensor
.
matrix
()
n
=
tensor
.
matrix
()
f
=
function
([
n
],
tensor
.
max
(
n
,
0
),
mode
=
self
.
mode
)
f
or
axis
in
[
0
,
1
,
-
1
]:
topo
=
f
.
maker
.
env
.
toposort
(
)
f
=
function
([
n
],
tensor
.
max
(
n
,
axis
),
mode
=
self
.
mode
)
assert
len
(
topo
)
==
1
topo
=
f
.
maker
.
env
.
toposort
()
assert
isinstance
(
topo
[
0
]
.
op
,
CAReduce
)
assert
len
(
topo
)
==
1
f
(
data
)
assert
isinstance
(
topo
[
0
]
.
op
,
CAReduce
)
f
(
data
)
f
=
function
([
n
],
tensor
.
max
(
-
n
,
0
),
mode
=
self
.
mode
)
f
=
function
([
n
],
tensor
.
max
(
-
n
,
axis
),
mode
=
self
.
mode
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
2
assert
len
(
topo
)
==
2
assert
isinstance
(
topo
[
0
]
.
op
,
Elemwise
)
assert
isinstance
(
topo
[
0
]
.
op
,
Elemwise
)
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
scalar
.
Neg
)
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
scalar
.
Neg
)
assert
isinstance
(
topo
[
1
]
.
op
,
CAReduce
)
assert
isinstance
(
topo
[
1
]
.
op
,
CAReduce
)
f
(
data
)
f
(
data
)
f
=
function
([
n
],
-
tensor
.
max
(
n
,
0
),
mode
=
self
.
mode
)
f
=
function
([
n
],
-
tensor
.
max
(
n
,
axis
),
mode
=
self
.
mode
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
2
assert
len
(
topo
)
==
2
assert
isinstance
(
topo
[
0
]
.
op
,
CAReduce
)
assert
isinstance
(
topo
[
0
]
.
op
,
CAReduce
)
assert
isinstance
(
topo
[
1
]
.
op
,
Elemwise
)
assert
isinstance
(
topo
[
1
]
.
op
,
Elemwise
)
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
scalar
.
Neg
)
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
scalar
.
Neg
)
f
(
data
)
f
(
data
)
f
=
function
([
n
],
-
tensor
.
max
(
-
n
,
0
),
mode
=
self
.
mode
)
f
=
function
([
n
],
-
tensor
.
max
(
-
n
,
axis
),
mode
=
self
.
mode
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
,
CAReduce
)
#
min
assert
isinstance
(
topo
[
0
]
.
op
,
CAReduce
)
#
min
f
(
data
)
f
(
data
)
def
test_optimization_min
(
self
):
def
test_optimization_min
(
self
):
data
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
2
,
3
),
dtype
=
config
.
floatX
)
data
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
2
,
3
),
dtype
=
config
.
floatX
)
n
=
tensor
.
matrix
()
n
=
tensor
.
matrix
()
f
=
function
([
n
],
tensor
.
min
(
n
,
0
),
mode
=
self
.
mode
)
f
or
axis
in
[
0
,
1
,
-
1
]:
topo
=
f
.
maker
.
env
.
toposort
(
)
f
=
function
([
n
],
tensor
.
min
(
n
,
axis
),
mode
=
self
.
mode
)
assert
len
(
topo
)
==
1
topo
=
f
.
maker
.
env
.
toposort
()
assert
isinstance
(
topo
[
0
]
.
op
,
CAReduce
)
assert
len
(
topo
)
==
1
f
(
data
)
assert
isinstance
(
topo
[
0
]
.
op
,
CAReduce
)
f
(
data
)
#test variant with neg to make sure we optimize correctly
f
=
function
([
n
],
tensor
.
min
(
-
n
,
0
),
mode
=
self
.
mode
)
#test variant with neg to make sure we optimize correctly
topo
=
f
.
maker
.
env
.
toposort
(
)
f
=
function
([
n
],
tensor
.
min
(
-
n
,
axis
),
mode
=
self
.
mode
)
assert
len
(
topo
)
==
2
topo
=
f
.
maker
.
env
.
toposort
()
assert
isinstance
(
topo
[
0
]
.
op
,
CAReduce
)
#max
assert
len
(
topo
)
==
2
assert
isinstance
(
topo
[
1
]
.
op
,
Elemwise
)
assert
isinstance
(
topo
[
0
]
.
op
,
CAReduce
)
# max
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
scalar
.
Neg
)
assert
isinstance
(
topo
[
1
]
.
op
,
Elemwise
)
f
(
data
)
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
scalar
.
Neg
)
f
(
data
)
f
=
function
([
n
],
-
tensor
.
min
(
n
,
0
),
mode
=
self
.
mode
)
topo
=
f
.
maker
.
env
.
toposort
(
)
f
=
function
([
n
],
-
tensor
.
min
(
n
,
axis
),
mode
=
self
.
mode
)
assert
len
(
topo
)
==
2
topo
=
f
.
maker
.
env
.
toposort
()
assert
isinstance
(
topo
[
0
]
.
op
,
Elemwise
)
assert
len
(
topo
)
==
2
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
scalar
.
Neg
)
assert
isinstance
(
topo
[
0
]
.
op
,
Elemwise
)
assert
isinstance
(
topo
[
1
]
.
op
,
CAReduce
)
#max
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
scalar
.
Neg
)
f
(
data
)
assert
isinstance
(
topo
[
1
]
.
op
,
CAReduce
)
# max
f
(
data
)
f
=
function
([
n
],
-
tensor
.
min
(
-
n
,
0
),
mode
=
self
.
mode
)
topo
=
f
.
maker
.
env
.
toposort
(
)
f
=
function
([
n
],
-
tensor
.
min
(
-
n
,
axis
),
mode
=
self
.
mode
)
assert
len
(
topo
)
==
1
topo
=
f
.
maker
.
env
.
toposort
()
assert
isinstance
(
topo
[
0
]
.
op
,
CAReduce
)
#max
assert
len
(
topo
)
==
1
f
(
data
)
assert
isinstance
(
topo
[
0
]
.
op
,
CAReduce
)
# max
f
(
data
)
theano/tensor/tests/test_sharedvar.py
浏览文件 @
90c3833e
...
@@ -350,27 +350,6 @@ def makeSharedTester(shared_constructor_,
...
@@ -350,27 +350,6 @@ def makeSharedTester(shared_constructor_,
assert
may_share_memory
(
old_data
,
x_shared
.
container
.
storage
[
0
])
assert
may_share_memory
(
old_data
,
x_shared
.
container
.
storage
[
0
])
x_shared
.
get_value
(
borrow
=
True
)
x_shared
.
get_value
(
borrow
=
True
)
# Test by .value
# As we know that .value is deprecated, we filter out the warning
warnings
.
filterwarnings
(
action
=
'ignore'
,
message
=
'The .value property of shared variables is deprecated.'
)
try
:
nd
+=
1
old_data
=
x_shared
.
container
.
storage
[
0
]
x_shared
.
value
=
nd
assert
numpy
.
allclose
(
self
.
ref_fct
(
x_shared
.
value
),
self
.
ref_fct
(
self
.
cast_value
(
nd
)))
assert
may_share_memory
(
old_data
,
x_shared
.
container
.
storage
[
0
])
==
self
.
set_value_inplace
finally
:
# Restore the default behavior.
# TODO There is a cleaner way to do this in Python 2.6, once
# Theano drops support of Python 2.4 and 2.5.
warnings
.
filterwarnings
(
action
=
'default'
,
message
=
'The .value property of shared variables is deprecated.'
)
# Test by set_value with borrow=False
# Test by set_value with borrow=False
nd
+=
1
nd
+=
1
old_data
=
x_shared
.
container
.
storage
[
0
]
old_data
=
x_shared
.
container
.
storage
[
0
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论