Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cb823769
提交
cb823769
authored
4月 18, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
merged base_tensor with tensor
上级
55f4d322
全部展开
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
145 行增加
和
153 行删除
+145
-153
__init__.py
__init__.py
+0
-2
_test_base_tensor.py
_test_base_tensor.py
+0
-142
_test_tensor.py
_test_tensor.py
+137
-0
base_tensor.py
base_tensor.py
+0
-0
elemwise.py
elemwise.py
+0
-1
sparse.py
sparse.py
+8
-8
tensor.py
tensor.py
+0
-0
没有找到文件。
__init__.py
浏览文件 @
cb823769
import
gof
import
gof
import
base_tensor
import
tensor
import
tensor
import
sparse
import
sparse
import
compile
import
compile
import
gradient
import
gradient
import
opt
import
opt
from
base_tensor
import
*
from
tensor
import
*
from
tensor
import
*
from
compile
import
*
from
compile
import
*
from
opt
import
*
from
opt
import
*
...
...
_test_base_tensor.py
deleted
100644 → 0
浏览文件 @
55f4d322
from
base_tensor
import
*
import
unittest
from
copy
import
copy
from
compile
import
Function
import
gof
def
_tensor
(
data
,
broadcastable
=
None
,
name
=
None
):
"""Return a BaseTensor containing given data"""
data
=
numpy
.
asarray
(
data
)
if
broadcastable
is
None
:
broadcastable
=
[
s
==
1
for
s
in
data
.
shape
]
elif
broadcastable
in
[
0
,
1
]:
broadcastable
=
[
broadcastable
]
*
len
(
data
.
shape
)
rval
=
BaseTensor
(
data
.
dtype
,
broadcastable
,
name
)
rval
.
data
=
data
# will raise if broadcastable was mis-specified
return
rval
class
T_tensor
(
unittest
.
TestCase
):
def
test0
(
self
):
# allocate from a scalar float
t
=
_tensor
(
1.0
)
self
.
failUnless
(
isinstance
(
t
,
BaseTensor
))
self
.
failUnless
(
t
.
dtype
==
'float64'
)
self
.
failUnless
(
t
.
broadcastable
==
())
self
.
failUnless
(
t
.
role
==
None
)
self
.
failUnless
(
isinstance
(
t
.
data
,
numpy
.
ndarray
))
self
.
failUnless
(
str
(
t
.
data
.
dtype
)
==
'float64'
)
self
.
failUnless
(
t
.
data
==
1.0
)
def
test0_int
(
self
):
# allocate from a scalar float
t
=
_tensor
(
1
)
self
.
failUnless
(
isinstance
(
t
,
BaseTensor
))
self
.
failUnless
(
t
.
dtype
==
'int64'
or
t
.
dtype
==
'int32'
)
def
test1
(
self
):
# allocate from a vector of ints, not broadcastable
t
=
_tensor
(
numpy
.
ones
(
5
,
dtype
=
'int32'
))
self
.
failUnless
(
isinstance
(
t
,
BaseTensor
))
self
.
failUnless
(
t
.
dtype
==
'int32'
)
self
.
failUnless
(
t
.
broadcastable
==
(
0
,))
self
.
failUnless
(
isinstance
(
t
.
data
,
numpy
.
ndarray
))
self
.
failUnless
(
str
(
t
.
data
.
dtype
)
==
'int32'
)
def
test2
(
self
):
# allocate from a column matrix of complex with name
t
=
_tensor
(
numpy
.
ones
((
5
,
1
),
dtype
=
'complex64'
),
name
=
'bart'
)
self
.
failUnless
(
isinstance
(
t
,
BaseTensor
))
self
.
failUnless
(
t
.
dtype
==
'complex64'
)
self
.
failUnless
(
t
.
broadcastable
==
(
0
,
1
))
self
.
failUnless
(
isinstance
(
t
.
data
,
numpy
.
ndarray
))
self
.
failUnless
(
t
.
name
==
'bart'
)
def
test2b
(
self
):
# allocate from a column matrix, not broadcastable
t
=
_tensor
(
numpy
.
ones
((
5
,
1
),
dtype
=
'complex64'
),
broadcastable
=
0
)
self
.
failUnless
(
isinstance
(
t
,
BaseTensor
))
self
.
failUnless
(
t
.
dtype
==
'complex64'
)
self
.
failUnless
(
t
.
broadcastable
==
(
0
,
0
))
self
.
failUnless
(
isinstance
(
t
.
data
,
numpy
.
ndarray
))
f
=
Function
([
t
],
[
t
],
linker_cls
=
gof
.
CLinker
)
self
.
failUnless
(
numpy
.
all
(
t
.
data
==
f
(
t
.
data
)))
def
test_data_normal
(
self
):
#test that assigning to .data works when it should
t
=
_tensor
(
numpy
.
ones
((
5
,
1
),
dtype
=
'complex64'
),
broadcastable
=
0
)
o27
=
numpy
.
ones
((
2
,
7
),
dtype
=
'complex64'
)
t
.
data
=
o27
lst
=
t
.
_data
self
.
failUnless
(
t
.
data
.
shape
==
(
2
,
7
))
self
.
failUnless
(
t
.
data
is
o27
)
self
.
failUnless
(
t
.
_data
is
lst
)
def
test_data_badrank0
(
self
):
t
=
_tensor
(
numpy
.
ones
((
5
,
1
),
dtype
=
'complex64'
),
broadcastable
=
0
)
try
:
t
.
data
=
numpy
.
ones
((
2
,
7
,
1
))
self
.
fail
()
except
ValueError
,
e
:
self
.
failUnless
(
e
[
0
]
is
BaseTensor
.
filter
.
E_rank
)
try
:
t
.
data
=
numpy
.
ones
(
1
)
self
.
fail
()
except
ValueError
,
e
:
self
.
failUnless
(
e
[
0
]
is
BaseTensor
.
filter
.
E_rank
)
def
test_data_badrank1
(
self
):
t
=
_tensor
(
numpy
.
ones
((
1
,
1
),
dtype
=
'complex64'
),
broadcastable
=
1
)
try
:
t
.
data
=
numpy
.
ones
((
1
,
1
,
1
))
self
.
fail
()
except
ValueError
,
e
:
self
.
failUnless
(
e
[
0
]
is
BaseTensor
.
filter
.
E_rank
)
try
:
t
.
data
=
numpy
.
ones
(
1
)
self
.
fail
()
except
ValueError
,
e
:
self
.
failUnless
(
e
[
0
]
is
BaseTensor
.
filter
.
E_rank
)
def
test_data_badshape0
(
self
):
t
=
_tensor
(
numpy
.
ones
((
1
,
1
),
dtype
=
'complex64'
),
broadcastable
=
1
)
try
:
t
.
data
=
numpy
.
ones
((
1
,
2
))
self
.
fail
()
except
ValueError
,
e
:
self
.
failUnless
(
e
[
0
]
is
BaseTensor
.
filter
.
E_shape
)
try
:
t
.
data
=
numpy
.
ones
((
0
,
1
))
self
.
fail
()
except
ValueError
,
e
:
self
.
failUnless
(
e
[
0
]
is
BaseTensor
.
filter
.
E_shape
)
def
test_cast0
(
self
):
t
=
BaseTensor
(
'float32'
,
[
0
])
t
.
data
=
numpy
.
random
.
rand
(
4
)
>
0.5
self
.
failUnless
(
str
(
t
.
data
.
dtype
)
==
t
.
dtype
)
class
T_stdlib
(
unittest
.
TestCase
):
def
test0
(
self
):
t
=
_tensor
(
1.0
)
tt
=
t
.
clone
(
False
)
self
.
failUnless
(
t
.
dtype
==
tt
.
dtype
)
self
.
failUnless
(
t
.
broadcastable
is
tt
.
broadcastable
)
self
.
failUnless
(
tt
.
data
is
None
)
self
.
failUnless
(
t
.
data
==
1.0
)
def
test0b
(
self
):
t
=
_tensor
(
1.0
)
tt
=
t
.
clone
()
self
.
failUnless
(
t
.
dtype
==
tt
.
dtype
)
self
.
failUnless
(
t
.
broadcastable
is
tt
.
broadcastable
)
self
.
failUnless
(
tt
.
data
is
None
)
self
.
failUnless
(
t
.
data
==
1.0
)
def
test1
(
self
):
t
=
_tensor
(
1.0
)
tt
=
t
.
clone
(
True
)
self
.
failUnless
(
t
.
dtype
==
tt
.
dtype
)
self
.
failUnless
(
t
.
broadcastable
is
tt
.
broadcastable
)
self
.
failUnless
(
tt
.
data
==
1.0
)
self
.
failUnless
(
t
.
data
==
1.0
)
self
.
failUnless
(
t
.
data
is
not
tt
.
data
)
def
test1b
(
self
):
t
=
_tensor
(
1.0
)
tt
=
copy
(
t
)
self
.
failUnless
(
t
.
dtype
==
tt
.
dtype
)
self
.
failUnless
(
t
.
broadcastable
is
tt
.
broadcastable
)
self
.
failUnless
(
tt
.
data
==
1.0
)
self
.
failUnless
(
t
.
data
==
1.0
)
self
.
failUnless
(
t
.
data
is
not
tt
.
data
)
if
__name__
==
'__main__'
:
unittest
.
main
()
_test_tensor.py
浏览文件 @
cb823769
...
@@ -1280,5 +1280,142 @@ class t_gemm(unittest.TestCase):
...
@@ -1280,5 +1280,142 @@ class t_gemm(unittest.TestCase):
self
.
fail
()
self
.
fail
()
def
_tensor
(
data
,
broadcastable
=
None
,
name
=
None
):
"""Return a Tensor containing given data"""
data
=
numpy
.
asarray
(
data
)
if
broadcastable
is
None
:
broadcastable
=
[
s
==
1
for
s
in
data
.
shape
]
elif
broadcastable
in
[
0
,
1
]:
broadcastable
=
[
broadcastable
]
*
len
(
data
.
shape
)
rval
=
Tensor
(
data
.
dtype
,
broadcastable
,
name
)
rval
.
data
=
data
# will raise if broadcastable was mis-specified
return
rval
class
T_tensor
(
unittest
.
TestCase
):
def
test0
(
self
):
# allocate from a scalar float
t
=
_tensor
(
1.0
)
self
.
failUnless
(
isinstance
(
t
,
Tensor
))
self
.
failUnless
(
t
.
dtype
==
'float64'
)
self
.
failUnless
(
t
.
broadcastable
==
())
self
.
failUnless
(
t
.
role
==
None
)
self
.
failUnless
(
isinstance
(
t
.
data
,
numpy
.
ndarray
))
self
.
failUnless
(
str
(
t
.
data
.
dtype
)
==
'float64'
)
self
.
failUnless
(
t
.
data
==
1.0
)
def
test0_int
(
self
):
# allocate from a scalar float
t
=
_tensor
(
1
)
self
.
failUnless
(
isinstance
(
t
,
Tensor
))
self
.
failUnless
(
t
.
dtype
==
'int64'
or
t
.
dtype
==
'int32'
)
def
test1
(
self
):
# allocate from a vector of ints, not broadcastable
t
=
_tensor
(
numpy
.
ones
(
5
,
dtype
=
'int32'
))
self
.
failUnless
(
isinstance
(
t
,
Tensor
))
self
.
failUnless
(
t
.
dtype
==
'int32'
)
self
.
failUnless
(
t
.
broadcastable
==
(
0
,))
self
.
failUnless
(
isinstance
(
t
.
data
,
numpy
.
ndarray
))
self
.
failUnless
(
str
(
t
.
data
.
dtype
)
==
'int32'
)
def
test2
(
self
):
# allocate from a column matrix of complex with name
t
=
_tensor
(
numpy
.
ones
((
5
,
1
),
dtype
=
'complex64'
),
name
=
'bart'
)
self
.
failUnless
(
isinstance
(
t
,
Tensor
))
self
.
failUnless
(
t
.
dtype
==
'complex64'
)
self
.
failUnless
(
t
.
broadcastable
==
(
0
,
1
))
self
.
failUnless
(
isinstance
(
t
.
data
,
numpy
.
ndarray
))
self
.
failUnless
(
t
.
name
==
'bart'
)
def
test2b
(
self
):
# allocate from a column matrix, not broadcastable
t
=
_tensor
(
numpy
.
ones
((
5
,
1
),
dtype
=
'complex64'
),
broadcastable
=
0
)
self
.
failUnless
(
isinstance
(
t
,
Tensor
))
self
.
failUnless
(
t
.
dtype
==
'complex64'
)
self
.
failUnless
(
t
.
broadcastable
==
(
0
,
0
))
self
.
failUnless
(
isinstance
(
t
.
data
,
numpy
.
ndarray
))
f
=
Function
([
t
],
[
t
],
linker_cls
=
gof
.
CLinker
)
self
.
failUnless
(
numpy
.
all
(
t
.
data
==
f
(
t
.
data
)))
def
test_data_normal
(
self
):
#test that assigning to .data works when it should
t
=
_tensor
(
numpy
.
ones
((
5
,
1
),
dtype
=
'complex64'
),
broadcastable
=
0
)
o27
=
numpy
.
ones
((
2
,
7
),
dtype
=
'complex64'
)
t
.
data
=
o27
lst
=
t
.
_data
self
.
failUnless
(
t
.
data
.
shape
==
(
2
,
7
))
self
.
failUnless
(
t
.
data
is
o27
)
self
.
failUnless
(
t
.
_data
is
lst
)
def
test_data_badrank0
(
self
):
t
=
_tensor
(
numpy
.
ones
((
5
,
1
),
dtype
=
'complex64'
),
broadcastable
=
0
)
try
:
t
.
data
=
numpy
.
ones
((
2
,
7
,
1
))
self
.
fail
()
except
ValueError
,
e
:
self
.
failUnless
(
e
[
0
]
is
Tensor
.
filter
.
E_rank
)
try
:
t
.
data
=
numpy
.
ones
(
1
)
self
.
fail
()
except
ValueError
,
e
:
self
.
failUnless
(
e
[
0
]
is
Tensor
.
filter
.
E_rank
)
def
test_data_badrank1
(
self
):
t
=
_tensor
(
numpy
.
ones
((
1
,
1
),
dtype
=
'complex64'
),
broadcastable
=
1
)
try
:
t
.
data
=
numpy
.
ones
((
1
,
1
,
1
))
self
.
fail
()
except
ValueError
,
e
:
self
.
failUnless
(
e
[
0
]
is
Tensor
.
filter
.
E_rank
)
try
:
t
.
data
=
numpy
.
ones
(
1
)
self
.
fail
()
except
ValueError
,
e
:
self
.
failUnless
(
e
[
0
]
is
Tensor
.
filter
.
E_rank
)
def
test_data_badshape0
(
self
):
t
=
_tensor
(
numpy
.
ones
((
1
,
1
),
dtype
=
'complex64'
),
broadcastable
=
1
)
try
:
t
.
data
=
numpy
.
ones
((
1
,
2
))
self
.
fail
()
except
ValueError
,
e
:
self
.
failUnless
(
e
[
0
]
is
Tensor
.
filter
.
E_shape
)
try
:
t
.
data
=
numpy
.
ones
((
0
,
1
))
self
.
fail
()
except
ValueError
,
e
:
self
.
failUnless
(
e
[
0
]
is
Tensor
.
filter
.
E_shape
)
def
test_cast0
(
self
):
t
=
Tensor
(
'float32'
,
[
0
])
t
.
data
=
numpy
.
random
.
rand
(
4
)
>
0.5
self
.
failUnless
(
str
(
t
.
data
.
dtype
)
==
t
.
dtype
)
class
T_stdlib
(
unittest
.
TestCase
):
def
test0
(
self
):
t
=
_tensor
(
1.0
)
tt
=
t
.
clone
(
False
)
self
.
failUnless
(
t
.
dtype
==
tt
.
dtype
)
self
.
failUnless
(
t
.
broadcastable
is
tt
.
broadcastable
)
self
.
failUnless
(
tt
.
data
is
None
)
self
.
failUnless
(
t
.
data
==
1.0
)
def
test0b
(
self
):
t
=
_tensor
(
1.0
)
tt
=
t
.
clone
()
self
.
failUnless
(
t
.
dtype
==
tt
.
dtype
)
self
.
failUnless
(
t
.
broadcastable
is
tt
.
broadcastable
)
self
.
failUnless
(
tt
.
data
is
None
)
self
.
failUnless
(
t
.
data
==
1.0
)
def
test1
(
self
):
t
=
_tensor
(
1.0
)
tt
=
t
.
clone
(
True
)
self
.
failUnless
(
t
.
dtype
==
tt
.
dtype
)
self
.
failUnless
(
t
.
broadcastable
is
tt
.
broadcastable
)
self
.
failUnless
(
tt
.
data
==
1.0
)
self
.
failUnless
(
t
.
data
==
1.0
)
self
.
failUnless
(
t
.
data
is
not
tt
.
data
)
def
test1b
(
self
):
t
=
_tensor
(
1.0
)
tt
=
copy
(
t
)
self
.
failUnless
(
t
.
dtype
==
tt
.
dtype
)
self
.
failUnless
(
t
.
broadcastable
is
tt
.
broadcastable
)
self
.
failUnless
(
tt
.
data
==
1.0
)
self
.
failUnless
(
t
.
data
==
1.0
)
self
.
failUnless
(
t
.
data
is
not
tt
.
data
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
base_tensor.py
deleted
100644 → 0
浏览文件 @
55f4d322
差异被折叠。
点击展开。
elemwise.py
浏览文件 @
cb823769
...
@@ -3,7 +3,6 @@ import elemwise_cgen as cgen
...
@@ -3,7 +3,6 @@ import elemwise_cgen as cgen
import
numpy
import
numpy
from
gof
import
Op
,
Viewer
,
Destroyer
from
gof
import
Op
,
Viewer
,
Destroyer
#from base_tensor import BaseTensor as Tensor
import
scalar
import
scalar
from
scalar
import
upcast
,
Scalar
from
scalar
import
upcast
,
Scalar
import
gof
import
gof
...
...
sparse.py
浏览文件 @
cb823769
...
@@ -11,7 +11,7 @@ import numpy
...
@@ -11,7 +11,7 @@ import numpy
from
scipy
import
sparse
from
scipy
import
sparse
import
gof.op
,
gof
.
result
import
gof.op
,
gof
.
result
import
tensor
,
base_tensor
import
tensor
...
@@ -20,19 +20,19 @@ import tensor, base_tensor
...
@@ -20,19 +20,19 @@ import tensor, base_tensor
def
_is_sparse_result
(
x
):
def
_is_sparse_result
(
x
):
"""
"""
@rtype: boolean
@rtype: boolean
@return: True iff x is a L{SparseResult} (and not a L{
base_tensor.Base
Tensor})
@return: True iff x is a L{SparseResult} (and not a L{
tensor.
Tensor})
"""
"""
if
not
isinstance
(
x
,
SparseResult
)
and
not
isinstance
(
x
,
base_tensor
.
Base
Tensor
):
if
not
isinstance
(
x
,
SparseResult
)
and
not
isinstance
(
x
,
tensor
.
Tensor
):
raise
NotImplementedError
(
"_is_sparse should only be called on sparse.SparseResult or
base_tensor.Base
Tensor, not,"
,
x
)
raise
NotImplementedError
(
"_is_sparse should only be called on sparse.SparseResult or
tensor.
Tensor, not,"
,
x
)
return
isinstance
(
x
,
SparseResult
)
return
isinstance
(
x
,
SparseResult
)
def
_is_dense_result
(
x
):
def
_is_dense_result
(
x
):
"""
"""
@rtype: boolean
@rtype: boolean
@return: True unless x is a L{SparseResult} (and not a L{
base_tensor.Base
Tensor})
@return: True unless x is a L{SparseResult} (and not a L{
tensor.
Tensor})
"""
"""
if
not
isinstance
(
x
,
SparseResult
)
and
not
isinstance
(
x
,
base_tensor
.
Base
Tensor
):
if
not
isinstance
(
x
,
SparseResult
)
and
not
isinstance
(
x
,
tensor
.
Tensor
):
raise
NotImplementedError
(
"_is_sparse should only be called on sparse.SparseResult or
base_tensor.Base
Tensor, not,"
,
x
)
raise
NotImplementedError
(
"_is_sparse should only be called on sparse.SparseResult or
tensor.
Tensor, not,"
,
x
)
return
isinstance
(
x
,
base_tensor
.
Base
Tensor
)
return
isinstance
(
x
,
tensor
.
Tensor
)
def
_is_sparse
(
x
):
def
_is_sparse
(
x
):
"""
"""
...
...
tensor.py
浏览文件 @
cb823769
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论