Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c8ed209a
提交
c8ed209a
authored
7月 11, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New internal interface to the sparse grad of AdvancedSubtensor1
上级
9345964d
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
26 行增加
和
6 行删除
+26
-6
__init__.py
theano/__init__.py
+2
-4
test_basic.py
theano/sparse/tests/test_basic.py
+8
-0
basic.py
theano/tensor/basic.py
+16
-2
没有找到文件。
theano/__init__.py
浏览文件 @
c8ed209a
...
@@ -176,10 +176,8 @@ def sparse_grad(var):
...
@@ -176,10 +176,8 @@ def sparse_grad(var):
"""
"""
assert
isinstance
(
var
.
owner
.
op
,
tensor
.
AdvancedSubtensor1
)
assert
isinstance
(
var
.
owner
.
op
,
tensor
.
AdvancedSubtensor1
)
# TODO change the internal representation!!!
ret
=
var
.
owner
.
op
.
__class__
(
sparse_grad
=
True
)(
*
var
.
owner
.
inputs
)
# It work, but bad as out.type is shared with var.type!!!
return
ret
var
.
owner
.
inputs
[
0
]
.
tag
.
sparse_grad
=
True
return
var
import
theano.tests
import
theano.tests
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
c8ed209a
...
@@ -450,6 +450,14 @@ class TestConstructSparseFromList(unittest.TestCase):
...
@@ -450,6 +450,14 @@ class TestConstructSparseFromList(unittest.TestCase):
g
=
theano
.
grad
(
sub
.
sum
(),
m
)
g
=
theano
.
grad
(
sub
.
sum
(),
m
)
assert
isinstance
(
g
.
owner
.
op
,
ConstructSparseFromList
)
assert
isinstance
(
g
.
owner
.
op
,
ConstructSparseFromList
)
# Test that we create a sparse grad when asked
# Op INTERFACE
m
=
theano
.
tensor
.
matrix
()
v
=
theano
.
tensor
.
ivector
()
sub
=
theano
.
tensor
.
AdvancedSubtensor1
(
sparse_grad
=
True
)(
m
,
v
)
g
=
theano
.
grad
(
sub
.
sum
(),
m
)
assert
isinstance
(
g
.
owner
.
op
,
ConstructSparseFromList
)
# Test the sparse grad
# Test the sparse grad
valm
=
numpy
.
random
.
rand
(
5
,
4
)
.
astype
(
config
.
floatX
)
valm
=
numpy
.
random
.
rand
(
5
,
4
)
.
astype
(
config
.
floatX
)
valv
=
numpy
.
random
.
random_integers
(
0
,
4
,
10
)
valv
=
numpy
.
random
.
random_integers
(
0
,
4
,
10
)
...
...
theano/tensor/basic.py
浏览文件 @
c8ed209a
...
@@ -706,6 +706,11 @@ class TensorType(Type):
...
@@ -706,6 +706,11 @@ class TensorType(Type):
self
.
name
=
name
self
.
name
=
name
self
.
numpy_dtype
=
numpy
.
dtype
(
self
.
dtype
)
self
.
numpy_dtype
=
numpy
.
dtype
(
self
.
dtype
)
self
.
sparse_grad
=
sparse_grad
self
.
sparse_grad
=
sparse_grad
if
sparse_grad
:
warnings
.
warn
(
"DEPRECATION WARNING: You use an old interface to"
" AdvancedSubtensor1 sparse_grad. Now use"
" theano.sparse_grad(a_tensor[an_int_vector])."
)
def
filter
(
self
,
data
,
strict
=
False
,
allow_downcast
=
None
):
def
filter
(
self
,
data
,
strict
=
False
,
allow_downcast
=
None
):
"""Convert `data` to something which can be associated to a
"""Convert `data` to something which can be associated to a
...
@@ -7153,6 +7158,9 @@ def inverse_permutation(perm):
...
@@ -7153,6 +7158,9 @@ def inverse_permutation(perm):
class
AdvancedSubtensor1
(
Op
):
class
AdvancedSubtensor1
(
Op
):
"""Implement x[ilist] where ilist is a vector of integers."""
"""Implement x[ilist] where ilist is a vector of integers."""
def
__init__
(
self
,
sparse_grad
=
False
):
self
.
sparse_grad
=
sparse_grad
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
(
type
(
self
))
return
hash
(
type
(
self
))
...
@@ -7212,8 +7220,14 @@ class AdvancedSubtensor1(Op):
...
@@ -7212,8 +7220,14 @@ class AdvancedSubtensor1(Op):
x
,
ilist
=
inputs
x
,
ilist
=
inputs
gz
,
=
grads
gz
,
=
grads
assert
len
(
inputs
)
==
2
assert
len
(
inputs
)
==
2
sparse
=
False
if
x
.
type
.
sparse_grad
:
if
getattr
(
x
.
type
,
'sparse_grad'
,
False
):
sparse
=
True
warnings
.
warn
(
"DEPRECATION WARNING: AdvancedSubtensor1, you are using"
" an old interface to the sparse grad. You should use"
" theano.sparse_grad(a_tensor[an_int_vector]). "
)
if
sparse
or
self
.
sparse_grad
:
if
x
.
type
.
ndim
!=
2
:
if
x
.
type
.
ndim
!=
2
:
raise
TypeError
(
raise
TypeError
(
"AdvancedSubtensor1: you can't take the sparse grad"
"AdvancedSubtensor1: you can't take the sparse grad"
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论