Unique: Difference between revisions
Jump to navigation
Jump to search
m (→History: Make Operators and Functions a page link instead of a reference) |
(Rip out the (wrong) model for unique.) |
||
Line 72: | Line 72: | ||
== APL model == | == APL model == | ||
An APL model suggested by Kamila Szewczyk begins with an implementation for vector (rank 1) and scalar (rank 0) arrays as follows: | |||
<syntaxhighlight lang=apl> | <syntaxhighlight lang=apl> | ||
v ← {1/⊃∪/⊂¨⍵} | |||
} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
{{Works in|[[Dyalog APL]]}} | {{Works in|[[Dyalog APL]]}} | ||
It is extended to arbitrary rank inputs as follows: | |||
<syntaxhighlight lang=apl> | <syntaxhighlight lang=apl> | ||
m ← {0∊⍴⍵:⍵⍴⍨≠∘0@⎕io⊢⍴⍵ ⋄ ↑1/⊃∪/⊂¨⊂⍤¯1⊢⍵} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
{{Works in|[[Dyalog APL | {{Works in|[[Dyalog APL]]}} | ||
The guard checks for a zero element in a shape because the general model does not handle the case where the leading axis has shape of zero. While a zero element in the shape in any other place is handled by the general model, the special case is faster and less complex hence preferred. If modelling the primitive via Union is not desirable due to how similar these two primitives are, it is possible to replace this particular usage of union (not in the general case!) as follows: | |||
<syntaxhighlight lang=apl> | <syntaxhighlight lang=apl> | ||
m ← {0∊⍴⍵:⍵ ⋄ ↑1/⊃(⊣,⊢⊢⍤/⍨(∧/∘.≢⍨))/⊂¨⊂⍤¯1⊢⍵} | |||
</syntaxhighlight> | </syntaxhighlight> | ||
{{Works in|[[Dyalog APL]]}} | {{Works in|[[Dyalog APL]]}} | ||
While the model <syntaxhighlight lang=apl inline>{((⍳≢⍵)=(⍵⍳⍵))⌿⍵}</syntaxhighlight>, based on [[Nub Sieve]], is often described as an implementation of Unique, it does not correctly handle [[tolerant comparison]].<ref>Hui, Roger. [https://dyalog.tv/Dyalog17/?v=fPWky9IOG40 Tolerant Unique]. [[Dyalog '17]].</ref> A correct implementation of Nub Sieve could be used to implement Unique, but writing such an implementation is no easier than implementing Unique directly. | While the model <syntaxhighlight lang=apl inline>{((⍳≢⍵)=(⍵⍳⍵))⌿⍵}</syntaxhighlight> for vector arguments, based on [[Nub Sieve]], is often described as an implementation of Unique, it does not correctly handle [[tolerant comparison]].<ref>Hui, Roger. [https://dyalog.tv/Dyalog17/?v=fPWky9IOG40 Tolerant Unique]. [[Dyalog '17]].</ref> A correct implementation of Nub Sieve could be used to implement Unique, but writing such an implementation is no easier than implementing Unique directly. | ||
== Properties == | == Properties == |