Documentation
¶
Overview ¶
Package vec implements vector operations acting on slices.
Operations usually take two forms: for example,
- Add(v0, v1) adds v0, v1, allocates a new vector to store the result and returns it.
- AddAssign(v0, v1, vOut) adds v0, v1 and writes the result to pre-allocated vOut without returning.
Note that in most cases, v0, v1, and vOut can overlap. However, for operations that cannot, InPlace methods are implemented separately.
For performance reasons, most functions in this package don't implement bound checks. If length mismatch happens, it may panic or produce wrong results.
Index ¶
- func Add[T num.Number](v0, v1 []T) []T
- func AddAssign[T num.Number](v0, v1, vOut []T)
- func BitReverseInPlace[T any](v []T)
- func Cast[T1, T2 num.Real](v []T1) []T2
- func CastAssign[T1, T2 num.Real](v []T1, vOut []T2)
- func CmplxToFloat4(v []complex128) []float64
- func CmplxToFloat4Assign(v []complex128, vOut []float64)
- func Copy[T any](v []T) []T
- func CopyAssign[T any](v0, v1 []T)
- func Dot[T num.Number](v0, v1 []T) T
- func ElementWiseMul[T num.Number](v0, v1 []T) []T
- func ElementWiseMulAddAssign[T num.Number](v0, v1, vOut []T)
- func ElementWiseMulAssign[T num.Number](v0, v1, vOut []T)
- func ElementWiseMulSubAssign[T num.Number](v0, v1, vOut []T)
- func Equals[T comparable](v0, v1 []T) bool
- func Fill[T any](v []T, x T)
- func Float4ToCmplx(v []float64) []complex128
- func Float4ToCmplxAssign(v []float64, vOut []complex128)
- func Neg[T num.Number](v0 []T) []T
- func NegAssign[T num.Number](v0, vOut []T)
- func Reverse[T any](v []T) []T
- func ReverseAssign[T any](v, vOut []T)
- func ReverseInPlace[T any](v []T)
- func Rotate[T any](v []T, l int) []T
- func RotateAssign[T any](v []T, l int, vOut []T)
- func RotateInPlace[T any](v []T, l int)
- func ScalarMul[T num.Number](v0 []T, c T) []T
- func ScalarMulAddAssign[T num.Number](v0 []T, c T, vOut []T)
- func ScalarMulAssign[T num.Number](v0 []T, c T, vOut []T)
- func ScalarMulSubAssign[T num.Number](v0 []T, c T, vOut []T)
- func Sub[T num.Number](v0, v1 []T) []T
- func SubAssign[T num.Number](v0, v1, vOut []T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BitReverseInPlace ¶
func BitReverseInPlace[T any](v []T)
BitReverseInPlace reorders v into bit-reversal order in-place.
func CastAssign ¶
CastAssign casts v of type []T1 to vOut of type []T2.
func CmplxToFloat4 ¶ added in v0.3.0
func CmplxToFloat4(v []complex128) []float64
CmplxToFloat4 converts a complex128 vector to float-4 representation used in fourier polynomials.
Namely, it converts
[(r0, i0), (r1, i1), (r2, i2), (r3, i3), ...]
to
[(r0, r1, r2, r3), (i0, i1, i2, i3), ...]
The length of the input vector should be multiple of 4.
func CmplxToFloat4Assign ¶ added in v0.3.0
func CmplxToFloat4Assign(v []complex128, vOut []float64)
CmplxToFloat4Assign converts a complex128 vector to float-4 representation used in fourier polynomials and writes it to vOut.
Namely, it converts
[(r0, i0), (r1, i1), (r2, i2), (r3, i3), ...]
to
[(r0, r1, r2, r3), (i0, i1, i2, i3), ...]
The length of the input vector should be multiple of 4, and the length of vOut should be 2 times of the length of v.
func ElementWiseMul ¶
ElementWiseMul returns v0 * v1, where * is an elementwise multiplication.
func ElementWiseMulAddAssign ¶
ElementWiseMulAddAssign computes vOut += v0 * v1, where * is an elementwise multiplication.
func ElementWiseMulAssign ¶
ElementWiseMulAssign computes vOut = v0 * v1, where * is an elementwise multiplication.
func ElementWiseMulSubAssign ¶
ElementWiseMulSubAssign computes vOut -= v0 * v1, where * is an elementwise multiplication.
func Float4ToCmplx ¶ added in v0.3.0
func Float4ToCmplx(v []float64) []complex128
Float4ToCmplx converts a float-4 complex vector to naturally represented complex128 vector.
Namely, it converts
[(r0, r1, r2, r3), (i0, i1, i2, i3), ...]
to
[(r0, i0), (r1, i1), (r2, i2), (r3, i3), ...]
The length of the input vector should be multiple of 8.
func Float4ToCmplxAssign ¶ added in v0.3.0
func Float4ToCmplxAssign(v []float64, vOut []complex128)
Float4ToCmplxAssign converts a float-4 complex vector to naturally represented complex128 vector and writes it to vOut.
Namely, it converts
[(r0, r1, r2, r3), (i0, i1, i2, i3), ...]
to
[(r0, i0), (r1, i1), (r2, i2), (r3, i3), ...]
The length of the input vector should be multiple of 8, and the length of vOut should be half of the length of v.
func ReverseAssign ¶
func ReverseAssign[T any](v, vOut []T)
ReverseAssign reverse v and writes it to vOut.
v and vOut should not overlap. For reversing a slice inplace, use vec.ReverseInPlace.
func Rotate ¶
Rotate rotates v l times to the right. If l < 0, then it rotates the vector l times to the left. If Abs(l) > len(s), it may panic.
func RotateAssign ¶
RotateAssign rotates v l times to the right and writes it to vOut. If l < 0, then it rotates the vector l times to the left.
v and vOut should not overlap. For rotating a slice inplace, use vec.RotateInPlace.
func RotateInPlace ¶
RotateInPlace rotates v l times to the right in-place. If l < 0, then it rotates the vector l times to the left.
func ScalarMulAddAssign ¶
ScalarMulAddAssign computes vOut += c * v0.
func ScalarMulAssign ¶
ScalarMulAssign computes vOut = c * v0.
func ScalarMulSubAssign ¶
ScalarMulSubAssign computes vOut -= c * v0.
Types ¶
This section is empty.