Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
29b9b721
提交
29b9b721
authored
4月 09, 2010
作者:
fsavard
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
75426101
6c5609e6
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
101 行增加
和
24 行删除
+101
-24
basic.txt
doc/library/tensor/basic.txt
+11
-1
test_function_module.py
theano/compile/tests/test_function_module.py
+11
-10
link.py
theano/gof/link.py
+1
-1
test_theano_object.py
theano/sandbox/test_theano_object.py
+3
-1
basic.py
theano/scalar/basic.py
+36
-0
basic.py
theano/tensor/basic.py
+16
-4
inplace.py
theano/tensor/inplace.py
+8
-0
test_sigm.py
theano/tensor/nnet/tests/test_sigm.py
+12
-5
sharedvar.py
theano/tensor/sharedvar.py
+1
-1
mlp_test.py
theano/tensor/tests/mlp_test.py
+2
-1
test_basic.py
theano/tensor/tests/test_basic.py
+0
-0
没有找到文件。
doc/library/tensor/basic.txt
浏览文件 @
29b9b721
...
@@ -601,7 +601,7 @@ dimensions, see :meth:`_tensor_py_operators.dimshuffle`
...
@@ -601,7 +601,7 @@ dimensions, see :meth:`_tensor_py_operators.dimshuffle`
Create a matrix by filling the shape of `a` with `b`
Create a matrix by filling the shape of `a` with `b`
.. function:: eye(n, m = None, k = 0, dtype=
'float64'
)
.. function:: eye(n, m = None, k = 0, dtype=
theano.config.floatX
)
:param n: number of rows in output (value or theano scalar)
:param n: number of rows in output (value or theano scalar)
:param m: number of columns in output (value or theano scalar)
:param m: number of columns in output (value or theano scalar)
...
@@ -628,6 +628,7 @@ Reductions
...
@@ -628,6 +628,7 @@ Reductions
:Parameter: *x* - symbolic Tensor (or compatible)
:Parameter: *x* - symbolic Tensor (or compatible)
:Parameter: *axis* - axis along which to compute the maximum
:Parameter: *axis* - axis along which to compute the maximum
:Returns: the maximum value along a given axis
:Returns: the maximum value along a given axis
:note: see maximum for elemwise max
If axis=None, then axis is assumed to be ndim(x)-1
If axis=None, then axis is assumed to be ndim(x)-1
...
@@ -636,6 +637,7 @@ Reductions
...
@@ -636,6 +637,7 @@ Reductions
:Parameter: *x* - symbolic Tensor (or compatible)
:Parameter: *x* - symbolic Tensor (or compatible)
:Parameter: *axis* - axis along which to compute the minimum
:Parameter: *axis* - axis along which to compute the minimum
:Returns: the minimum value along a given axis
:Returns: the minimum value along a given axis
:note: see miminum for elemwise min
if axis=None, then axis is assumed to be ndim(x)-1
if axis=None, then axis is assumed to be ndim(x)-1
...
@@ -920,6 +922,14 @@ Mathematical
...
@@ -920,6 +922,14 @@ Mathematical
Returns a variable representing the exponential of a, ie e^a.
Returns a variable representing the exponential of a, ie e^a.
.. function:: maximum(a,b)
Returns a variable representing the maximum element by element of a and b
.. function:: minimum(a,b)
Returns a variable representing the minimum element by element of a and b
.. function:: neg(a)
.. function:: neg(a)
Returns a variable representing the negation of `a` (also ``-a``).
Returns a variable representing the negation of `a` (also ``-a``).
...
...
theano/compile/tests/test_function_module.py
浏览文件 @
29b9b721
...
@@ -393,16 +393,17 @@ class T_picklefunction(unittest.TestCase):
...
@@ -393,16 +393,17 @@ class T_picklefunction(unittest.TestCase):
old_default_opt
=
config
.
optimizer
old_default_opt
=
config
.
optimizer
old_default_link
=
config
.
linker
old_default_link
=
config
.
linker
try
:
try
:
str_f
=
cPickle
.
dumps
(
f
)
try
:
config
.
mode
=
'Mode'
str_f
=
cPickle
.
dumps
(
f
)
config
.
linker
=
'py'
config
.
mode
=
'Mode'
config
.
optimizer
=
'None'
config
.
linker
=
'py'
g
=
cPickle
.
loads
(
str_f
)
config
.
optimizer
=
'None'
#print g.maker.mode
g
=
cPickle
.
loads
(
str_f
)
#print compile.mode.default_mode
#print g.maker.mode
except
NotImplementedError
,
e
:
#print compile.mode.default_mode
if
e
[
0
]
.
startswith
(
'DebugMode is not pickl'
):
except
NotImplementedError
,
e
:
g
=
'ok'
if
e
[
0
]
.
startswith
(
'DebugMode is not pickl'
):
g
=
'ok'
finally
:
finally
:
config
.
mode
=
old_default_mode
config
.
mode
=
old_default_mode
config
.
optimizer
=
old_default_opt
config
.
optimizer
=
old_default_opt
...
...
theano/gof/link.py
浏览文件 @
29b9b721
...
@@ -46,7 +46,7 @@ def raise_with_op(op, exc_info = None):
...
@@ -46,7 +46,7 @@ def raise_with_op(op, exc_info = None):
except
AttributeError
:
except
AttributeError
:
trace
=
()
trace
=
()
exc_value
.
__thunk_trace__
=
trace
exc_value
.
__thunk_trace__
=
trace
exc_value
.
args
=
exc_value
.
args
+
(
op
,
)
exc_value
.
args
=
exc_value
.
args
+
(
op
,
)
+
(
'Sequence id of Apply node='
+
str
(
op
.
env
.
toposort
()
.
index
(
op
)),)
raise
exc_type
,
exc_value
,
exc_trace
raise
exc_type
,
exc_value
,
exc_trace
...
...
theano/sandbox/test_theano_object.py
浏览文件 @
29b9b721
...
@@ -7,7 +7,9 @@ def run(TF):
...
@@ -7,7 +7,9 @@ def run(TF):
if
TF
and
RUN_TESTS
:
if
TF
and
RUN_TESTS
:
print
'running test'
,
f
.
__name__
print
'running test'
,
f
.
__name__
f
()
f
()
return
f
if
RUN_TESTS
else
None
if
RUN_TESTS
:
return
f
else
:
return
None
return
deco
return
deco
...
...
theano/scalar/basic.py
浏览文件 @
29b9b721
...
@@ -726,6 +726,42 @@ invert = Invert()
...
@@ -726,6 +726,42 @@ invert = Invert()
# Arithmetic
# Arithmetic
##############
##############
class
Maximum
(
BinaryScalarOp
):
commutative
=
True
associative
=
True
def
impl
(
self
,
*
inputs
):
return
max
(
inputs
)
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
return
"
%(z)
s = ((
%(y)
s)>(
%(x)
s)? (
%(y)
s):(
%(x)
s));"
%
locals
()
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
gx
,
gy
=
None
,
None
if
x
.
type
in
grad_types
:
gx
=
eq
(
maximum
(
x
,
y
),
x
)
*
gz
if
y
.
type
in
grad_types
:
gy
=
eq
(
maximum
(
x
,
y
),
y
)
*
gz
return
(
gx
,
gy
)
maximum
=
Maximum
(
upcast_out
,
name
=
'maximum'
)
class
Minimum
(
BinaryScalarOp
):
commutative
=
True
associative
=
True
def
impl
(
self
,
*
inputs
):
return
min
(
inputs
)
def
c_code
(
self
,
node
,
name
,
(
x
,
y
),
(
z
,
),
sub
):
return
"
%(z)
s = ((
%(y)
s)<(
%(x)
s)? (
%(y)
s):(
%(x)
s));"
%
locals
()
def
grad
(
self
,
(
x
,
y
),
(
gz
,
)):
gx
,
gy
=
None
,
None
if
x
.
type
in
grad_types
:
gx
=
eq
(
minimum
(
x
,
y
),
x
)
*
gz
if
y
.
type
in
grad_types
:
gy
=
eq
(
minimum
(
x
,
y
),
y
)
*
gz
return
(
gx
,
gy
)
minimum
=
Minimum
(
upcast_out
,
name
=
'minimum'
)
class
Add
(
ScalarOp
):
class
Add
(
ScalarOp
):
identity
=
0
identity
=
0
commutative
=
True
commutative
=
True
...
...
theano/tensor/basic.py
浏览文件 @
29b9b721
...
@@ -1703,7 +1703,7 @@ def zeros_like(model):
...
@@ -1703,7 +1703,7 @@ def zeros_like(model):
return
fill
(
model
,
constant
(
0.0
,
dtype
=
model
.
type
.
dtype
))
return
fill
(
model
,
constant
(
0.0
,
dtype
=
model
.
type
.
dtype
))
class
Eye
(
gof
.
Op
):
class
Eye
(
gof
.
Op
):
def
__init__
(
self
,
dtype
=
'float64'
):
def
__init__
(
self
,
dtype
=
config
.
floatX
):
self
.
dtype
=
dtype
self
.
dtype
=
dtype
def
make_node
(
self
,
n
,
m
,
k
):
def
make_node
(
self
,
n
,
m
,
k
):
n
=
as_tensor_variable
(
n
)
n
=
as_tensor_variable
(
n
)
...
@@ -1724,7 +1724,7 @@ class Eye(gof.Op):
...
@@ -1724,7 +1724,7 @@ class Eye(gof.Op):
return
hash
(
self
.
dtype
)
^
hash
(
type
(
self
))
return
hash
(
self
.
dtype
)
^
hash
(
type
(
self
))
def
eye
(
n
,
m
=
None
,
k
=
0
,
dtype
=
'float64'
):
def
eye
(
n
,
m
=
None
,
k
=
0
,
dtype
=
config
.
floatX
):
if
m
==
None
:
if
m
==
None
:
m
=
n
m
=
n
localop
=
Eye
(
dtype
)
localop
=
Eye
(
dtype
)
...
@@ -2029,6 +2029,17 @@ setdefault = default # legacy
...
@@ -2029,6 +2029,17 @@ setdefault = default # legacy
##########################
##########################
# Arithmetics
# Arithmetics
##########################
##########################
@_scal_elemwise
def
maximum
(
x
,
y
):
"""elemwise maximum. See max for the maximum in one tensor
"""
# see decorator for function body
@_scal_elemwise
def
minimum
(
x
,
y
):
"""elemwise minimum. See min for the minimum in one tensor
"""
# see decorator for function body
def
div_proxy
(
x
,
y
):
def
div_proxy
(
x
,
y
):
"""Proxy for either true_div or int_div, depending on types of x, y.
"""Proxy for either true_div or int_div, depending on types of x, y.
...
@@ -3172,9 +3183,10 @@ class ARange(Op):
...
@@ -3172,9 +3183,10 @@ class ARange(Op):
if
is_constant_value
(
start
,
0
):
if
is_constant_value
(
start
,
0
):
return
[(
cast
(
stop
,
'int64'
),)]
return
[(
cast
(
stop
,
'int64'
),)]
else
:
else
:
return
[(
theano
.
tensor
.
max
([
cast
(
stop
-
start
,
'int64'
),
0
]
),)]
return
[(
maximum
(
cast
(
stop
-
start
,
'int64'
),
0
),)]
else
:
else
:
return
[(
theano
.
tensor
.
max
([
cast
(
ceil
(
cast
((
stop
-
start
),
'float64'
)
/
step
),
'int64'
),
0
]),)]
return
[(
maximum
(
cast
(
ceil
(
cast
((
stop
-
start
),
'float64'
)
/
step
),
'int64'
),
0
),)]
def
perform
(
self
,
node
,
(
start
,
stop
,
step
),
(
out
,)):
def
perform
(
self
,
node
,
(
start
,
stop
,
step
),
(
out
,)):
start
=
start
.
item
()
start
=
start
.
item
()
...
...
theano/tensor/inplace.py
浏览文件 @
29b9b721
...
@@ -168,6 +168,14 @@ fill_inplace = second_inplace
...
@@ -168,6 +168,14 @@ fill_inplace = second_inplace
pprint
.
assign
(
fill_inplace
,
printing
.
FunctionPrinter
(
'fill='
))
pprint
.
assign
(
fill_inplace
,
printing
.
FunctionPrinter
(
'fill='
))
@_scal_inplace
def
maximum_inplace
(
a
,
b
):
"""elementwise addition (inplace on `a`)"""
@_scal_inplace
def
minimum_inplace
(
a
,
b
):
"""elementwise addition (inplace on `a`)"""
@_scal_inplace
@_scal_inplace
def
add_inplace
(
a
,
b
):
def
add_inplace
(
a
,
b
):
"""elementwise addition (inplace on `a`)"""
"""elementwise addition (inplace on `a`)"""
...
...
theano/tensor/nnet/tests/test_sigm.py
浏览文件 @
29b9b721
...
@@ -43,17 +43,24 @@ class T_sigmoid_opts(unittest.TestCase):
...
@@ -43,17 +43,24 @@ class T_sigmoid_opts(unittest.TestCase):
# tests inv_1_plus_exp with neg
# tests inv_1_plus_exp with neg
f
=
theano
.
function
([
x
],
T
.
fill
(
x
,
-
1.0
)
/
(
1
+
T
.
exp
(
-
x
)),
mode
=
m
)
f
=
theano
.
function
([
x
],
T
.
fill
(
x
,
-
1.0
)
/
(
1
+
T
.
exp
(
-
x
)),
mode
=
m
)
#theano.printing.debugprint(f)
#theano.printing.debugprint(f)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
sigmoid
,
assert
len
(
f
.
maker
.
env
.
toposort
())
==
1
T
.
inplace
.
neg_inplace
]
assert
str
(
f
.
maker
.
env
.
toposort
()[
0
]
.
op
)
==
'Elemwise{Composite{scalar_sigmoid,neg}}'
#without fusion
#assert [node.op for node in f.maker.env.toposort()] == [sigmoid,
# T.inplace.neg_inplace]
# tests double inv_1_plus_exp with neg
# tests double inv_1_plus_exp with neg
# (-1)(exp(x)) / (1+exp(x))(1+exp(-x))
# (-1)(exp(x)) / (1+exp(x))(1+exp(-x))
# = (-1)/(1+exp(-x)) * exp(x)/(1+exp(x))
# = (-1)/(1+exp(-x)) * exp(x)/(1+exp(x))
# = - (sigm(x) * sigm(x))
# = - (sigm(x) * sigm(x))
f
=
theano
.
function
([
x
],
(
T
.
fill
(
x
,
-
1.0
)
*
T
.
exp
(
x
))
/
((
1
+
T
.
exp
(
x
))
*
(
1
+
T
.
exp
(
-
x
))),
mode
=
m
)
f
=
theano
.
function
([
x
],
(
T
.
fill
(
x
,
-
1.0
)
*
T
.
exp
(
x
))
/
((
1
+
T
.
exp
(
x
))
*
(
1
+
T
.
exp
(
-
x
))),
mode
=
m
)
theano
.
printing
.
debugprint
(
f
)
theano
.
printing
.
debugprint
(
f
)
assert
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
==
[
sigmoid
,
assert
len
(
f
.
maker
.
env
.
toposort
())
==
2
T
.
mul
,
T
.
inplace
.
neg_inplace
]
assert
f
.
maker
.
env
.
toposort
()[
0
]
.
op
==
sigmoid
assert
str
(
f
.
maker
.
env
.
toposort
()[
1
]
.
op
)
==
'Elemwise{Composite{mul,neg}}'
#without fusion
#assert [node.op for node in f.maker.env.toposort()] == [sigmoid,
# T.mul, T.inplace.neg_inplace]
def
test_1msigmoid
(
self
):
def
test_1msigmoid
(
self
):
if
not
register_local_1msigmoid
:
if
not
register_local_1msigmoid
:
...
...
theano/tensor/sharedvar.py
浏览文件 @
29b9b721
import
traceback
import
numpy
import
numpy
import
theano.tensor.basic
import
theano.tensor.basic
from
basic
import
TensorType
,
_tensor_py_operators
from
basic
import
TensorType
,
_tensor_py_operators
...
...
theano/tensor/tests/mlp_test.py
浏览文件 @
29b9b721
...
@@ -9,6 +9,7 @@ import numpy
...
@@ -9,6 +9,7 @@ import numpy
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
T
from
theano.gof.python25
import
any
def
gen_data
():
def
gen_data
():
...
@@ -301,7 +302,7 @@ def test_mlp():
...
@@ -301,7 +302,7 @@ def test_mlp():
y
:
train_set_y
[
index
*
batch_size
:(
index
+
1
)
*
batch_size
]},
y
:
train_set_y
[
index
*
batch_size
:(
index
+
1
)
*
batch_size
]},
mode
=
mode
)
mode
=
mode
)
for
i
in
train_model
.
maker
.
env
.
toposort
():
print
i
for
i
in
train_model
.
maker
.
env
.
toposort
():
print
i
theano
.
printing
.
pydotprint
(
train_model
)
#
theano.printing.pydotprint(train_model)
assert
any
(
[
isinstance
(
i
.
op
,
T
.
nnet
.
CrossentropySoftmax1HotWithBiasDx
)
for
i
in
train_model
.
maker
.
env
.
toposort
()])
assert
any
(
[
isinstance
(
i
.
op
,
T
.
nnet
.
CrossentropySoftmax1HotWithBiasDx
)
for
i
in
train_model
.
maker
.
env
.
toposort
()])
train_model
=
theano
.
function
(
inputs
=
[
index
],
train_model
=
theano
.
function
(
inputs
=
[
index
],
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
29b9b721
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论