[Libva] [PATCH v2] test: use valarray for raw image comparison
Xiang, Haihao
haihao.xiang at intel.com
Wed Oct 19 13:34:31 UTC 2016
It works well for me, applied.
Thanks
Haihao
>-----Original Message-----
>From: Libva [mailto:libva-bounces at lists.freedesktop.org] On Behalf Of Eoff,
>Ullysses A
>Sent: Wednesday, October 19, 2016 2:38 AM
>To: Phillips, Scott D <scott.d.phillips at intel.com>; libva at lists.freedesktop.org
>Subject: Re: [Libva] [PATCH v2] test: use valarray for raw image comparison
>
>Ah, I overlooked the data types on my first review. Indeed it's important to
>take it into account when diff'ing. This is why they were being cast to "int"
>previously to calculate the diff.
>
>On my system /dev/urandom seems to work (i.e. not all zeros). But I agree,
>let's drop it since it does not seem to be very uniform.
>
>This version looks much better to me.
>
>Thanks,
>
>U. Artie
>
>> -----Original Message-----
>> From: Libva [mailto:libva-bounces at lists.freedesktop.org] On Behalf Of
>> Scott D Phillips
>> Sent: Monday, October 17, 2016 1:01 PM
>> To: libva at lists.freedesktop.org
>> Subject: [Libva] [PATCH v2] test: use valarray for raw image
>> comparison
>>
>> std::valarray can fuse elementwise operations across arrays for more
>> efficient comparison.
>>
>> Signed-off-by: Scott D Phillips <scott.d.phillips at intel.com>
>> ---
>> Changes since v1:
>> - s/width * height/sizes/
>> - Added another array 'signs' which ensures that 0 and 255 never
>> compare as separated by one.
>>
>> Also, the patch about /dev/urandom actually was accidentally
>> generating all zeroes instead of random data. Fixing the bug there
>> eliminated the performance gain, so I'm dropping that patch from the
>> series.
>>
>> test/i965_jpeg_encode_test.cpp | 29 +++++++++++++----------------
>> 1 file changed, 13 insertions(+), 16 deletions(-)
>>
>> diff --git a/test/i965_jpeg_encode_test.cpp
>> b/test/i965_jpeg_encode_test.cpp index 29c14dc..173cd93 100644
>> --- a/test/i965_jpeg_encode_test.cpp
>> +++ b/test/i965_jpeg_encode_test.cpp
>> @@ -30,6 +30,7 @@
>> #include <cstring>
>> #include <memory>
>> #include <tuple>
>> +#include <valarray>
>>
>> namespace JPEG {
>> namespace Encode {
>> @@ -400,23 +401,19 @@ protected:
>> ASSERT_EQ(expect->height(), image.height);
>> ASSERT_NO_FAILURE(uint8_t *data =
>> mapBuffer<uint8_t>(image.buf));
>>
>> - auto isClose = [](const uint8_t& a, const uint8_t& b) {
>> - return std::abs(int(a)-int(b)) <= 2;
>> - };
>> -
>> for (size_t i(0); i < image.num_planes; ++i) {
>> - size_t w = expect->widths[i];
>> - size_t h = expect->heights[i];
>> -
>> - const ByteData::value_type *source = expect->plane(i);
>> - const uint8_t *result = data + image.offsets[i];
>> - ASSERT_GE(image.pitches[i], w);
>> - for (size_t r(0); r < h; ++r) {
>> - EXPECT_TRUE(std::equal(result, result + w, source, isClose))
>> - << "Byte(s) mismatch in plane " << i << " row " << r;
>> - source += w;
>> - result += image.pitches[i];
>> - }
>> + ASSERT_GE(image.pitches[i], expect->widths[i]);
>> + std::valarray<uint8_t> source(expect->plane(i), expect->sizes[i]);
>> + std::gslice result_slice(0, {expect->heights[i], expect->widths[i]},
>> + {image.pitches[i], 1});
>> + std::valarray<uint8_t> result = std::valarray<uint8_t>(
>> + data + image.offsets[i],
>> + image.pitches[i] * expect->heights[i])[result_slice];
>> + std::valarray<uint8_t> signs(1, result.size());
>> + signs[result > source] = -1;
>> + ASSERT_EQ(source.size(), result.size());
>> + EXPECT_TRUE((source * signs - result * signs).max() <= 2)
>> + << "Byte(s) mismatch in plane " << i;
>> }
>>
>> unmapBuffer(image.buf);
>> --
>> 2.7.4
>>
>> _______________________________________________
>> Libva mailing list
>> Libva at lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/libva
>_______________________________________________
>Libva mailing list
>Libva at lists.freedesktop.org
>https://lists.freedesktop.org/mailman/listinfo/libva
More information about the Libva
mailing list