Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
60eb8ce2
提交
60eb8ce2
authored
5月 07, 2008
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added __eq__ and __hash__ to NumpyGenerator
上级
8085810d
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
49 行增加
和
14 行删除
+49
-14
_test_tensor_random.py
_test_tensor_random.py
+13
-0
blas.py
blas.py
+2
-10
utils.py
gof/utils.py
+15
-0
tensor_random.py
tensor_random.py
+19
-4
没有找到文件。
_test_tensor_random.py
浏览文件 @
60eb8ce2
...
@@ -68,6 +68,19 @@ class T_Random(unittest.TestCase):
...
@@ -68,6 +68,19 @@ class T_Random(unittest.TestCase):
self
.
failUnless
(
str
(
v0
[
0
,
0
])
.
startswith
(
'0.013259'
))
self
.
failUnless
(
str
(
v0
[
0
,
0
])
.
startswith
(
'0.013259'
))
self
.
failUnless
(
str
(
v0
[
1
,
2
])
.
startswith
(
'0.753368'
))
self
.
failUnless
(
str
(
v0
[
1
,
2
])
.
startswith
(
'0.753368'
))
def
test5
(
self
):
"""Test that two NumpyGenerators with the same dist compare equal"""
rng0
=
RandomState
(
123456
)
rng1
=
RandomState
(
123456
)
d0
=
rng0
.
gen
((
'beta'
,{
'a'
:
0.5
,
'b'
:
0.65
}),
(
2
,
3
,
4
))
d1
=
rng1
.
gen
((
'beta'
,{
'a'
:
0.5
,
'b'
:
0.65
}),
(
2
,
3
,
4
))
self
.
failUnless
(
d0
.
owner
.
op
==
d1
.
owner
.
op
)
self
.
failUnless
(
hash
(
d0
.
owner
.
op
)
==
hash
(
d1
.
owner
.
op
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
blas.py
浏览文件 @
60eb8ce2
import
os
,
sys
import
os
,
sys
import
scipy.weave
as
weave
import
scipy.weave
as
weave
import
gof.utils
"""
"""
File: omega/blas.py
File: omega/blas.py
...
@@ -794,16 +795,7 @@ def blas_proto():
...
@@ -794,16 +795,7 @@ def blas_proto():
}
}
"""
"""
def
_constant
(
f
):
@gof.utils.memoize
"""Return a function that always returns its first call value
"""
def
rval
(
*
args
,
**
kwargs
):
if
not
hasattr
(
f
,
'rval'
):
f
.
rval
=
f
(
*
args
,
**
kwargs
)
return
f
.
rval
return
rval
@_constant
def
ldflags
():
def
ldflags
():
"""Return a list of libraries against which an Op's object file should be
"""Return a list of libraries against which an Op's object file should be
linked to benefit from a BLAS implementation.
linked to benefit from a BLAS implementation.
...
...
gof/utils.py
浏览文件 @
60eb8ce2
...
@@ -36,6 +36,21 @@ class scratchpad:
...
@@ -36,6 +36,21 @@ class scratchpad:
print
"scratch"
+
str
(
self
.
__dict__
)
print
"scratch"
+
str
(
self
.
__dict__
)
def
memoize
(
f
):
"""Cache the return value for each tuple of arguments
(which must be hashable) """
cache
=
{}
def
rval
(
*
args
,
**
kwargs
):
kwtup
=
tuple
(
kwargs
.
items
())
key
=
(
args
,
kwtup
)
if
key
not
in
cache
:
val
=
f
(
*
args
,
**
kwargs
)
cache
[
key
]
=
val
else
:
val
=
cache
[
key
]
return
val
return
rval
def
deprecated
(
filename
,
msg
=
''
):
def
deprecated
(
filename
,
msg
=
''
):
...
...
tensor_random.py
浏览文件 @
60eb8ce2
...
@@ -3,16 +3,23 @@ import tensor
...
@@ -3,16 +3,23 @@ import tensor
import
numpy
import
numpy
import
functools
import
functools
def
fn_from_dist
(
dist
):
# the optional argument implements a closure
# the cache is used so that we we can be sure that
# id(self.fn) in NumpyGenerator identifies
# the computation performed.
def
fn_from_dist
(
dist
,
cache
=
{}):
if
callable
(
dist
):
if
callable
(
dist
):
return
dist
return
dist
if
isinstance
(
dist
,
str
):
if
isinstance
(
dist
,
str
):
return
getattr
(
numpy
.
random
.
RandomState
,
dist
)
return
getattr
(
numpy
.
random
.
RandomState
,
dist
)
name
,
kwargs
=
dist
name
,
kwargs
=
dist
key
=
(
name
,
tuple
(
kwargs
.
items
()))
if
key
not
in
cache
:
fn
=
getattr
(
numpy
.
random
.
RandomState
,
name
)
fn
=
getattr
(
numpy
.
random
.
RandomState
,
name
)
fn
=
functools
.
partial
(
fn
,
**
kwargs
)
fn
=
functools
.
partial
(
fn
,
**
kwargs
)
return
fn
cache
[
key
]
=
fn
return
cache
[
key
]
class
RandomState
(
object
):
class
RandomState
(
object
):
def
__init__
(
self
,
seed
):
def
__init__
(
self
,
seed
):
...
@@ -45,14 +52,22 @@ class NumpyGenerator(gof.op.Op):
...
@@ -45,14 +52,22 @@ class NumpyGenerator(gof.op.Op):
self
.
ndim
=
ndim
self
.
ndim
=
ndim
self
.
fn
=
fn
self
.
fn
=
fn
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
is
type
(
other
))
\
and
self
.
__class__
is
NumpyGenerator
\
and
self
.
seed
==
other
.
seed
\
and
self
.
ndim
==
other
.
ndim
\
and
self
.
fn
==
other
.
fn
def
__hash__
(
self
):
return
self
.
seed
^
self
.
ndim
^
id
(
self
.
fn
)
def
make_node
(
self
,
_shape
):
def
make_node
(
self
,
_shape
):
#TODO: check for constant shape, and guess the broadcastable bits
#TODO: check for constant shape, and guess the broadcastable bits
shape
=
tensor
.
convert_to_int64
(
_shape
)
shape
=
tensor
.
convert_to_int64
(
_shape
)
if
shape
.
type
.
ndim
!=
1
:
if
shape
.
type
.
ndim
!=
1
:
raise
TypeError
(
'shape argument was not converted to 1-d tensor'
,
_shape
)
raise
TypeError
(
'shape argument was not converted to 1-d tensor'
,
_shape
)
inputs
=
[
gof
.
Value
(
gof
.
type
.
generic
,
numpy
.
random
.
RandomState
(
self
.
seed
)),
shape
]
inputs
=
[
gof
.
Value
(
gof
.
type
.
generic
,
numpy
.
random
.
RandomState
(
self
.
seed
)),
shape
]
outputs
=
[
gof
.
Result
(
tensor
.
Tensor
(
dtype
=
'float64'
,
broadcastable
=
outputs
=
[
tensor
.
Tensor
(
dtype
=
'float64'
,
broadcastable
=
[
False
]
*
self
.
ndim
)
.
make_result
()]
[
False
]
*
self
.
ndim
))]
return
gof
.
Apply
(
op
=
self
,
inputs
=
inputs
,
outputs
=
outputs
)
return
gof
.
Apply
(
op
=
self
,
inputs
=
inputs
,
outputs
=
outputs
)
def
grad
(
self
,
inputs
,
grad_outputs
):
def
grad
(
self
,
inputs
,
grad_outputs
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论