Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
8565e504
A
avocado
项目概览
openeuler
/
avocado
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
avocado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8565e504
编写于
5月 25, 2016
作者:
H
Harish
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adding compare_matrices utility
上级
fc2f163c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
80 addition
and
0 deletion
+80
-0
avocado/utils/data_structures.py
avocado/utils/data_structures.py
+68
-0
selftests/unit/test_data_structures.py
selftests/unit/test_data_structures.py
+12
-0
未找到文件。
avocado/utils/data_structures.py
浏览文件 @
8565e504
...
...
@@ -23,6 +23,7 @@ avocado core code or plugins.
import
sys
import
math
from
itertools
import
izip
def
ordered_list_unique
(
object_list
):
...
...
@@ -52,6 +53,73 @@ def geometric_mean(values):
return
math
.
exp
(
sum
([
math
.
log
(
number
)
for
number
in
values
])
/
no_values
)
def
compare_matrices
(
matrix1
,
matrix2
,
threshold
=
0.05
):
"""
Compare 2 matrices nxm and return a matrix nxm with comparison data and
stats. When the first columns match, they are considered as header and
included in the results intact.
:param matrix1: Reference Matrix of floats; first column could be header.
:param matrix2: Matrix that will be compared; first column could be header
:param threshold: Any difference greater than this percent threshold will
be reported.
:retrun: Matrix with the difference in comparison, number of improvements,
number of regressions, total number of comparisons.
"""
improvements
=
0
regressions
=
0
same
=
0
new_matrix
=
[]
for
line1
,
line2
in
zip
(
matrix1
,
matrix2
):
new_line
=
[]
elements
=
izip
(
line1
,
line2
)
try
:
element1
,
element2
=
elements
.
next
()
except
StopIteration
:
# no data in this row
new_matrix
.
append
(
new_line
)
continue
if
element1
==
element2
:
# this column contains header
new_line
.
append
(
element1
)
try
:
element1
,
element2
=
elements
.
next
()
except
StopIteration
:
new_matrix
.
append
(
new_line
)
continue
while
True
:
try
:
ratio
=
float
(
element2
)
/
float
(
element1
)
except
ZeroDivisionError
:
# For 0s, allow exact match or error
if
float
(
element2
)
==
0
:
new_line
.
append
(
"."
)
same
+=
1
else
:
new_line
.
append
(
"Error %s/%s"
%
(
element2
,
element1
))
improvements
+=
1
try
:
element1
,
element2
=
elements
.
next
()
except
StopIteration
:
break
continue
if
ratio
<
(
1
-
threshold
):
# handling regression
regressions
+=
1
new_line
.
append
(
100
*
ratio
-
100
)
elif
ratio
>
(
1
+
threshold
):
# handling improvements
improvements
+=
1
new_line
.
append
(
"+"
+
str
(
100
*
ratio
-
100
))
else
:
same
+=
1
new_line
.
append
(
"."
)
try
:
element1
,
element2
=
elements
.
next
()
except
StopIteration
:
break
new_matrix
.
append
(
new_line
)
total
=
improvements
+
regressions
+
same
return
(
new_matrix
,
improvements
,
regressions
,
total
)
class
Borg
:
"""
...
...
selftests/unit/test_data_structures.py
浏览文件 @
8565e504
...
...
@@ -29,6 +29,18 @@ class TestDataStructures(unittest.TestCase):
self
.
assertEqual
(
data_structures
.
geometric_mean
(
xrange
(
1
,
180
)),
67.1555819421869
)
def
test_compare_matrices
(
self
):
"""
Verify the correct value is produced when comparing matrices.
"""
# Note that first row contains header in first column, while the
# second contains only values (for testing purposes)
matrix1
=
[[
"header"
,
51.7
,
60
],
[
1
,
0
,
0
]]
matrix2
=
[[
"header"
,
57.2
,
54
],
[
2
,
51
,
0
]]
self
.
assertEqual
(
data_structures
.
compare_matrices
(
matrix1
,
matrix2
),
([[
"header"
,
'+10.6382978723'
,
-
10.0
],
[
'+100.0'
,
'Error 51/0'
,
'.'
]],
3
,
1
,
5
))
def
test_lazy_property
(
self
):
"""
Verify the value is initialized lazily with the correct value
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录