New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test utility functions to compare af::arrays #2249
Conversation
8095946
to
0eca39e
Compare
Now that the basic functionalities of the new test utilities are working, I'm going to try using them in several existing tests we have so far |
- Create the ASSERT_ARRAY_EQ macro to compare two af::array or af_array - Tests types, dims, and values. - Prints the index of the values that are different. - Prints a more readable error message
- Added type comparison in array-vector assert compare. - Changed array and vector names for more clarity. - Changed C API assert to not free C af_array after assert
ca4b014
to
a392e8e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome. This will really improve our testing and make it easy to do. I have made a couple of comments that need to be updated. We are almost ready.
test/basic.cpp
Outdated
} | ||
|
||
TEST(Assert, TestEqualsDiffValue) { | ||
// array A = af::randu(3, 3, 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comment
test/basic.cpp
Outdated
} | ||
|
||
TEST(Assert, TestEqualsDiffComplexValue) { | ||
// array A = af::randu(3, 3, 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment
test/basic.cpp
Outdated
} | ||
|
||
TEST(Assert, TestVectorDiffVecSize) { | ||
// array A = af::randu(3, 3, 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment
test/basic.cpp
Outdated
} | ||
|
||
TEST(Assert, TestVectorDiffDim4) { | ||
// array A = af::randu(3, 3, 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment
test/testHelpers.hpp
Outdated
return os << name; | ||
} | ||
|
||
af::dim4 unravelIdx(uint idx, af::dim4 dims, af::dim4 strides) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment here explaining the function would be nice.
- Changed ASSERT_EQ(AF_SUCCESS, ...) to ASSERT_SUCCESS(...) - Changed ASSERT_TRUE(allTrue<bool>...) to ASSERT_ARRAY_EQ() in tests
ec22fe7
to
3a34907
Compare
A lot of tests have common code for gtest asserts. One of those common code is comparing two arrays for equality. The usual method is to get the raw data from the backend to the host and then iterate over the two host arrays for element-wise comparison. A new utility function would simplify that so that we could just pass in the af::arrays directly. It will:
for comparing elements, display an n-dimensional window around the mismatched elementsfor floating-point types, use a threshold of machine error to the equality operator or let the test-writer to define that thresholdfor images, provide an option to save/display the difference between the reference and output images(Strikethroughed items will be done in a separate PR)
Another utility function would be to simplify the assert for error code-returning C arrayfire calls. Instead of displaying the error code in its raw numeric form, the utility function would display the enum name for that error code, thereby making the error message more human-readable. (done)
p.s. I modified
test/basic.cpp
for now to try out how the error messages come out.The tests will failThe tests should pass in the CI since we useASSERT_FALSE()
on the utility function within the test cases, but when one uses the actual new macro, it should fail and give back an easy-to-read error message.