Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c8de0d44
提交
c8de0d44
authored
5月 06, 2022
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
5月 08, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean up NumPy imports
上级
f4ad0ed8
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
44 行增加
和
47 行删除
+44
-47
unittest.rst
doc/extending/unittest.rst
+19
-13
test_blas.py
tests/tensor/test_blas.py
+25
-34
没有找到文件。
doc/extending/unittest.rst
浏览文件 @
c8de0d44
...
@@ -240,22 +240,28 @@ product :class:`Op`:
...
@@ -240,22 +240,28 @@ product :class:`Op`:
.. testcode::
.. testcode::
from numpy import dot
import numpy as np
from numpy.random import rand
from tests.tensor.utils import makeTester
from tests.tensor.utils import makeTester
TestDot = makeTester(name = 'DotTester',
rng = np.random.default_rng(23098)
op = dot,
expected = lambda x, y: numpy.dot(x, y),
TestDot = makeTester(
checks = {},
name="DotTester",
good = dict(correct1 = (rand(5, 7), rand(7, 5)),
op=np.dot,
correct2 = (rand(5, 7), rand(7, 9)),
expected=lambda x, y: numpy.dot(x, y),
correct3 = (rand(5, 7), rand(7))),
checks={},
bad_build = dict(),
good=dict(
bad_runtime = dict(bad1 = (rand(5, 7), rand(5, 7)),
correct1=(rng.rand(5, 7), rng.rand(7, 5)),
bad2 = (rand(5, 7), rand(8,3))),
correct2=(rng.rand(5, 7), rng.rand(7, 9)),
grad = dict())
correct3=(rng.rand(5, 7), rng.rand(7)),
),
bad_build=dict(),
bad_runtime=dict(
bad1=(rng.rand(5, 7), rng.rand(5, 7)), bad2=(rng.rand(5, 7), rng.rand(8, 3))
),
grad=dict(),
)
In the above example, we provide a name and a reference to the :class:`Op` we
In the above example, we provide a name and a reference to the :class:`Op` we
want to test. We then provide in the ``expected`` field, a function
want to test. We then provide in the ``expected`` field, a function
...
...
tests/tensor/test_blas.py
浏览文件 @
c8de0d44
...
@@ -3,19 +3,6 @@ from itertools import product
...
@@ -3,19 +3,6 @@ from itertools import product
import
numpy
as
np
import
numpy
as
np
import
pytest
import
pytest
from
numpy
import
(
arange
,
array
,
common_type
,
complex64
,
complex128
,
float32
,
float64
,
newaxis
,
shape
,
transpose
,
zeros
,
)
from
numpy.testing
import
assert_array_almost_equal
from
numpy.testing
import
assert_array_almost_equal
import
aesara
import
aesara
...
@@ -1505,11 +1492,11 @@ class TestGemv(unittest_tools.OptimizationTestMixin):
...
@@ -1505,11 +1492,11 @@ class TestGemv(unittest_tools.OptimizationTestMixin):
def
matrixmultiply
(
a
,
b
):
def
matrixmultiply
(
a
,
b
):
if
len
(
b
.
shape
)
==
1
:
if
len
(
b
.
shape
)
==
1
:
b_is_vector
=
True
b_is_vector
=
True
b
=
b
[:,
newaxis
]
b
=
b
[:,
n
p
.
n
ewaxis
]
else
:
else
:
b_is_vector
=
False
b_is_vector
=
False
assert
a
.
shape
[
1
]
==
b
.
shape
[
0
]
assert
a
.
shape
[
1
]
==
b
.
shape
[
0
]
c
=
zeros
((
a
.
shape
[
0
],
b
.
shape
[
1
]),
common_type
(
a
,
b
))
c
=
np
.
zeros
((
a
.
shape
[
0
],
b
.
shape
[
1
]),
np
.
common_type
(
a
,
b
))
for
i
in
range
(
a
.
shape
[
0
]):
for
i
in
range
(
a
.
shape
[
0
]):
for
j
in
range
(
b
.
shape
[
1
]):
for
j
in
range
(
b
.
shape
[
1
]):
s
=
0
s
=
0
...
@@ -1527,14 +1514,14 @@ class BaseGemv:
...
@@ -1527,14 +1514,14 @@ class BaseGemv:
def
get_data
(
self
,
x_stride
=
1
,
y_stride
=
1
):
def
get_data
(
self
,
x_stride
=
1
,
y_stride
=
1
):
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
unittest_tools
.
fetch_seed
())
mult
=
array
(
1
,
dtype
=
self
.
dtype
)
mult
=
np
.
array
(
1
,
dtype
=
self
.
dtype
)
if
self
.
dtype
in
[
complex64
,
complex128
]:
if
self
.
dtype
in
[
np
.
complex64
,
np
.
complex128
]:
mult
=
array
(
1
+
1
j
,
dtype
=
self
.
dtype
)
mult
=
np
.
array
(
1
+
1
j
,
dtype
=
self
.
dtype
)
alpha
=
array
(
1.0
,
dtype
=
self
.
dtype
)
*
mult
alpha
=
np
.
array
(
1.0
,
dtype
=
self
.
dtype
)
*
mult
beta
=
array
(
1.0
,
dtype
=
self
.
dtype
)
*
mult
beta
=
np
.
array
(
1.0
,
dtype
=
self
.
dtype
)
*
mult
a
=
rng
.
standard_normal
((
3
,
3
))
.
astype
(
self
.
dtype
)
*
mult
a
=
rng
.
standard_normal
((
3
,
3
))
.
astype
(
self
.
dtype
)
*
mult
x
=
arange
(
shape
(
a
)[
0
]
*
x_stride
,
dtype
=
self
.
dtype
)
*
mult
x
=
np
.
arange
(
np
.
shape
(
a
)[
0
]
*
x_stride
,
dtype
=
self
.
dtype
)
*
mult
y
=
arange
(
shape
(
a
)[
1
]
*
y_stride
,
dtype
=
self
.
dtype
)
*
mult
y
=
np
.
arange
(
np
.
shape
(
a
)[
1
]
*
y_stride
,
dtype
=
self
.
dtype
)
*
mult
return
alpha
,
beta
,
a
,
x
,
y
return
alpha
,
beta
,
a
,
x
,
y
def
test_simple
(
self
):
def
test_simple
(
self
):
...
@@ -1578,7 +1565,7 @@ class BaseGemv:
...
@@ -1578,7 +1565,7 @@ class BaseGemv:
alpha_v
,
beta_v
,
a_v
,
x_v
,
y_v
=
vs
alpha_v
,
beta_v
,
a_v
,
x_v
,
y_v
=
vs
alpha
,
beta
,
a
,
x
,
y
=
[
shared
(
v
)
for
v
in
vs
]
alpha
,
beta
,
a
,
x
,
y
=
[
shared
(
v
)
for
v
in
vs
]
desired_oy
=
alpha_v
*
matrixmultiply
(
transpose
(
a_v
),
x_v
)
+
beta_v
*
y_v
desired_oy
=
alpha_v
*
matrixmultiply
(
np
.
transpose
(
a_v
),
x_v
)
+
beta_v
*
y_v
oy
=
alpha
*
dot
(
a
.
T
,
x
)
+
beta
*
y
oy
=
alpha
*
dot
(
a
.
T
,
x
)
+
beta
*
y
...
@@ -1610,7 +1597,9 @@ class BaseGemv:
...
@@ -1610,7 +1597,9 @@ class BaseGemv:
alpha_v
,
beta_v
,
a_v
,
x_v
,
y_v
=
vs
alpha_v
,
beta_v
,
a_v
,
x_v
,
y_v
=
vs
alpha
,
beta
,
a
,
x
,
y
=
[
shared
(
v
)
for
v
in
vs
]
alpha
,
beta
,
a
,
x
,
y
=
[
shared
(
v
)
for
v
in
vs
]
desired_oy
=
alpha_v
*
matrixmultiply
(
transpose
(
a_v
),
x_v
[::
2
])
+
beta_v
*
y_v
desired_oy
=
(
alpha_v
*
matrixmultiply
(
np
.
transpose
(
a_v
),
x_v
[::
2
])
+
beta_v
*
y_v
)
oy
=
alpha
*
dot
(
a
.
T
,
x
[::
2
])
+
beta
*
y
oy
=
alpha
*
dot
(
a
.
T
,
x
[::
2
])
+
beta
*
y
...
@@ -1642,7 +1631,9 @@ class BaseGemv:
...
@@ -1642,7 +1631,9 @@ class BaseGemv:
alpha_v
,
beta_v
,
a_v
,
x_v
,
y_v
=
vs
alpha_v
,
beta_v
,
a_v
,
x_v
,
y_v
=
vs
alpha
,
beta
,
a
,
x
,
y
=
[
shared
(
v
)
for
v
in
vs
]
alpha
,
beta
,
a
,
x
,
y
=
[
shared
(
v
)
for
v
in
vs
]
desired_oy
=
alpha_v
*
matrixmultiply
(
transpose
(
a_v
),
x_v
)
+
beta_v
*
y_v
[::
2
]
desired_oy
=
(
alpha_v
*
matrixmultiply
(
np
.
transpose
(
a_v
),
x_v
)
+
beta_v
*
y_v
[::
2
]
)
oy
=
alpha
*
dot
(
a
.
T
,
x
)
+
beta
*
y
[::
2
]
oy
=
alpha
*
dot
(
a
.
T
,
x
)
+
beta
*
y
[::
2
]
...
@@ -1682,7 +1673,7 @@ class BaseGemv:
...
@@ -1682,7 +1673,7 @@ class BaseGemv:
a
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)[::
-
1
,
::
-
1
],
borrow
=
True
a
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)[::
-
1
,
::
-
1
],
borrow
=
True
)
)
desired_oy
=
alpha_v
*
matrixmultiply
(
transpose
(
a_v
),
x_v
)
+
beta_v
*
y_v
desired_oy
=
alpha_v
*
matrixmultiply
(
np
.
transpose
(
a_v
),
x_v
)
+
beta_v
*
y_v
oy
=
alpha
*
dot
(
a
.
T
,
x
)
+
beta
*
y
oy
=
alpha
*
dot
(
a
.
T
,
x
)
+
beta
*
y
...
@@ -1728,13 +1719,13 @@ class BaseGemv:
...
@@ -1728,13 +1719,13 @@ class BaseGemv:
class
TestSgemv
(
BaseGemv
,
unittest_tools
.
OptimizationTestMixin
):
class
TestSgemv
(
BaseGemv
,
unittest_tools
.
OptimizationTestMixin
):
dtype
=
float32
dtype
=
np
.
float32
gemv
=
gemv_no_inplace
gemv
=
gemv_no_inplace
gemv_inplace
=
gemv_inplace
gemv_inplace
=
gemv_inplace
class
TestDgemv
(
BaseGemv
,
unittest_tools
.
OptimizationTestMixin
):
class
TestDgemv
(
BaseGemv
,
unittest_tools
.
OptimizationTestMixin
):
dtype
=
float64
dtype
=
np
.
float64
gemv
=
gemv_no_inplace
gemv
=
gemv_no_inplace
gemv_inplace
=
gemv_inplace
gemv_inplace
=
gemv_inplace
...
@@ -2269,25 +2260,25 @@ class TestBlasStrides:
...
@@ -2269,25 +2260,25 @@ class TestBlasStrides:
assert
np
.
allclose
(
a
.
get_value
(),
a_n
)
assert
np
.
allclose
(
a
.
get_value
(),
a_n
)
a_t
.
set_value
(
a_t
.
set_value
(
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
np
.
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
)
)
f_tnn
()
f_tnn
()
assert
np
.
allclose
(
a_t
.
get_value
(),
at_n
)
assert
np
.
allclose
(
a_t
.
get_value
(),
at_n
)
a_t
.
set_value
(
a_t
.
set_value
(
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
np
.
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
)
)
f_tnt
()
f_tnt
()
assert
np
.
allclose
(
a_t
.
get_value
(),
at_n
)
assert
np
.
allclose
(
a_t
.
get_value
(),
at_n
)
a_t
.
set_value
(
a_t
.
set_value
(
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
np
.
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
)
)
f_ttn
()
f_ttn
()
assert
np
.
allclose
(
a_t
.
get_value
(),
at_n
)
assert
np
.
allclose
(
a_t
.
get_value
(),
at_n
)
a_t
.
set_value
(
a_t
.
set_value
(
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
np
.
transpose
(
a_dev
.
copy
())[::
a_step2
,
::
a_step1
],
borrow
=
True
)
)
f_ttt
()
f_ttt
()
assert
np
.
allclose
(
a_t
.
get_value
(),
at_n
)
assert
np
.
allclose
(
a_t
.
get_value
(),
at_n
)
...
@@ -2335,7 +2326,7 @@ class TestBlasStrides:
...
@@ -2335,7 +2326,7 @@ class TestBlasStrides:
a
.
set_value
(
a_dev
.
copy
()[::
a_step
],
borrow
=
True
)
a
.
set_value
(
a_dev
.
copy
()[::
a_step
],
borrow
=
True
)
b
.
set_value
(
b_dev
.
copy
()[::
b_step1
,
::
b_step2
],
borrow
=
True
)
b
.
set_value
(
b_dev
.
copy
()[::
b_step1
,
::
b_step2
],
borrow
=
True
)
b_t
.
set_value
(
b_t
.
set_value
(
transpose
(
b_dev
.
copy
())[::
b_step2
,
::
b_step1
],
borrow
=
True
np
.
transpose
(
b_dev
.
copy
())[::
b_step2
,
::
b_step1
],
borrow
=
True
)
)
c
.
set_value
(
c_dev
.
copy
()[::
c_step
],
borrow
=
True
)
c
.
set_value
(
c_dev
.
copy
()[::
c_step
],
borrow
=
True
)
...
@@ -2386,7 +2377,7 @@ class TestBlasStrides:
...
@@ -2386,7 +2377,7 @@ class TestBlasStrides:
a
.
set_value
(
a_dev
.
copy
()[::
a_step1
,
::
a_step2
],
borrow
=
True
)
a
.
set_value
(
a_dev
.
copy
()[::
a_step1
,
::
a_step2
],
borrow
=
True
)
a_t
.
set_value
(
a_t
.
set_value
(
transpose
(
a_dev
.
copy
())[::
a_step1
,
::
a_step2
],
borrow
=
True
np
.
transpose
(
a_dev
.
copy
())[::
a_step1
,
::
a_step2
],
borrow
=
True
)
)
b
.
set_value
(
b_dev
.
copy
()[::
b_step
],
borrow
=
True
)
b
.
set_value
(
b_dev
.
copy
()[::
b_step
],
borrow
=
True
)
c
.
set_value
(
c_dev
.
copy
()[::
c_step
],
borrow
=
True
)
c
.
set_value
(
c_dev
.
copy
()[::
c_step
],
borrow
=
True
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论