Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2480f1d1
提交
2480f1d1
authored
9月 24, 2008
作者:
james@crane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
oplist, draft 1
上级
96a7d0f5
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
62 行增加
和
10 行删除
+62
-10
gen_oplist.py
gen_oplist.py
+42
-10
tensor.py
tensor.py
+20
-0
没有找到文件。
gen_oplist.py
浏览文件 @
2480f1d1
import
sys
import
sys
import
gof
import
gof
import
tensor
def
isOp
(
thing
):
def
isOpClass
(
thing
):
return
hasattr
(
thing
,
'perform'
)
return
hasattr
(
thing
,
'perform'
)
and
not
isinstance
(
thing
,
gof
.
Op
)
def
isOpConstructor
(
thing
,
module
):
return
hasattr
(
thing
,
'perform'
)
and
isinstance
(
thing
,
gof
.
Op
)
\
or
thing
in
getattr
(
module
,
'_constructor_list'
,
[])
def
print_title
(
title_string
,
under_char
):
print
title_string
print
under_char
*
len
(
title_string
)
def
chomp
(
s
):
def
chomp
(
s
):
"""interpret and left-align a docstring"""
"""interpret and left-align a docstring"""
...
@@ -35,28 +42,53 @@ def chomp(s):
...
@@ -35,28 +42,53 @@ def chomp(s):
return
""
.
join
(
r
)
return
""
.
join
(
r
)
for
module
in
[
tensor
]:
import
elemwise
,
scalar
,
sparse
,
tensor
title
=
'Ops in module: `
%
s`'
%
module
.
__name__
print
title
print_title
(
"Theano Op List"
,
"~"
)
print
'-'
*
len
(
title
)
print
""
print
".. contents:: "
print
""
for
module
in
[
elemwise
,
scalar
,
sparse
,
tensor
]:
print_title
(
'module: `
%
s`'
%
module
.
__name__
,
'='
)
print_title
(
'Op Classes'
,
'-'
)
for
symbol_name
in
dir
(
module
):
for
symbol_name
in
dir
(
module
):
symbol
=
getattr
(
module
,
symbol_name
)
symbol
=
getattr
(
module
,
symbol_name
)
if
isOp
(
symbol
)
:
if
isOp
Class
(
symbol
)
and
symbol
.
__module__
==
module
.
__name__
:
print
""
print
""
print
"- :api:`
%
s.
%
s`"
%
(
module
.
__name__
,
symbol_name
)
print
"- :api:`
%
s.
%
s`"
%
(
module
.
__name__
,
symbol_name
)
docstring
=
getattr
(
symbol
,
'__doc__'
,
""
)
docstring
=
getattr
(
symbol
,
'__doc__'
,
""
)
if
not
docstring
:
if
not
docstring
:
print
" "
,
'
No documentation
'
print
" "
,
'
(no doc)
'
elif
len
(
docstring
)
<
50
:
elif
len
(
docstring
)
<
50
:
print
" "
,
chomp
(
docstring
)
print
" "
,
chomp
(
docstring
)
else
:
else
:
print
" "
,
chomp
(
docstring
[:
40
]),
"..."
print
" "
,
chomp
(
docstring
[:
40
]),
"..."
# a little trailing whitespace
# a little trailing whitespace
print
""
print
""
print_title
(
'Op Constructors'
,
'-'
)
for
symbol_name
in
dir
(
module
):
symbol
=
getattr
(
module
,
symbol_name
)
if
isOpConstructor
(
symbol
,
module
)
\
and
symbol
.
__module__
==
module
.
__name__
:
print
""
print
"- :api:`
%
s.
%
s`"
%
(
module
.
__name__
,
symbol_name
)
docstring
=
getattr
(
symbol
,
'__doc__'
,
""
)
if
not
docstring
:
print
" "
,
'No documentation'
elif
len
(
docstring
)
<
50
:
print
" "
,
chomp
(
docstring
)
else
:
print
" "
,
chomp
(
docstring
[:
40
]),
"..."
# a little trailing whitespace
print
""
print
""
tensor.py
浏览文件 @
2480f1d1
...
@@ -26,6 +26,14 @@ from elemwise import Elemwise, DimShuffle, CAReduce, Sum
...
@@ -26,6 +26,14 @@ from elemwise import Elemwise, DimShuffle, CAReduce, Sum
import
tensor_random
as
random
import
tensor_random
as
random
_constructor_list
=
[]
"""List of functions to be listed as op constructors in the oplist (`gen_oplist`, doc/oplist.txt)."""
def
constructor
(
f
):
"""Make `f` appear as a constructor in the oplist (`gen_oplist`, doc/oplist.txt)."""
_constructor_list
.
append
(
f
)
return
f
def
as_tensor
(
x
,
name
=
None
):
def
as_tensor
(
x
,
name
=
None
):
"""Return `x`, transformed into a `Tensor`
"""Return `x`, transformed into a `Tensor`
...
@@ -485,6 +493,8 @@ def _elemwise(scalar_op, name):
...
@@ -485,6 +493,8 @@ def _elemwise(scalar_op, name):
straight
=
elemwise
.
Elemwise
(
scalar_op
,
name
=
name
)
straight
=
elemwise
.
Elemwise
(
scalar_op
,
name
=
name
)
inplace_scalar_op
=
scalar_op
.
__class__
(
scal
.
transfer_type
(
0
))
inplace_scalar_op
=
scalar_op
.
__class__
(
scal
.
transfer_type
(
0
))
inplace
=
elemwise
.
Elemwise
(
inplace_scalar_op
,
{
0
:
0
},
name
=
name
+
"_inplace"
)
inplace
=
elemwise
.
Elemwise
(
inplace_scalar_op
,
{
0
:
0
},
name
=
name
+
"_inplace"
)
_constructor_list
.
append
(
straight
)
# don't add the inplace versions, they aren't supposed to be part of the user interface
return
straight
,
inplace
return
straight
,
inplace
...
@@ -520,6 +530,7 @@ class ScalarFromTensor(Op):
...
@@ -520,6 +530,7 @@ class ScalarFromTensor(Op):
scalar_from_tensor
=
ScalarFromTensor
()
scalar_from_tensor
=
ScalarFromTensor
()
@constructor
def
cast
(
t
,
dtype
):
def
cast
(
t
,
dtype
):
mapping
=
{
'int8'
:
convert_to_int8
,
mapping
=
{
'int8'
:
convert_to_int8
,
'int16'
:
convert_to_int16
,
'int16'
:
convert_to_int16
,
...
@@ -596,6 +607,7 @@ max_and_argmax = MaxAndArgmax()
...
@@ -596,6 +607,7 @@ max_and_argmax = MaxAndArgmax()
@constructor
def
max
(
x
,
axis
=
None
):
def
max
(
x
,
axis
=
None
):
"""Return indexes of maximum elements obtained by iterating over given axis
"""Return indexes of maximum elements obtained by iterating over given axis
...
@@ -606,6 +618,7 @@ def max(x, axis=None):
...
@@ -606,6 +618,7 @@ def max(x, axis=None):
# but when Argmax.c_impl() is in place, it should be fine.
# but when Argmax.c_impl() is in place, it should be fine.
return
max_and_argmax
(
x
,
axis
)[
0
]
return
max_and_argmax
(
x
,
axis
)[
0
]
@constructor
def
argmax
(
x
,
axis
=
None
):
def
argmax
(
x
,
axis
=
None
):
"""Return maximum elements obtained by iterating over given axis
"""Return maximum elements obtained by iterating over given axis
...
@@ -665,9 +678,12 @@ tanh, tanh_inplace = _elemwise(scal.tanh, 'tanh')
...
@@ -665,9 +678,12 @@ tanh, tanh_inplace = _elemwise(scal.tanh, 'tanh')
fill
,
fill_inplace
=
_elemwise
(
scal
.
second
,
'fill'
)
fill
,
fill_inplace
=
_elemwise
(
scal
.
second
,
'fill'
)
@constructor
def
ones_like
(
model
):
def
ones_like
(
model
):
#return Ones(model.type.ndim)(shape(model))
#return Ones(model.type.ndim)(shape(model))
return
fill
(
model
,
1.0
)
return
fill
(
model
,
1.0
)
@constructor
def
zeros_like
(
model
):
def
zeros_like
(
model
):
#return Zeros(model.type.ndim)(shape(model))
#return Zeros(model.type.ndim)(shape(model))
return
fill
(
model
,
0.0
)
return
fill
(
model
,
0.0
)
...
@@ -708,12 +724,14 @@ class Filler(gof.Op):
...
@@ -708,12 +724,14 @@ class Filler(gof.Op):
Zeros
=
functools
.
partial
(
Filler
,
0
)
Zeros
=
functools
.
partial
(
Filler
,
0
)
Ones
=
functools
.
partial
(
Filler
,
1
)
Ones
=
functools
.
partial
(
Filler
,
1
)
@constructor
def
zero
():
def
zero
():
"""
"""
Return a scalar zero, e.g. for initializing sums.
Return a scalar zero, e.g. for initializing sums.
"""
"""
return
Zeros
(
0
)([])
return
Zeros
(
0
)([])
@constructor
def
one
():
def
one
():
return
Ones
(
0
)([])
return
Ones
(
0
)([])
...
@@ -721,9 +739,11 @@ def one():
...
@@ -721,9 +739,11 @@ def one():
tensor_copy
=
elemwise
.
Elemwise
(
scal
.
identity
)
tensor_copy
=
elemwise
.
Elemwise
(
scal
.
identity
)
identity
=
elemwise
.
Elemwise
(
scal
.
identity
,
inplace_pattern
=
{
0
:
[
0
]})
identity
=
elemwise
.
Elemwise
(
scal
.
identity
,
inplace_pattern
=
{
0
:
[
0
]})
@constructor
def
sum
(
input
,
axis
=
None
):
def
sum
(
input
,
axis
=
None
):
return
elemwise
.
Sum
(
axis
)(
input
)
return
elemwise
.
Sum
(
axis
)(
input
)
@constructor
def
mean
(
input
,
axis
=
None
):
def
mean
(
input
,
axis
=
None
):
s
=
sum
(
input
,
axis
)
s
=
sum
(
input
,
axis
)
shp
=
shape
(
input
)
shp
=
shape
(
input
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论