Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fb547b73
提交
fb547b73
authored
6月 04, 2014
作者:
Hengjean
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Made every int32 int64 and added c_cache_version
上级
165eb70c
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
36 行增加
和
18 行删除
+36
-18
basic.py
theano/typed_list/basic.py
+21
-6
test_basic.py
theano/typed_list/tests/test_basic.py
+10
-10
test_opt.py
theano/typed_list/tests/test_opt.py
+2
-2
type.py
theano/typed_list/type.py
+3
-0
没有找到文件。
theano/typed_list/basic.py
浏览文件 @
fb547b73
...
@@ -63,12 +63,12 @@ class GetItem(Op):
...
@@ -63,12 +63,12 @@ class GetItem(Op):
index
=
Constant
(
SliceType
(),
index
)
index
=
Constant
(
SliceType
(),
index
)
return
Apply
(
self
,
[
x
,
index
],
[
x
.
type
()])
return
Apply
(
self
,
[
x
,
index
],
[
x
.
type
()])
else
:
else
:
index
=
T
.
constant
(
index
,
ndim
=
0
,
dtype
=
'int
32
'
)
index
=
T
.
constant
(
index
,
ndim
=
0
,
dtype
=
'int
64
'
)
return
Apply
(
self
,
[
x
,
index
],
[
x
.
ttype
()])
return
Apply
(
self
,
[
x
,
index
],
[
x
.
ttype
()])
if
isinstance
(
index
.
type
,
SliceType
):
if
isinstance
(
index
.
type
,
SliceType
):
return
Apply
(
self
,
[
x
,
index
],
[
x
.
type
()])
return
Apply
(
self
,
[
x
,
index
],
[
x
.
type
()])
elif
isinstance
(
index
,
T
.
TensorVariable
)
and
index
.
ndim
==
0
:
elif
isinstance
(
index
,
T
.
TensorVariable
)
and
index
.
ndim
==
0
:
assert
index
.
dtype
==
'int
32
'
assert
index
.
dtype
==
'int
64
'
return
Apply
(
self
,
[
x
,
index
],
[
x
.
ttype
()])
return
Apply
(
self
,
[
x
,
index
],
[
x
.
ttype
()])
else
:
else
:
raise
TypeError
(
'Expected scalar or slice as index.'
)
raise
TypeError
(
'Expected scalar or slice as index.'
)
...
@@ -86,13 +86,16 @@ class GetItem(Op):
...
@@ -86,13 +86,16 @@ class GetItem(Op):
output_name
=
out
[
0
]
output_name
=
out
[
0
]
fail
=
sub
[
'fail'
]
fail
=
sub
[
'fail'
]
return
"""
return
"""
%(output_name)
s = (typeof
%(output_name)
s) PyList_GetItem( (PyObject*)
%(x_name)
s, *((
int
*) PyArray_DATA(
%(index)
s)));
%(output_name)
s = (typeof
%(output_name)
s) PyList_GetItem( (PyObject*)
%(x_name)
s, *((
npy_int64
*) PyArray_DATA(
%(index)
s)));
if(
%(output_name)
s == NULL){
if(
%(output_name)
s == NULL){
%(fail)
s
%(fail)
s
}
}
Py_INCREF(
%(output_name)
s);
Py_INCREF(
%(output_name)
s);
"""
%
locals
()
"""
%
locals
()
def
c_code_cache_version
(
self
):
return
(
1
,)
getitem
=
GetItem
()
getitem
=
GetItem
()
...
@@ -149,6 +152,9 @@ class Append(Op):
...
@@ -149,6 +152,9 @@ class Append(Op):
Py_INCREF(
%(output_name)
s);
Py_INCREF(
%(output_name)
s);
"""
%
locals
()
"""
%
locals
()
def
c_code_cache_version
(
self
):
return
(
1
,)
append
=
Append
()
append
=
Append
()
...
@@ -209,6 +215,9 @@ class Extend(Op):
...
@@ -209,6 +215,9 @@ class Extend(Op):
Py_INCREF(
%(output_name)
s);
Py_INCREF(
%(output_name)
s);
"""
%
locals
()
"""
%
locals
()
def
c_code_cache_version
(
self
):
return
(
1
,)
extend
=
Extend
()
extend
=
Extend
()
...
@@ -229,9 +238,9 @@ class Insert(Op):
...
@@ -229,9 +238,9 @@ class Insert(Op):
assert
isinstance
(
x
.
type
,
TypedListType
)
assert
isinstance
(
x
.
type
,
TypedListType
)
assert
x
.
ttype
==
toInsert
.
type
assert
x
.
ttype
==
toInsert
.
type
if
not
isinstance
(
index
,
Variable
):
if
not
isinstance
(
index
,
Variable
):
index
=
T
.
constant
(
index
,
ndim
=
0
,
dtype
=
'int
32
'
)
index
=
T
.
constant
(
index
,
ndim
=
0
,
dtype
=
'int
64
'
)
else
:
else
:
assert
index
.
dtype
==
'int
32
'
assert
index
.
dtype
==
'int
64
'
assert
isinstance
(
index
,
T
.
TensorVariable
)
and
index
.
ndim
==
0
assert
isinstance
(
index
,
T
.
TensorVariable
)
and
index
.
ndim
==
0
return
Apply
(
self
,
[
x
,
index
,
toInsert
],
[
x
.
type
()])
return
Apply
(
self
,
[
x
,
index
,
toInsert
],
[
x
.
type
()])
...
@@ -261,12 +270,15 @@ class Insert(Op):
...
@@ -261,12 +270,15 @@ class Insert(Op):
if(
%(output_name)
s==NULL){
if(
%(output_name)
s==NULL){
%(fail)
s
%(fail)
s
};
};
if(PyList_Insert((PyObject*)
%(output_name)
s, *((
int
*) PyArray_DATA(
%(index)
s)), (PyObject*)
%(toInsert)
s)==-1){
if(PyList_Insert((PyObject*)
%(output_name)
s, *((
npy_int64
*) PyArray_DATA(
%(index)
s)), (PyObject*)
%(toInsert)
s)==-1){
%(fail)
s
%(fail)
s
};
};
Py_INCREF(
%(output_name)
s);
Py_INCREF(
%(output_name)
s);
"""
%
locals
()
"""
%
locals
()
def
c_code_cache_version
(
self
):
return
(
1
,)
insert
=
Insert
()
insert
=
Insert
()
...
@@ -361,6 +373,9 @@ class Reverse(Op):
...
@@ -361,6 +373,9 @@ class Reverse(Op):
Py_INCREF(
%(output_name)
s);
Py_INCREF(
%(output_name)
s);
"""
%
locals
()
"""
%
locals
()
def
c_code_cache_version
(
self
):
return
(
1
,)
reverse
=
Reverse
()
reverse
=
Reverse
()
...
...
theano/typed_list/tests/test_basic.py
浏览文件 @
fb547b73
...
@@ -68,7 +68,7 @@ class test_get_item(unittest.TestCase):
...
@@ -68,7 +68,7 @@ class test_get_item(unittest.TestCase):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
theano
.
config
.
floatX
,
(
False
,
False
)))()
mySymbolicScalar
=
T
.
scalar
(
dtype
=
'int
32
'
)
mySymbolicScalar
=
T
.
scalar
(
dtype
=
'int
64
'
)
z
=
GetItem
()(
mySymbolicMatricesList
,
mySymbolicScalar
)
z
=
GetItem
()(
mySymbolicMatricesList
,
mySymbolicScalar
)
...
@@ -79,12 +79,12 @@ class test_get_item(unittest.TestCase):
...
@@ -79,12 +79,12 @@ class test_get_item(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
],
numpy
.
asarray
(
0
,
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
numpy
.
asarray
(
0
,
dtype
=
'int
32
'
)),
x
))
dtype
=
'int
64
'
)),
x
))
def
test_interface
(
self
):
def
test_interface
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
theano
.
config
.
floatX
,
(
False
,
False
)))()
mySymbolicScalar
=
T
.
scalar
(
dtype
=
'int
32
'
)
mySymbolicScalar
=
T
.
scalar
(
dtype
=
'int
64
'
)
z
=
mySymbolicMatricesList
[
mySymbolicScalar
]
z
=
mySymbolicMatricesList
[
mySymbolicScalar
]
...
@@ -94,7 +94,7 @@ class test_get_item(unittest.TestCase):
...
@@ -94,7 +94,7 @@ class test_get_item(unittest.TestCase):
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
101
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
numpy
.
asarray
(
0
,
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
numpy
.
asarray
(
0
,
dtype
=
'int
32
'
)),
x
))
dtype
=
'int
64
'
)),
x
))
z
=
mySymbolicMatricesList
[
0
]
z
=
mySymbolicMatricesList
[
0
]
...
@@ -241,7 +241,7 @@ class test_insert(unittest.TestCase):
...
@@ -241,7 +241,7 @@ class test_insert(unittest.TestCase):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
theano
.
config
.
floatX
,
(
False
,
False
)))()
myMatrix
=
T
.
matrix
()
myMatrix
=
T
.
matrix
()
myScalar
=
T
.
scalar
(
dtype
=
'int
32
'
)
myScalar
=
T
.
scalar
(
dtype
=
'int
64
'
)
z
=
Insert
(
True
)(
mySymbolicMatricesList
,
myScalar
,
myMatrix
)
z
=
Insert
(
True
)(
mySymbolicMatricesList
,
myScalar
,
myMatrix
)
...
@@ -253,13 +253,13 @@ class test_insert(unittest.TestCase):
...
@@ -253,13 +253,13 @@ class test_insert(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
],
numpy
.
asarray
(
1
,
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
numpy
.
asarray
(
1
,
dtype
=
'int
32
'
),
y
),
[
x
,
y
]))
dtype
=
'int
64
'
),
y
),
[
x
,
y
]))
def
test_sanity_check
(
self
):
def
test_sanity_check
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
theano
.
config
.
floatX
,
(
False
,
False
)))()
myMatrix
=
T
.
matrix
()
myMatrix
=
T
.
matrix
()
myScalar
=
T
.
scalar
(
dtype
=
'int
32
'
)
myScalar
=
T
.
scalar
(
dtype
=
'int
64
'
)
z
=
Insert
()(
mySymbolicMatricesList
,
myScalar
,
myMatrix
)
z
=
Insert
()(
mySymbolicMatricesList
,
myScalar
,
myMatrix
)
...
@@ -270,13 +270,13 @@ class test_insert(unittest.TestCase):
...
@@ -270,13 +270,13 @@ class test_insert(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
],
numpy
.
asarray
(
1
,
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
numpy
.
asarray
(
1
,
dtype
=
'int
32
'
),
y
),
[
x
,
y
]))
dtype
=
'int
64
'
),
y
),
[
x
,
y
]))
def
test_interface
(
self
):
def
test_interface
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
theano
.
config
.
floatX
,
(
False
,
False
)))()
myMatrix
=
T
.
matrix
()
myMatrix
=
T
.
matrix
()
myScalar
=
T
.
scalar
(
dtype
=
'int
32
'
)
myScalar
=
T
.
scalar
(
dtype
=
'int
64
'
)
z
=
mySymbolicMatricesList
.
insert
(
myScalar
,
myMatrix
)
z
=
mySymbolicMatricesList
.
insert
(
myScalar
,
myMatrix
)
...
@@ -287,7 +287,7 @@ class test_insert(unittest.TestCase):
...
@@ -287,7 +287,7 @@ class test_insert(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
],
numpy
.
asarray
(
1
,
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
numpy
.
asarray
(
1
,
dtype
=
'int
32
'
),
y
),
[
x
,
y
]))
dtype
=
'int
64
'
),
y
),
[
x
,
y
]))
class
test_remove
(
unittest
.
TestCase
):
class
test_remove
(
unittest
.
TestCase
):
...
...
theano/typed_list/tests/test_opt.py
浏览文件 @
fb547b73
...
@@ -77,7 +77,7 @@ class test_inplace(unittest.TestCase):
...
@@ -77,7 +77,7 @@ class test_inplace(unittest.TestCase):
def
test_insert_inplace
(
self
):
def
test_insert_inplace
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
theano
.
config
.
floatX
,
(
False
,
False
)))()
mySymbolicIndex
=
T
.
scalar
(
dtype
=
'int
32
'
)
mySymbolicIndex
=
T
.
scalar
(
dtype
=
'int
64
'
)
mySymbolicMatrix
=
T
.
matrix
()
mySymbolicMatrix
=
T
.
matrix
()
z
=
Insert
()(
mySymbolicMatricesList
,
mySymbolicIndex
,
mySymbolicMatrix
)
z
=
Insert
()(
mySymbolicMatricesList
,
mySymbolicIndex
,
mySymbolicMatrix
)
...
@@ -93,7 +93,7 @@ class test_inplace(unittest.TestCase):
...
@@ -93,7 +93,7 @@ class test_inplace(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
],
numpy
.
asarray
(
1
,
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
numpy
.
asarray
(
1
,
dtype
=
'int
32
'
),
y
),
[
x
,
y
]))
dtype
=
'int
64
'
),
y
),
[
x
,
y
]))
def
test_remove_inplace
(
self
):
def
test_remove_inplace
(
self
):
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
mySymbolicMatricesList
=
TypedListType
(
T
.
TensorType
(
...
...
theano/typed_list/type.py
浏览文件 @
fb547b73
...
@@ -105,3 +105,6 @@ class TypedListType(gof.Type):
...
@@ -105,3 +105,6 @@ class TypedListType(gof.Type):
def
c_cleanup
(
self
,
name
,
sub
):
def
c_cleanup
(
self
,
name
,
sub
):
return
""
return
""
def
c_code_cache_version
(
self
):
return
(
1
,)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论