Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0e018bc4
提交
0e018bc4
authored
1月 12, 2012
作者:
Arnaud Bergeron
提交者:
Olivier Delalleau
1月 23, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add TensorVariable.zeros_like() and SparseVariable.zeros_like()
Code for sparse was stolen from Yann Dauphin.
上级
b9977855
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
27 行增加
和
5 行删除
+27
-5
basic.py
theano/sparse/basic.py
+9
-0
test_basic.py
theano/sparse/tests/test_basic.py
+11
-0
basic.py
theano/tensor/basic.py
+7
-5
没有找到文件。
theano/sparse/basic.py
浏览文件 @
0e018bc4
...
...
@@ -137,6 +137,11 @@ def sp_ones_like(x):
data
,
indices
,
indptr
,
shape
=
csm_properties
(
x
)
#TODO: don't restrict to CSM formats
return
CSM
(
format
=
x
.
format
)(
tensor
.
ones_like
(
data
),
indices
,
indptr
,
shape
)
def
sp_zeros_like
(
x
):
_
,
_
,
indptr
,
shape
=
csm_properties
(
x
)
#TODO: don't restrict to CSM formats
return
CSM
(
format
=
x
.
format
)(
numpy
.
array
([],
dtype
=
x
.
type
.
dtype
),
numpy
.
array
([]),
tensor
.
zeros_like
(
indptr
),
shape
)
class
_sparse_py_operators
:
T
=
property
(
lambda
self
:
transpose
(
self
),
doc
=
"Return aliased transpose of self (read-only)"
)
def
__neg__
(
self
):
return
neg
(
self
)
...
...
@@ -184,6 +189,10 @@ class SparseVariable(gof.Variable, _sparse_py_operators):
def
__repr__
(
self
):
return
str
(
self
)
def
zeros_like
(
model
,
dtype
=
None
):
# TODO: don't ignore dtype
return
sp_zeros_like
(
model
)
class
SparseConstantSignature
(
tuple
):
def
__eq__
(
self
,
other
):
(
a
,
b
),
(
x
,
y
)
=
self
,
other
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
0e018bc4
...
...
@@ -820,6 +820,17 @@ class UsmmTests(unittest.TestCase):
for
node
in
topo
])
==
nb
class
test_zeros_like
(
unittest
.
TestCase
):
def
test
(
self
):
x
=
theano
.
sparse
.
csr_matrix
()
f
=
theano
.
function
([
x
],
theano
.
sparse
.
sp_zeros_like
(
x
))
vx
=
scipy
.
sparse
.
csr_matrix
(
numpy
.
asarray
(
numpy
.
random
.
binomial
(
1
,
0.5
,
(
100
,
100
)),
dtype
=
theano
.
config
.
floatX
))
fx
=
f
(
vx
)
assert
fx
.
nnz
==
0
assert
fx
.
shape
==
vx
.
shape
def
test_shape_i
():
sparse_dtype
=
'float32'
...
...
theano/tensor/basic.py
浏览文件 @
0e018bc4
...
...
@@ -1454,7 +1454,12 @@ class _tensor_py_operators:
class
TensorVariable
(
_tensor_py_operators
,
Variable
):
"""Subclass to add the tensor operators to the basic `Variable` class."""
def
zeros_like
(
model
,
dtype
=
None
):
"Used for grad, Lop and Rop"
# Tested through the zeros_like method below
if
dtype
is
None
:
dtype
=
model
.
type
.
dtype
return
fill
(
model
,
constant
(
0.0
,
dtype
=
dtype
))
TensorType
.
Variable
=
TensorVariable
...
...
@@ -2364,10 +2369,7 @@ def ones_like(model, dtype=None):
@constructor
def
zeros_like
(
model
,
dtype
=
None
):
"""equivalent of numpy.zeros_like"""
if
dtype
is
None
:
dtype
=
model
.
type
.
dtype
return
fill
(
model
,
constant
(
0.0
,
dtype
=
dtype
))
return
TensorVariable
.
zeros_like
(
model
,
dtype
=
None
)
def
zeros
(
shape
,
dtype
=
config
.
floatX
):
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论