« first day (2321 days earlier)      last day (326 days later) » 

12:44 AM
sorry, I'm probably just tired, but where's the cover code for Display? Can't see it in your safe-exec
 
 
3 hours later…
3:25 AM
@MasterQuiz Here's an alternative using ⌽ and ⊖ that performs better for larger matrices. This can easily be golfed more, but this is a simple definition. Not sure how you want to handle borders -- we can get around that by padding:
 HasConsecutiveZeros←{
     b←0=⍵
     p←(0⍪0,b,0)⍪0
     1∊(p∧(1⌽p))∨(p∧(1⊖p))
 }
      f ← ⍉∨⍥(∨/∘,2⍴0∘⍷)⊢∘×
      m←2=?1e6 100⍴2 ⍝ 100m elements in this boolean matrix
      ⍴ m
1000000 100
      ]runtime -c "HasConsecutiveZeros m" "f m"

  HasConsecutiveZeros m → 6.3E¯2 |     0% ⎕
  f m                   → 2.7E0  | +4236% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
forgot to remove a lot of those parens:
 HasConsecutiveZeros←{
     b←0=⍵
     p←(0⍪0,b,0)⍪0
     1∊(p∧1⌽p)∨p∧1⊖p
 }
I wonder if a defined operator for the last line makes the code more clear or not
 HasConsecutiveZeros←{
     b←0=⍵
     p←(0⍪0,b,0)⍪0
     X←{⍵∧1 ⍺⍺ ⍵}
     1∊(⌽X p)∨(⊖X p)
 }
 
 
2 hours later…
5:17 AM
@JoshD @MasterQuiz Maybe I'm misunderstanding something, but isn't this just 2(⍱/∨⍥(0∘∊)⍱⌿)⊢ which is about twice as fast as HasConsecutiveZeros?
 
 
5 hours later…
10:34 AM
1
Q: Is another way to write this APL pattern?

Alden LuthfiCONTEXT let ns be an unsorted array of unique integers of arbitrary length, return the smallest missing positive number of that array. for example ns = {-1, -3, -2} -> 1 ns = {7, 8, 9} -> 10 ns = {-1, 5, 1} -> 2 I saw this on an APL youtube video and decided to give it a try myself, my solution ...

 
 
4 hours later…
2:29 PM
@Adám Oh wow, the 2 windowed reduce option didn't come to me initially. That is interesting that all those windowed comparisons are quicker even on large matrices -- wonder how a similar stencil solution would perform. Gotta run but I'll experiment later. Right now your definition is giving me a domain error on numeric mats & failed a test with a matrix of all 1's
 
 
6 hours later…
8:24 PM
I'm seeing mixed performance results for the windowed reduction approach. Generally it does seem faster than HasConsecutiveRows, but still atleast in the same order of magnitude. I'd say the windowed reduction approach is better though. The padding hack is kind of hacky IMO. Also curious about how these would perform against eachother in co-dfns GPU
       ]runtime -c "{b←0=⍵ ⋄ (1∊2^/b)∨(1∊2^⌿b)}m" "HasConsecutiveZeros m" "f m"

  {b←0=⍵ ⋄ (1∊2^/b)∨(1∊2^⌿b)}m → 1.1E¯1 |     0% ⎕
  HasConsecutiveZeros m        → 9.4E¯2 |   -16% ⎕
  f m                          → 3.5E0  | +3014% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
       ]runtime -c "{b←0=⍵ ⋄ (1∊2^/b)∨(1∊2^⌿b)}m" "HasConsecutiveZeros m"

  {b←0=⍵ ⋄ (1∊2^/b)∨(1∊2^⌿b)}m → 5.9E¯2 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
  HasConsecutiveZeros m        → 8.7E¯2 | +48% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
The other interesting approach would be with ⍸
my guess is that performance would vary a lot with how dense/sparsely consecutive 0s are found in the matrix. Materializing those booleans to ints would be pretty costly IMO
esp with high indices
The padding is pretty costly too. Without it, HasConsecutiveRows beats the windowed reduce approach. Down to 3.7E¯2 (-36%) instead of +48%
My above definition of f was not displayed right (taken from ]defs)
Use the original definition from Master Quiz if you want to recreate:
f←(⍉∨⍥(∨/∘,0 0∘⍷)⊢)∘×
 

« first day (2321 days earlier)      last day (326 days later) »