Fork me on GitHub
Arraymancer Technical reference Tutorial Spellbook (How-To's) Under the hood

Module accessors_macros_syntax

Types

SteppedSlice = object
  a*, b*: int
  step*: int
  a_from_end*: bool
  b_from_end*: bool
Internal: A slice object related to a tensor single dimension:
  • a, b: Respectively the beginning and the end of the range of the dimension
  • step: The stepping of the slice (can be negative)
  • a/b_from_end: Indicates if a/b should be counted from 0 or from the end of the tensor relevant dimension.

Slicing syntax like a[2, 1..<5, _] will be converted at compile-time to SteppedSlices

  Source Edit
Step = object
  b: int
  step: int

Internal: Workaround to build SteppedSlice without using parenthesis.

Expected syntax is tensor[0..10|1].

Due to operator precedence of | over .. [0..10|1] is interpreted as [0..(10|1)]

  Source Edit
Ellipsis = object
Dummy type for ellipsis i.e. "Don't slice the rest of dimensions"   Source Edit
ArrayOfSlices = DynamicStackArray[SteppedSlice]
  Source Edit

Consts

_ = (a: 0, b: 1, step: 1, a_from_end: false, b_from_end: true)
  Source Edit
... = ()
  Source Edit

Procs

proc toArrayOfSlices(s: varargs[SteppedSlice]): ArrayOfSlices {.
inline, raises: [], tags: []
.}
  Source Edit
proc initSpanSlices(len: int): ArrayOfSlices {.
inline, raises: [], tags: []
.}
  Source Edit
proc `|`(s: Slice[int]; step: int): SteppedSlice {.
noSideEffect, inline, raises: [], tags: []
.}
Internal: A SteppedSlice constructor
Input:
  • a slice
  • a step
Returns:
  • a SteppedSlice
  Source Edit
proc `|`(b, step: int): Step {.
noSideEffect, inline, raises: [], tags: []
.}

Internal: A Step constructor

Step is a workaround due to operator precedence.

[0..10|1] is interpreted as [0..(10|1)]

Input:
  • the end of a slice range
  • a step
Returns:
  • a Step
  Source Edit
proc `|`(ss: SteppedSlice; step: int): SteppedSlice {.
noSideEffect, inline, raises: [], tags: []
.}
Internal: Modifies the step of a SteppedSlice
Input:
  • a SteppedSLice
  • the new stepping
Returns:
  • a SteppedSLice
  Source Edit
proc `|+`(s: Slice[int]; step: int): SteppedSlice {.
noSideEffect, inline, raises: [], tags: []
.}
Internal: Alias for |   Source Edit
proc `|+`(b, step: int): Step {.
noSideEffect, inline, raises: [], tags: []
.}
Internal: Alias for |   Source Edit
proc `|+`(ss: SteppedSlice; step: int): SteppedSlice {.
noSideEffect, inline, raises: [], tags: []
.}
Internal: Alias for |   Source Edit
proc `|-`(s: Slice[int]; step: int): SteppedSlice {.
noSideEffect, inline, raises: [], tags: []
.}

Internal: A SteppedSlice constructor

Workaround to tensor[slice|-1] being interpreted as [slice |- 1]

Properly create SteppedSLice with negative stepping

  Source Edit
proc `|-`(b, step: int): Step {.
noSideEffect, inline, raises: [], tags: []
.}

Internal: A SteppedSlice constructor

Workaround to tensor[0..10|-1] being intepreted as [0 .. (10 |- 1)]

Properly create SteppedSLice with negative stepping

  Source Edit
proc `|-`(ss: SteppedSlice; step: int): SteppedSlice {.
noSideEffect, inline, raises: [], tags: []
.}

Internal: Modifies the step of a SteppedSlice

Workaround to tensor[slice|-1] being interpreted as [slice |- 1]

Properly create SteppedSLice with negative stepping

  Source Edit
proc `..`(a: int; s: Step): SteppedSlice {.
noSideEffect, inline, raises: [], tags: []
.}
Internal: Build a SteppedSlice from [a .. (b|step)] (workaround to operator precedence)
Input:
  • the beginning of the slice range
  • a Step workaround object
Returns:
  • a SteppedSlice, end of range will be inclusive
  Source Edit
proc `..<`(a: int; s: Step): SteppedSlice {.
noSideEffect, inline, raises: [], tags: []
.}
Internal: Build a SteppedSlice from [a ..< (b|step)] (workaround to operator precedence)
Input:
  • the beginning of the slice range
  • a Step workaround object
Returns:
  • a SteppedSlice, end of range will be exclusive.
  Source Edit
proc `..^`(a: int; s: Step): SteppedSlice {.
noSideEffect, inline, raises: [], tags: []
.}
Internal: Build a SteppedSlice from [a ..^ (b|step)] (workaround to operator precedence and ..^b not being interpreted as .. ^b)
Input:
  • the beginning of the slice range
  • a Step workaround object
Returns:
  • a SteppedSlice, end of range will start at "b" away from the end
  Source Edit
proc `^`(s: SteppedSlice): SteppedSlice {.
noSideEffect, inline, raises: [], tags: []
.}
Internal: Prefix to a to indicate starting the slice at "a" away from the end Note: This does not automatically inverse stepping, what if we want ^5..^1   Source Edit
proc `^`(s: Slice): SteppedSlice {.
noSideEffect, inline
.}
Internal: Prefix to a to indicate starting the slice at "a" away from the end Note: This does not automatically inverse stepping, what if we want ^5..^1   Source Edit