Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
81c7aa5c
提交
81c7aa5c
authored
2月 26, 2008
作者:
bergstrj@iro.umontreal.ca
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added constructor.py
上级
db8f8a2a
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
84 行增加
和
1 行删除
+84
-1
constructor.py
constructor.py
+76
-0
constructor_fodder.py
constructor_fodder.py
+7
-0
sparse.py
sparse.py
+1
-1
没有找到文件。
constructor.py
0 → 100644
浏览文件 @
81c7aa5c
import
unittest
import
constructor_fodder
as
cf
class
Allocator
:
def
__init__
(
self
,
cls
,
ctor
):
self
.
cls
=
cls
self
.
ctor
=
ctor
def
__call__
(
self
,
*
args
,
**
kwargs
):
rval
=
self
.
cls
.
__new__
(
self
.
cls
,
*
args
,
**
kwargs
)
rval
.
__init__
(
*
args
,
**
kwargs
)
return
rval
class
ModeOpAllocator
:
def
__init__
(
self
,
cls
,
ctor
):
self
.
cls
=
cls
self
.
ctor
=
ctor
def
__call__
(
self
,
*
args
,
**
kwargs
):
op
=
self
.
cls
.
__new__
(
self
.
cls
,
*
args
,
**
kwargs
)
op
.
__init__
(
*
args
,
**
kwargs
)
mode
=
self
.
ctor
.
mode
()
if
mode
==
'eval'
:
op
.
perform
()
if
op
.
nout
==
1
:
return
op
.
out
.
data
else
:
return
[
output
.
data
for
output
in
op
.
outputs
]
elif
mode
==
'build_eval'
:
op
.
perform
()
if
op
.
nout
==
1
:
return
op
.
out
else
:
return
op
.
outputs
class
Constructor
:
def
__init__
(
self
):
pass
def
add_module
(
self
,
module
,
module_name
,
accept
=
lambda
x
:
issubclass
(
x
,
cf
.
base
)):
dct
=
{}
for
symbol
in
dir
(
module
):
if
symbol
[:
2
]
==
'__'
:
continue
obj
=
getattr
(
module
,
symbol
)
if
accept
(
obj
):
dct
[
symbol
]
=
Allocator
(
obj
)
class
Dummy
:
pass
self
.
__dict__
[
module_name
]
=
Dummy
()
self
.
__dict__
[
module_name
]
.
__dict__
.
update
(
dct
)
def
add_from_module
(
self
,
module
,
accept
=
lambda
x
:
issubclass
(
x
,
cf
.
base
)):
for
symbol
in
dir
(
module
):
if
symbol
[:
2
]
==
'__'
:
continue
obj
=
getattr
(
module
,
symbol
)
#print 'considering', symbol, obj
if
accept
(
obj
):
self
.
__dict__
[
symbol
]
=
Allocator
(
obj
)
def
add_globals_from_module
(
self
,
module
,
accept
=
lambda
x
:
issubclass
(
x
,
cf
.
base
)):
for
symbol
in
dir
(
module
):
if
symbol
[:
2
]
==
'__'
:
continue
obj
=
getattr
(
module
,
symbol
)
#print 'considering', symbol, obj
if
accept
(
obj
):
if
hasattr
(
globals
(),
symbol
):
print
'Warning, overwriting global variable:
%
s'
%
symbol
globals
()[
symbol
]
=
Allocator
(
obj
)
if
__name__
==
'__main__'
:
c
=
Constructor
()
c
.
add_module
(
cf
,
'cf'
)
aa
,
bb
=
c
.
cf
.
A
(),
c
.
cf
.
B
()
print
aa
,
bb
c
.
add_from_module
(
cf
)
a
,
b
=
c
.
A
(),
c
.
B
()
print
a
,
b
c
.
add_globals_from_module
(
cf
)
d
,
e
=
A
(),
B
()
print
d
,
e
constructor_fodder.py
0 → 100644
浏览文件 @
81c7aa5c
class
base
(
object
):
pass
class
A
(
base
):
pass
class
B
(
base
):
pass
class
C
(
base
):
pass
sparse.py
浏览文件 @
81c7aa5c
...
@@ -69,7 +69,7 @@ class SparseR(core.ResultBase):
...
@@ -69,7 +69,7 @@ class SparseR(core.ResultBase):
# convenience base class
# convenience base class
class
op
(
gof
.
PythonOp
,
grad
.
update_gradient_via_grad
):
class
op
(
gof
.
PythonOp
,
grad
.
update_gradient_via_grad
):
pass
"""unite PythonOp with update_gradient_via_grad"""
#
#
# Conversion
# Conversion
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论