-
Notifications
You must be signed in to change notification settings - Fork 20
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
similar_type implementation #118
Conversation
It's now no longer necessary to have the versions taking a Type{T} parameter, since the unary version of map now correctly inferrs the output FSA type. (And the comment here was wrong.)
* Rename similar to similar_type since it produces slightly different output. * Implement default similar_type which returns the type unchanged if it exactly matches, and falls back to Vec/Mat otherwise * Implement similar_type for Vec,Point,Mat and tests as necessary.
Current coverage is 91.33%@@ master #118 diff @@
==========================================
Files 11 11
Lines 607 611 +4
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 546 558 +12
+ Misses 61 53 -8
Partials 0 0
|
Wow, coverage increase and docs! :) Thanks a lot! |
similar{FSA <: Mat}(::Type{FSA}, SZ::NTuple{2,Int}) = similar(FSA, eltype(FSA), SZ) | ||
similar{N,M,S, T}(::Type{Mat{N,M,S}}, ::Type{T}) = Mat{N,M,T} | ||
similar_type{FSA<:Mat,T}(::Type{FSA}, ::Type{T}, sz::NTuple{2, Int}) = Mat{sz[1], sz[2], T} | ||
similar_type{N,M,S, T}(::Type{Mat{N,M,S}}, ::Type{T}) = Mat{N,M,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.
Hmm, looks like I missed marking these as @pure
, and it's not technically necessary to have the second version here (though it's type stable even in 0.4 in contrast to the first version).
No probs, I also just did a little extra cleanup and removed a couple of extraneous definitions in the service of minimalism. |
* Document FSA abstract types which are actually in use (no docs for Mutable FSAs yet, since I'm not sure anybody is using them) * Document concrete FSA types provided by the package * Document the requirement to overload `similar_type` in certian cases.
* Avoid some duplication in similar_type definitions * Move `@pure` somewhere more sensible * Remove similar_type convenience function for simplicity
Ah, hang on! @andyferris has just enlightened me to the fact that |
Wow, that rabbit hole turned into at least a mid sized dungeon. @andyferris @SimonDanisch - have another look if you have time. Yup, BTW @SimonDanisch how do you want to do the "looks good to me, merge it" thing for this repo? In other repos people variously use LGTM (looks good to me), +1, etc. (Heh, I recently even saw 🚢 🇮🇹 ( |
Make similar_type() work by default in nearly all circumstances, by introspecting the type tree using fsa_abstract(), supertype() and a bunch of other ugly stuff involving `TypeVar`s. Ugh... just ugh, but I hope it'll make it easier for users. * Remove the specialized similar_type() implementations for concrete types as they're no longer needed * Fix up README to reflect the new implementation * Add some extra tests
The complexity of |
Thanks for having a look, yeah the complexity is nasty. The more code I wrote there the less it seemed like a good idea! But on the other hand, people are much less likely to have to define similar_type with the current implementation so if it changes later the disruption will be a lot less. |
It's like the "expression problem" which was solved for numbers with multiple dispatch and |
@mschauer Indeed. Note that we can have the same issue for how other types of What's in there in this PR seems to be the "closest" generic guess you might come up with, but that's my opinion. 🚢 🇮🇹 👍 |
As discussed in #116, I've had a crack at replacing
similar
withsimilar_type
. I think this is more systematic than what we've got now, but it still may not quite be right. I'm open to other ways to define the default implementation ofsimilar_type
, but it's clear to me that any default implementation has problems for one case or other. Again, see #116 for some other options.I also had a go at updating the readme for this, and also to document the types which are defined and address the uncertainty around what
Point
actually is meant to represent.