The OpenD Programming Language

swapped

Swaps two dimensions.

  1. template swapped(size_t dimensionA, size_t dimensionB)
  2. auto swapped(Slice!(Iterator, N, kind) _slice, size_t dimensionA, size_t dimensionB)
    swapped
    (
    Iterator
    size_t N
    SliceKind kind
    )
    (
    Slice!(Iterator, N, kind) _slice
    ,
    size_t dimensionA
    ,
    size_t dimensionB
    )
  3. Slice!(Iterator, 2, Universal) swapped(Slice!(Iterator, 2, kind) slice)

Parameters

dimensionA size_t

first dimension

dimensionB size_t

second dimension

Return Value

Type: auto

n-dimensional slice

Examples

Template

import mir.ndslice.slice;
import mir.ndslice.topology: iota;

assert(iota(3, 4, 5, 6)
    .swapped!(2, 1)
    .shape == cast(size_t[4])[3, 5, 4, 6]);

assert(iota(3, 4, 5, 6)
    .swapped!(3, 1)
    .shape == cast(size_t[4])[3, 6, 5, 4]);

Function

import mir.ndslice.slice;
import mir.ndslice.topology: iota;

assert(iota(3, 4, 5, 6)
    .swapped(1, 2)
    .shape == cast(size_t[4])[3, 5, 4, 6]);

assert(iota(3, 4, 5, 6)
    .swapped(1, 3)
    .shape == cast(size_t[4])[3, 6, 5, 4]);

2D

import mir.ndslice.slice;
import mir.ndslice.topology: iota;
assert(iota(3, 4)
    .swapped
    .shape == cast(size_t[2])[4, 3]);

See Also

Meta