Skip to content

Commit

Permalink
address issue with vector equivalent utility (#777)
Browse files Browse the repository at this point in the history
Closes #772 , Address various issue with vector equivalent utility.

Authors:
  - Michael Wang (https://github.com/isVoid)

Approvers:
  - Mark Harris (https://github.com/harrism)

URL: #777
  • Loading branch information
isVoid authored Nov 8, 2022
1 parent 870f103 commit 48fbedf
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <limits>
#include <type_traits>

namespace cuspatial {
Expand Down Expand Up @@ -57,7 +58,7 @@ auto floating_eq_by_abs_error(T val, T abs_error)
if constexpr (std::is_same_v<T, float>) {
return ::testing::FloatNear(val, abs_error);
} else {
return ::testing::FloatNear(val, abs_error);
return ::testing::DoubleNear(val, abs_error);
}
}

Expand Down Expand Up @@ -99,7 +100,8 @@ MATCHER(float_matcher, std::string(negation ? "are not" : "are") + " approximate

if (::testing::Matches(floating_eq_by_ulp(rhs))(lhs)) return true;

*result_listener << std::setprecision(18) << lhs << " != " << rhs;
*result_listener << std::setprecision(std::numeric_limits<decltype(lhs)>::max_digits10) << lhs
<< " != " << rhs;

return false;
}
Expand All @@ -113,7 +115,8 @@ MATCHER_P(float_near_matcher,

if (::testing::Matches(floating_eq_by_abs_error(rhs, abs_error))(lhs)) return true;

*result_listener << std::setprecision(18) << lhs << " != " << rhs;
*result_listener << std::setprecision(std::numeric_limits<decltype(lhs)>::max_digits10) << lhs
<< " != " << rhs;

return false;
}
Expand Down Expand Up @@ -169,10 +172,10 @@ inline void expect_vector_equivalent(Vector1 const& lhs, Vector2 const& rhs, T a
}
}

#define CUSPATIAL_EXPECT_VECTORS_EQUIVALENT(lhs, rhs, ...) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
expect_vector_equivalent(lhs, rhs, ##__VA_ARGS__); \
#define CUSPATIAL_EXPECT_VECTORS_EQUIVALENT(lhs, rhs, ...) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cuspatial::test::expect_vector_equivalent(lhs, rhs, ##__VA_ARGS__); \
} while (0)

} // namespace test
Expand Down
2 changes: 1 addition & 1 deletion cpp/tests/experimental/indexing/point_quadtree_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#include "tests/utility/vector_equality.hpp"
#include <cuspatial_test/vector_equality.hpp>

#include <cuspatial/experimental/point_quadtree.cuh>
#include <cuspatial/vec_2d.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

#include "tests/utility/vector_equality.hpp"
#include <cuspatial/constants.hpp>
#include <cuspatial/error.hpp>
#include <cuspatial/experimental/coordinate_transform.cuh>
#include <cuspatial_test/vector_equality.hpp>

#include <rmm/device_vector.hpp>

Expand Down
2 changes: 1 addition & 1 deletion cpp/tests/experimental/spatial/hausdorff_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#include "tests/utility/vector_equality.hpp"
#include <cuspatial_test/vector_equality.hpp>

#include <cuspatial/error.hpp>
#include <cuspatial/experimental/hausdorff.cuh>
Expand Down
2 changes: 1 addition & 1 deletion cpp/tests/experimental/spatial/haversine_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#include <tests/utility/vector_equality.hpp>
#include <cuspatial_test/vector_equality.hpp>

#include <cuspatial/error.hpp>
#include <cuspatial/experimental/haversine.cuh>
Expand Down
10 changes: 3 additions & 7 deletions cpp/tests/experimental/spatial/linestring_distance_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* limitations under the License.
*/

#include <tests/utility/vector_equality.hpp>

#include <cuspatial_test/vector_equality.hpp>
#include <cuspatial_test/vector_factories.cuh>

#include <cuspatial/error.hpp>
Expand All @@ -26,8 +25,8 @@
#include <thrust/iterator/constant_iterator.h>
#include <thrust/iterator/counting_iterator.h>

namespace cuspatial {
namespace test {
using namespace cuspatial;
using namespace cuspatial::test;

template <typename T>
struct PairwiseLinestringDistanceTest : public ::testing::Test {
Expand Down Expand Up @@ -949,6 +948,3 @@ TYPED_TEST(PairwiseLinestringDistanceTest, FourPairsSingleLineString)
CUSPATIAL_EXPECT_VECTORS_EQUIVALENT(expected, got);
EXPECT_EQ(num_pairs, std::distance(got.begin(), ret));
}

} // namespace test
} // namespace cuspatial
2 changes: 1 addition & 1 deletion cpp/tests/experimental/spatial/point_distance_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#include "../../utility/vector_equality.hpp"
#include <cuspatial_test/vector_equality.hpp>

#include <cuspatial_test/random.cuh>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#include "tests/utility/vector_equality.hpp"
#include <cuspatial_test/vector_equality.hpp>

#include <cuspatial/detail/iterator.hpp>
#include <cuspatial/error.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* limitations under the License.
*/

#include "../../utility/vector_equality.hpp"
#include "cuspatial/experimental/point_distance.cuh"
#include <cuspatial_test/vector_equality.hpp>

#include <cuspatial/detail/iterator.hpp>
#include <cuspatial/error.hpp>
Expand All @@ -32,8 +31,8 @@

#include <type_traits>

namespace cuspatial {
namespace test {
using namespace cuspatial;
using namespace cuspatial::test;

template <typename T>
struct PairwisePointLinestringNearestPointsTest : public ::testing::Test {
Expand Down Expand Up @@ -421,6 +420,3 @@ TYPED_TEST(PairwisePointLinestringNearestPointsTest, ThreePairMultiComponent)
CartVec{{3.545131432802666, 2.30503517215846}, {9.9, 9.4}, {0.0, -8.7}});
EXPECT_EQ(std::distance(output_it, ret), num_pairs);
}

} // namespace test
} // namespace cuspatial
2 changes: 1 addition & 1 deletion cpp/tests/experimental/spatial/points_in_range_test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#include "tests/utility/vector_equality.hpp"
#include <cuspatial_test/vector_equality.hpp>

#include <cuspatial/error.hpp>
#include <cuspatial/experimental/points_in_range.cuh>
Expand Down
12 changes: 4 additions & 8 deletions cpp/tests/spatial/linestring_distance_test_medium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
#include <cudf_test/column_wrapper.hpp>
#include <cudf_test/type_lists.hpp>

namespace cuspatial {
namespace test {
using namespace cuspatial;

using namespace cudf;
using namespace cudf::test;
Expand All @@ -32,16 +31,16 @@ template <typename T>
using wrapper = fixed_width_column_wrapper<T>;

template <typename T>
struct PairwiseLinestringDistanceTest : public BaseFixture {
struct PairwiseLinestringDistanceTestMedium : public BaseFixture {
};

// float and double are logically the same but would require separate tests due to precision.
using TestTypes = FloatingPointTypes;
TYPED_TEST_CASE(PairwiseLinestringDistanceTest, TestTypes);
TYPED_TEST_CASE(PairwiseLinestringDistanceTestMedium, TestTypes);

constexpr cudf::test::debug_output_level verbosity{cudf::test::debug_output_level::ALL_ERRORS};

TYPED_TEST(PairwiseLinestringDistanceTest, RandomDataset100)
TYPED_TEST(PairwiseLinestringDistanceTestMedium, RandomDataset100)
{
using T = TypeParam;
wrapper<cudf::size_type> linestring1_offsets{
Expand Down Expand Up @@ -1051,6 +1050,3 @@ TYPED_TEST(PairwiseLinestringDistanceTest, RandomDataset100)
linestring2_points_y);
expect_columns_equivalent(expected, *got, verbosity);
}

} // namespace test
} // namespace cuspatial

0 comments on commit 48fbedf

Please sign in to comment.