Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5dd95de0
提交
5dd95de0
authored
3月 25, 2008
作者:
bergstrj@iro.umontreal.ca
浏览文件
操作
浏览文件
下载
差异文件
default optimizations for Function, misc bug fixes
上级
5b24c9e5
2310b26e
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
40 行增加
和
19 行删除
+40
-19
_test_tensor.py
_test_tensor.py
+17
-8
base_tensor.py
base_tensor.py
+1
-1
compile.py
compile.py
+9
-1
__init__.py
gof/__init__.py
+2
-1
opt.py
gof/opt.py
+5
-2
tensor.py
tensor.py
+6
-6
没有找到文件。
_test_tensor.py
浏览文件 @
5dd95de0
...
...
@@ -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
))
...
...
@@ -404,6 +405,14 @@ class T_fill(unittest.TestCase):
# self.failUnless(o.inputs[1].dtype[0:3] == 'flo')
self
.
failUnless
(
o
.
outputs
[
0
]
.
broadcastable
==
(
0
,))
# self.failUnless(o.outputs[0].dtype[0:3] == 'flo')
self
.
failUnless
(
numpy
.
all
(
eval_outputs
([
t
])
==
[
9
,
9
,
9
]))
def
test1
(
self
):
x
=
astensor
(
numpy
.
ones
((
4
,
5
)))
l
=
ones_like
(
x
[:,
0
:
1
])
r
=
ones_like
(
x
[
0
:
1
,:])
xx
=
x
+
dot
(
l
,
r
)
self
.
failUnless
(
numpy
.
mean
(
eval_outputs
([
xx
])
==
2.0
))
class
T_sum
(
unittest
.
TestCase
):
def
test_impl
(
self
):
...
...
base_tensor.py
浏览文件 @
5dd95de0
...
...
@@ -100,7 +100,7 @@ class BaseTensor(ResultBase):
# Hash for constant folding
#
def
hash
(
self
):
if
self
.
data
:
if
self
.
data
is
not
None
:
return
(
BaseTensor
,
self
.
dtype
,
self
.
broadcastable
,
self
.
data
.
data
[:])
else
:
return
(
BaseTensor
,
self
.
dtype
,
self
.
broadcastable
,
None
)
...
...
compile.py
浏览文件 @
5dd95de0
...
...
@@ -14,6 +14,13 @@ def exec_opt(inputs, outputs, features=[]):
return
Function
(
intputs
,
outputs
,
features
,
exec_opt
.
optimizer
,
gof
.
link
.
PerformLinker
,
False
)
exec_opt
.
optimizer
=
None
def
default_optimizer
(
env
):
default_optimizer
.
const
(
env
)
default_optimizer
.
merge
(
env
)
pass
default_optimizer
.
merge
=
gof
.
opt
.
MergeOptimizer
()
default_optimizer
.
const
=
gof
.
opt
.
ConstantFinder
()
def
_mark_indestructible
(
results
):
for
r
in
results
:
r
.
indestructible
=
True
...
...
@@ -38,7 +45,7 @@ class Function:
"""
def
__init__
(
self
,
inputs
,
outputs
,
features
=
[],
optimizer
=
None
,
optimizer
=
default_optimizer
,
linker_cls
=
gof
.
link
.
PerformLinker
,
unpack_single
=
True
,
except_unreachable_input
=
True
,
...
...
@@ -97,6 +104,7 @@ class Function:
def
__call__
(
self
,
*
args
):
return
self
.
fn
(
*
args
)
def
eval_outputs
(
outputs
,
features
=
[],
optimizer
=
None
,
...
...
gof/__init__.py
浏览文件 @
5dd95de0
import
op
,
result
,
ext
,
link
,
env
,
features
,
toolbox
,
graph
,
cc
import
op
,
result
,
ext
,
link
,
env
,
features
,
toolbox
,
graph
,
cc
,
opt
from
op
import
*
from
result
import
*
...
...
@@ -9,6 +9,7 @@ from env import *
from
features
import
*
from
toolbox
import
*
from
cc
import
*
from
opt
import
*
...
...
gof/opt.py
浏览文件 @
5dd95de0
...
...
@@ -34,6 +34,9 @@ class Optimizer:
env
.
satisfy
(
self
)
self
.
apply
(
env
)
def
__call__
(
self
,
env
):
return
self
.
optimize
(
env
)
DummyOpt
=
Optimizer
()
DummyOpt
.
__doc__
=
"Does nothing."
...
...
@@ -378,8 +381,8 @@ class MergeOptimizer(Optimizer):
"""
def
apply
(
self
,
env
):
cid
=
{}
inv_cid
=
{}
cid
=
{}
#result -> result.hash() (for constants)
inv_cid
=
{}
#hash -> result (for constants)
for
i
,
r
in
enumerate
(
env
.
orphans
()
.
union
(
env
.
inputs
)):
if
getattr
(
r
,
'constant'
,
False
)
and
hasattr
(
r
,
'hash'
):
ref
=
(
'const'
,
r
.
hash
())
...
...
tensor.py
浏览文件 @
5dd95de0
...
...
@@ -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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论