Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c99f5cb3
提交
c99f5cb3
authored
8月 13, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
numpydoc for theano/gof/utils.py
上级
9260f716
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
50 行增加
和
20 行删除
+50
-20
utils.py
theano/gof/utils.py
+50
-20
没有找到文件。
theano/gof/utils.py
浏览文件 @
c99f5cb3
...
@@ -11,13 +11,14 @@ from theano.compat import OrderedDict, PY3
...
@@ -11,13 +11,14 @@ from theano.compat import OrderedDict, PY3
def
simple_extract_stack
(
f
=
None
,
limit
=
None
):
def
simple_extract_stack
(
f
=
None
,
limit
=
None
):
"""
This is traceback.extract_stack from python 2.7 with this
"""
change:
This is traceback.extract_stack from python 2.7 with this
change:
- Comment the update of the cache
- Comment the update of the cache
.
This is because this update cause an call to os.stat to get the
This is because this update cause an call to os.stat to get the
line content. This cause too much long on cluster.
line content. This cause too much long on cluster.
"""
"""
if
f
is
None
:
if
f
is
None
:
try
:
try
:
...
@@ -54,14 +55,22 @@ if sys.version_info[:2] > (3, 4):
...
@@ -54,14 +55,22 @@ if sys.version_info[:2] > (3, 4):
def
add_tag_trace
(
thing
,
user_line
=
1
):
def
add_tag_trace
(
thing
,
user_line
=
1
):
"""Add tag.trace to an node or variable.
"""
Add tag.trace to an node or variable.
The argument is returned after being affected (inplace).
The argument is returned after being affected (inplace).
:param thing: the object where we add .tag.trace
:param user_line: The max number of user line to keep.
:note: we alse use config.traceback.limit for the maximum number
Parameters
of stack level we look.
----------
thing
The object where we add .tag.trace.
user_line
The max number of user line to keep.
Notes
-----
We alse use config.traceback.limit for the maximum number of stack level
we look.
"""
"""
limit
=
config
.
traceback
.
limit
limit
=
config
.
traceback
.
limit
...
@@ -117,6 +126,7 @@ class MethodNotDefined(Exception):
...
@@ -117,6 +126,7 @@ class MethodNotDefined(Exception):
When the user sees such an error, it is because an important interface
When the user sees such an error, it is because an important interface
function has been left out of an implementation class.
function has been left out of an implementation class.
"""
"""
...
@@ -159,8 +169,10 @@ class D:
...
@@ -159,8 +169,10 @@ class D:
def
memoize
(
f
):
def
memoize
(
f
):
"""Cache the return value for each tuple of arguments
"""
(which must be hashable) """
Cache the return value for each tuple of arguments (which must be hashable).
"""
cache
=
{}
cache
=
{}
def
rval
(
*
args
,
**
kwargs
):
def
rval
(
*
args
,
**
kwargs
):
...
@@ -177,15 +189,16 @@ def memoize(f):
...
@@ -177,15 +189,16 @@ def memoize(f):
def
deprecated
(
filename
,
msg
=
''
):
def
deprecated
(
filename
,
msg
=
''
):
"""Decorator which will print a warning message on the first call.
"""
Decorator which will print a warning message on the first call.
Use it like this:
:
Use it like this:
@deprecated('myfile', 'do something different...')
@deprecated('myfile', 'do something different...')
def fn_name(...)
def fn_name(...)
...
...
And it will print:
:
And it will print:
WARNING myfile.fn_name deprecated. do something different...
WARNING myfile.fn_name deprecated. do something different...
...
@@ -209,6 +222,7 @@ def uniq(seq):
...
@@ -209,6 +222,7 @@ def uniq(seq):
Do not use set, this must always return the same value at the same index.
Do not use set, this must always return the same value at the same index.
If we just exchange other values, but keep the same pattern of duplication,
If we just exchange other values, but keep the same pattern of duplication,
we must keep the same order.
we must keep the same order.
"""
"""
# TODO: consider building a set out of seq so that the if condition
# TODO: consider building a set out of seq so that the if condition
# is constant time -JB
# is constant time -JB
...
@@ -217,7 +231,8 @@ def uniq(seq):
...
@@ -217,7 +231,8 @@ def uniq(seq):
def
difference
(
seq1
,
seq2
):
def
difference
(
seq1
,
seq2
):
"""
"""
Returns all elements in seq1 which are not in seq2: i.e ``seq1
\
seq2``
Returns all elements in seq1 which are not in seq2: i.e ``seq1
\
seq2``.
"""
"""
try
:
try
:
# try to use O(const * len(seq1)) algo
# try to use O(const * len(seq1)) algo
...
@@ -252,6 +267,7 @@ def toposort(prereqs_d):
...
@@ -252,6 +267,7 @@ def toposort(prereqs_d):
prereqs_d[x] contains all the elements that must come before x
prereqs_d[x] contains all the elements that must come before x
in the ordering.
in the ordering.
"""
"""
# all1 = set(prereqs_d.keys())
# all1 = set(prereqs_d.keys())
...
@@ -390,6 +406,7 @@ def type_guard(type1):
...
@@ -390,6 +406,7 @@ def type_guard(type1):
def
flatten
(
a
):
def
flatten
(
a
):
"""
"""
Recursively flatten tuple, list and set in a list.
Recursively flatten tuple, list and set in a list.
"""
"""
if
isinstance
(
a
,
(
tuple
,
list
,
set
)):
if
isinstance
(
a
,
(
tuple
,
list
,
set
)):
l
=
[]
l
=
[]
...
@@ -412,9 +429,12 @@ def hist(coll):
...
@@ -412,9 +429,12 @@ def hist(coll):
def
give_variables_names
(
variables
):
def
give_variables_names
(
variables
):
""" Gives unique names to an iterable of variables. Modifies input.
"""
Gives unique names to an iterable of variables. Modifies input.
This function is idempotent."""
This function is idempotent.
"""
names
=
[
var
.
name
for
var
in
variables
]
names
=
[
var
.
name
for
var
in
variables
]
h
=
hist
(
names
)
h
=
hist
(
names
)
...
@@ -431,13 +451,17 @@ def give_variables_names(variables):
...
@@ -431,13 +451,17 @@ def give_variables_names(variables):
def
remove
(
predicate
,
coll
):
def
remove
(
predicate
,
coll
):
""" Return those items of collection for which predicate(item) is true.
"""
Return those items of collection for which predicate(item) is true.
Examples
--------
>>> from itertoolz import remove
>>> from itertoolz import remove
>>> def even(x):
>>> def even(x):
... return x
% 2
== 0
... return x
% 2
== 0
>>> remove(even, [1, 2, 3, 4])
>>> remove(even, [1, 2, 3, 4])
[1, 3]
[1, 3]
"""
"""
return
[
x
for
x
in
coll
if
not
predicate
(
x
)]
return
[
x
for
x
in
coll
if
not
predicate
(
x
)]
...
@@ -466,12 +490,16 @@ else:
...
@@ -466,12 +490,16 @@ else:
def
hash_from_file
(
file_path
):
def
hash_from_file
(
file_path
):
"""Return the MD5 hash of a file."""
"""
Return the MD5 hash of a file.
"""
return
hash_from_code
(
open
(
file_path
,
'rb'
)
.
read
())
return
hash_from_code
(
open
(
file_path
,
'rb'
)
.
read
())
def
hash_from_dict
(
d
):
def
hash_from_dict
(
d
):
"""Work around the fact that dict are not hashable in python
"""
Work around the fact that dict are not hashable in python.
This request that all object have a sorted order that depend only
This request that all object have a sorted order that depend only
on the key of the object. We support only integer/float/string keys.
on the key of the object. We support only integer/float/string keys.
...
@@ -479,7 +507,9 @@ def hash_from_dict(d):
...
@@ -479,7 +507,9 @@ def hash_from_dict(d):
Also, we transform values that are list into tuple as list are not
Also, we transform values that are list into tuple as list are not
hashable.
hashable.
:note: special case for OrderedDict, it use the order of the dict,
Notes
-----
Special case for OrderedDict, it use the order of the dict,
so the key don't need to be sortable.
so the key don't need to be sortable.
"""
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论