Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ef279e19
提交
ef279e19
authored
10月 19, 2020
作者:
Brandon T. Willard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace theano.tensor alias T with tt in tests.tensor
上级
ac7b5225
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
43 行增加
和
43 行删除
+43
-43
test_basic.py
tests/tensor/test_basic.py
+0
-0
test_blas.py
tests/tensor/test_blas.py
+0
-0
test_elemwise.py
tests/tensor/test_elemwise.py
+0
-0
test_fft.py
tests/tensor/test_fft.py
+3
-2
test_gc.py
tests/tensor/test_gc.py
+9
-7
test_merge.py
tests/tensor/test_merge.py
+11
-10
test_mlp.py
tests/tensor/test_mlp.py
+20
-24
test_opt.py
tests/tensor/test_opt.py
+0
-0
test_subtensor.py
tests/tensor/test_subtensor.py
+0
-0
没有找到文件。
tests/tensor/test_basic.py
浏览文件 @
ef279e19
差异被折叠。
点击展开。
tests/tensor/test_blas.py
浏览文件 @
ef279e19
差异被折叠。
点击展开。
tests/tensor/test_elemwise.py
浏览文件 @
ef279e19
差异被折叠。
点击展开。
tests/tensor/test_fft.py
浏览文件 @
ef279e19
import
numpy
as
np
import
pytest
import
theano
import
theano.tensor
as
tt
from
theano
import
tensor
as
T
from
theano.tensor
import
fft
from
tests
import
unittest_tools
as
utt
...
...
@@ -31,7 +32,7 @@ class TestFFT:
def
test_1Drfft
(
self
):
inputs_val
=
np
.
random
.
random
((
1
,
N
))
.
astype
(
theano
.
config
.
floatX
)
x
=
T
.
matrix
(
"x"
)
x
=
tt
.
matrix
(
"x"
)
rfft
=
fft
.
rfft
(
x
)
f_rfft
=
theano
.
function
([
x
],
rfft
)
res_rfft
=
f_rfft
(
inputs_val
)
...
...
tests/tensor/test_gc.py
浏览文件 @
ef279e19
import
numpy
as
np
import
time
import
six.moves.cPickle
as
pickle
import
numpy
as
np
import
theano
from
theano
import
tensor
as
T
import
time
import
theano.tensor
as
tt
def
test_no_reuse
():
x
=
T
.
lvector
()
y
=
T
.
lvector
()
x
=
tt
.
lvector
()
y
=
tt
.
lvector
()
f
=
theano
.
function
([
x
,
y
],
x
+
y
)
# provide both inputs in the first call
...
...
@@ -22,7 +24,7 @@ def test_no_reuse():
def
test_gc_never_pickles_temporaries
():
x
=
T
.
dvector
()
x
=
tt
.
dvector
()
r
=
x
for
i
in
range
(
2
):
# TODO: 30 causes like LONG compilation due to MERGE
...
...
@@ -105,7 +107,7 @@ def test_merge_opt_runtime():
#
# Ironically, there is actually no merging to do in this graph.
x
=
T
.
dvector
()
x
=
tt
.
dvector
()
r
=
x
for
i
in
range
(
50
):
r
=
r
+
r
/
10
...
...
tests/tensor/test_merge.py
浏览文件 @
ef279e19
import
numpy
as
np
import
theano.tensor.basic
as
tt
from
theano.gof.type
import
Type
from
theano.gof.graph
import
Variable
,
Apply
from
theano.gof.op
import
Op
from
theano.gof.opt
import
MergeOptimizer
from
theano.gof.fg
import
FunctionGraph
as
Env
import
theano.tensor.basic
as
T
from
theano.gof.fg
import
FunctionGraph
def
a
s_variable
(
x
):
def
i
s_variable
(
x
):
if
not
isinstance
(
x
,
Variable
):
raise
TypeError
(
"not a Variable"
,
x
)
return
x
...
...
@@ -30,7 +31,7 @@ class MyOp(Op):
self
.
x
=
x
def
make_node
(
self
,
*
inputs
):
inputs
=
list
(
map
(
a
s_variable
,
inputs
))
inputs
=
list
(
map
(
i
s_variable
,
inputs
))
for
input
in
inputs
:
if
not
isinstance
(
input
.
type
,
MyType
):
raise
Exception
(
"Error 1"
)
...
...
@@ -65,9 +66,9 @@ def test_merge_with_weird_eq():
# numpy arrays don't compare equal like other python objects
# SCALAR CASE
x
=
T
.
constant
(
np
.
asarray
(
1
),
name
=
"x"
)
y
=
T
.
constant
(
np
.
asarray
(
1
),
name
=
"y"
)
g
=
Env
([
x
,
y
],
[
x
+
y
])
x
=
tt
.
constant
(
np
.
asarray
(
1
),
name
=
"x"
)
y
=
tt
.
constant
(
np
.
asarray
(
1
),
name
=
"y"
)
g
=
FunctionGraph
([
x
,
y
],
[
x
+
y
])
MergeOptimizer
()
.
optimize
(
g
)
assert
len
(
g
.
apply_nodes
)
==
1
...
...
@@ -77,9 +78,9 @@ def test_merge_with_weird_eq():
# NONSCALAR CASE
# This was created to test TensorConstantSignature
x
=
T
.
constant
(
np
.
ones
(
5
),
name
=
"x"
)
y
=
T
.
constant
(
np
.
ones
(
5
),
name
=
"y"
)
g
=
Env
([
x
,
y
],
[
x
+
y
])
x
=
tt
.
constant
(
np
.
ones
(
5
),
name
=
"x"
)
y
=
tt
.
constant
(
np
.
ones
(
5
),
name
=
"y"
)
g
=
FunctionGraph
([
x
,
y
],
[
x
+
y
])
MergeOptimizer
()
.
optimize
(
g
)
assert
len
(
g
.
apply_nodes
)
==
1
...
...
tests/tensor/test_mlp.py
浏览文件 @
ef279e19
"""
This is a minimized version of the mlp.py in the tutorial. We removed stuff that make this mlp don't work.
But this test a bug that we saw. This bug made the Shape_i object not being lifted, that caused the CrossentropySoftmax... op not being inserted.
This is a minimized version of the mlp.py in the tutorial. We removed stuff
that make this mlp don't work. But this test a bug that we saw. This bug made
the Shape_i object not being lifted, that caused the CrossentropySoftmax... op
not being inserted.
"""
__docformat__
=
"restructedtext en"
from
collections
import
OrderedDict
import
numpy
as
np
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
tt
def
gen_data
():
...
...
@@ -49,7 +49,7 @@ def gen_data():
# floats it doesn't make sense) therefore instead of returning
# ``shared_y`` we will have to cast it to int. This little hack
# lets ous get around this issue
return
shared_x
,
T
.
cast
(
shared_y
,
"int32"
)
return
shared_x
,
tt
.
cast
(
shared_y
,
"int32"
)
test_set_x
,
test_set_y
=
shared_dataset
(
test_set
)
valid_set_x
,
valid_set_y
=
shared_dataset
(
valid_set
)
...
...
@@ -96,11 +96,11 @@ class LogisticRegression(object):
)
# compute vector of class-membership probabilities in symbolic form
self
.
p_y_given_x
=
T
.
nnet
.
softmax
(
T
.
dot
(
input
,
self
.
W
))
self
.
p_y_given_x
=
tt
.
nnet
.
softmax
(
tt
.
dot
(
input
,
self
.
W
))
# compute prediction as class whose probability is maximal in
# symbolic form
self
.
y_pred
=
T
.
argmax
(
self
.
p_y_given_x
,
axis
=
1
)
self
.
y_pred
=
tt
.
argmax
(
self
.
p_y_given_x
,
axis
=
1
)
# parameters of the model
self
.
params
=
[
self
.
W
]
...
...
@@ -128,11 +128,11 @@ class LogisticRegression(object):
# LP[T.arange(y.shape[0]),y] is a vector v containing [LP[0,y[0]], LP[1,y[1]], LP[2,y[2]], ..., LP[n-1,y[n-1]]]
# and T.mean(LP[T.arange(y.shape[0]),y]) is the mean (across minibatch examples) of the elements in v,
# i.e., the mean log-likelihood across the minibatch.
return
T
.
log
(
self
.
p_y_given_x
[
T
.
arange
(
y
.
shape
[
0
]),
y
])
return
tt
.
log
(
self
.
p_y_given_x
[
tt
.
arange
(
y
.
shape
[
0
]),
y
])
class
HiddenLayer
(
object
):
def
__init__
(
self
,
rng
,
input
,
n_in
,
n_out
,
activation
=
T
.
tanh
,
name_prefix
=
""
):
def
__init__
(
self
,
rng
,
input
,
n_in
,
n_out
,
activation
=
tt
.
tanh
,
name_prefix
=
""
):
"""
Typical hidden layer of a MLP: units are fully-connected and have
sigmoidal activation function. Weight matrix W is of shape (n_in,n_out)
...
...
@@ -174,7 +174,7 @@ class HiddenLayer(object):
)
self
.
W
=
theano
.
shared
(
value
=
W_values
,
name
=
name_prefix
+
"W"
)
self
.
output
=
T
.
dot
(
input
,
self
.
W
)
self
.
output
=
tt
.
dot
(
input
,
self
.
W
)
# parameters of the model
self
.
params
=
[
self
.
W
]
...
...
@@ -222,7 +222,7 @@ class MLP(object):
input
=
input
,
n_in
=
n_in
,
n_out
=
n_hidden
,
activation
=
T
.
tanh
,
activation
=
tt
.
tanh
,
name_prefix
=
"hid_"
,
)
...
...
@@ -284,9 +284,9 @@ def test_mlp():
# print '... building the model'
# allocate symbolic variables for the data
index
=
T
.
lscalar
()
# index to a [mini]batch
x
=
T
.
matrix
(
"x"
)
# the data is presented as rasterized images
y
=
T
.
ivector
(
"y"
)
# the labels are presented as 1D vector of
index
=
tt
.
lscalar
()
# index to a [mini]batch
x
=
tt
.
matrix
(
"x"
)
# the data is presented as rasterized images
y
=
tt
.
ivector
(
"y"
)
# the labels are presented as 1D vector of
# [int] labels
rng
=
np
.
random
.
RandomState
(
1234
)
...
...
@@ -303,7 +303,7 @@ def test_mlp():
# the resulting gradients will be stored in a list gparams
gparams
=
[]
for
param
in
classifier
.
params
:
gparam
=
T
.
grad
(
cost
,
param
)
gparam
=
tt
.
grad
(
cost
,
param
)
gparams
.
append
(
gparam
)
# Some optimizations needed are tagged with 'fast_run'
...
...
@@ -312,7 +312,7 @@ def test_mlp():
updates2
=
OrderedDict
()
updates2
[
classifier
.
hiddenLayer
.
params
[
0
]]
=
T
.
grad
(
updates2
[
classifier
.
hiddenLayer
.
params
[
0
]]
=
tt
.
grad
(
cost
,
classifier
.
hiddenLayer
.
params
[
0
]
)
train_model
=
theano
.
function
(
...
...
@@ -328,7 +328,7 @@ def test_mlp():
# theano.printing.debugprint(train_model, print_type=True)
assert
any
(
[
isinstance
(
i
.
op
,
T
.
nnet
.
CrossentropySoftmax1HotWithBiasDx
)
isinstance
(
i
.
op
,
tt
.
nnet
.
CrossentropySoftmax1HotWithBiasDx
)
for
i
in
train_model
.
maker
.
fgraph
.
toposort
()
]
)
...
...
@@ -348,11 +348,7 @@ def test_mlp():
# theano.printing.debugprint(train_model, print_type=True)
assert
any
(
[
isinstance
(
i
.
op
,
T
.
nnet
.
CrossentropySoftmax1HotWithBiasDx
)
isinstance
(
i
.
op
,
tt
.
nnet
.
CrossentropySoftmax1HotWithBiasDx
)
for
i
in
train_model
.
maker
.
fgraph
.
toposort
()
]
)
if
__name__
==
"__main__"
:
test_mlp
()
tests/tensor/test_opt.py
浏览文件 @
ef279e19
This source diff could not be displayed because it is too large. You can
view the blob
instead.
tests/tensor/test_subtensor.py
浏览文件 @
ef279e19
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论