-
Notifications
You must be signed in to change notification settings - Fork 98
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
Relax type signature for result_type
and allow it to act on numbers
#192
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are we sure we want to preserve units if inputs have them for all kinds of distances?
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'm not sure; I guess that's a question for @johnnychen94, since the method came from #185. To me the "all kinds of distances" isn't super worrying since any distance could just provide a more specialized method, but to be honest I'm not super confident in the interplay between units and distances and maybe that could be tedious or painful.
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.
Yes, as we've discussed in the original issue #190, this change gives other packages the ability to reuse the name
result_type
without introducing type piracy. BecauseDistances
definesresult_type
, the fallback should be defined inDistances
.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.
To be clear,
result_type
is exported byDistances
.Distances.jl/src/Distances.jl
Lines 6 to 13 in e50899d
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.
ah good point, it is exported!
I think @nalimilan's question here was about
oneunit
, any thoughts on that @johnnychen94?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'm not sure if I understand the question clearly and I don't know what that question intends to suggest.
I don't know why the fallback is
Float64
forPreMetric
, it's probably written down whenresult_type
wasn't exported and the main consideration is probably arithmetic performance inside Distances only.FixedPointNumbers has introduced a better strategy
floattype(x)
to rewrite thatN0f8
( normalizedUInt8
) should get promoted toFloat32
instead ofFloat16
. I think Distances should follow the same pattern and should not hard code the result type intoFloat64
. People don't like changes, so it's okay to keep the internalDistances
unchanged.We're not changing
Distances
internal implementation here. As is said, we're adding a fallback that will be overridden by all the internal distances' implementation.I think for any general function
f
(not limited to Distances itself), callingf
on the units is a more generic fallback. Let me give two examples here:For
Unitful
:Also for JuliaImages,
ColorVectorSpaces
has defined a lot of basic operations forGray
andRGB
, so it makes sense to letresult_type
beGray
/RGB
if that's what they are supposed to be.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.
OK. Actually I hadn't realized that
oneunit
is already used by existing methods:Distances.jl/src/metrics.jl
Lines 216 to 221 in e50899d
Float64
is indeed not a great default. Do you know whether it's actually used in Distances ? Maybe we could remove the fallback method and always rely ononeunit
.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.
By removing this fallback, and observing the test errors, it tells me that only
BhattacharyyaDist
,HellingerDist
andBregman
requires this fallback for itscolwise
implementation. Currently, it makes sense to me to remove this fallback (probably in another PR).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.
Thanks for checking. I think it would be better to try removing the fallback in this PR. Otherwise the new method wouldn't actually be used for
PreMetric
so it would be misleading to call thatDistances.result_type
!