Skip to content
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

Merged
merged 4 commits into from Aug 1, 2018

Conversation

mark-poscablo
Copy link
Contributor

@mark-poscablo mark-poscablo commented Jul 20, 2018

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:

  • compare types (done)
  • compare dimension sizes (done)
  • compare elements for equality (done, but float types are compared using simple equality for now)
  • display the difference in any of the above (done)
  • for comparing elements, display an n-dimensional window around the mismatched elements
  • for floating-point types, use a threshold of machine error to the equality operator or let the test-writer to define that threshold
  • for 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 use ASSERT_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.

@mark-poscablo
Copy link
Contributor Author

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
Copy link
Member

@umar456 umar456 left a 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);
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

return os << name;
}

af::dim4 unravelIdx(uint idx, af::dim4 dims, af::dim4 strides) {
Copy link
Member

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
@umar456 umar456 changed the title Add test utility functions for simplifying comparison of reference and output af::arrays Add test utility functions to compare af::arrays Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants