Re: [julia-users] Find sequence in array?

2015-09-12 Thread Milan Bouchet-Valat
Le vendredi 11 septembre 2015 à 16:03 -0700, cormull...@mac.com a écrit
 :
> Is there a Julia function/method to find the location(s) of a
> sequence of elements in a 1-D array?
> 
> With strings, you can do:
> 
> search("longstring", "str")
> 
> 5:7
> 
> so with arrays it would hopefully be something like:
> 
> searcharray( [1, 3, 5, 7, 9, 11, 13], [5, 7, 9])
> 
> 3:5
It doesn't exist at the moment, though an implementation would
certainly be accepted. It could be a method for search(), or a new
function called findseq():
https://github.com/JuliaLang/julia/issues/10593#issuecomment-90249829

If you want to give it a try, you could generalize a bit the existing
method for search() which only works on UInt8 arrays:

julia> search(UInt8[1, 3, 5, 7, 9, 11, 13], UInt8[5, 7, 9], 1)
3:5


Regards


Re: [julia-users] Find sequence in array?

2015-09-12 Thread cormullion
Hi Milan - thanks for the clues! I found `Base._searchindex`, which work 
for integers:

julia> a = rand(1:10, 100);

julia> Base._searchindex(a, [19272, 52257], 1)

   86

It's pretty quick, too.