-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: Remove find type assertion to allow other iterables #16110
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,6 +362,14 @@ a = [0,1,2,3,0,1,2,3] | |
@test findprev(isodd, [2,4,5,3,9,2,0], 7) == 5 | ||
@test findprev(isodd, [2,4,5,3,9,2,0], 2) == 0 | ||
|
||
# find with general iterables | ||
s = "julia" | ||
@test find(s) == [1,2,3,4,5] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test conflicts directly with #16024. I also think that this is bizarre behavior: julia> find("foo\0bar")
6-element Array{Int64,1}:
1
2
3
5
6
7 Sure, that's what falls out of the definition, but how is this a useful or meaningful operation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential solutions:
The last retains the bizarre behavior for strings of finding the indices of all characters but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah crap, I didn't realize this was getting the non-null indices; I thought it was getting all indices. (Though in retrospect it should have been obvious that it would do this. 😕) I definitely should have added a test for that. This behavior isn't what I had intended. Would it make sense to add a separate method for strings that just does something like What do you think about that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I vote for either keeping the current behaviour, or adding a method just to raise an error. Do we have a use case for this (it didn't work until now...)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't have a use case in mind for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but returning all valid indices isn't the definition of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, |
||
@test find(c -> c == 'l', s) == [3] | ||
g = graphemes("日本語") | ||
@test find(g) == [1,2,3] | ||
@test find(isascii, g) == Int[] | ||
|
||
## findn ## | ||
|
||
b = findn(ones(2,2,2,2)) | ||
|
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.
does this change the dimensionality of the output when the input is an
AbstractArray
?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
find
always returns a vector: this is whatsimilar
did as a single dimension argument was passed. Anyway it doesn't make sense to keep the size of the input array.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.
Yeah these methods with size arguments to
similar
always make me scratch my head in terms of what they're for. I guesssimilar(::SparseVector, T, n)
could return something other thanVector
, but wouldn't make too much sense to use that forfind
.