Skip to content

Instantly share code, notes, and snippets.

View abrudz's full-sized avatar
🍏

Adám Brudzewsky abrudz

🍏
View GitHub Profile
@abrudz
abrudz / cmpOver.dyalog
Last active September 13, 2018 16:36
cmp with Over operator
cmp←{ ⍝ compare basic arrays, results in ¯1 (⍺ precedes ⍵), 0 (⍺ is identical to ⍵), or 1 (⍺ follows ⍵)
⍝ DEFINITION:
⍝ ┌
⍝ │ ¯1 if ⍺ strictly precedes ⍵
⍝ ⍺ cmp ⍵ = │ 0 if ⍺ exactly matches ⍵
⍝ │ 1 if ⍺ strictly follows ⍵
⍝ └
⍝ AXIOMS:
@abrudz
abrudz / Math.dyalog
Created December 20, 2017 22:25
Eigen function (and its helper functions) as currently shipped with Dyalog APL
∇ vv←Eigen mat;vecs;vals;code;n
n←≢mat
:If Real mat
:If (Sym mat)∧2≠n ⍝ symmetric
(vals vecs code)←Dsyev mat
:Else ⍝ general
(vals vecs code)←Dgeev mat
:EndIf
@abrudz
abrudz / Eigen.dyalog
Created December 20, 2017 22:19
Eigen function in as it used to be in old versions of Dyalog APL
Eigen←{⎕IO ⎕ML←1 ⍝ Eigen values⍪vectors
⍝ graeme@dyadic.com
dsyev←{ ⍝ real symmetric:
args←'dsyev_'assoc↓⍉↑⌽{ ⍝ associate external fn.
⍵,⊂' <T1 ' 'V'}{ ⍝ JOBZ
⍵,⊂' <T1 ' 'L'}{ ⍝ UPLO
⍵,⊂' <I4 'n}{ ⍝ N
⍵,⊂' =F8[] '(,mat)}{ ⍝ A
⍵,⊂' <I4 'n}{ ⍝ LDA
⍵,⊂' >F8[] 'n}{ ⍝ W
@abrudz
abrudz / TAO.dyalog
Created December 7, 2017 15:30
Sorting and grading any Dyalog APL array.
Sort←{⎕ML←1 ⍝ Total array ordering (TAO) comparison.
acmp←{ ⍝ array comparison.
≡/⍵:¯1 ⍝ match: equal.
~≡/⍴∘⍴¨⍵:∇ xrnk ⍵ ⍝ ranks differ: reshape with 1-axes.
⊃⊃⍷/⍵:1 ⍝ prefixes precede their continuations.
⊃⊃⍷/⌽⍵:0 ⍝ continuations follow their prefixes.
~≡/⍴¨⍵:∇ xshp ⍵ ⍝ shapes differ: stretch with fills.
0=×/⍴⊃⍵:∇⊃¨⍵ ⍝ null: comparison of proto items.
~⍵≡⊃¨⍵:∇ halves,¨⍵ ⍝ non-atomic: item-wise comparison.