Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cd3134be
提交
cd3134be
authored
5月 21, 2014
作者:
Hengjean
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added remove op
上级
ba9d8c57
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
80 行增加
和
3 行删除
+80
-3
basic.py
theano/typed_list/basic.py
+45
-1
test_basic.py
theano/typed_list/tests/test_basic.py
+35
-2
没有找到文件。
theano/typed_list/basic.py
浏览文件 @
cd3134be
...
...
@@ -4,6 +4,8 @@ from theano.gof import Apply, Constant, Op, Variable
from
theano.tensor.type_other
import
SliceType
from
theano
import
tensor
as
T
import
numpy
class
_typed_list_py_operators
:
...
...
@@ -146,7 +148,7 @@ class Insert(Op):
index
=
index
=
T
.
constant
(
index
,
ndim
=
0
)
else
:
assert
isinstance
(
index
,
T
.
TensorVariable
)
and
index
.
ndim
==
0
return
Apply
(
self
,
[
x
,
index
,
toInsert
],
[
x
.
t
t
ype
()])
return
Apply
(
self
,
[
x
,
index
,
toInsert
],
[
x
.
type
()])
def
perform
(
self
,
node
,
(
x
,
index
,
toInsert
),
(
out
,
)):
if
not
self
.
inplace
:
...
...
@@ -157,3 +159,45 @@ class Insert(Op):
def
__str__
(
self
):
return
self
.
__class__
.
__name__
class
Remove
(
Op
):
def
__init__
(
self
,
inplace
=
False
):
self
.
inplace
=
inplace
if
self
.
inplace
:
self
.
destroy_map
=
{
0
:
[
0
]}
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
make_node
(
self
,
x
,
toRemove
):
assert
isinstance
(
x
.
type
,
TypedListType
)
assert
x
.
ttype
==
toRemove
.
type
return
Apply
(
self
,
[
x
,
toRemove
],
[
x
.
type
()])
def
perform
(
self
,
node
,
(
x
,
toRemove
),
(
out
,
)):
if
not
self
.
inplace
:
out
[
0
]
=
list
(
x
)
else
:
out
[
0
]
=
x
"""
inelegant workaround for ValueError: The truth value of an
array with more than one element is ambiguous. Use a.any() or a.all()
being thrown when trying to remove a matrix from a matrices list
"""
if
isinstance
(
toRemove
,
numpy
.
ndarray
):
for
y
in
x
:
if
numpy
.
array_equal
(
y
,
toRemove
):
toRemove
=
y
break
out
[
0
]
.
remove
(
toRemove
)
def
__str__
(
self
):
return
self
.
__class__
.
__name__
theano/typed_list/tests/test_basic.py
浏览文件 @
cd3134be
...
...
@@ -8,7 +8,7 @@ from theano import tensor as T
from
theano.tensor.type_other
import
SliceType
from
theano.typed_list.type
import
TypedListType
from
theano.typed_list.basic
import
(
GetItem
,
Insert
,
Append
,
Extend
)
Append
,
Extend
,
Remove
)
from
theano.tests
import
unittest_tools
as
utt
...
...
@@ -212,7 +212,6 @@ class test_extend(unittest.TestCase):
class
test_insert
(
unittest
.
TestCase
):
#FAILING ValueError: expected an ndarray
def
test_inplace
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
...
...
@@ -245,3 +244,37 @@ class test_insert(unittest.TestCase):
y
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
numpy
.
asarray
(
1
),
y
),
[
x
,
y
]))
class
test_remove
(
unittest
.
TestCase
):
def
test_inplace
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
myMatrix
=
T
.
matrix
()
z
=
Remove
(
True
)(
mySymbolicMatricesList
,
myMatrix
)
f
=
theano
.
function
([
mySymbolicMatricesList
,
myMatrix
],
z
,
accept_inplace
=
True
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
y
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
,
y
],
y
),
[
x
]))
def
test_sanity_check
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
myMatrix
=
T
.
matrix
()
z
=
Remove
()(
mySymbolicMatricesList
,
myMatrix
)
f
=
theano
.
function
([
mySymbolicMatricesList
,
myMatrix
],
z
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
y
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
,
y
],
y
),
[
x
]))
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论