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

Change Point, Box, Sphere CTAD #1145

Merged
merged 1 commit into from
Oct 1, 2024
Merged

Conversation

aprokop
Copy link
Contributor

@aprokop aprokop commented Sep 13, 2024

Allow CTAD only for floating point types without any promotion.

@aprokop aprokop marked this pull request as draft September 14, 2024 02:33
@aprokop
Copy link
Contributor Author

aprokop commented Sep 14, 2024

Will rebase on #1100 once merged.

@dalg24
Copy link
Contributor

dalg24 commented Sep 14, 2024

What is the rational behind promoting integral types to float instead of double like it is done in the standard library math functions?

@dalg24
Copy link
Contributor

dalg24 commented Sep 14, 2024

Also why should we enable mixing types rather than being strict?

@aprokop
Copy link
Contributor Author

aprokop commented Sep 14, 2024

What is the rational behind promoting integral types to float instead of double like it is done in the standard library math functions?

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.
Removing it would require us to always having to cast, like Point{0.f, 1.f} or Point{i}.

Also why should we enable mixing types rather than being strict?

Mostly so that Point{.3f, 0} would work.

@aprokop
Copy link
Contributor Author

aprokop commented Sep 18, 2024

Passed the tests. Warnings are unrelated.

@aprokop aprokop added the backward incompatible Modifications that may break users' code label Sep 22, 2024
@aprokop aprokop force-pushed the change_points_ctad branch 4 times, most recently from 6fee055 to 07bcdb3 Compare September 23, 2024 16:24
@@ -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()
Copy link
Contributor

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.

test/tstCompileOnlyGeometry.cpp Show resolved Hide resolved
KOKKOS_FUNCTION
#endif
Box(T const (&)[N], T const (&)[N])
-> Box<N, std::conditional_t<std::is_integral_v<T>, double, T>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
-> 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

Copy link
Contributor Author

@aprokop aprokop Sep 23, 2024

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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>.

#else
KOKKOS_FUNCTION
#endif
Point(T, Ts...) -> Point<
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@masterleinad
Copy link
Collaborator

Is there a good use cases for allowing Coordinate to be integral or should we just restrict to floating point types (and don't try to convert anything)?

@aprokop
Copy link
Contributor Author

aprokop commented Sep 24, 2024

Is there a good use cases for allowing Coordinate to be integral or should we just restrict to floating point types (and don't try to convert anything)?

The only current use case is in our tests, like ArborX::Point{0, 0, 0}. Those would all require changes. Otherwise, I think not allowing integral types could be ok.

@masterleinad
Copy link
Collaborator

The only current use case is in our tests, like ArborX::Point{0, 0, 0}. Those would all require changes. Otherwise, I think not allowing integral types could be ok.

I think enforcing the the type of the constructor parameters to match and use as Coordinate would be the most straightforward then.

@aprokop aprokop changed the title Change Point CTAD Change Point, Box, Sphere CTAD Sep 25, 2024
src/geometry/ArborX_Point.hpp Outdated Show resolved Hide resolved
Comment on lines 52 to 50
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>>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator

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?

Copy link
Contributor Author

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}.

@aprokop
Copy link
Contributor Author

aprokop commented Sep 30, 2024

@dalg24 @masterleinad Any objections to merging this?

@masterleinad
Copy link
Collaborator

@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, int arguments aren't very good.

@aprokop
Copy link
Contributor Author

aprokop commented Sep 30, 2024

OK. I made CTAD as simple as possible. It does not do any checks on the types anymore.

@aprokop
Copy link
Contributor Author

aprokop commented Oct 1, 2024

OK, this version should be good enough. If we change our minds, we'll change it before the release.

@aprokop aprokop merged commit 4dbf7e3 into arborx:master Oct 1, 2024
1 of 2 checks passed
@aprokop aprokop deleted the change_points_ctad branch October 1, 2024 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backward incompatible Modifications that may break users' code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants