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 个修改的文件
包含
69 行增加
和
13 行删除
+69
-13
basic.py
theano/tensor/basic.py
+69
-13
没有找到文件。
theano/tensor/basic.py
浏览文件 @
45d20c3f
...
@@ -1678,7 +1678,10 @@ def zeros_like(model):
...
@@ -1678,7 +1678,10 @@ 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"""
"""WRITEME"""
def
__init__
(
self
,
value
,
ndim
,
dtype
=
'float64'
):
def
__init__
(
self
,
value
,
ndim
,
dtype
=
'float64'
):
self
.
value
=
value
self
.
value
=
value
...
@@ -1712,26 +1715,76 @@ class Filler(gof.Op):
...
@@ -1712,26 +1715,76 @@ class Filler(gof.Op):
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
(
self
.
ndim
)
^
hash
(
self
.
dtype
)
return
hash
(
self
.
ndim
)
^
hash
(
self
.
dtype
)
Zeros
=
partial
(
Filler
,
0
)
Zeros
=
partial
(
Filler
,
0
)
"""WRITEME"""
"""WRITEME"""
Ones
=
partial
(
Filler
,
1
)
Ones
=
partial
(
Filler
,
1
)
"""WRITEME"""
"""WRITEME"""
@constructor
@constructor
def
zero
():
def
zero
():
"""
"""
Return a scalar zero, e.g. for initializing sums.
Return a scalar zero, e.g. for initializing sums.
"""
"""
return
Zeros
(
0
)([])
return
Zeros
(
0
)([])
@constructor
@constructor
def
one
():
def
one
():
"""WRITEME"""
"""WRITEME"""
return
Ones
(
0
)([])
return
Ones
(
0
)([])
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
==
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'
))
pprint
.
assign
(
lambda
pstate
,
r
:
r
.
owner
and
isinstance
(
r
.
owner
.
op
,
Filler
)
and
r
.
owner
.
op
.
value
==
1
,
printing
.
FunctionPrinter
(
'ones'
))
class
Alloc
(
gof
.
Op
):
"""Create a Tensor from an initial value and a desired shape
alloc(value, shape0, shape1, ..., shapeN)
Returns an N-dimensional tensor initialized by `value` using something equivalent to
>>> z = numpy.zeros(shape, value.dtype)
>>> z += value
The result has N dimensions, has the dtype of `value` and is obtained by broadcasting value
over the output ndarray.
This Op is used to replace fill() during optimizations because after shapes are lifted,
the first argument to fill can often be pruned from the graph.
"""
def
__init__
(
self
,
dtype
):
self
.
dtype
=
dtype
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
and
self
.
dtype
==
other
.
dtype
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
]
@_redefine
(
elemwise
.
Elemwise
(
scal
.
identity
))
@_redefine
(
elemwise
.
Elemwise
(
scal
.
identity
))
def
tensor_copy
(
a
):
def
tensor_copy
(
a
):
...
@@ -1851,7 +1904,10 @@ def var(input, axis = None):
...
@@ -1851,7 +1904,10 @@ 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
## TODO (DOCUMENT AND WRITE TESTS) OR DELETE
class
Repeat
(
gof
.
Op
):
def
make_node
(
self
,
input
,
repeats
,
axis
):
def
make_node
(
self
,
input
,
repeats
,
axis
):
assert
isinstance
(
input
.
type
,
TensorType
)
assert
isinstance
(
input
.
type
,
TensorType
)
...
@@ -1877,7 +1933,7 @@ class Repeat(gof.Op):
...
@@ -1877,7 +1933,7 @@ class Repeat(gof.Op):
def
grad
(
self
,
(
input
,
repeats
,
axis
),
(
gout
,
)):
def
grad
(
self
,
(
input
,
repeats
,
axis
),
(
gout
,
)):
return
add
.
grad
((
input
,
gout
),
(
gout
,))[:
1
]
return
add
.
grad
((
input
,
gout
),
(
gout
,))[:
1
]
repeat
=
Repeat
()
repeat
=
Repeat
()
class
Default
(
gof
.
Op
):
class
Default
(
gof
.
Op
):
"""
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论