Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9d451659
提交
9d451659
authored
4月 10, 2015
作者:
Melanie Ducoffe
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
class AllocEmpty
上级
1528acdc
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
88 行增加
和
1 行删除
+88
-1
basic.py
theano/tensor/basic.py
+88
-1
没有找到文件。
theano/tensor/basic.py
浏览文件 @
9d451659
...
@@ -589,7 +589,8 @@ def get_scalar_constant_value(orig_v, elemwise=True,
...
@@ -589,7 +589,8 @@ def get_scalar_constant_value(orig_v, elemwise=True,
continue
continue
elif
isinstance
(
v
.
owner
.
op
,
theano
.
compile
.
ops
.
Shape_i
):
elif
isinstance
(
v
.
owner
.
op
,
theano
.
compile
.
ops
.
Shape_i
):
if
isinstance
(
v
.
owner
.
inputs
[
0
],
Constant
):
if
isinstance
(
v
.
owner
.
inputs
[
0
],
Constant
):
return
numpy
.
asarray
(
v
.
owner
.
inputs
[
0
]
.
data
.
shape
[
v
.
owner
.
op
.
i
])
return
numpy
.
asarray
(
v
.
owner
.
inputs
[
0
]
.
data
.
shape
[
v
.
owner
.
op
.
i
])
# Don't act as the constant_folding optimization here as this
# Don't act as the constant_folding optimization here as this
# fct is used too early in the optimization phase. This would
# fct is used too early in the optimization phase. This would
# mess with the stabilization optimization and be too slow.
# mess with the stabilization optimization and be too slow.
...
@@ -5468,3 +5469,89 @@ class Choose(Op):
...
@@ -5468,3 +5469,89 @@ class Choose(Op):
choice
=
inputs
[
1
]
choice
=
inputs
[
1
]
# TODO reuse out?
# TODO reuse out?
z
[
0
]
=
numpy
.
choose
(
a
,
choice
,
mode
=
self
.
mode
)
z
[
0
]
=
numpy
.
choose
(
a
,
choice
,
mode
=
self
.
mode
)
class
AllocEmpty
(
gof
.
Op
):
"""Implement Alloc on the gpu, but without initializing memory."""
__props__
=
()
# specify the type of the data
def
__init__
(
self
,
dtype
):
assert
isinstance
(
dtype
,
string
)
self
.
dtype
=
'NPY_'
+
dtype
.
upper
()
@staticmethod
def
validate_shape
(
shape
):
sh
=
[
tensor
.
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
=
None
bcast
.
append
(
numpy
.
all
(
1
==
const_shp
))
otype
=
tensor
.
TensorType
(
dtype
=
'float32'
,
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
return
Apply
(
self
,
shape
,
[
output
])
def
perform
(
self
,
node
,
inputs
,
out_
):
out
,
=
out_
sh
=
tuple
([
int
(
i
)
for
i
in
inputs
])
if
out
[
0
]
is
None
or
out
[
0
]
.
shape
!=
sh
:
# XXX: We could implement and call CudaNdarray.empty(sh) instead.
out
[
0
]
=
numpy
.
zeros
(
sh
)
def
do_merge
(
self
,
node
):
return
False
def
c_code
(
self
,
node
,
name
,
inputs
,
out_
,
sub
):
dtype
=
self
.
dtype
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
):
str
+=
"||PyArray_DIMS(
%(out)
s)[
%(idx)
s]!=dims[
%(idx)
s]"
%
locals
()
str
+=
"""){
/* Reference received to invalid output variable.
Decrease received reference's ref count and allocate new
output variable */
Py_XDECREF(
%(out)
s);
%(out)
s = (PyArrayObject*)PyArray_EMPTY(
%(nd)
s,
PyArray_DIMS(dims),
%(dtype)
s,
0);
if (!
%(out)
s)
{
// exception already set
%(fail)
s;
}
}
"""
%
locals
()
return
str
def
infer_shape
(
self
,
node
,
input_shapes
):
return
[
node
.
inputs
]
def
c_code_cache_version
(
self
):
return
(
1
,)
def
do_constant_folding
(
self
,
node
):
return
False
alloc_empty
=
AllocEmpty
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论