Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
12c6df35
提交
12c6df35
authored
5月 20, 2014
作者:
Hengjean
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed errors and typos
上级
b40baa32
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
34 行增加
和
49 行删除
+34
-49
type_other.py
theano/tensor/type_other.py
+4
-1
basic.py
theano/typed_list/basic.py
+7
-7
test_basic.py
theano/typed_list/tests/test_basic.py
+13
-17
test_type.py
theano/typed_list/tests/test_type.py
+2
-7
type.py
theano/typed_list/type.py
+8
-17
没有找到文件。
theano/tensor/type_other.py
浏览文件 @
12c6df35
...
...
@@ -2,7 +2,7 @@
# Slice type and Op. None Type and NoneConst.
#
import
theano
from
theano.gof
import
Apply
,
Constant
,
Generic
,
Op
,
Type
from
theano.gof
import
Apply
,
Constant
,
Generic
,
Op
,
Type
,
hashtype
from
theano.gradient
import
DisconnectedType
...
...
@@ -55,6 +55,9 @@ class SliceType(Type):
def
__eq__
(
self
,
other
):
return
type
(
self
)
is
SliceType
and
type
(
other
)
is
SliceType
def
__hash__
(
self
):
return
hashtype
(
self
)
slicetype
=
SliceType
()
...
...
theano/typed_list/basic.py
浏览文件 @
12c6df35
...
...
@@ -8,13 +8,13 @@ from theano import tensor as T
class
_typed_list_py_operators
:
def
__getitem__
(
self
,
index
):
return
get_i
tem
()(
self
,
index
)
return
GetI
tem
()(
self
,
index
)
def
append
(
self
,
toAppend
):
return
a
ppend
()(
self
,
toAppend
)
return
A
ppend
()(
self
,
toAppend
)
def
extend
(
self
,
toAppend
):
return
e
xtend
()(
self
,
toAppend
)
return
E
xtend
()(
self
,
toAppend
)
class
TypedListVariable
(
_typed_list_py_operators
,
Variable
):
...
...
@@ -25,7 +25,7 @@ class TypedListVariable(_typed_list_py_operators, Variable):
TypedListType
.
Variable
=
TypedListVariable
class
get_i
tem
(
Op
):
class
GetI
tem
(
Op
):
"""
get specified slice of a typed list
"""
...
...
@@ -37,7 +37,7 @@ class get_item(Op):
def
make_node
(
self
,
x
,
index
):
assert
isinstance
(
x
.
type
,
TypedListType
)
if
i
ndex
.
type
==
SliceType
(
):
if
i
sinstance
(
index
.
type
,
SliceType
):
return
Apply
(
self
,
[
x
,
index
],
[
x
.
type
()])
elif
isinstance
(
index
,
T
.
TensorVariable
)
and
index
.
ndim
==
0
:
return
Apply
(
self
,
[
x
,
index
],
[
x
.
ttype
()])
...
...
@@ -53,7 +53,7 @@ class get_item(Op):
return
self
.
__class__
.
__name__
class
a
ppend
(
Op
):
class
A
ppend
(
Op
):
"""
#append an element at the end of another list
"""
...
...
@@ -76,7 +76,7 @@ class append(Op):
return
self
.
__class__
.
__name__
class
e
xtend
(
Op
):
class
E
xtend
(
Op
):
"""
append all element of a list at the end of another list
"""
...
...
theano/typed_list/tests/test_basic.py
浏览文件 @
12c6df35
import
unittest
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.attrib
import
attr
import
numpy
from
numpy.testing
import
dec
,
assert_array_equal
,
assert_allclose
from
numpy.testing.noseclasses
import
KnownFailureTest
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
(
get_item
,
append
,
e
xtend
)
from
theano.typed_list.basic
import
(
GetItem
,
Append
,
E
xtend
)
from
theano.tests
import
unittest_tools
as
utt
...
...
@@ -33,14 +29,14 @@ class test_get_item(unittest.TestCase):
mySymbolicSlice
=
SliceType
()()
z
=
get_i
tem
()(
mySymbolicMatricesList
,
mySymbolicSlice
)
z
=
GetI
tem
()(
mySymbolicMatricesList
,
mySymbolicSlice
)
self
.
assertFalse
(
isinstance
(
z
,
T
.
TensorVariable
))
f
=
theano
.
function
([
mySymbolicMatricesList
,
mySymbolicSlice
],
z
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
10
0
])
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
10
1
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
slice
(
0
,
1
,
1
)),
[
x
]))
...
...
@@ -51,12 +47,12 @@ class test_get_item(unittest.TestCase):
mySymbolicScalar
=
T
.
scalar
()
z
=
get_i
tem
()(
mySymbolicMatricesList
,
mySymbolicScalar
)
z
=
GetI
tem
()(
mySymbolicMatricesList
,
mySymbolicScalar
)
f
=
theano
.
function
([
mySymbolicMatricesList
,
mySymbolicScalar
],
z
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
10
0
])
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
10
1
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
numpy
.
asarray
(
0
)),
x
))
...
...
@@ -70,7 +66,7 @@ class test_get_item(unittest.TestCase):
f
=
theano
.
function
([
mySymbolicMatricesList
,
mySymbolicScalar
],
z
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
10
0
])
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
10
1
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
numpy
.
asarray
(
0
)),
x
))
...
...
@@ -79,7 +75,7 @@ class test_get_item(unittest.TestCase):
theano
.
config
.
floatX
,
(
False
,
False
)))()
mySymbolicMatrix
=
T
.
matrix
()
self
.
assertRaises
(
TypeError
,
get_i
tem
(),
mySymbolicMatricesList
,
self
.
assertRaises
(
TypeError
,
GetI
tem
(),
mySymbolicMatricesList
,
mySymbolicMatrix
)
...
...
@@ -90,13 +86,13 @@ class test_append(unittest.TestCase):
theano
.
config
.
floatX
,
(
False
,
False
)))()
myMatrix
=
T
.
matrix
()
z
=
a
ppend
()(
mySymbolicMatricesList
,
myMatrix
)
z
=
A
ppend
()(
mySymbolicMatricesList
,
myMatrix
)
f
=
theano
.
function
([
mySymbolicMatricesList
,
myMatrix
],
z
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
10
0
])
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
10
1
])
y
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
10
0
])
y
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
10
1
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
y
),
[
x
,
y
]))
...
...
@@ -109,13 +105,13 @@ class test_extend(unittest.TestCase):
mySymbolicMatricesList2
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
(
False
,
False
)))()
z
=
e
xtend
()(
mySymbolicMatricesList1
,
mySymbolicMatricesList2
)
z
=
E
xtend
()(
mySymbolicMatricesList1
,
mySymbolicMatricesList2
)
f
=
theano
.
function
([
mySymbolicMatricesList1
,
mySymbolicMatricesList2
],
z
)
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
10
0
])
x
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
10
1
])
y
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
10
0
])
y
=
rand_ranged_matrix
(
-
1000
,
1000
,
[
100
,
10
1
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
([
x
],
[
y
]),
[
x
,
y
]))
theano/typed_list/tests/test_type.py
浏览文件 @
12c6df35
import
unittest
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.attrib
import
attr
import
numpy
from
numpy.testing
import
dec
,
assert_array_equal
,
assert_allclose
from
numpy.testing.noseclasses
import
KnownFailureTest
import
theano
import
theano.typed_list
...
...
@@ -91,15 +87,14 @@ class test_typed_list_type(unittest.TestCase):
def
test_intern_filter
(
self
):
"""
(supposing theano.config.floatX = floatX)
Test checking if values contained are themselves
filtered. If they weren't this code would raise
an exception.
"""
myType
=
TypedListType
(
T
.
TensorType
(
theano
.
config
.
floatX
,
myType
=
TypedListType
(
T
.
TensorType
(
'float64'
,
(
False
,
False
)))
x
=
numpy
.
asarray
([[
4
,
5
],
[
4
,
5
]],
dtype
=
'
F
loat32'
)
x
=
numpy
.
asarray
([[
4
,
5
],
[
4
,
5
]],
dtype
=
'
f
loat32'
)
self
.
assertTrue
(
numpy
.
array_equal
(
myType
.
filter
([
x
]),
[
x
]))
...
...
theano/typed_list/type.py
浏览文件 @
12c6df35
...
...
@@ -15,8 +15,8 @@ class TypedListType(gof.Type):
if
depth
<
0
:
raise
ValueError
(
'Please specify a depth superior or'
'equal to 0'
)
if
not
hasattr
(
ttype
,
'is_valid_value'
):
raise
TypeError
(
'Expected a Theano
t
ype'
)
if
not
isinstance
(
ttype
,
gof
.
Type
):
raise
TypeError
(
'Expected a Theano
T
ype'
)
if
depth
==
0
:
self
.
ttype
=
ttype
...
...
@@ -36,8 +36,6 @@ class TypedListType(gof.Type):
if
not
isinstance
(
x
,
list
):
raise
TypeError
(
'Expected a python list'
)
else
:
x
=
list
(
x
)
x
=
[
self
.
ttype
.
filter
(
y
)
for
y
in
x
]
if
all
(
self
.
ttype
.
is_valid_value
(
y
)
for
y
in
x
):
...
...
@@ -55,27 +53,20 @@ class TypedListType(gof.Type):
if
not
hasattr
(
other
,
'ttype'
):
return
False
return
(
self
.
ttype
==
other
.
ttype
)
return
type
(
self
)
==
type
(
other
)
and
self
.
ttype
==
other
.
ttype
def
__hash__
(
self
):
return
gof
.
hashtype
(
self
)
^
hash
(
self
.
ttype
)
def
__str__
(
self
):
return
'Typed
List <'
+
str
(
self
.
ttype
)
+
'>'
return
'TypedList <'
+
str
(
self
.
ttype
)
+
'>'
def
get_depth
(
self
):
"""
utilitary function to get the 0 based
level of the list
"""
if
hasattr
(
self
.
ttype
,
'get_depth'
):
if
isinstance
(
self
.
ttype
,
TypedListType
):
return
self
.
ttype
.
get_depth
()
+
1
else
:
return
0
def
make_variable
(
self
,
name
=
None
):
"""Return a `TypedListVariable` of this type
:Parameters:
- `name`: str
A pretty name to identify this `Variable` when printing and
debugging
"""
return
self
.
Variable
(
self
,
name
=
name
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论