4,494
edits
m (Text replacement - "<source" to "<syntaxhighlight") |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
Line 9: | Line 9: | ||
¯3 ↓ 5 4 3 2 1 | ¯3 ↓ 5 4 3 2 1 | ||
5 4 | 5 4 | ||
</ | </syntaxhighlight> | ||
Removing more elements than the length of the axis gives an [[empty]] result: | Removing more elements than the length of the axis gives an [[empty]] result: | ||
Line 15: | Line 15: | ||
¯8 ↓ 5 4 3 2 1 | ¯8 ↓ 5 4 3 2 1 | ||
</ | </syntaxhighlight> | ||
{{Works in|[[Dyalog APL]], [[ngn/apl]]}} | {{Works in|[[Dyalog APL]], [[ngn/apl]]}} | ||
Line 26: | Line 26: | ||
│4 4│4 5│ | │4 4│4 5│ | ||
└───┴───┘ | └───┴───┘ | ||
</ | </syntaxhighlight> | ||
== Description == | == Description == | ||
Line 32: | Line 32: | ||
The arguments to Drop must be valid arguments to [[Take]], and elements of the left argument are matched to [[axes]] of the right in the same way. Like Take, the left argument is subject to [[scalar rank extension]], and in some APLs the right is as well. | The arguments to Drop must be valid arguments to [[Take]], and elements of the left argument are matched to [[axes]] of the right in the same way. Like Take, the left argument is subject to [[scalar rank extension]], and in some APLs the right is as well. | ||
Each axis with a matching left argument element <syntaxhighlight lang=apl inline>d</ | Each axis with a matching left argument element <syntaxhighlight lang=apl inline>d</syntaxhighlight> is modified to remove <syntaxhighlight lang=apl inline>|d</syntaxhighlight> indices, or all of them if <syntaxhighlight lang=apl inline>|d</syntaxhighlight> is larger than the length of the axis. Indices are removed starting from the beginning if <syntaxhighlight lang=apl inline>d</syntaxhighlight> is positive and starting from the end if it is negative (if <syntaxhighlight lang=apl inline>d</syntaxhighlight> is 0, then no indices are removed). Equivalently, for an axis of length <syntaxhighlight lang=apl inline>l</syntaxhighlight>, <syntaxhighlight lang=apl inline>l-l⌊|d</syntaxhighlight> axes are retained—not dropped—from the axis starting from the opposite side: the end if <syntaxhighlight lang=apl inline>d</syntaxhighlight> is positive and the beginning otherwise. If <syntaxhighlight lang=apl inline>|d</syntaxhighlight> is greater than or equal to <syntaxhighlight lang=apl inline>l</syntaxhighlight> for any axis, then the result is [[empty array|empty]] and shares a [[prototype]] with the argument. | ||
=== APL Model === | === APL Model === | ||
Line 44: | Line 44: | ||
((sׯ1*⍺>0) + (-s)⌈s⌊⍺) ↑ ⍵ | ((sׯ1*⍺>0) + (-s)⌈s⌊⍺) ↑ ⍵ | ||
} | } | ||
</ | </syntaxhighlight> | ||
The code works by modifying the left argument using the right argument's shape. First, the shape is used to restrict the left argument's range (<syntaxhighlight lang=apl inline>(-s)⌈s⌊⍺</ | The code works by modifying the left argument using the right argument's shape. First, the shape is used to restrict the left argument's range (<syntaxhighlight lang=apl inline>(-s)⌈s⌊⍺</syntaxhighlight>) so that the maximum number of indices dropped is the length of the axis. Then, the shape is added or subtracted so that the left argument's sign is flipped. | ||
This implementation inherits all argument extensions from Take. The two middle lines are used to support right argument scalar rank extension and the [[SHARP APL]] short left argument extension. If Take does not have these extensions then they have no effect and can be removed. | This implementation inherits all argument extensions from Take. The two middle lines are used to support right argument scalar rank extension and the [[SHARP APL]] short left argument extension. If Take does not have these extensions then they have no effect and can be removed. | ||
Line 61: | Line 61: | ||
* [http://microapl.com/apl_help/ch_020_020_570.htm APLX] | * [http://microapl.com/apl_help/ch_020_020_570.htm APLX] | ||
* [https://www.jsoftware.com/help/dictionary/d531.htm J Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/curlyrtdot#dyadic J NuVoc] (as <syntaxhighlight lang=apl inline>}.</ | * [https://www.jsoftware.com/help/dictionary/d531.htm J Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/curlyrtdot#dyadic J NuVoc] (as <syntaxhighlight lang=apl inline>}.</syntaxhighlight>) | ||
* [https://mlochbaum.github.io/BQN/doc/take.html BQN] | * [https://mlochbaum.github.io/BQN/doc/take.html BQN] | ||
{{APL built-ins}}[[Category:Primitive functions]] | {{APL built-ins}}[[Category:Primitive functions]] |