Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9e2a2b17
提交
9e2a2b17
authored
5月 27, 2014
作者:
Hengjean
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added index op.
上级
fc40a93c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
87 行增加
和
1 行删除
+87
-1
basic.py
theano/typed_list/basic.py
+35
-0
test_basic.py
theano/typed_list/tests/test_basic.py
+52
-1
没有找到文件。
theano/typed_list/basic.py
浏览文件 @
9e2a2b17
...
@@ -27,6 +27,10 @@ class _typed_list_py_operators:
...
@@ -27,6 +27,10 @@ class _typed_list_py_operators:
def
reverse
(
self
):
def
reverse
(
self
):
return
Reverse
()(
self
)
return
Reverse
()(
self
)
#name "index" is already used by an attribute
def
ind
(
self
,
elem
):
return
Index
()(
self
,
elem
)
ttype
=
property
(
lambda
self
:
self
.
type
.
ttype
)
ttype
=
property
(
lambda
self
:
self
.
type
.
ttype
)
...
@@ -239,3 +243,34 @@ class Reverse(Op):
...
@@ -239,3 +243,34 @@ class Reverse(Op):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
__class__
.
__name__
return
self
.
__class__
.
__name__
class
Index
(
Op
):
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
make_node
(
self
,
x
,
elem
):
assert
isinstance
(
x
.
type
,
TypedListType
)
assert
x
.
ttype
==
elem
.
type
return
Apply
(
self
,
[
x
,
elem
],
[
T
.
scalar
()])
def
perform
(
self
,
node
,
(
x
,
elem
),
(
out
,
)):
"""
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
(
elem
,
numpy
.
ndarray
):
for
y
in
range
(
x
.
__len__
()):
if
numpy
.
array_equal
(
x
[
y
],
elem
):
out
[
0
]
=
numpy
.
asarray
([
y
])
break
else
:
out
[
0
]
=
numpy
.
asarray
([
x
.
index
(
elem
)])
def
__str__
(
self
):
return
self
.
__class__
.
__name__
theano/typed_list/tests/test_basic.py
浏览文件 @
9e2a2b17
...
@@ -8,7 +8,8 @@ from theano import tensor as T
...
@@ -8,7 +8,8 @@ from theano import tensor as T
from
theano.tensor.type_other
import
SliceType
from
theano.tensor.type_other
import
SliceType
from
theano.typed_list.type
import
TypedListType
from
theano.typed_list.type
import
TypedListType
from
theano.typed_list.basic
import
(
GetItem
,
Insert
,
from
theano.typed_list.basic
import
(
GetItem
,
Insert
,
Append
,
Extend
,
Remove
,
Reverse
)
Append
,
Extend
,
Remove
,
Reverse
,
Index
)
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
...
@@ -355,3 +356,53 @@ class test_reverse(unittest.TestCase):
...
@@ -355,3 +356,53 @@ class test_reverse(unittest.TestCase):
y
=
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
]))
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
,
y
]),
[
y
,
x
]))
class
test_index
(
unittest
.
TestCase
):
def
test_sanity_check
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
myMatrix
=
T
.
matrix
()
z
=
Index
()(
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
(
f
([
x
,
y
],
y
)
==
1
)
def
test_interface
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
myMatrix
=
T
.
matrix
()
z
=
mySymbolicMatricesList
.
ind
(
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
(
f
([
x
,
y
],
y
)
==
1
)
def
test_non_tensor_type
(
self
):
mySymbolicNestedMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)),
1
)()
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
z
=
mySymbolicNestedMatricesList
.
ind
(
mySymbolicMatricesList
)
f
=
theano
.
function
([
mySymbolicNestedMatricesList
,
mySymbolicMatricesList
],
z
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
y
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
self
.
assertTrue
(
f
([[
x
,
y
],
[
x
,
y
,
y
]],
[
x
,
y
])
==
0
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论