Drop: Difference between revisions

Jump to navigation Jump to search
24 bytes added ,  09:07, 29 October 2019
m
Text replacement - "</code>" to "</source>"
Miraheze>Adám Brudzewsky
m (Text replacement - "<code>" to "<source lang=apl inline>")
Miraheze>Adám Brudzewsky
m (Text replacement - "</code>" to "</source>")
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 <source lang=apl inline>d</code> is modified to remove <source lang=apl inline>|d</code> indices, or all of them if <source lang=apl inline>|d</code> is larger than the length of the axis. Indices are removed starting from the beginning if <source lang=apl inline>d</code> is positive and starting from the end if it is negative (if <source lang=apl inline>d</code> is 0, then no indices are removed). Equivalently, for an axis of length <source lang=apl inline>l</code>, <source lang=apl inline>l-l⌊|d</code> axes are retained—not dropped—from the axis starting from the opposite side: the end if <source lang=apl inline>d</code> is positive and the beginning otherwise. If <source lang=apl inline>|d</code> is greater than or equal to <source lang=apl inline>l</code> for any axis, then the result is [[empty array|empty]] and shares a [[prototype]] with the argument.
Each axis with a matching left argument element <source lang=apl inline>d</source> is modified to remove <source lang=apl inline>|d</source> indices, or all of them if <source lang=apl inline>|d</source> is larger than the length of the axis. Indices are removed starting from the beginning if <source lang=apl inline>d</source> is positive and starting from the end if it is negative (if <source lang=apl inline>d</source> is 0, then no indices are removed). Equivalently, for an axis of length <source lang=apl inline>l</source>, <source lang=apl inline>l-l⌊|d</source> axes are retained—not dropped—from the axis starting from the opposite side: the end if <source lang=apl inline>d</source> is positive and the beginning otherwise. If <source lang=apl inline>|d</source> is greater than or equal to <source lang=apl inline>l</source> for any axis, then the result is [[empty array|empty]] and shares a [[prototype]] with the argument.


=== APL Model ===
=== APL Model ===
Line 45: Line 45:
}
}
</source>
</source>
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 (<source lang=apl inline>(-s)⌈s⌊⍺</code>) 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.
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 (<source lang=apl inline>(-s)⌈s⌊⍺</source>) 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 <source lang=apl inline>}.</code>)
* [https://www.jsoftware.com/help/dictionary/d531.htm J Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/curlyrtdot#dyadic J NuVoc] (as <source lang=apl inline>}.</source>)
{{APL built-ins}}
{{APL built-ins}}

Navigation menu