Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d82eb54a
提交
d82eb54a
authored
6月 14, 2014
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1917 from Hengjean/TypedListLength
Added Length Op to typed list.
上级
de8c4a4c
037b5c66
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
71 行增加
和
1 行删除
+71
-1
basic.py
theano/typed_list/basic.py
+44
-0
test_basic.py
theano/typed_list/tests/test_basic.py
+27
-1
没有找到文件。
theano/typed_list/basic.py
浏览文件 @
d82eb54a
...
@@ -13,6 +13,9 @@ class _typed_list_py_operators:
...
@@ -13,6 +13,9 @@ class _typed_list_py_operators:
def
__getitem__
(
self
,
index
):
def
__getitem__
(
self
,
index
):
return
getitem
(
self
,
index
)
return
getitem
(
self
,
index
)
def
__len__
(
self
):
return
length
(
self
)
def
append
(
self
,
toAppend
):
def
append
(
self
,
toAppend
):
return
append
(
self
,
toAppend
)
return
append
(
self
,
toAppend
)
...
@@ -438,3 +441,44 @@ class Count(Op):
...
@@ -438,3 +441,44 @@ class Count(Op):
return
self
.
__class__
.
__name__
return
self
.
__class__
.
__name__
count
=
Count
()
count
=
Count
()
class
Length
(
Op
):
# See doc in instance of this Op after the class definition.
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
make_node
(
self
,
x
):
assert
isinstance
(
x
.
type
,
TypedListType
)
return
Apply
(
self
,
[
x
],
[
T
.
scalar
(
dtype
=
'int64'
)])
def
perform
(
self
,
node
,
x
,
(
out
,
)):
out
[
0
]
=
numpy
.
asarray
(
len
(
x
[
0
]),
'int64'
)
def
__str__
(
self
):
return
self
.
__class__
.
__name__
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
x_name
=
inp
[
0
]
output_name
=
out
[
0
]
fail
=
sub
[
'fail'
]
return
"""
if(!
%(output_name)
s)
%(output_name)
s=(PyArrayObject*)PyArray_EMPTY(0, NULL, NPY_INT64, 0);
((npy_int64*)PyArray_DATA(
%(output_name)
s))[0]=PyList_Size((PyObject*)
%(x_name)
s);
Py_INCREF(
%(output_name)
s);
"""
%
locals
()
def
c_code_cache_version
(
self
):
return
(
1
,)
length
=
Length
()
"""
Returns the size of a list.
:param x: typed list.
"""
theano/typed_list/tests/test_basic.py
浏览文件 @
d82eb54a
...
@@ -9,7 +9,7 @@ from theano.tensor.type_other import SliceType
...
@@ -9,7 +9,7 @@ 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
,
Count
)
Index
,
Count
,
Length
)
from
theano
import
sparse
from
theano
import
sparse
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
import
scipy.sparse
as
sp
import
scipy.sparse
as
sp
...
@@ -511,3 +511,29 @@ class test_count(unittest.TestCase):
...
@@ -511,3 +511,29 @@ class test_count(unittest.TestCase):
y
=
sp
.
csr_matrix
(
random_lil
((
10
,
40
),
theano
.
config
.
floatX
,
3
))
y
=
sp
.
csr_matrix
(
random_lil
((
10
,
40
),
theano
.
config
.
floatX
,
3
))
self
.
assertTrue
(
f
([
x
,
y
,
y
],
y
)
==
2
)
self
.
assertTrue
(
f
([
x
,
y
,
y
],
y
)
==
2
)
class
test_length
(
unittest
.
TestCase
):
def
test_sanity_check
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
z
=
Length
()(
mySymbolicMatricesList
)
f
=
theano
.
function
([
mySymbolicMatricesList
],
z
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
self
.
assertTrue
(
f
([
x
,
x
,
x
,
x
])
==
4
)
def
test_interface
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
z
=
mySymbolicMatricesList
.
__len__
()
f
=
theano
.
function
([
mySymbolicMatricesList
],
z
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
self
.
assertTrue
(
f
([
x
,
x
])
==
2
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论