Skip to main content
Log in

Mojo struct

SIMD

Represents a small vector that is backed by a hardware vector element.

SIMD allows a single instruction to be executed across the multiple data elements of the vector.

Constraints:

The size of the SIMD vector to be positive and a power of 2.

Parameters

  • type (DType): The data type of SIMD vector elements.
  • size (Int): The size of the SIMD vector.

Aliases

  • element_type = type:
  • MAX = max_or_inf[::DType](): Gets the maximum value for the SIMD value, potentially +inf.
  • MIN = min_or_neg_inf[::DType](): Gets the minimum value for the SIMD value, potentially -inf.
  • MAX_FINITE = max_finite[::DType](): Returns the maximum finite value of SIMD value.
  • MIN_FINITE = min_finite[::DType](): Returns the minimum (lowest) finite value of SIMD value.

Fields

  • value (simd<#lit.struct.extract<:@stdlib::@builtin::@int::@Int size, "value">, #lit.struct.extract<:@stdlib::@builtin::@dtype::@DType type, "value">>): The underlying storage for the vector.

Implemented traits

Absable, AnyType, Boolable, BoolableCollectionElement, CeilDivable, Ceilable, CollectionElement, CollectionElementNew, Copyable, ExplicitlyCopyable, Floorable, Formattable, Hashable, Intable, Movable, Powable, Representable, Roundable, Sized, Stringable, Truncable

Methods

__init__

__init__(inout self: Self)

Default initializer of the SIMD vector.

By default the SIMD vectors are initialized to all zeros.

__init__(inout self: Self, *, other: Self)

Explicitly copy the provided value.

Args:

  • other (Self): The value to copy.

__init__(inout self: Self, value: UInt)

Initializes the SIMD vector with an unsigned integer.

The unsigned integer value is splatted across all the elements of the SIMD vector.

Args:

  • value (UInt): The input value.

__init__(inout self: Self, value: Int)

Initializes the SIMD vector with a signed integer.

The signed integer value is splatted across all the elements of the SIMD vector.

Args:

  • value (Int): The input value.

__init__(inout self: Self, value: IntLiteral)

Initializes the SIMD vector with an integer.

The integer value is splatted across all the elements of the SIMD vector.

Args:

  • value (IntLiteral): The input value.

__init__(inout self: SIMD[bool, size], value: Bool, /)

Initializes the SIMD vector with a bool value.

The bool value is splatted across all elements of the SIMD vector.

Args:

  • value (Bool): The bool value.

__init__(inout self: Self, value: simd<#lit.struct.extract<:_stdlib::_builtin::_int::_Int size, "value">, #lit.struct.extract<:_stdlib::_builtin::_dtype::_DType type, "value">>)

Initializes the SIMD vector with the underlying mlir value.

Args:

  • value (simd<#lit.struct.extract<:_stdlib::_builtin::_int::_Int size, "value">, #lit.struct.extract<:_stdlib::_builtin::_dtype::_DType type, "value">>): The input value.

__init__(inout self: Self, value: SIMD[type, 1], /)

Constructs a SIMD vector by splatting a scalar value.

The input value is splatted across all elements of the SIMD vector.

Args:

  • value (SIMD[type, 1]): The value to splat to the elements of the vector.

__init__(inout self: Self, *elems: SIMD[type, 1])

Constructs a SIMD vector via a variadic list of elements.

The input values are assigned to the corresponding elements of the SIMD vector.

Constraints:

The number of input values is equal to size of the SIMD vector.

Args:

  • *elems (SIMD[type, 1]): The variadic list of elements from which the SIMD vector is constructed.

__init__(inout self: Self, value: FloatLiteral)

Initializes the SIMD vector with a float.

The value is splatted across all the elements of the SIMD vector.

Args:

  • value (FloatLiteral): The input value.

__bool__

__bool__(self: Self) -> Bool

Converts the SIMD scalar into a boolean value.

Constraints:

The size of the SIMD vector must be 1.

Returns:

True if the SIMD scalar is non-zero and False otherwise.

__getitem__

__getitem__(self: Self, idx: Int) -> SIMD[type, 1]

Gets an element from the vector.

Args:

  • idx (Int): The element index.

Returns:

The value at position idx.

__setitem__

__setitem__(inout self: Self, idx: Int, val: SIMD[type, 1])

Sets an element in the vector.

Args:

  • idx (Int): The index to set.
  • val (SIMD[type, 1]): The value to set.

__neg__

__neg__(self: Self) -> Self

Defines the unary - operation.

Returns:

The negation of this SIMD vector.

__pos__

__pos__(self: Self) -> Self

Defines the unary + operation.

Returns:

This SIMD vector.

__invert__

__invert__(self: Self) -> Self

Returns ~self.

Constraints:

The element type of the SIMD vector must be boolean or integral.

Returns:

The ~self value.

__lt__

__lt__(self: Self, rhs: Self) -> SIMD[bool, size]

Compares two SIMD vectors using less-than comparison.

Args:

  • rhs (Self): The rhs of the operation.

Returns:

A new bool SIMD vector of the same size whose element at position i is True or False depending on the expression self[i] < rhs[i].

__le__

__le__(self: Self, rhs: Self) -> SIMD[bool, size]

Compares two SIMD vectors using less-than-or-equal comparison.

Args:

  • rhs (Self): The rhs of the operation.

Returns:

A new bool SIMD vector of the same size whose element at position i is True or False depending on the expression self[i] <= rhs[i].

__eq__

__eq__(self: Self, rhs: Self) -> SIMD[bool, size]

Compares two SIMD vectors using equal-to comparison.

Args:

  • rhs (Self): The rhs of the operation.

Returns:

A new bool SIMD vector of the same size whose element at position i is True or False depending on the expression self[i] == rhs[i].

__ne__

__ne__(self: Self, rhs: Self) -> SIMD[bool, size]

Compares two SIMD vectors using not-equal comparison.

Args:

  • rhs (Self): The rhs of the operation.

Returns:

A new bool SIMD vector of the same size whose element at position i is True or False depending on the expression self[i] != rhs[i].

__gt__

__gt__(self: Self, rhs: Self) -> SIMD[bool, size]

Compares two SIMD vectors using greater-than comparison.

Args:

  • rhs (Self): The rhs of the operation.

Returns:

A new bool SIMD vector of the same size whose element at position i is True or False depending on the expression self[i] > rhs[i].

__ge__

__ge__(self: Self, rhs: Self) -> SIMD[bool, size]

Compares two SIMD vectors using greater-than-or-equal comparison.

Args:

  • rhs (Self): The rhs of the operation.

Returns:

A new bool SIMD vector of the same size whose element at position i is True or False depending on the expression self[i] >= rhs[i].

__contains__

__contains__(self: Self, value: SIMD[type, 1]) -> Bool

Whether the vector contains the value.

Args:

  • value (SIMD[type, 1]): The value.

Returns:

Whether the vector contains the value.

__add__

__add__(self: Self, rhs: Self) -> Self

Computes self + rhs.

Args:

  • rhs (Self): The rhs value.

Returns:

A new vector whose element at position i is computed as self[i] + rhs[i].

__sub__

__sub__(self: Self, rhs: Self) -> Self

Computes self - rhs.

Args:

  • rhs (Self): The rhs value.

Returns:

A new vector whose element at position i is computed as self[i] - rhs[i].

__mul__

__mul__(self: Self, rhs: Self) -> Self

Computes self * rhs.

Args:

  • rhs (Self): The rhs value.

Returns:

A new vector whose element at position i is computed as self[i] * rhs[i].

__truediv__

__truediv__(self: Self, rhs: Self) -> Self

Computes self / rhs.

Args:

  • rhs (Self): The rhs value.

Returns:

A new vector whose element at position i is computed as self[i] / rhs[i].

__floordiv__

__floordiv__(self: Self, rhs: Self) -> Self

Returns the division of self and rhs rounded down to the nearest integer.

Constraints:

The element type of the SIMD vector must be numeric.

Args:

  • rhs (Self): The value to divide with.

Returns:

floor(self / rhs) value.

__mod__

__mod__(self: Self, rhs: Self) -> Self

Returns the remainder of self divided by rhs.

Args:

  • rhs (Self): The value to divide on.

Returns:

The remainder of dividing self by rhs.

__pow__

__pow__(self: Self, exp: Int) -> Self

Computes the vector raised to the power of the input integer value.

Args:

  • exp (Int): The exponent value.

Returns:

A SIMD vector where each element is raised to the power of the specified exponent value.

__pow__(self: Self, exp: Self) -> Self

Computes the vector raised elementwise to the right hand side power.

Args:

  • exp (Self): The exponent value.

Returns:

A SIMD vector where each element is raised to the power of the specified exponent value.

__lshift__

__lshift__(self: Self, rhs: Self) -> Self

Returns self << rhs.

Constraints:

The element type of the SIMD vector must be integral.

Args:

  • rhs (Self): The RHS value.

Returns:

self << rhs.

__rshift__

__rshift__(self: Self, rhs: Self) -> Self

Returns self >> rhs.

Constraints:

The element type of the SIMD vector must be integral.

Args:

  • rhs (Self): The RHS value.

Returns:

self >> rhs.

__and__

__and__(self: Self, rhs: Self) -> Self

Returns self & rhs.

Constraints:

The element type of the SIMD vector must be bool or integral.

Args:

  • rhs (Self): The RHS value.

Returns:

self & rhs.

__or__

__or__(self: Self, rhs: Self) -> Self

Returns self | rhs.

Constraints:

The element type of the SIMD vector must be bool or integral.

Args:

  • rhs (Self): The RHS value.

Returns:

self | rhs.

__xor__

__xor__(self: Self, rhs: Self) -> Self

Returns self ^ rhs.

Constraints:

The element type of the SIMD vector must be bool or integral.

Args:

  • rhs (Self): The RHS value.

Returns:

self ^ rhs.

__radd__

__radd__(self: Self, value: Self) -> Self

Returns value + self.

Args:

  • value (Self): The other value.

Returns:

value + self.

__rsub__

__rsub__(self: Self, value: Self) -> Self

Returns value - self.

Args:

  • value (Self): The other value.

Returns:

value - self.

__rmul__

__rmul__(self: Self, value: Self) -> Self

Returns value * self.

Args:

  • value (Self): The other value.

Returns:

value * self.

__rtruediv__

__rtruediv__(self: Self, value: Self) -> Self

Returns value / self.

Args:

  • value (Self): The other value.

Returns:

value / self.

__rfloordiv__

__rfloordiv__(self: Self, rhs: Self) -> Self

Returns the division of rhs and self rounded down to the nearest integer.

Constraints:

The element type of the SIMD vector must be numeric.

Args:

  • rhs (Self): The value to divide by self.

Returns:

floor(rhs / self) value.

__rmod__

__rmod__(self: Self, value: Self) -> Self

Returns value mod self.

Args:

  • value (Self): The other value.

Returns:

value mod self.

__rlshift__

__rlshift__(self: Self, value: Self) -> Self

Returns value << self.

Constraints:

The element type of the SIMD vector must be integral.

Args:

  • value (Self): The other value.

Returns:

value << self.

__rrshift__

__rrshift__(self: Self, value: Self) -> Self

Returns value >> self.

Constraints:

The element type of the SIMD vector must be integral.

Args:

  • value (Self): The other value.

Returns:

value >> self.

__rand__

__rand__(self: Self, value: Self) -> Self

Returns value & self.

Constraints:

The element type of the SIMD vector must be bool or integral.

Args:

  • value (Self): The other value.

Returns:

value & self.

__ror__

__ror__(self: Self, value: Self) -> Self

Returns value | self.

Constraints:

The element type of the SIMD vector must be bool or integral.

Args:

  • value (Self): The other value.

Returns:

value | self.

__rxor__

__rxor__(self: Self, value: Self) -> Self

Returns value ^ self.

Constraints:

The element type of the SIMD vector must be bool or integral.

Args:

  • value (Self): The other value.

Returns:

value ^ self.

__iadd__

__iadd__(inout self: Self, rhs: Self)

Performs in-place addition.

The vector is mutated where each element at position i is computed as self[i] + rhs[i].

Args:

  • rhs (Self): The rhs of the addition operation.

__isub__

__isub__(inout self: Self, rhs: Self)

Performs in-place subtraction.

The vector is mutated where each element at position i is computed as self[i] - rhs[i].

Args:

  • rhs (Self): The rhs of the operation.

__imul__

__imul__(inout self: Self, rhs: Self)

Performs in-place multiplication.

The vector is mutated where each element at position i is computed as self[i] * rhs[i].

Args:

  • rhs (Self): The rhs of the operation.

__itruediv__

__itruediv__(inout self: Self, rhs: Self)

In-place true divide operator.

The vector is mutated where each element at position i is computed as self[i] / rhs[i].

Args:

  • rhs (Self): The rhs of the operation.

__ifloordiv__

__ifloordiv__(inout self: Self, rhs: Self)

In-place flood div operator.

The vector is mutated where each element at position i is computed as self[i] // rhs[i].

Args:

  • rhs (Self): The rhs of the operation.

__imod__

__imod__(inout self: Self, rhs: Self)

In-place mod operator.

The vector is mutated where each element at position i is computed as self[i] % rhs[i].

Args:

  • rhs (Self): The rhs of the operation.

__ipow__

__ipow__(inout self: Self, rhs: Int)

In-place pow operator.

The vector is mutated where each element at position i is computed as pow(self[i], rhs).

Args:

  • rhs (Int): The rhs of the operation.

__ilshift__

__ilshift__(inout self: Self, rhs: Self)

Computes self << rhs and save the result in self.

Constraints:

The element type of the SIMD vector must be integral.

Args:

  • rhs (Self): The RHS value.

__irshift__

__irshift__(inout self: Self, rhs: Self)

Computes self >> rhs and save the result in self.

Constraints:

The element type of the SIMD vector must be integral.

Args:

  • rhs (Self): The RHS value.

__iand__

__iand__(inout self: Self, rhs: Self)

Computes self & rhs and save the result in self.

Constraints:

The element type of the SIMD vector must be bool or integral.

Args:

  • rhs (Self): The RHS value.

__ixor__

__ixor__(inout self: Self, rhs: Self)

Computes self ^ rhs and save the result in self.

Constraints:

The element type of the SIMD vector must be bool or integral.

Args:

  • rhs (Self): The RHS value.

__ior__

__ior__(inout self: Self, rhs: Self)

Computes self | rhs and save the result in self.

Constraints:

The element type of the SIMD vector must be bool or integral.

Args:

  • rhs (Self): The RHS value.

__len__

__len__(self: Self) -> Int

Gets the length of the SIMD vector.

Returns:

The length of the SIMD vector.

__int__

__int__(self: Self) -> Int

Casts to the value to an Int. If there is a fractional component, then the fractional part is truncated.

Constraints:

The size of the SIMD vector must be 1.

Returns:

The value as an integer.

__str__

__str__(self: Self) -> String

Get the SIMD as a string.

Returns:

A string representation.

__repr__

__repr__(self: Self) -> String

Get the representation of the SIMD value e.g. "SIMD[DType.int8, 2](1, 2)".

Returns:

The representation of the SIMD value.

__floor__

__floor__(self: Self) -> Self

Performs elementwise floor on the elements of a SIMD vector.

Returns:

The elementwise floor of this SIMD vector.

__ceil__

__ceil__(self: Self) -> Self

Performs elementwise ceiling on the elements of a SIMD vector.

Returns:

The elementwise ceiling of this SIMD vector.

__trunc__

__trunc__(self: Self) -> Self

Performs elementwise truncation on the elements of a SIMD vector.

Returns:

The elementwise truncated values of this SIMD vector.

__abs__

__abs__(self: Self) -> Self

Defines the absolute value operation.

Returns:

The absolute value of this SIMD vector.

__round__

__round__(self: Self) -> Self

Performs elementwise rounding on the elements of a SIMD vector.

This rounding goes to the nearest integer with ties away from zero.

Returns:

The elementwise rounded value of this SIMD vector.

__round__(self: Self, ndigits: Int) -> Self

Performs elementwise rounding on the elements of a SIMD vector.

This rounding goes to the nearest integer with ties away from zero.

Args:

  • ndigits (Int): The number of digits to round to.

Returns:

The elementwise rounded value of this SIMD vector.

__hash__

__hash__(self: Self) -> UInt

Hash the value using builtin hash.

Returns:

A 64-bit hash value. This value is not suitable for cryptographic uses. Its intended usage is for data structures. See the hash builtin documentation for more details.

cast

cast[target: DType](self: Self) -> SIMD[$0, size]

Casts the elements of the SIMD vector to the target element type.

Parameters:

  • target (DType): The target DType.

Returns:

A new SIMD vector whose elements have been casted to the target element type.

format_to

format_to(self: Self, inout writer: Formatter)

Formats this SIMD value to the provided formatter.

Args:

  • writer (Formatter): The formatter to write to.

format_to[use_scientific_notation: Bool](self: Self, inout writer: Formatter)

Formats this SIMD value to the provided formatter.

Parameters:

  • use_scientific_notation (Bool): Whether floats should use scientific notation. This parameter does not apply to integer types.

Args:

  • writer (Formatter): The formatter to write to.

clamp

clamp(self: Self, lower_bound: Self, upper_bound: Self) -> Self

Clamps the values in a SIMD vector to be in a certain range.

Clamp cuts values in the input SIMD vector off at the upper bound and lower bound values. For example, SIMD vector [0, 1, 2, 3] clamped to a lower bound of 1 and an upper bound of 2 would return [1, 1, 2, 2].

Args:

  • lower_bound (Self): Minimum of the range to clamp to.
  • upper_bound (Self): Maximum of the range to clamp to.

Returns:

A new SIMD vector containing x clamped to be within lower_bound and upper_bound.

roundeven

roundeven(self: Self) -> Self

Performs elementwise banker's rounding on the elements of a SIMD vector.

This rounding goes to the nearest integer with ties toward the nearest even integer.

Returns:

The elementwise banker's rounding of this SIMD vector.

fma

fma(self: Self, multiplier: Self, accumulator: Self) -> Self

Performs a fused multiply-add operation, i.e. self*multiplier + accumulator.

Args:

  • multiplier (Self): The value to multiply.
  • accumulator (Self): The value to accumulate.

Returns:

A new vector whose element at position i is computed as self[i]*multiplier[i] + accumulator[i].

shuffle

shuffle[*mask: Int](self: Self) -> Self

Shuffles (also called blend) the values of the current vector with the other value using the specified mask (permutation). The mask values must be within 2 * len(self).

Parameters:

  • *mask (Int): The permutation to use in the shuffle.

Returns:

A new vector with the same length as the mask where the value at position i is (self)[permutation[i]].

shuffle[*mask: Int](self: Self, other: Self) -> Self

Shuffles (also called blend) the values of the current vector with the other value using the specified mask (permutation). The mask values must be within 2 * len(self).

Parameters:

  • *mask (Int): The permutation to use in the shuffle.

Args:

  • other (Self): The other vector to shuffle with.

Returns:

A new vector with the same length as the mask where the value at position i is (self + other)[permutation[i]].

shuffle[mask: StaticIntTuple[size]](self: Self) -> Self

Shuffles (also called blend) the values of the current vector with the other value using the specified mask (permutation). The mask values must be within 2 * len(self).

Parameters:

  • mask (StaticIntTuple[size]): The permutation to use in the shuffle.

Returns:

A new vector with the same length as the mask where the value at position i is (self)[permutation[i]].

shuffle[mask: StaticIntTuple[size]](self: Self, other: Self) -> Self

Shuffles (also called blend) the values of the current vector with the other value using the specified mask (permutation). The mask values must be within 2 * len(self).

Parameters:

  • mask (StaticIntTuple[size]): The permutation to use in the shuffle.

Args:

  • other (Self): The other vector to shuffle with.

Returns:

A new vector with the same length as the mask where the value at position i is (self + other)[permutation[i]].

slice

slice[output_width: Int, /, *, offset: Int = 0](self: Self) -> SIMD[type, $0]

Returns a slice of the vector of the specified width with the given offset.

Constraints:

output_width + offset must not exceed the size of this SIMD vector.

Parameters:

  • output_width (Int): The output SIMD vector size.
  • offset (Int): The given offset for the slice.

Returns:

A new vector whose elements map to self[offset:offset+output_width].

insert

insert[*, offset: Int = 0](self: Self, value: SIMD[type, size]) -> Self

Returns a new vector where the elements between offset and offset + input_width have been replaced with the elements in value.

Parameters:

  • offset (Int): The offset to insert at.

Args:

  • value (SIMD[type, size]): The value to be inserted.

Returns:

A new vector whose elements at self[offset:offset+input_width] contain the values of value.

join

join(self: Self, other: Self) -> SIMD[type, __mul__(2, size)]

Concatenates the two vectors together.

Args:

  • other (Self): The other SIMD vector.

Returns:

A new vector self_0, self_1, ..., self_n, other_0, ..., other_n.

interleave

interleave(self: Self, other: Self) -> SIMD[type, __mul__(2, size)]

Constructs a vector by interleaving two input vectors.

Args:

  • other (Self): The other SIMD vector.

Returns:

A new vector self_0, other_0, ..., self_n, other_n.

split

split(self: Self) -> Tuple[SIMD[type, __floordiv__(size, 2)], SIMD[type, __floordiv__(size, 2)]]

Splits the SIMD vector into 2 subvectors.

Returns:

A new vector self_0:N/2, self_N/2:N.

deinterleave

deinterleave(self: Self) -> Tuple[SIMD[type, __floordiv__(size, 2)], SIMD[type, __floordiv__(size, 2)]]

Constructs two vectors by deinterleaving the even and odd lanes of the vector.

Constraints:

The vector size must be greater than 1.

Returns:

Two vectors the first of the form self_0, self_2, ..., self_{n-2} and the other being self_1, self_3, ..., self_{n-1}.

reduce

reduce[func: fn[DType, Int](SIMD[$0, $1], SIMD[$0, $1]) capturing -> SIMD[$0, $1], size_out: Int = 1](self: Self) -> SIMD[type, $1]

Reduces the vector using a provided reduce operator.

Constraints:

size_out must not exceed width of the vector.

Parameters:

  • func (fn[DType, Int](SIMD[$0, $1], SIMD[$0, $1]) capturing -> SIMD[$0, $1]): The reduce function to apply to elements in this SIMD.
  • size_out (Int): The width of the reduction.

Returns:

A new scalar which is the reduction of all vector elements.

reduce_max

reduce_max[size_out: Int = 1](self: Self) -> SIMD[type, $0]

Reduces the vector using the max operator.

Constraints:

size_out must not exceed width of the vector. The element type of the vector must be integer or FP.

Parameters:

  • size_out (Int): The width of the reduction.

Returns:

The maximum element of the vector.

reduce_min

reduce_min[size_out: Int = 1](self: Self) -> SIMD[type, $0]

Reduces the vector using the min operator.

Constraints:

size_out must not exceed width of the vector. The element type of the vector must be integer or FP.

Parameters:

  • size_out (Int): The width of the reduction.

Returns:

The minimum element of the vector.

reduce_add

reduce_add[size_out: Int = 1](self: Self) -> SIMD[type, $0]

Reduces the vector using the add operator.

Constraints:

size_out must not exceed width of the vector.

Parameters:

  • size_out (Int): The width of the reduction.

Returns:

The sum of all vector elements.

reduce_mul

reduce_mul[size_out: Int = 1](self: Self) -> SIMD[type, $0]

Reduces the vector using the mul operator.

Constraints:

size_out must not exceed width of the vector. The element type of the vector must be integer or FP.

Parameters:

  • size_out (Int): The width of the reduction.

Returns:

The product of all vector elements.

reduce_and

reduce_and[size_out: Int = 1](self: Self) -> SIMD[type, $0]

Reduces the vector using the bitwise & operator.

Constraints:

size_out must not exceed width of the vector. The element type of the vector must be integer or boolean.

Parameters:

  • size_out (Int): The width of the reduction.

Returns:

The reduced vector.

reduce_or

reduce_or[size_out: Int = 1](self: Self) -> SIMD[type, $0]

Reduces the vector using the bitwise | operator.

Constraints:

size_out must not exceed width of the vector. The element type of the vector must be integer or boolean.

Parameters:

  • size_out (Int): The width of the reduction.

Returns:

The reduced vector.

reduce_bit_count

reduce_bit_count(self: Self) -> Int

Returns the total number of bits set in the SIMD vector.

Constraints:

Must be either an integral or a boolean type.

Returns:

Count of set bits across all elements of the vector.

select

select[result_type: DType](self: Self, true_case: SIMD[result_type, size], false_case: SIMD[result_type, size]) -> SIMD[$0, size]

Selects the values of the true_case or the false_case based on the current boolean values of the SIMD vector.

Constraints:

The element type of the vector must be boolean.

Parameters:

  • result_type (DType): The element type of the input and output SIMD vectors.

Args:

  • true_case (SIMD[result_type, size]): The values selected if the positional value is True.
  • false_case (SIMD[result_type, size]): The values selected if the positional value is False.

Returns:

A new vector of the form [true_case[i] if elem else false_case[i] for i, elem in enumerate(self)].

rotate_left

rotate_left[shift: Int](self: Self) -> Self

Shifts the elements of a SIMD vector to the left by shift elements (with wrap-around).

Constraints:

-size <= shift < size

Parameters:

  • shift (Int): The number of positions by which to rotate the elements of SIMD vector to the left (with wrap-around).

Returns:

The SIMD vector rotated to the left by shift elements (with wrap-around).

rotate_right

rotate_right[shift: Int](self: Self) -> Self

Shifts the elements of a SIMD vector to the right by shift elements (with wrap-around).

Constraints:

-size < shift <= size

Parameters:

  • shift (Int): The number of positions by which to rotate the elements of SIMD vector to the right (with wrap-around).

Returns:

The SIMD vector rotated to the right by shift elements (with wrap-around).

shift_left

shift_left[shift: Int](self: Self) -> Self

Shifts the elements of a SIMD vector to the left by shift elements (no wrap-around, fill with zero).

Constraints:

0 <= shift <= size

Parameters:

  • shift (Int): The number of positions by which to rotate the elements of SIMD vector to the left (no wrap-around, fill with zero).

Returns:

The SIMD vector rotated to the left by shift elements (no wrap-around, fill with zero).

shift_right

shift_right[shift: Int](self: Self) -> Self

Shifts the elements of a SIMD vector to the right by shift elements (no wrap-around, fill with zero).

Constraints:

0 <= shift <= size

Parameters:

  • shift (Int): The number of positions by which to rotate the elements of SIMD vector to the right (no wrap-around, fill with zero).

Returns:

The SIMD vector rotated to the right by shift elements (no wrap-around, fill with zero).

Was this page helpful?