Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2310b26e
提交
2310b26e
authored
3月 25, 2008
作者:
bergstrj@iro.umontreal.ca
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed transpose as per bug #81
上级
f5801429
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
15 行增加
和
14 行删除
+15
-14
_test_tensor.py
_test_tensor.py
+9
-8
tensor.py
tensor.py
+6
-6
没有找到文件。
_test_tensor.py
浏览文件 @
2310b26e
...
...
@@ -159,41 +159,42 @@ class T_transpose(unittest.TestCase):
def
test0
(
self
):
n
=
astensor
(
numpy
.
ones
(()))
t
=
transpose
(
n
)
self
.
failUnless
(
t
.
owner
.
__class__
is
Transpose
)
self
.
failUnless
(
t
.
owner
.
__class__
is
Transpose
Inplace
)
f
=
Function
([
n
],
[
t
])
tval
=
f
(
n
.
data
)
self
.
failUnless
(
tval
.
shape
==
n
.
data
.
shape
)
#test aliasing
tval
+=
55.0
self
.
failUnless
(
n
.
data
==
56
.0
)
self
.
failUnless
(
n
.
data
==
1
.0
)
def
test1
(
self
):
n
=
astensor
(
numpy
.
ones
(
5
))
t
=
transpose
(
n
)
self
.
failUnless
(
t
.
owner
.
__class__
is
Transpose
)
self
.
failUnless
(
t
.
owner
.
__class__
is
Transpose
Inplace
)
f
=
Function
([
n
],
[
t
])
tval
=
f
(
n
.
data
)
self
.
failUnless
(
tval
.
shape
==
n
.
data
.
shape
)
#test aliasing
tval
+=
55.0
self
.
failUnless
(
n
.
data
[
0
]
==
56
.0
)
self
.
failUnless
(
n
.
data
[
0
]
==
1
.0
)
def
test2
(
self
):
n
=
astensor
(
numpy
.
ones
((
5
,
3
)))
t
=
transpose
(
n
)
self
.
failUnless
(
t
.
owner
.
__class__
is
Transpose
)
self
.
failUnless
(
t
.
owner
.
__class__
is
Transpose
Inplace
)
f
=
Function
([
n
],
[
t
])
tval
=
f
(
n
.
data
)
self
.
failUnless
(
tval
.
shape
==
(
3
,
5
))
#test aliasing
tval
+=
55.0
self
.
failUnless
(
n
.
data
[
0
,
0
]
==
56
.0
)
self
.
failUnless
(
n
.
data
[
0
,
0
]
==
1
.0
)
def
test3
(
self
):
"""Test transpose of tensor, inplace version"""
n
=
astensor
(
numpy
.
ones
((
5
,
3
,
2
)))
t
=
transpose
(
n
)
self
.
failUnless
(
t
.
owner
.
__class__
is
Transpose
)
t
=
transpose
_inplace
(
n
)
self
.
failUnless
(
t
.
owner
.
__class__
is
Transpose
Inplace
)
f
=
Function
([
n
],
[
t
])
tval
=
f
(
n
.
data
)
self
.
failUnless
(
tval
.
shape
==
(
2
,
3
,
5
))
...
...
tensor.py
浏览文件 @
2310b26e
...
...
@@ -59,9 +59,7 @@ class Tensor(BaseTensor):
def
__rpow__
(
self
,
other
):
return
pow
(
other
,
self
)
#TRANSPOSE
def
__get_T
(
self
):
return
tensor_copy
(
transpose
(
self
))
T
=
property
(
__get_T
)
T
=
property
(
lambda
self
:
transpose
(
self
))
#SLICING
def
__getitem__
(
self
,
item
):
return
subtensor
(
self
,
item
)
...
...
@@ -357,7 +355,7 @@ tensor_copy = gof.op.constructor(TensorCopy)
# View Operations
##########################
class
Transpose
(
_Op
,
Viewer
):
class
Transpose
Inplace
(
_Op
,
Viewer
):
def
view_map
(
self
):
return
{
self
.
out
:
[
self
.
inputs
[
0
]]}
def
propagate_broadcastable
(
self
,
x
):
...
...
@@ -367,7 +365,7 @@ class Transpose(_Op, Viewer):
def
impl
(
self
,
x
):
return
x
.
T
#numpy's transpose
def
grad
(
self
,
x
,
gz
):
return
transpose
_copy
(
gz
)
return
transpose
(
gz
)
def
c_impl
(
self
,
x
,
z
):
return
"""
...
...
@@ -377,7 +375,9 @@ class Transpose(_Op, Viewer):
}
%(z)
s = transposed;
"""
transpose
=
gof
.
op
.
constructor
(
Transpose
)
transpose_inplace
=
gof
.
op
.
constructor
(
TransposeInplace
)
def
transpose
(
x
,
**
kwargs
):
return
transpose_inplace
(
tensor_copy
(
x
),
**
kwargs
)
class
Subtensor
(
Op
,
Viewer
):
nin
=
2
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论