Tag Info

Hot answers tagged


Unless both lists given to Equal are packed arrays Equal will first unpack. Unfortunately for this case {} is not a packable expression, therefore list == {} will always unpack list, assuming it starts packed. That unpacking takes time: test = RandomInteger[100000000, 10000000]; Developer`FromPackedArray[test]; // AbsoluteTiming {0.207012, Null} ...


Here's my functional variant of your code: findSeam2[e_List] := Module[{f = FoldList[MinFilter[#1, 1] + #2 &, First[e], Rest[e]]}, Reverse@ FoldList[#1 + First@Ordering[#2[[Max[1, #1 - 1] ;; Min[Length[#2], #1 + 1]]]] - 1 - If[#1 == 1, 0, 1] &, First@Ordering[Last[f], 1], Reverse@Most[f]]]; And my test case ...


Updated with cleaner and easier to adapt method: The checking of the patterns gets expensive, more so when conditions are attached. Looking at your generators, it's clear that the fulfillment of the patterns and/or conditions is quite sparse. Better to generate directly the hits, and create the array from those. Using your 'c' generator with just the ...


I ran your code on my computer, a 4-year old i7 iMac running V10.0.2 on OS X 10.6.8 (Snow Leopard). The first set of timings I got were 0.105747 0.105747 16.865200 The above timings are slower than yours. I attribute that to age of the iMac. For the ratios I got 48.9902 159.486 which are a little better than yours.

Only top voted, non community-wiki answers of a minimum length are eligible