Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f14933a5
提交
f14933a5
authored
6月 04, 2014
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1875 from Hengjean/TypedListC
Added C interface for TypedListType, GetItem, insert, append and extend
上级
82a9d523
fb547b73
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
178 行增加
和
0 行删除
+178
-0
__init__.py
theano/typed_list/__init__.py
+1
-0
basic.py
theano/typed_list/basic.py
+0
-0
opt.py
theano/typed_list/opt.py
+21
-0
test_basic.py
theano/typed_list/tests/test_basic.py
+0
-0
test_opt.py
theano/typed_list/tests/test_opt.py
+113
-0
type.py
theano/typed_list/type.py
+43
-0
没有找到文件。
theano/typed_list/__init__.py
浏览文件 @
f14933a5
from
type
import
TypedListType
from
type
import
TypedListType
from
basic
import
*
from
basic
import
*
import
opt
theano/typed_list/basic.py
浏览文件 @
f14933a5
差异被折叠。
点击展开。
theano/typed_list/opt.py
0 → 100644
浏览文件 @
f14933a5
from
theano
import
gof
from
theano
import
compile
from
theano.gof
import
TopoOptimizer
from
theano.typed_list.basic
import
(
Reverse
,
Append
,
Extend
,
Insert
,
Remove
)
@gof.local_optimizer
([
Append
,
Extend
,
Insert
,
Reverse
,
Remove
],
inplace
=
True
)
def
typed_list_inplace_opt
(
node
):
if
isinstance
(
node
.
op
,
(
Append
,
Extend
,
Insert
,
Reverse
,
Remove
))
\
and
not
node
.
op
.
inplace
:
new_op
=
node
.
op
.
__class__
(
inplace
=
True
)
new_node
=
new_op
(
*
node
.
inputs
)
return
[
new_node
]
return
False
compile
.
optdb
.
register
(
'typed_list_inplace_opt'
,
TopoOptimizer
(
typed_list_inplace_opt
,
failure_callback
=
TopoOptimizer
.
warn_inplace
),
60
,
'fast_run'
,
'inplace'
)
theano/typed_list/tests/test_basic.py
浏览文件 @
f14933a5
差异被折叠。
点击展开。
theano/typed_list/tests/test_opt.py
0 → 100644
浏览文件 @
f14933a5
import
unittest
import
numpy
import
theano
import
theano.typed_list
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
,
Remove
,
Reverse
,
Index
,
Count
)
from
theano
import
In
#took from tensors/tests/test_basic.py
def
rand_ranged_matrix
(
minimum
,
maximum
,
shape
):
return
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shape
)
*
(
maximum
-
minimum
)
+
minimum
,
dtype
=
theano
.
config
.
floatX
)
class
test_inplace
(
unittest
.
TestCase
):
def
test_reverse_inplace
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
z
=
Reverse
()(
mySymbolicMatricesList
)
m
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
"typed_list_inplace_opt"
)
f
=
theano
.
function
([
In
(
mySymbolicMatricesList
,
borrow
=
True
,
mutable
=
True
)],
z
,
accept_inplace
=
True
,
mode
=
m
)
self
.
assertTrue
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
inplace
)
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_append_inplace
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
mySymbolicMatrix
=
T
.
matrix
()
z
=
Append
()(
mySymbolicMatricesList
,
mySymbolicMatrix
)
m
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
"typed_list_inplace_opt"
)
f
=
theano
.
function
([
In
(
mySymbolicMatricesList
,
borrow
=
True
,
mutable
=
True
),
In
(
mySymbolicMatrix
,
borrow
=
True
,
mutable
=
True
)],
z
,
accept_inplace
=
True
,
mode
=
m
)
self
.
assertTrue
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
inplace
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
y
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
y
),
[
x
,
y
]))
def
test_extend_inplace
(
self
):
mySymbolicMatricesList1
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
mySymbolicMatricesList2
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
z
=
Extend
()(
mySymbolicMatricesList1
,
mySymbolicMatricesList2
)
m
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
"typed_list_inplace_opt"
)
f
=
theano
.
function
([
In
(
mySymbolicMatricesList1
,
borrow
=
True
,
mutable
=
True
),
mySymbolicMatricesList2
],
z
,
mode
=
m
)
self
.
assertTrue
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
inplace
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
y
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
[
y
]),
[
x
,
y
]))
def
test_insert_inplace
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
mySymbolicIndex
=
T
.
scalar
(
dtype
=
'int64'
)
mySymbolicMatrix
=
T
.
matrix
()
z
=
Insert
()(
mySymbolicMatricesList
,
mySymbolicIndex
,
mySymbolicMatrix
)
m
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
"typed_list_inplace_opt"
)
f
=
theano
.
function
([
In
(
mySymbolicMatricesList
,
borrow
=
True
,
mutable
=
True
),
mySymbolicIndex
,
mySymbolicMatrix
],
z
,
accept_inplace
=
True
,
mode
=
m
)
self
.
assertTrue
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
inplace
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
y
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
numpy
.
asarray
(
1
,
dtype
=
'int64'
),
y
),
[
x
,
y
]))
def
test_remove_inplace
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
mySymbolicMatrix
=
T
.
matrix
()
z
=
Remove
()(
mySymbolicMatricesList
,
mySymbolicMatrix
)
m
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
"typed_list_inplace_opt"
)
f
=
theano
.
function
([
In
(
mySymbolicMatricesList
,
borrow
=
True
,
mutable
=
True
),
In
(
mySymbolicMatrix
,
borrow
=
True
,
mutable
=
True
)],
z
,
accept_inplace
=
True
,
mode
=
m
)
self
.
assertTrue
(
f
.
maker
.
fgraph
.
toposort
()[
0
]
.
op
.
inplace
)
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
]))
theano/typed_list/type.py
浏览文件 @
f14933a5
...
@@ -65,3 +65,46 @@ class TypedListType(gof.Type):
...
@@ -65,3 +65,46 @@ class TypedListType(gof.Type):
return
self
.
ttype
.
get_depth
()
+
1
return
self
.
ttype
.
get_depth
()
+
1
else
:
else
:
return
0
return
0
def
values_eq
(
self
,
a
,
b
):
if
not
len
(
a
)
==
len
(
b
):
return
False
for
x
in
range
(
len
(
a
)):
if
not
self
.
ttype
.
values_eq
(
a
[
x
],
b
[
x
]):
return
False
return
True
def
c_declare
(
self
,
name
,
sub
):
return
"""
PyListObject*
%(name)
s;
"""
%
dict
(
name
=
name
)
def
c_init
(
self
,
name
,
sub
):
return
"""
%(name)
s = NULL;
"""
%
dict
(
name
=
name
)
def
c_extract
(
self
,
name
,
sub
):
return
"""
if (!PyList_Check(py_
%(name)
s)) {
PyErr_SetString(PyExc_TypeError, "expected a list");
%(fail)
s
}
%(name)
s = (PyListObject*) (py_
%(name)
s);
"""
%
dict
(
name
=
name
,
fail
=
sub
[
'fail'
])
def
c_sync
(
self
,
name
,
sub
):
return
"""
Py_XDECREF(py_
%(name)
s);
py_
%(name)
s = (PyObject*)(
%(name)
s);
Py_INCREF(py_
%(name)
s);
"""
%
dict
(
name
=
name
)
def
c_cleanup
(
self
,
name
,
sub
):
return
""
def
c_code_cache_version
(
self
):
return
(
1
,)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论