Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ea3e7426
提交
ea3e7426
authored
5月 01, 2015
作者:
Melanie Ducoffe
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
en cours
Conflicts: theano/tensor/tests/test_basic.py
上级
a6a7afb4
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
32 行增加
和
12 行删除
+32
-12
basic.py
theano/tensor/basic.py
+12
-11
test_basic.py
theano/tensor/tests/test_basic.py
+20
-1
没有找到文件。
theano/tensor/basic.py
浏览文件 @
ea3e7426
...
...
@@ -17,7 +17,7 @@ from theano.tensor import elemwise
from
theano.tensor.var
import
(
AsTensorError
,
TensorVariable
,
TensorConstant
,
_tensor_py_operators
)
from
theano.tensor.type
import
TensorType
from
theano.tensor.type
import
TensorType
,
values_eq_approx_always_true
from
theano.tensor.type_other
import
NoneConst
from
theano
import
scalar
as
scal
from
theano.compat
import
partial
...
...
@@ -5478,28 +5478,27 @@ class AllocEmpty(gof.Op):
# specify the type of the data
def
__init__
(
self
,
dtype
):
assert
isinstance
(
dtype
,
str
)
self
.
dtype
=
'NPY_'
+
dtype
.
upp
er
()
self
.
dtype
=
dtype
.
low
er
()
@staticmethod
def
validate_shape
(
shape
):
sh
=
[
tensor
.
as_tensor_variable
(
s
)
for
s
in
shape
]
def
validate_shape
(
self
,
shape
):
sh
=
[
as_tensor_variable
(
s
)
for
s
in
shape
]
bcast
=
[]
for
s
in
sh
:
if
s
.
type
.
dtype
[:
3
]
not
in
(
'int'
,
'uin'
):
raise
TypeError
(
'Shape arguments must be integers'
,
s
)
# if s is constant 1, then we're broadcastable in that dim
try
:
const_shp
=
tensor
.
get_scalar_constant_value
(
s
)
except
tensor
.
NotScalarConstantError
:
const_shp
=
get_scalar_constant_value
(
s
)
except
NotScalarConstantError
:
const_shp
=
None
bcast
.
append
(
numpy
.
all
(
1
==
const_shp
))
otype
=
tensor
.
TensorType
(
dtype
=
self
.
dtype
,
broadcastable
=
bcast
)
otype
=
TensorType
(
dtype
=
self
.
dtype
,
broadcastable
=
bcast
)
output
=
otype
()
return
sh
,
output
def
make_node
(
self
,
*
shape
):
shape
,
output
=
self
.
validate_shape
(
shape
)
output
.
tag
.
values_eq_approx
=
tensor
.
type
.
values_eq_approx_always_true
output
.
tag
.
values_eq_approx
=
values_eq_approx_always_true
return
Apply
(
self
,
shape
,
[
output
])
def
perform
(
self
,
node
,
inputs
,
out_
):
...
...
@@ -5513,15 +5512,17 @@ class AllocEmpty(gof.Op):
return
False
def
c_code
(
self
,
node
,
name
,
inputs
,
out_
,
sub
):
dtype
=
self
.
dtype
dtype
=
"NPY_"
+
self
.
dtype
.
upper
()
out
,
=
out_
fail
=
sub
[
'fail'
]
shps
=
inputs
nd
=
len
(
shps
)
str
=
"int dims[
%(nd)
s];
\n
"
%
locals
()
for
idx
,
sh
in
enumerate
(
shps
):
str
+=
"dims[
%(idx)
s] ="
\
"PyInt_AsLong((PyObject*)
%(sh)
s);
\n
"
%
locals
()
# Validate that the output storage exists
str
+=
"if(
%(out)
s==NULL
\n
"
%
locals
()
for
idx
,
sh
in
enumerate
(
shps
):
...
...
@@ -5533,7 +5534,7 @@ class AllocEmpty(gof.Op):
output variable */
Py_XDECREF(
%(out)
s);
%(out)
s = (PyArrayObject*)PyArray_EMPTY(
%(nd)
s,
PyArray_DIMS(dims)
,
dims
,
%(dtype)
s,
0);
if (!
%(out)
s)
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
ea3e7426
...
...
@@ -46,7 +46,7 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
itensor3
,
Tile
,
switch
,
Diagonal
,
Diag
,
nonzero
,
flatnonzero
,
nonzero_values
,
stacklists
,
DimShuffle
,
hessian
,
ptp
,
power
,
swapaxes
,
choose
,
Choose
,
NoneConst
,
swapaxes
,
choose
,
Choose
,
NoneConst
,
AllocEmpty
)
from
theano.tests
import
unittest_tools
as
utt
...
...
@@ -7536,6 +7536,25 @@ class T_Choose(utt.InferShapeTester):
# Op that should be removed from the graph.
self
.
op_class
)
def
test_allocempty
():
# Test that we allocated correctly
f
=
theano
.
function
([],
AllocEmpty
(
"float32"
)(
2
,
3
))
# change
assert
len
(
f
.
maker
.
fgraph
.
apply_nodes
)
==
1
out
=
f
()
assert
out
.
shape
==
(
2
,
3
)
assert
out
.
dtype
==
'float32'
# Test that we do not merge them.
f
=
theano
.
function
([],
[
AllocEmpty
(
"float32"
)(
2
,
3
),
AllocEmpty
(
"float32"
)(
2
,
3
)])
out
=
f
()
assert
out
[
0
]
.
shape
==
(
2
,
3
)
assert
out
[
0
]
.
dtype
==
'float32'
assert
out
[
1
]
.
shape
==
(
2
,
3
)
assert
out
[
1
]
.
dtype
==
'float32'
assert
len
([
node
for
node
in
f
.
maker
.
fgraph
.
apply_nodes
if
isinstance
(
node
.
op
,
AllocEmpty
)])
==
2
"""
if __name__ == '__main__':
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论