Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9db375d7
提交
9db375d7
authored
2月 05, 2008
作者:
bergstrj@iro.umontreal.ca
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dot test cases
上级
2b6275d0
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
121 行增加
和
7 行删除
+121
-7
autotest.py
autotest.py
+13
-0
compile.py
compile.py
+1
-1
core.py
core.py
+101
-3
lib.py
gof/lib.py
+6
-3
没有找到文件。
autotest.py
0 → 100644
浏览文件 @
9db375d7
import
unittest
,
os
,
sys
for
filename
in
os
.
listdir
(
'.'
):
if
filename
==
__file__
:
continue
#continue
if
filename
[
-
3
:]
==
'.py'
:
modname
=
filename
[:
-
3
]
suite
=
unittest
.
TestLoader
()
.
loadTestsFromModule
(
__import__
(
modname
))
#suite.addTests(unittest.TestLoader().loadTestsFromModule(__import__(modname)))
if
suite
.
countTestCases
()
>
0
:
print
>>
sys
.
stderr
,
'Testing'
,
modname
,
'(
%
s)'
%
(
filename
),
unittest
.
TextTestRunner
(
verbosity
=
1
)
.
run
(
suite
)
compile.py
浏览文件 @
9db375d7
...
@@ -31,7 +31,7 @@ def experimental_linker(env, target = None):
...
@@ -31,7 +31,7 @@ def experimental_linker(env, target = None):
except
NotImplementedError
:
except
NotImplementedError
:
result
=
op
.
_perform
result
=
op
.
_perform
py_ops
.
add
(
op
)
py_ops
.
add
(
op
)
thunks
.
append
((
result
,
op
.
_perform_
like_c
))
thunks
.
append
((
result
,
op
.
_perform_
inplace
))
def
ret
():
def
ret
():
for
thunk
,
fallback
in
thunks
:
for
thunk
,
fallback
in
thunks
:
...
...
core.py
浏览文件 @
9db375d7
...
@@ -16,6 +16,7 @@ from gof import current_mode, set_mode, build_mode, eval_mode, build_eval_mode,
...
@@ -16,6 +16,7 @@ from gof import current_mode, set_mode, build_mode, eval_mode, build_eval_mode,
import
type_spec
import
type_spec
import
cutils
import
cutils
import
blas
import
blas
import
compile
# __all__ = ['set_mode', 'get_mode', 'NumpyR', 'NumpyOp']
# __all__ = ['set_mode', 'get_mode', 'NumpyR', 'NumpyOp']
...
@@ -37,6 +38,14 @@ def as_string(*rs):
...
@@ -37,6 +38,14 @@ def as_string(*rs):
def
print_graph
(
*
rs
):
def
print_graph
(
*
rs
):
print
as_string
(
*
rs
)
print
as_string
(
*
rs
)
def
_approx_eq
(
a
,
b
,
eps
=
1.0e-9
):
a
=
numpy
.
asarray
(
a
)
b
=
numpy
.
asarray
(
b
)
if
a
.
shape
!=
b
.
shape
:
return
False
d
=
abs
(
a
-
b
)
return
numpy
.
all
(
d
<
eps
)
literals_db
=
{}
literals_db
=
{}
#literals_id_db = weakref.WeakValueDictionary()
#literals_id_db = weakref.WeakValueDictionary()
...
@@ -680,6 +689,17 @@ class NumpyR(gof.PythonR):
...
@@ -680,6 +689,17 @@ class NumpyR(gof.PythonR):
self
.
refresh
()
self
.
refresh
()
self
.
up_to_date
=
True
self
.
up_to_date
=
True
def
set_value_inplace
(
self
,
value
):
if
value
is
UNCOMPUTED
:
raise
ValueError
()
else
:
if
0
==
len
(
self
.
data
.
shape
):
self
.
data
.
itemset
(
value
)
else
:
self
.
data
[:]
=
value
self
.
refresh
()
self
.
up_to_date
=
True
def
refresh
(
self
):
def
refresh
(
self
):
if
self
.
data
is
not
UNCOMPUTED
:
if
self
.
data
is
not
UNCOMPUTED
:
self
.
spec
=
(
numpy
.
ndarray
,
self
.
data
.
dtype
,
self
.
data
.
shape
)
self
.
spec
=
(
numpy
.
ndarray
,
self
.
data
.
dtype
,
self
.
data
.
shape
)
...
@@ -938,9 +958,19 @@ class dot(omega_op):
...
@@ -938,9 +958,19 @@ class dot(omega_op):
def
grad
(
x
,
y
,
gz
):
def
grad
(
x
,
y
,
gz
):
return
dot
(
gz
,
transpose
(
y
)),
dot
(
transpose
(
x
),
gz
)
return
dot
(
gz
,
transpose
(
y
)),
dot
(
transpose
(
x
),
gz
)
def
specs
(
x
,
y
):
def
specs
(
x
,
y
):
# todo: handle all tensors!
xshape
=
x
[
2
]
assert
x
[
2
][
1
]
==
y
[
2
][
0
]
yshape
=
y
[
2
]
shape
=
(
x
[
2
][
0
],
y
[
2
][
1
])
if
len
(
xshape
)
==
0
:
# x is a scalar
shape
=
yshape
else
:
if
len
(
yshape
)
>=
2
:
#y is a matrix or tensor
assert
xshape
[
-
1
]
==
yshape
[
-
2
]
shape
=
tuple
(
xshape
[:
-
1
]
+
yshape
[:
-
2
]
+
yshape
[
-
1
:])
elif
len
(
yshape
)
==
1
:
#y is vector
assert
xshape
[
-
1
]
==
yshape
[
-
1
]
shape
=
tuple
(
xshape
[:
-
1
])
else
:
#y is a scalar
shape
=
xshape
return
(
numpy
.
ndarray
,
upcast
(
x
[
1
],
y
[
1
]),
shape
)
return
(
numpy
.
ndarray
,
upcast
(
x
[
1
],
y
[
1
]),
shape
)
def
c_support_code
(
self
):
def
c_support_code
(
self
):
return
blas
.
cblas_header_text
()
return
blas
.
cblas_header_text
()
...
@@ -998,6 +1028,74 @@ class gemm(omega_op, inplace):
...
@@ -998,6 +1028,74 @@ class gemm(omega_op, inplace):
'(_a->descr->type_num == PyArray_FLOAT) ? (REAL)(((float*)_a->data)[0]) : (REAL)(((double*)_a->data)[0])'
,
'(_a->descr->type_num == PyArray_FLOAT) ? (REAL)(((float*)_a->data)[0]) : (REAL)(((double*)_a->data)[0])'
,
'(_b->descr->type_num == PyArray_FLOAT) ? (REAL)(((float*)_b->data)[0]) : (REAL)(((double*)_b->data)[0])'
)
'(_b->descr->type_num == PyArray_FLOAT) ? (REAL)(((float*)_b->data)[0]) : (REAL)(((double*)_b->data)[0])'
)
class
_testCase_dotgemm
(
unittest
.
TestCase
):
def
setUp
(
self
):
build_eval_mode
()
numpy
.
random
.
seed
(
44
)
def
tearDown
(
self
):
pop_mode
()
@staticmethod
def
rand
(
*
args
):
return
numpy
.
random
.
rand
(
*
args
)
def
cmp_dot
(
self
,
x
,
y
):
def
spec
(
x
):
x
=
numpy
.
asarray
(
x
)
return
type
(
x
),
x
.
dtype
,
x
.
shape
zspec
=
dot
.
specs
(
spec
(
x
),
spec
(
y
))
nz
=
numpy
.
dot
(
x
,
y
)
self
.
failUnless
(
zspec
==
spec
(
nz
))
self
.
failUnless
(
_approx_eq
(
dot
(
x
,
y
),
numpy
.
dot
(
x
,
y
)))
def
cmp_dot_comp
(
self
,
x
,
y
):
x
=
numpy
.
asarray
(
x
)
y
=
numpy
.
asarray
(
y
)
z
=
dot
(
x
,
y
)
p
=
compile
.
single
(
z
)
if
len
(
x
.
shape
):
x
[:]
=
numpy
.
random
.
rand
(
*
x
.
shape
)
else
:
x
.
fill
(
numpy
.
random
.
rand
(
*
x
.
shape
))
if
len
(
y
.
shape
):
y
[:]
=
numpy
.
random
.
rand
(
*
y
.
shape
)
else
:
y
.
fill
(
numpy
.
random
.
rand
(
*
y
.
shape
))
p
()
# recalculate z
self
.
failUnless
(
_approx_eq
(
z
,
numpy
.
dot
(
x
,
y
)))
def
test_dot_0d_0d
(
self
):
self
.
cmp_dot
(
1.1
,
2.2
)
def
test_dot_0d_1d
(
self
):
self
.
cmp_dot
(
1.1
,
self
.
rand
(
5
))
def
test_dot_0d_2d
(
self
):
self
.
cmp_dot
(
3.0
,
self
.
rand
(
6
,
7
))
def
test_dot_0d_3d
(
self
):
self
.
cmp_dot
(
3.0
,
self
.
rand
(
8
,
6
,
7
))
def
test_dot_1d_0d
(
self
):
self
.
cmp_dot
(
self
.
rand
(
5
),
1.1
)
def
test_dot_1d_1d
(
self
):
self
.
cmp_dot
(
self
.
rand
(
5
),
self
.
rand
(
5
))
def
test_dot_1d_2d
(
self
):
self
.
cmp_dot
(
self
.
rand
(
6
),
self
.
rand
(
6
,
7
))
def
test_dot_1d_3d
(
self
):
self
.
cmp_dot
(
self
.
rand
(
6
),
self
.
rand
(
8
,
6
,
7
))
def
test_dot_2d_0d
(
self
):
self
.
cmp_dot
(
self
.
rand
(
5
,
6
),
1.0
)
def
test_dot_2d_1d
(
self
):
self
.
cmp_dot
(
self
.
rand
(
5
,
6
),
self
.
rand
(
6
))
def
test_dot_2d_2d
(
self
):
self
.
cmp_dot
(
self
.
rand
(
5
,
6
),
self
.
rand
(
6
,
7
))
def
test_dot_2d_3d
(
self
):
self
.
cmp_dot
(
self
.
rand
(
5
,
6
),
self
.
rand
(
8
,
6
,
7
))
def
test_dot_3d_0d
(
self
):
self
.
cmp_dot
(
self
.
rand
(
4
,
5
,
6
),
1.0
)
def
test_dot_3d_1d
(
self
):
self
.
cmp_dot
(
self
.
rand
(
4
,
5
,
6
),
self
.
rand
(
6
))
def
test_dot_3d_2d
(
self
):
self
.
cmp_dot
(
self
.
rand
(
4
,
5
,
6
),
self
.
rand
(
6
,
7
))
def
test_dot_3d_3d
(
self
):
self
.
cmp_dot
(
self
.
rand
(
4
,
5
,
6
),
self
.
rand
(
8
,
6
,
7
))
def
test_dot_0d_0d_
(
self
):
self
.
cmp_dot_comp
(
1.1
,
2.2
)
def
test_dot_0d_1d_
(
self
):
self
.
cmp_dot_comp
(
1.1
,
self
.
rand
(
5
))
def
test_dot_0d_2d_
(
self
):
self
.
cmp_dot_comp
(
3.0
,
self
.
rand
(
6
,
7
))
def
test_dot_0d_3d_
(
self
):
self
.
cmp_dot_comp
(
3.0
,
self
.
rand
(
8
,
6
,
7
))
def
test_dot_1d_0d_
(
self
):
self
.
cmp_dot_comp
(
self
.
rand
(
5
),
1.1
)
def
test_dot_1d_1d_
(
self
):
self
.
cmp_dot_comp
(
self
.
rand
(
5
),
self
.
rand
(
5
))
def
test_dot_1d_2d_
(
self
):
self
.
cmp_dot_comp
(
self
.
rand
(
6
),
self
.
rand
(
6
,
7
))
def
test_dot_1d_3d_
(
self
):
self
.
cmp_dot_comp
(
self
.
rand
(
6
),
self
.
rand
(
8
,
6
,
7
))
def
test_dot_2d_0d_
(
self
):
self
.
cmp_dot_comp
(
self
.
rand
(
5
,
6
),
1.0
)
def
test_dot_2d_1d_
(
self
):
self
.
cmp_dot_comp
(
self
.
rand
(
5
,
6
),
self
.
rand
(
6
))
def
test_dot_2d_2d_
(
self
):
self
.
cmp_dot_comp
(
self
.
rand
(
5
,
6
),
self
.
rand
(
6
,
7
))
def
test_dot_2d_3d_
(
self
):
self
.
cmp_dot_comp
(
self
.
rand
(
5
,
6
),
self
.
rand
(
8
,
6
,
7
))
def
test_dot_3d_0d_
(
self
):
self
.
cmp_dot_comp
(
self
.
rand
(
4
,
5
,
6
),
1.0
)
def
test_dot_3d_1d_
(
self
):
self
.
cmp_dot_comp
(
self
.
rand
(
4
,
5
,
6
),
self
.
rand
(
6
))
def
test_dot_3d_2d_
(
self
):
self
.
cmp_dot_comp
(
self
.
rand
(
4
,
5
,
6
),
self
.
rand
(
6
,
7
))
def
test_dot_3d_3d_
(
self
):
self
.
cmp_dot_comp
(
self
.
rand
(
4
,
5
,
6
),
self
.
rand
(
8
,
6
,
7
))
## Transposition ##
## Transposition ##
...
...
gof/lib.py
浏览文件 @
9db375d7
...
@@ -102,6 +102,9 @@ class PythonR(Result):
...
@@ -102,6 +102,9 @@ class PythonR(Result):
self
.
up_to_date
=
True
self
.
up_to_date
=
True
self
.
refresh
()
self
.
refresh
()
def
set_value_inplace
(
self
,
value
):
raise
NotImplementedError
()
def
__str__
(
self
):
def
__str__
(
self
):
return
str
(
self
.
data
)
return
str
(
self
.
data
)
...
@@ -231,14 +234,14 @@ class PythonOp(Op):
...
@@ -231,14 +234,14 @@ class PythonOp(Op):
for
result
,
output
in
zip
(
results
,
self
.
outputs
):
for
result
,
output
in
zip
(
results
,
self
.
outputs
):
output
.
set_value
(
result
)
output
.
set_value
(
result
)
def
_perform_
like_c
(
self
):
def
_perform_
inplace
(
self
):
results
=
self
.
_impl
()
results
=
self
.
_impl
()
if
self
.
nout
==
1
:
if
self
.
nout
==
1
:
self
.
out
puts
[
0
]
.
data
[:]
=
results
self
.
out
.
set_value_inplace
(
results
)
else
:
else
:
assert
self
.
nout
==
len
(
results
)
assert
self
.
nout
==
len
(
results
)
for
result
,
output
in
zip
(
results
,
self
.
outputs
):
for
result
,
output
in
zip
(
results
,
self
.
outputs
):
output
.
data
[:]
=
result
output
.
set_value_inplace
(
result
)
def
_impl
(
self
):
def
_impl
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论