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

[REVIEW] Adding floating point specialization to comparators for NaNs #3239

Conversation

rgsl888prabhu
Copy link
Contributor

Added floating point specialization to comparators for NaNs and test cases to evaluate.

close #3226

@rgsl888prabhu rgsl888prabhu requested review from a team as code owners October 29, 2019 20:35
@rgsl888prabhu rgsl888prabhu self-assigned this Oct 29, 2019
@rgsl888prabhu rgsl888prabhu changed the title [WIP] Adding floating point specialization to comparators for NaNs [REVIEW] Adding floating point specialization to comparators for NaNs Oct 29, 2019
@rgsl888prabhu rgsl888prabhu added 3 - Ready for Review Ready for review by team libcudf++ labels Oct 29, 2019
@codecov
Copy link

codecov bot commented Oct 29, 2019

Codecov Report

Merging #3239 into branch-0.11 will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##           branch-0.11    #3239   +/-   ##
============================================
  Coverage        87.13%   87.13%           
============================================
  Files               49       49           
  Lines             9269     9269           
============================================
  Hits              8077     8077           
  Misses            1192     1192

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6bca9f6...ef59466. Read the comment docs.

Copy link
Member

@harrism harrism left a comment

Choose a reason for hiding this comment

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

I have some concerns about the semantics and the overheads.

cpp/include/cudf/table/row_operators.cuh Outdated Show resolved Hide resolved
cpp/include/cudf/table/row_operators.cuh Outdated Show resolved Hide resolved
cpp/include/cudf/table/row_operators.cuh Outdated Show resolved Hide resolved
cpp/include/cudf/table/row_operators.cuh Outdated Show resolved Hide resolved
cpp/include/cudf/table/row_operators.cuh Outdated Show resolved Hide resolved
cpp/include/cudf/table/row_operators.cuh Outdated Show resolved Hide resolved
cpp/include/cudf/table/row_operators.cuh Outdated Show resolved Hide resolved
cpp/include/cudf/table/row_operators.cuh Outdated Show resolved Hide resolved
cpp/include/cudf/table/row_operators.cuh Outdated Show resolved Hide resolved
@jrhemstad
Copy link
Contributor

@rgsl888prabhu a pattern like this is more along the lines of what I was envisioning:
https://wandbox.org/permlink/BEXfhMZWdwDKBprS

template <typename Element, std::enable_if_t<cudf::is_relationally_comparable<
                                  Element, Element>()>* = nullptr>
  __device__ weak_ordering operator()(size_type lhs_element_index,
                                      size_type rhs_element_index) const
      noexcept {
    if (has_nulls) {
      bool const lhs_is_null{lhs.nullable() and lhs.is_null(lhs_element_index)};
      bool const rhs_is_null{rhs.nullable() and rhs.is_null(rhs_element_index)};

      if (lhs_is_null and rhs_is_null) {  // null <? null
        return weak_ordering::EQUIVALENT;
      } else if (lhs_is_null) {  // null <? x
        return (null_precedence == null_order::BEFORE) ? weak_ordering::LESS
                                                       : weak_ordering::GREATER;
      } else if (rhs_is_null) {  // x <? null
        return (null_precedence == null_order::AFTER) ? weak_ordering::LESS
                                                      : weak_ordering::GREATER;
      }
    }

    Element const lhs_element = lhs.element<Element>(lhs_element_index);
    Element const rhs_element = rhs.element<Element>(rhs_element_index);

    return compare(lhs_element, rhs_element);
  }

This should vastly simplify the implementation you have here.

@rgsl888prabhu
Copy link
Contributor Author

@rgsl888prabhu a pattern like this is more along the lines of what I was envisioning:
https://wandbox.org/permlink/BEXfhMZWdwDKBprS

template <typename Element, std::enable_if_t<cudf::is_relationally_comparable<
                                  Element, Element>()>* = nullptr>
  __device__ weak_ordering operator()(size_type lhs_element_index,
                                      size_type rhs_element_index) const
      noexcept {
    if (has_nulls) {
      bool const lhs_is_null{lhs.nullable() and lhs.is_null(lhs_element_index)};
      bool const rhs_is_null{rhs.nullable() and rhs.is_null(rhs_element_index)};

      if (lhs_is_null and rhs_is_null) {  // null <? null
        return weak_ordering::EQUIVALENT;
      } else if (lhs_is_null) {  // null <? x
        return (null_precedence == null_order::BEFORE) ? weak_ordering::LESS
                                                       : weak_ordering::GREATER;
      } else if (rhs_is_null) {  // x <? null
        return (null_precedence == null_order::AFTER) ? weak_ordering::LESS
                                                      : weak_ordering::GREATER;
      }
    }

    Element const lhs_element = lhs.element<Element>(lhs_element_index);
    Element const rhs_element = rhs.element<Element>(rhs_element_index);

    return compare(lhs_element, rhs_element);
  }

This should vastly simplify the implementation you have here.

@jrhemstad So, we will have two sets of functions one for floating point and other for non-floating type.

@jrhemstad
Copy link
Contributor

@jrhemstad So, we will have two sets of functions one for floating point and other for non-floating type.

Yes, but it's limited to the logic that needs to be specialized between floating/non-floating types.

cpp/include/cudf/table/row_operators.cuh Outdated Show resolved Hide resolved
cpp/include/cudf/table/row_operators.cuh Outdated Show resolved Hide resolved
cpp/include/cudf/table/row_operators.cuh Outdated Show resolved Hide resolved
Copy link
Contributor

@jrhemstad jrhemstad left a comment

Choose a reason for hiding this comment

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

One small change, otherwise looks great!

cpp/include/cudf/table/row_operators.cuh Outdated Show resolved Hide resolved
Copy link
Contributor

@jrhemstad jrhemstad left a comment

Choose a reason for hiding this comment

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

I think you just need to merge the latest branch-0.11 into your PR to get CI to pass.

@rgsl888prabhu
Copy link
Contributor Author

@harrism

@jrhemstad jrhemstad requested a review from harrism October 31, 2019 20:42
Copy link
Member

@harrism harrism left a comment

Choose a reason for hiding this comment

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

Very clean solution.

* @brief A specialization for floating-point `Element` type rerlational comparison
* to derive the order of the elements with respect to `lhs`. Specialization is to
* handle `nan` in the order shown below.
* `[-Inf, -ve, 0, -0, +ve, +Inf, NaN, NaN, null] (for null_order::AFTER)`
Copy link
Member

Choose a reason for hiding this comment

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

Why does NaN appear twice in these?

Copy link
Contributor

Choose a reason for hiding this comment

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

To show NaN == NaN

@jrhemstad jrhemstad merged commit 4ecaeae into rapidsai:branch-0.11 Nov 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for Review Ready for review by team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA] Add floating point specialization to comparators for NaNs
3 participants