Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e9719c9e
提交
e9719c9e
authored
6月 13, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add documentation about typed list.
上级
d82eb54a
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
93 行增加
和
16 行删除
+93
-16
index.txt
doc/library/index.txt
+1
-0
typed_list.txt
doc/library/typed_list.txt
+35
-0
basic.py
theano/sparse/basic.py
+1
-0
basic.py
theano/typed_list/basic.py
+56
-16
没有找到文件。
doc/library/index.txt
浏览文件 @
e9719c9e
...
...
@@ -22,6 +22,7 @@ Types and Ops that you can use to build and compile expression graphs.
gof/index
scan
sandbox/index
typed_list
There are also some top-level imports that you might find more convenient:
...
...
doc/library/typed_list.txt
0 → 100644
浏览文件 @
e9719c9e
.. _libdoc_typed_list:
===============================
:mod:`typed_list` -- Typed List
===============================
This is a type that represent a list in Theano. All element must have
the same Theano type. Here is an example::
import theano.typed_list
tl = theano.typed_list.TypedListType(theano.tensor.fvector)()
v = theano.tensor.fvector()
o = theano.typed_list.append(tl, v)
f = theano.function([tl, v], o)
print f([[1, 2, 3], [4, 5]], [2])
#[array([ 1., 2., 3.], dtype=float32), array([ 4., 5.], dtype=float32), array([ 2.], dtype=float32)]
A second example with Scan. Scan don't have yet direct support of
TypedList, so you can only use it as non_sequences(not in sequences or
as outputs).::
import theano.typed_list
a = theano.typed_list.TypedListType(theano.tensor.fvector)()
s, _ = theano.scan(fn=lambda i, tl: tl[i].sum(),
non_sequences=[a],
sequences=[theano.tensor.arange(2, dtype='int64')])
f = theano.function([a], s)
f([[1, 2, 3], [4, 5]])
#array([ 6., 9.], dtype=float32)
.. automodule:: theano.typed_list.basic
:members:
theano/sparse/basic.py
浏览文件 @
e9719c9e
...
...
@@ -406,6 +406,7 @@ class SparseConstant(gof.Constant, _sparse_py_operators):
SparseType
.
Variable
=
SparseVariable
SparseType
.
Constant
=
SparseConstant
# for more dtypes, call SparseType(format, dtype)
def
matrix
(
format
,
name
=
None
,
dtype
=
None
):
if
dtype
is
None
:
...
...
theano/typed_list/basic.py
浏览文件 @
e9719c9e
...
...
@@ -50,9 +50,7 @@ TypedListType.Variable = TypedListVariable
class
GetItem
(
Op
):
"""
get specified slice of a typed list
"""
# See doc in instance of this Op after the class definition.
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
...
...
@@ -100,13 +98,16 @@ class GetItem(Op):
return
(
1
,)
getitem
=
GetItem
()
"""
Get specified slice of a typed list..
:param x: type type list.
:param index: the index of the value to return from `x`.
"""
class
Append
(
Op
):
"""
#append an element at the end of another list
"""
class
Append
(
Op
):
# See doc in instance of this Op after the class definition.
def
__init__
(
self
,
inplace
=
False
):
self
.
inplace
=
inplace
if
self
.
inplace
:
...
...
@@ -159,13 +160,16 @@ class Append(Op):
return
(
1
,)
append
=
Append
()
"""
Append an element at the end of another list.
:param x: the base typed list.
:param y: the element to append to `x`.
"""
class
Extend
(
Op
):
"""
append all element of a list at the end of another list
"""
class
Extend
(
Op
):
# See doc in instance of this Op after the class definition.
def
__init__
(
self
,
inplace
=
False
):
self
.
inplace
=
inplace
if
self
.
inplace
:
...
...
@@ -222,10 +226,16 @@ class Extend(Op):
return
(
1
,)
extend
=
Extend
()
"""
Append all element of a list at the end of another list.
:param x: The typed list to extend.
:param toAppend: The typed list that will be added at the end of `x`.
"""
class
Insert
(
Op
):
class
Insert
(
Op
):
# See doc in instance of this Op after the class definition.
def
__init__
(
self
,
inplace
=
False
):
self
.
inplace
=
inplace
if
self
.
inplace
:
...
...
@@ -283,10 +293,17 @@ class Insert(Op):
return
(
1
,)
insert
=
Insert
()
"""
Insert an element at an index in a typed list.
:param x: the typed list to modified.
:param index: the index where to put the new element in `x`.
:param toInsert: The new element to insert.
"""
class
Remove
(
Op
):
class
Remove
(
Op
):
# See doc in instance of this Op after the class definition.
def
__init__
(
self
,
inplace
=
False
):
self
.
inplace
=
inplace
if
self
.
inplace
:
...
...
@@ -324,10 +341,19 @@ class Remove(Op):
return
self
.
__class__
.
__name__
remove
=
Remove
()
"""
Remove an element from a typed list.
:param x: the typed list to be changed.
:param toRemove: an element to be removed from the typed list.
We remove only the first instance.
It work with ndarray.
"""
class
Reverse
(
Op
):
class
Reverse
(
Op
):
# See doc in instance of this Op after the class definition.
def
__init__
(
self
,
inplace
=
False
):
self
.
inplace
=
inplace
if
self
.
inplace
:
...
...
@@ -380,10 +406,15 @@ class Reverse(Op):
return
(
1
,)
reverse
=
Reverse
()
"""
Reverse the order of a typed list.
:param x: the typed list to be reversed.
"""
class
Index
(
Op
):
class
Index
(
Op
):
# See doc in instance of this Op after the class definition.
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
...
...
@@ -413,7 +444,7 @@ index_ = Index()
class
Count
(
Op
):
# See doc in instance of this Op after the class definition.
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
...
...
@@ -441,6 +472,15 @@ class Count(Op):
return
self
.
__class__
.
__name__
count
=
Count
()
"""
Count the number of time an element is in the typed list.
:param x: The typed list to look into.
:param elem: The element we want to count in list.
The element must evaluate to equal.
They don't need to be the same instance. Work with ndrray.
"""
class
Length
(
Op
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论