Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
45d20c3f
提交
45d20c3f
authored
2月 18, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
If 0'd out Filler and Repeat Ops for a lack of documentation, testing and
internal use. I created a new Alloc() Op that is used for fill-lifting Optimizations.
上级
8f9c55c7
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
125 行增加
和
69 行删除
+125
-69
basic.py
theano/tensor/basic.py
+125
-69
没有找到文件。
theano/tensor/basic.py
浏览文件 @
45d20c3f
...
@@ -1678,60 +1678,113 @@ def zeros_like(model):
...
@@ -1678,60 +1678,113 @@ def zeros_like(model):
#return Zeros(model.type.ndim)(shape(model))
#return Zeros(model.type.ndim)(shape(model))
return
fill
(
model
,
constant
(
0.0
,
dtype
=
model
.
type
.
dtype
))
return
fill
(
model
,
constant
(
0.0
,
dtype
=
model
.
type
.
dtype
))
class
Filler
(
gof
.
Op
):
if
0
:
## COMMENTED OUT FEB 17 2010
## TODO (DOCUMENT AND WRITE TESTS) OR DELETE
class
Filler
(
gof
.
Op
):
"""WRITEME"""
def
__init__
(
self
,
value
,
ndim
,
dtype
=
'float64'
):
self
.
value
=
value
self
.
ndim
=
ndim
self
.
dtype
=
dtype
self
.
type
=
TensorType
(
dtype
=
dtype
,
broadcastable
=
(
False
,)
*
ndim
)
def
make_node
(
self
,
dims
):
dims
=
as_tensor_variable
(
dims
)
return
gof
.
Apply
(
self
,
[
dims
],
[
self
.
type
()])
def
perform
(
self
,
node
,
(
dims
,),
(
out
,)):
if
out
[
0
]
is
not
None
:
out
[
0
]
.
resize
(
dims
,
refcheck
=
0
)
out
[
0
]
.
fill
(
self
.
value
)
else
:
if
self
.
value
==
0
:
out
[
0
]
=
numpy
.
zeros
(
dims
,
dtype
=
self
.
dtype
)
elif
self
.
value
==
1
:
out
[
0
]
=
numpy
.
ones
(
dims
,
dtype
=
self
.
dtype
)
else
:
out
[
0
]
=
numpy
.
ones
(
dims
,
dtype
=
self
.
dtype
)
*
self
.
value
def
grad
(
self
,
(
dims
,),
(
gout
,)):
return
None
,
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
and
self
.
ndim
==
other
.
ndim
and
self
.
dtype
==
other
.
dtype
def
__hash__
(
self
):
return
hash
(
self
.
ndim
)
^
hash
(
self
.
dtype
)
Zeros
=
partial
(
Filler
,
0
)
"""WRITEME"""
Ones
=
partial
(
Filler
,
1
)
"""WRITEME"""
"""WRITEME"""
def
__init__
(
self
,
value
,
ndim
,
dtype
=
'float64'
):
self
.
value
=
value
self
.
ndim
=
ndim
self
.
dtype
=
dtype
self
.
type
=
TensorType
(
dtype
=
dtype
,
broadcastable
=
(
False
,)
*
ndim
)
def
make_node
(
self
,
dims
):
@constructor
dims
=
as_tensor_variable
(
dims
)
def
zero
():
return
gof
.
Apply
(
self
,
[
dims
],
[
self
.
type
()])
"""
Return a scalar zero, e.g. for initializing sums.
"""
return
Zeros
(
0
)([])
def
perform
(
self
,
node
,
(
dims
,),
(
out
,)):
@constructor
if
out
[
0
]
is
not
None
:
def
one
():
out
[
0
]
.
resize
(
dims
,
refcheck
=
0
)
"""WRITEME"""
out
[
0
]
.
fill
(
self
.
value
)
return
Ones
(
0
)([])
else
:
if
self
.
value
==
0
:
out
[
0
]
=
numpy
.
zeros
(
dims
,
dtype
=
self
.
dtype
)
elif
self
.
value
==
1
:
out
[
0
]
=
numpy
.
ones
(
dims
,
dtype
=
self
.
dtype
)
else
:
out
[
0
]
=
numpy
.
ones
(
dims
,
dtype
=
self
.
dtype
)
*
self
.
value
def
grad
(
self
,
(
dims
,),
(
gout
,)):
pprint
.
assign
(
lambda
pstate
,
r
:
r
.
owner
and
isinstance
(
r
.
owner
.
op
,
Filler
)
and
r
.
owner
.
op
.
value
==
0
,
printing
.
FunctionPrinter
(
'zeros'
))
return
None
,
pprint
.
assign
(
lambda
pstate
,
r
:
r
.
owner
and
isinstance
(
r
.
owner
.
op
,
Filler
)
and
r
.
owner
.
op
.
value
==
1
,
printing
.
FunctionPrinter
(
'ones'
))
def
__eq__
(
self
,
other
):
class
Alloc
(
gof
.
Op
):
return
type
(
self
)
==
type
(
other
)
and
self
.
ndim
==
other
.
ndim
and
self
.
dtype
==
other
.
dty
pe
"""Create a Tensor from an initial value and a desired sha
pe
def
__hash__
(
self
):
alloc(value, shape0, shape1, ..., shapeN)
return
hash
(
self
.
ndim
)
^
hash
(
self
.
dtype
)
Zeros
=
partial
(
Filler
,
0
)
Returns an N-dimensional tensor initialized by `value` using something equivalent to
"""WRITEME"""
>>> z = numpy.zeros(shape, value.dtype)
>>> z += value
Ones
=
partial
(
Filler
,
1
)
The result has N dimensions, has the dtype of `value` and is obtained by broadcasting value
"""WRITEME"""
over the output ndarray.
@constructor
This Op is used to replace fill() during optimizations because after shapes are lifted,
def
zero
():
the first argument to fill can often be pruned from the graph.
"""
Return a scalar zero, e.g. for initializing sums.
"""
"""
return
Zeros
(
0
)([])
def
__init__
(
self
,
dtype
):
self
.
dtype
=
dtype
@constructor
def
__eq__
(
self
,
other
):
def
one
():
return
type
(
self
)
==
type
(
other
)
and
self
.
dtype
==
other
.
dtype
"""WRITEME"""
return
Ones
(
0
)([])
def
__hash__
(
self
):
return
hash
(
type
(
self
))
^
hash
(
self
.
dtype
)
def
__str__
(
self
):
return
'
%
s{
%
s}'
%
(
self
.
__class__
.
__name__
,
self
.
dtype
)
def
make_node
(
self
,
value
,
*
shape
):
v
=
as_tensor_variable
(
value
)
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
bcast
.
append
(
isinstance
(
s
,
TensorConstant
)
and
(
s
.
data
==
1
))
otype
=
TensorType
(
dtype
=
self
.
dtype
,
broadcastable
=
bcast
)
return
gof
.
Apply
(
self
,
[
v
]
+
sh
,
[
otype
()])
def
perform
(
self
,
node
,
inputs
,
(
out
,)):
v
=
inputs
[
0
]
sh
=
tuple
([
int
(
i
)
for
i
in
inputs
[
1
:]])
if
out
[
0
]
is
None
or
out
[
0
]
.
shape
!=
sh
:
out
[
0
]
=
numpy
.
zeros
(
sh
,
dtype
=
self
.
dtype
)
out
[
0
][
...
]
+=
v
# broadcast v to fill us up
def
grad
(
self
,
inputs
,
(
gout
,)):
return
[
None
for
i
in
inputs
]
pprint
.
assign
(
lambda
pstate
,
r
:
r
.
owner
and
isinstance
(
r
.
owner
.
op
,
Filler
)
and
r
.
owner
.
op
.
value
==
0
,
printing
.
FunctionPrinter
(
'zeros'
))
pprint
.
assign
(
lambda
pstate
,
r
:
r
.
owner
and
isinstance
(
r
.
owner
.
op
,
Filler
)
and
r
.
owner
.
op
.
value
==
1
,
printing
.
FunctionPrinter
(
'ones'
))
@_redefine
(
elemwise
.
Elemwise
(
scal
.
identity
))
@_redefine
(
elemwise
.
Elemwise
(
scal
.
identity
))
def
tensor_copy
(
a
):
def
tensor_copy
(
a
):
...
@@ -1851,33 +1904,36 @@ def var(input, axis = None):
...
@@ -1851,33 +1904,36 @@ def var(input, axis = None):
#return the mean sqr
#return the mean sqr
return
mean
(
centered_input
**
2
,
axis
)
return
mean
(
centered_input
**
2
,
axis
)
class
Repeat
(
gof
.
Op
):
if
0
:
## COMMENTED OUT FEB 17 2010
def
make_node
(
self
,
input
,
repeats
,
axis
):
## TODO (DOCUMENT AND WRITE TESTS) OR DELETE
assert
isinstance
(
input
.
type
,
TensorType
)
class
Repeat
(
gof
.
Op
):
assert
repeats
.
type
==
iscalar
assert
axis
.
type
==
iscalar
def
make_node
(
self
,
input
,
repeats
,
axis
):
broadcastable
=
[]
assert
isinstance
(
input
.
type
,
TensorType
)
for
i
,
x
in
enumerate
(
input
.
broadcastable
):
assert
repeats
.
type
==
iscalar
if
i
==
axis
:
assert
axis
.
type
==
iscalar
broadcastable
+=
[
False
]
broadcastable
=
[]
else
:
for
i
,
x
in
enumerate
(
input
.
broadcastable
):
broadcastable
+=
[
x
]
if
i
==
axis
:
broadcastable
+=
[
False
]
type
=
TensorType
(
dtype
=
input
.
type
.
dtype
,
broadcastable
=
\
else
:
broadcastable
)
broadcastable
+=
[
x
]
#backport
#type = TensorType(dtype = input.type.dtype,
type
=
TensorType
(
dtype
=
input
.
type
.
dtype
,
broadcastable
=
\
# broadcastable = [False if i==axis else x for i, x in enumerate(input.broadcastable)])
broadcastable
)
return
gof
.
Apply
(
self
,
[
inputs
,
repeats
,
axis
],
[
type
()])
#backport
#type = TensorType(dtype = input.type.dtype,
def
perform
(
self
,
node
,
(
input
,
repeats
,
axis
),
(
out
,
)):
# broadcastable = [False if i==axis else x for i, x in enumerate(input.broadcastable)])
out
[
0
]
=
numpy
.
repeat
(
input
,
repeats
,
axis
)
return
gof
.
Apply
(
self
,
[
inputs
,
repeats
,
axis
],
[
type
()])
def
grad
(
self
,
(
input
,
repeats
,
axis
),
(
gout
,
)):
def
perform
(
self
,
node
,
(
input
,
repeats
,
axis
),
(
out
,
)):
return
add
.
grad
((
input
,
gout
),
(
gout
,))[:
1
]
out
[
0
]
=
numpy
.
repeat
(
input
,
repeats
,
axis
)
repeat
=
Repeat
()
def
grad
(
self
,
(
input
,
repeats
,
axis
),
(
gout
,
)):
return
add
.
grad
((
input
,
gout
),
(
gout
,))[:
1
]
repeat
=
Repeat
()
class
Default
(
gof
.
Op
):
class
Default
(
gof
.
Op
):
"""
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论