Fork me on GitHub

src/arraymancer/tensor/accessors_macros_syntax

  Source Edit

Types

Ellipsis = object
Dummy type for ellipsis i.e. "Don't slice the rest of dimensions"   Source Edit
Step = object

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
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 a2, 1..<5, _ will be converted at compile-time to SteppedSlices

  Source Edit

Consts

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

Procs

proc `..`(a: int; s: Step): SteppedSlice {.noSideEffect, inline, ...raises: [],
    tags: [], forbids: [].}
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: [], forbids: [].}
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: [], forbids: [].}
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: 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
proc `^`(s: SteppedSlice): SteppedSlice {.noSideEffect, inline, ...raises: [],
    tags: [], forbids: [].}
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 initSpanSlices(len: int): ArrayOfSlices {.inline, ...raises: [], tags: [],
    forbids: [].}
  Source Edit
proc toArrayOfSlices(s: varargs[SteppedSlice]): ArrayOfSlices {.inline,
    ...raises: [], tags: [], forbids: [].}
  Source Edit
proc `|`(b, step: int): Step {.noSideEffect, inline, ...raises: [], tags: [],
                               forbids: [].}

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 `|`(s: Slice[int]; step: int): SteppedSlice {.noSideEffect, inline,
    ...raises: [], tags: [], forbids: [].}
Internal: A SteppedSlice constructor Input:
- a slice
- a step

Returns:

- a ``SteppedSlice``
  Source Edit
proc `|`(ss: SteppedSlice; step: int): SteppedSlice {.noSideEffect, inline,
    ...raises: [], tags: [], forbids: [].}
Internal: Modifies the step of a SteppedSlice Input:
- a ``SteppedSLice``
- the new stepping

Returns:

- a ``SteppedSLice``
  Source Edit
proc `|+`(b, step: int): Step {.noSideEffect, inline, ...raises: [], tags: [],
                                forbids: [].}
Internal: Alias for |   Source Edit
proc `|+`(s: Slice[int]; step: int): SteppedSlice {.noSideEffect, inline,
    ...raises: [], tags: [], forbids: [].}
Internal: Alias for |   Source Edit
proc `|+`(ss: SteppedSlice; step: int): SteppedSlice {.noSideEffect, inline,
    ...raises: [], tags: [], forbids: [].}
Internal: Alias for |   Source Edit
proc `|-`(b, step: int): Step {.noSideEffect, inline, ...raises: [], tags: [],
                                forbids: [].}

Internal: A SteppedSlice constructor

Workaround to tensor0..10|-1 being intepreted as 0 .. (10 `|-` 1)

Properly create SteppedSLice with negative stepping

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

Internal: A SteppedSlice constructor

Workaround to tensorslice|-1 being interpreted as slice `|-` 1

Properly create SteppedSLice with negative stepping

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

Internal: Modifies the step of a SteppedSlice

Workaround to tensorslice|-1 being interpreted as slice `|-` 1

Properly create SteppedSLice with negative stepping

  Source Edit
Arraymancer Technical reference Tutorial Spellbook (How-To's) Under the hood