-
Notifications
You must be signed in to change notification settings - Fork 39
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
Change Point, Box, Sphere CTAD #1145
Conversation
Will rebase on #1100 once merged. |
What is the rational behind promoting integral types to |
Also why should we enable mixing types rather than being strict? |
Originally I was thinking performance as operations with floats on GPUs are much faster than with doubles. However, you asking the questions makes me think. Not all integers are represented with floats. Even fewer long ints are represented with floats. So maybe that's why the standard library converts integers to doubles by default, as all 32-bit integers can be represented by doubles. At the same time, not all 64-bit integers are represented by doubles either. I guess we need to decide when this utility is useful, and what assumptions go into it.
Mostly so that |
b6f9897
to
d8f2d94
Compare
d8f2d94
to
9f8e2a6
Compare
Passed the tests. Warnings are unrelated. |
6fee055
to
07bcdb3
Compare
test/tstCompileOnlyGeometry.cpp
Outdated
@@ -228,19 +228,38 @@ void test_point_cv_compile_only() | |||
static_assert(GT::is_point_v<Point const>); | |||
} | |||
|
|||
void test_point_ctad() | |||
void test_geometry_ctad() |
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.
I'd slightly prefer having separate functions for the different types.
src/geometry/ArborX_Box.hpp
Outdated
KOKKOS_FUNCTION | ||
#endif | ||
Box(T const (&)[N], T const (&)[N]) | ||
-> Box<N, std::conditional_t<std::is_integral_v<T>, double, T>>; |
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.
-> Box<N, std::conditional_t<std::is_integral_v<T>, double, T>>; | |
-> Box<N, std::enable_if_t<std::is_integral_v<T>, double>>; |
Not tested but it feels like we would potentially enable deductions we did not mean to with your version
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.
I think you version would not deduce Box{{float}, {float}}
.
Not tested but it feels like we would potentially enable deductions we did not mean to with your version
Which ones?
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.
I thought we were only enabling CTAD for arithmetic types. Is that not what the intent was?
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.
I had a dual intent: enable conversion for arithmetic types, and allow CTAD for a single type.
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.
I have mixed feelings about the promotion of integral types if all other types are treated differently and we don't spell out any constraint.
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.
I think I understand your concern. However, I would not want Point(0, 0, 0)
to produce Point<3, int>
.
src/geometry/ArborX_Point.hpp
Outdated
#else | ||
KOKKOS_FUNCTION | ||
#endif | ||
Point(T, Ts...) -> Point< |
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.
Why do we have both T
and Ts
?
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.
So that we could check that all types are identical. It feels easier than trying to get the first type from a parameter pack.
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.
Why do we have both this guide and the array reference one?
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.
I thought users may benefit from that one too. I don't have a strong need for it at the moment.
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.
You mean not needing brace initialization?
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.
I think users may expect both Point(a, b, c)
and Point({a, b, c})
working.
Is there a good use cases for allowing |
The only current use case is in our tests, like |
I think enforcing the the type of the constructor parameters to match and use as |
src/geometry/ArborX_Point.hpp
Outdated
std::enable_if_t<std::is_floating_point_v<T> && | ||
(... && std::is_floating_point_v<Ts>)&&( | ||
... &&std::is_same_v<std::decay_t<T>, | ||
std::decay_t<Ts>>), | ||
T>>; |
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.
std::enable_if_t<std::is_floating_point_v<T> && | |
(... && std::is_floating_point_v<Ts>)&&( | |
... &&std::is_same_v<std::decay_t<T>, | |
std::decay_t<Ts>>), | |
T>>; | |
std::enable_if_t<std::conjunction_v<std::is_same<T, Ts>...>, T>>; |
seems to do the job just fine, see https://godbolt.org/z/hMM69qGPr. The error messages are better when the decution guide doesn't constraint to floating point types bu the class has a corresponding static_assert
.
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.
The error messages are better when the dedution guide doesn't constraint to floating point types but the class has a corresponding
static_assert
.
I don't think it's a good idea to put that static assert in the class. If a user really points to use Point<D,int>
, we should let them do that.
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.
Drop the decay and if Ts are the same as T and T is a floating point you don't need to check that Ts are floating points
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.
Done.
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.
I don't think it's a good idea to put that static assert in the class. If a user really points to use
Point<D,int>
, we should let them do that.
Why would we then restrict the deduction guide at all?
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.
Why would we then restrict the deduction guide at all?
I think that Point{0,0,0}
resulting in Point<3, int>
may not be what most user expect. I'd rather have them explicitly write Point<3, int>{0, 0, 0}
.
9eb9c88
to
ecb04b4
Compare
@dalg24 @masterleinad Any objections to merging this? |
I'm still not liking it too much that we restrict CTAD but not the class itself. Maybe, that really is a separate question but the error messages when trying CTAD with, say, |
fa86f97
to
2dadc8c
Compare
OK. I made CTAD as simple as possible. It does not do any checks on the types anymore. |
OK, this version should be good enough. If we change our minds, we'll change it before the release. |
Allow CTAD only for floating point types without any promotion.