2
19
Fork
You've already forked array
3

Implement monadic (Unique Mask / Nub Sieve) #10

Closed
opened 2024年04月18日 10:51:42 +02:00 by elcaro · 2 comments
Collaborator
Copy link

Per the APL Wiki article

Nub Sieve returns a 1 for each major cell in the argument that is unique, and a 0 if it's a duplicate

The article provides an implementation using other primitives, translated to Kap as follows

N  (2/ ̄1,⌈\«»(1/))

Which will be used for the following test case examples.

The unique mask on a vector is such that Replicating with the mask produces the same result as

> a  "abracadabra"
> a < N a
───────────────────────────────┐
@a @b @r @a @c @a @d @a @b @r @a
 1 1 1 0 1 0 1 0 0 0 0
└────────────────────────────────┘
> ((N a)  a)  ( a)
1

At higher dimensions, such as matrices, I expect it to work on major cells.
Of note, does not work on a matrix without first converting to a vector of major cells

>  m  ? 10 3  2
────┐
1 1 1
1 0 0
1 1 0
1 0 0
1 0 1
1 0 0
1 0 1
1 0 1
0 0 0
0 0 1
└─────┘
>   ,/ m
────┐
1 1 1
1 0 0
1 1 0
1 0 1
0 0 0
0 0 1
└─────┘

I'm not sure if this is a misunderstanding on my part.
In any case, I will demonstrate Unique Mask on a matrix in the same way

> m , ⍉< N ,/ m
──────────┐
│┌────┐ ┐│
1 1 1 1││
││1 0 0 1││
││1 1 0 1││
││1 0 0 0││
││1 0 1 1││
││1 0 0 0││
││1 0 1 0││
││1 0 1 0││
││0 0 0 1││
││0 0 1 1││
│└─────┘ └─┘│
└───────────┘
> ((N ,/ m)  ,/ m)  ( ,/ m)
1
Per the [APL Wiki article](https://aplwiki.com/wiki/Nub_Sieve) > Nub Sieve returns a 1 for each major cell in the argument that is unique, and a 0 if it's a duplicate The article provides an implementation using other primitives, translated to Kap as follows ```apl N ⇐ (2≠/ ̄1,⌈\∪«⍳»(1/⊢)) ``` Which will be used for the following test case examples. The unique mask on a vector is such that Replicating with the mask produces the same result as `∪` ```apl > a ← "abracadabra" > a ⍪⍥< N a ┌→───────────────────────────────┐ ↓@a @b @r @a @c @a @d @a @b @r @a│ │ 1 1 1 0 1 0 1 0 0 0 0│ └────────────────────────────────┘ > ((N a) ⫽ a) ≡ (∪ a) 1 ``` At higher dimensions, such as matrices, I expect it to work on major cells. Of note, `∪` does not work on a matrix without first converting to a vector of major cells ```apl > ⊢ m ← ? 10 3 ⍴ 2 ┌→────┐ ↓1 1 1│ │1 0 0│ │1 1 0│ │1 0 0│ │1 0 1│ │1 0 0│ │1 0 1│ │1 0 1│ │0 0 0│ │0 0 1│ └─────┘ > ⊃ ∪ ,/ m ┌→────┐ ↓1 1 1│ │1 0 0│ │1 1 0│ │1 0 1│ │0 0 0│ │0 0 1│ └─────┘ ``` I'm not sure if this is a misunderstanding on my part. In any case, I will demonstrate Unique Mask on a matrix in the same way ```apl > m ,⍥⊂ ⍉< N ,/ m ┌→──────────┐ │┌→────┐ ┌→┐│ │↓1 1 1│ ↓1││ ││1 0 0│ │1││ ││1 1 0│ │1││ ││1 0 0│ │0││ ││1 0 1│ │1││ ││1 0 0│ │0││ ││1 0 1│ │0││ ││1 0 1│ │0││ ││0 0 0│ │1││ ││0 0 1│ │1││ │└─────┘ └─┘│ └───────────┘ > ((N ,/ m) ⫽ ,/ m) ≡⍥⊃ (∪ ,/ m) 1 ```
Author
Collaborator
Copy link

Although not the topic of this issue, I mentioned that did not work on matrices and higher dimensions.

I can confirm 516125711b resolves this issue with matrices, as well has higher dimensions.

   ? 20 2 2  2
─────┐
12 2 2
└──────┘
   ? 200 2 2 2  2
────────┐
140 2 2 2
└─────────┘
Although not the topic of this issue, I mentioned that `∪` did not work on matrices and higher dimensions. I can confirm 516125711b resolves this issue with matrices, as well has higher dimensions. ```apl ⊢ ⍴ ∪ ? 20 2 2 ⍴ 2 ┌→─────┐ │12 2 2│ └──────┘ ⊢ ⍴ ∪ ? 200 2 2 2 ⍴ 2 ┌→────────┐ │140 2 2 2│ └─────────┘ ```
Owner
Copy link

This has already been implemented. Can you confirm if the implementation conforms to your expectation?

This has already been implemented. Can you confirm if the implementation conforms to your expectation?
Sign in to join this conversation.
No Branch/Tag specified
master
calcite-module
jdk25
tmp-generic-window-management
experiment-assign-to-function-expression
feature-error-highlight
feature-mosaic-ui
feature-sdl
feature-rationalise-reduced
adaptive-experiment
bugfix-linux-charconversions
vector-ops
vector-jvm
sane-reduce
formatter
bitarrays
array-builder
jvm-android-split-new
nested-function-calls-bug
multi-dimensional-string-formatting
ride-impl
codeberg-test
jvm-android-split
libreoffice-module-classloader
optimise-single-element-array
parser-callbacks
new-jline-completion
java-readline
test-tools
int-list-opt
linux-ffi
ffi
isqrt
inter-thread-datatransfer
metadata-highlight
numeric-total-ordering
libreoffice
langbar-javafx
port-mpbignum-to-wasmjs
aesh-test
zero-parser
java21
fxcontrols-spreadsheet-fork
javafx-reporting
new-http
new-optimiser
sixel-renderer
native-input
lambda-scope
custom-renderer
formatter-test
local-functions-fix
kap-rational
bigint2
bigint
reporting
dynamic-assign
structure-viewer2
return-impl
escape-analysis
fork-new-syntax
structural-under
axis-eval
binomial-impl
new-enclose
short-fn-definition
compose-impl
specialised-arrays
ops
domino
clientweb
lcm
gui-experiments
suspend
thread-support
closures_wip
inner-join
maths_axis
keyboard
resultlist3
error-locations
axis-work
No results found.
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
loke/array#10
Reference in a new issue
loke/array
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?