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

similar_type implementation #118

Merged
merged 6 commits into from
Jun 1, 2016
Merged

similar_type implementation #118

merged 6 commits into from
Jun 1, 2016

Conversation

c42f
Copy link
Collaborator

@c42f c42f commented May 31, 2016

As discussed in #116, I've had a crack at replacing similar with similar_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 of similar_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.

c42f and others added 3 commits May 29, 2016 07:59
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.
@codecov-io
Copy link

codecov-io commented May 31, 2016

Current coverage is 91.33%

Merging #118 into master will increase coverage by 1.37%

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

Powered by Codecov. Last updated by b68bc74...9763f27

@coveralls
Copy link

coveralls commented May 31, 2016

Coverage Status

Coverage increased (+1.4%) to 91.354% when pulling 7b9f80a on c42f:similar-type into b68bc74 on SimonDanisch:master.

@SimonDanisch
Copy link
Owner

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}
Copy link
Collaborator Author

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

@coveralls
Copy link

coveralls commented May 31, 2016

Coverage Status

Coverage increased (+1.4%) to 91.326% when pulling 17a7b05 on c42f:similar-type into b68bc74 on SimonDanisch:master.

@c42f
Copy link
Collaborator Author

c42f commented May 31, 2016

No probs, I also just did a little extra cleanup and removed a couple of extraneous definitions in the service of minimalism.

Chris Foster and others added 2 commits June 1, 2016 10:54
* 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
@coveralls
Copy link

coveralls commented Jun 1, 2016

Coverage Status

Coverage increased (+1.4%) to 91.326% when pulling 39a9595 on c42f:similar-type into b68bc74 on SimonDanisch:master.

@c42f
Copy link
Collaborator Author

c42f commented Jun 1, 2016

Ah, hang on! @andyferris has just enlightened me to the fact that supertype propagates TypeVar as we actually need to make the default similar_type more intelligent. I'll try another iteration.

@coveralls
Copy link

coveralls commented Jun 1, 2016

Coverage Status

Coverage increased (+1.5%) to 91.456% when pulling a2a762d on c42f:similar-type into b68bc74 on SimonDanisch:master.

@c42f
Copy link
Collaborator Author

c42f commented Jun 1, 2016

Wow, that rabbit hole turned into at least a mid sized dungeon. similar_type should now work without users having to overload it in nearly all circumstances (thanks for the suggestions @andyferris!)

@andyferris @SimonDanisch - have another look if you have time. Yup, similar_type now looks ugly and a bit fragile, but I think it's about as convenient for users as I can make it.

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 🚢 🇮🇹 (:ship: :it:))

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
@coveralls
Copy link

coveralls commented Jun 1, 2016

Coverage Status

Coverage increased (+2.0%) to 91.93% when pulling 34bc334 on c42f:similar-type into b68bc74 on SimonDanisch:master.

@SimonDanisch
Copy link
Owner

The complexity of similar_type makes me wonder, if we shouldn't just offer a macro for creating subtypes of FixedSizeArrays.
This would also make it less breaking, if we introduce changes to the type itself.
But it seems to work like this for now, so from me: 🚢 🇮🇹 ;)
I think we can warm up that discussion, when we actually inherit from AbstractArray ;)

@c42f
Copy link
Collaborator Author

c42f commented Jun 1, 2016

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.

@mschauer
Copy link
Collaborator

mschauer commented Jun 1, 2016

It's like the "expression problem" which was solved for numbers with multiple dispatch and promote_rules comes back with a vengance for fixed size arrays.

@andyferris
Copy link
Contributor

andyferris commented Jun 1, 2016

@mschauer Indeed. Note that we can have the same issue for how other types of AbstractArrays interact with each other but that Array is so complete and what to do with SparseArray, etc, is pretty obvious that it hasn't become an issue. However, this package is practically begging users to define their own array types (emphasis on plural) that some logic to how they interact needs to be implemented by the user.

What's in there in this PR seems to be the "closest" generic guess you might come up with, but that's my opinion.

🚢 🇮🇹 👍

@c42f c42f merged commit 34bc334 into SimonDanisch:master Jun 1, 2016
@c42f c42f deleted the similar-type branch June 1, 2016 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants