vec32

package
v0.0.0-...-e16fa26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package vec32 provides functions for efficiently manipulating fixed-length arrays of size 32.

It is one of several packages, each operating on a single size of array:

Index

Constants

View Source
const Length = 32

Variables

This section is empty.

Functions

func Abs

func Abs[Element constraintsExt.OrderedNumber](m Bool, a [Length]Element) (r [Length]Element)

func Add

func Add[Element constraintsExt.Number](m Bool, a, b [Length]Element) (r [Length]Element)

func And

func And[Element constraints.Integer](m Bool, a, b [Length]Element) (r [Length]Element)

func AndNot

func AndNot[Element constraints.Integer](m Bool, a, b [Length]Element) (r [Length]Element)

func Blend

func Blend[Element constraintsExt.Number](m Bool, a, b [Length]Element) (r [Length]Element)

Blend returns a vector with each element drawn from b if the corresponding mask bit in m is set or a if the bit is not set. Unlike most other vector functions, Blend does not set elements in the result to zero if the corresponding mask bit is not set.

func Broadcast

func Broadcast[Element constraintsExt.Number](a Element) (r [Length]Element)

Broadcast returns a vector with a single value a copied into every element. This can be used to combine a vector with a scalar; for example: multiply every element of a vector by 10 `b := vec2.Mul(mask.SelectAll(), a, vec2.Broadcast(10))`

(Note: README-DESIGN.md explains absence of mask parameter)

func Convert

func Convert[OldType, NewType constraintsExt.OrderedNumber](m Bool, a [Length]OldType) (r [Length]NewType)

Convert returns a vector with all elements converted to another numeric type.

func Deinterlace

func Deinterlace[Element constraintsExt.Number](n int, a [Length]Element) (r, s [Length / 2]Element)

Deinterlace splits a vector into 2 half-length vectors r and s, placing n consecutive elements in r, then n consecutive elements in s. This is repeated until all the elements of a are present in r and s. This is the reverse of Interlace.

func Div

func Div[Element constraintsExt.Number](m Bool, a, b [Length]Element) (r [Length]Element)

func ElementMax

func ElementMax[Element constraints.Ordered](m Bool, a [Length]Element) (min Element, ok bool)

ElementMax returns the maximum of the elements selected by the Bool mask. If no elements are selected by the Bool mask, the result ok is false.

func ElementMin

func ElementMin[Element constraints.Ordered](m Bool, a [Length]Element) (min Element, ok bool)

ElementMin returns the minimum of the elements selected by the Bool mask. If no elements are selected by the Bool mask, the result ok is false.

func ElementProduct

func ElementProduct[Element constraintsExt.Number](m Bool, a [Length]Element) (r Element)

ElementProduct multiplies each element selected by the Bool mask and returns their product. If no elements are selected by the Bool mask, the result is 1.

func ElementSum

func ElementSum[Element constraintsExt.Number](m Bool, a [Length]Element) (r Element)

ElementSum adds each element selected by the Bool mask and returns their sum. If no elements are selected by the Bool mask, the result is 0.

func FMA

func FMA[Element constraintsExt.Number](m Bool, a, b, c [Length]Element) (r [Length]Element)

func Gather

func Gather[Element constraintsExt.Number](m Bool, p [Length]*Element) (r [Length]Element)

func GatherSlice

func GatherSlice[Element constraintsExt.Number, Index constraints.Integer](m Bool, s []Element, index [Length]Index) (r [Length]Element)

func Interlace

func Interlace[Element constraintsExt.Number](n int, a, b [Length / 2]Element) (r [Length]Element)

Interlace copies elements from two half-length vectors a and b into a single vector, taking n consecutive elements from a, then n consecutive elements from b. This is repeated until all elements of a and b have been included in the result. For example, if n is 1, the first few elements of the result will contain elements a[0], b[0], a[1], b[1], a[2], b[2], etc. If n is 2 the first few elements of the result will contain a[0], a[1], b[0], b[1], a[2], a[3], b[2], b[3], etc. Panics if n is greater than vector length or is not a power of 2.

func LeadingZeros

func LeadingZeros[Element constraints.Unsigned](m Bool, a [Length]Element) (r [Length]int)

func Max

func Max[Element constraintsExt.OrderedNumber](m Bool, a, b [Length]Element) (r [Length]Element)

func Min

func Min[Element constraintsExt.OrderedNumber](m Bool, a, b [Length]Element) (r [Length]Element)

func Mul

func Mul[Element constraintsExt.Number](m Bool, a, b [Length]Element) (r [Length]Element)

func Neg

func Neg[Element constraintsExt.Number](m Bool, a [Length]Element) (r [Length]Element)

func Not

func Not[Element constraints.Integer](m Bool, a [Length]Element) (r [Length]Element)

func OnesCount

func OnesCount[Element constraints.Unsigned](m Bool, a [Length]Element) (r [Length]int)

func Or

func Or[Element constraints.Integer](m Bool, a, b [Length]Element) (r [Length]Element)

func Permute

func Permute[Index constraints.Integer, Element constraintsExt.Number](m Bool, a [Length]Index, b [Length]Element) (r [Length]Element)

Permute returns a masked vector containing elements from b chosen from indices in a. An element from b may appear more than once in the result, or may be absent.

func ReduceElements

func ReduceElements[Element any](m Bool, a [Length]Element, f func(x, y Element) Element) (result Element, ok bool)

func RotateLeft

func RotateLeft[T constraints.Unsigned, U constraints.Integer](m Bool, a [Length]T, b [Length]U) (r [Length]T)

func Scatter

func Scatter[Element constraintsExt.Number](m Bool, p [Length]*Element, a [Length]Element)

func ScatterSlice

func ScatterSlice[Element constraintsExt.Number, Index constraints.Integer](m Bool, s []Element, index [Length]Index, a [Length]Element)

func ShiftLeft

func ShiftLeft[T, U constraints.Integer](m Bool, a [Length]T, b [Length]U) (r [Length]T)

func ShiftRight

func ShiftRight[T, U constraints.Integer](m Bool, a [Length]T, b [Length]U) (r [Length]T)

func Sub

func Sub[Element constraintsExt.Number](m Bool, a, b [Length]Element) (r [Length]Element)

func TrailingZeros

func TrailingZeros[Element constraints.Unsigned](m Bool, a [Length]Element) (r [Length]int)

func Xor

func Xor[Element constraints.Integer](m Bool, a, b [Length]Element) (r [Length]Element)

func Zero

func Zero[Element constraintsExt.Number](m Bool, a [Length]Element) (r [Length]Element)

Zero returns a vector of elements drawn from a, except where the corresponding mask bit in m is not set, in which case, the element is set to zero.

Types

type Bool

type Bool struct {
	// contains filtered or unexported fields
}

func AndNotZero

func AndNotZero[Element constraints.Integer](m Bool, a, b [Length]Element) (r Bool)

func Equal

func Equal[Element constraints.Ordered](m Bool, a, b [Length]Element) (r Bool)

func Greater

func Greater[Element constraints.Ordered](m Bool, a, b [Length]Element) (r Bool)

func GreaterOrEqual

func GreaterOrEqual[Element constraints.Ordered](m Bool, a, b [Length]Element) (r Bool)

func IsDuplicate

func IsDuplicate[Element constraintsExt.Number](m Bool, a [Length]Element) (r Bool)

IsDuplicate checks elements of vector a for values which are equal to one another. If several elements have the same value, exactly one is chosen as the original. Elements other than the original are deemed to be duplicates and have the corresponding bit set in the boolean vector result. It is not defined which value is chosen as the original. Your code should assume it is chosen at random.

func IsInf

func IsInf[Element constraints.Float](m Bool, a [Length]Element, sign int) (r Bool)

func IsNaN

func IsNaN[Element constraints.Float](m Bool, a [Length]Element) (r Bool)

func Less

func Less[Element constraints.Ordered](m Bool, a, b [Length]Element) (r Bool)

func LessOrEqual

func LessOrEqual[Element constraints.Ordered](m Bool, a, b [Length]Element) (r Bool)

func NotEqual

func NotEqual[Element constraints.Ordered](m Bool, a, b [Length]Element) (r Bool)

func SelectAll

func SelectAll() (r Bool)

func SelectFirst

func SelectFirst(n int) (r Bool)

func SelectLast

func SelectLast(n int) (r Bool)

func SelectNone

func SelectNone() (r Bool)

func (Bool) AllTrue

func (m Bool) AllTrue() bool

func (Bool) And

func (m Bool) And(n Bool) (r Bool)

func (Bool) AndNot

func (m Bool) AndNot(n Bool) (r Bool)

func (Bool) AnyTrue

func (m Bool) AnyTrue() bool

func (Bool) CountTrue

func (m Bool) CountTrue() int

func (Bool) FirstTrue

func (m Bool) FirstTrue() (i int, ok bool)

func (Bool) For

func (m Bool) For(f func(i int, c bool))

func (Bool) ForTrue

func (m Bool) ForTrue(f func(i int))

func (Bool) IsTrue

func (m Bool) IsTrue(i int) bool

func (Bool) Not

func (m Bool) Not() (r Bool)

func (Bool) Or

func (m Bool) Or(n Bool) (r Bool)

func (Bool) Set

func (m Bool) Set(i int, b bool) (r Bool)

func (Bool) ShiftLeft

func (m Bool) ShiftLeft(i int) (r Bool)

func (Bool) ShiftRight

func (m Bool) ShiftRight(i int) (r Bool)

func (Bool) Xor

func (m Bool) Xor(n Bool) (r Bool)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL