Documentation ¶
Overview ¶
Package vecf64 provides common functions and methods for slices of float64.
Name ¶
In the days of yore, scientists who computed with computers would use arrays to represent vectors, each value representing magnitude and/or direction. Then came the C++ Standard Templates Library, which sought to provide this data type in the standard library. Now, everyone conflates a term "vector" with dynamic arrays.
In the C++ book, Bjarne Stroustrup has this to say:
One could argue that valarray should have been called vector because is is a traditional mathematical vector and that vector should have been called array. However, this is not the way that the terminology evolved. A valarray is a vector optimized for numeric computation; a vector is a flexible container designed for holding and manipulating objects of a wide variety of types; and an array is a low-level built-in type
Go has a better name for representing dynamically allocated arrays of any type - "slice". However, "slice" is both a noun and verb and many libraries that I use already use "slice"-as-a-verb as a name, so I had to settle for the second best name: "vector".
It should be noted that while the names used in this package were definitely mathematically inspired, they bear only little resemblance the actual mathematical operations performed.
Naming Convention ¶
The names of the operations assume you're working with slices of float64s. Hence `Add` performs elementwise addition between two []float64.
Operations between []float64 and float64 are also supported, however they are differently named. Here are the equivalents:
+------------------------+--------------------------------------+ | []float64-[]float64 Op | []float64-float64 Op | +------------------------+--------------------------------------+ | Add(a, b []float64) | Trans(a float64, b []float64) | | Sub(a, b []float64) | Trans/TransR(a float64, b []float64) | | Mul(a, b []float64) | Scale(a float64, b []float64) | | Div(a, b []float64) | Scale/DivR(a float64, b []float64) | | Pow(a, b []float64) | PowOf/PowOfR(a float64, b []float64) | +------------------------+--------------------------------------+
You may note that for the []float64 - float64 binary operations, the scalar (float64) is always the first operand. In operations that are not commutative, an additional function is provided, suffixed with "R" (for reverse)
Range Check and BCE ¶
This package does not provide range checking. If indices are out of range, the functions will panic. This package should play well with BCE.
TODO: provide SIMD vectorization for Incr and []float32-float64 functions. Pull requests accepted
Index ¶
- func Add(a, b []float64)
- func Argmax(a []float64) int
- func Argmin(a []float64) int
- func Div(a, b []float64)
- func IncrAdd(a, b, incr []float64)
- func IncrDiv(a, b, incr []float64)
- func IncrMod(a, b, incr []float64)
- func IncrMul(a, b, incr []float64)
- func IncrPow(a, b, incr []float64)
- func IncrPowOf(a []float64, s float64, incr []float64)
- func IncrPowOfR(a []float64, s float64, incr []float64)
- func IncrScale(a []float64, s float64, incr []float64)
- func IncrScaleInv(a []float64, s float64, incr []float64)
- func IncrScaleInvR(a []float64, s float64, incr []float64)
- func IncrSub(a, b, incr []float64)
- func IncrTrans(a []float64, s float64, incr []float64)
- func IncrTransInv(a []float64, s float64, incr []float64)
- func IncrTransInvR(a []float64, s float64, incr []float64)
- func InvSqrt(a []float64)
- func Max(a, b []float64)
- func MaxOf(a []float64) (retVal float64)
- func Min(a, b []float64)
- func MinOf(a []float64) (retVal float64)
- func Mod(a, b []float64)
- func Mul(a, b []float64)
- func Pow(a, b []float64)
- func PowOf(a []float64, s float64)
- func PowOfR(a []float64, s float64)
- func Range(start, end int) []float64
- func Reduce(f func(a, b float64) float64, def float64, l ...float64) (retVal float64)
- func Scale(a []float64, s float64)
- func ScaleInv(a []float64, s float64)
- func ScaleInvR(a []float64, s float64)
- func Sqrt(a []float64)
- func Sub(a, b []float64)
- func Sum(a []float64) float64
- func Trans(a []float64, s float64)
- func TransInv(a []float64, s float64)
- func TransInvR(a []float64, s float64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IncrAdd ¶
func IncrAdd(a, b, incr []float64)
IncrAdd performs a̅ + b̅ and then adds it elementwise to the incr slice
func IncrMul ¶
func IncrMul(a, b, incr []float64)
IncrMul performs a̅ × b̅ and then adds it elementwise to the incr slice
func IncrPowOf ¶
IncrPowOf performs elementwise power function and then increments the incr slice
incr += a̅ ^ s
func IncrPowOfR ¶
PowOfR performs elementwise power function below and then increments the incr slice.
incr += s ^ a̅
func IncrScale ¶
Scale multiplies all values in the slice by the scalar and then increments the incr slice
incr += a̅ * s
func IncrScaleInv ¶
IncrScaleInv divides all values in the slice by the scalar and then increments the incr slice
incr += a̅ / s
func IncrScaleInvR ¶
/ IncrScaleInvR divides all numbers in the slice by a scalar and then increments the incr slice
incr += s / a̅
func IncrSub ¶
func IncrSub(a, b, incr []float64)
IncrSub performs a̅ = b̅ and then adds it elementwise to the incr slice
func IncrTrans ¶
IncrTrans adds all the values in the slice by a scalar and then increments the incr slice
incr += a̅ + s
func IncrTransInv ¶
IncrTransInv subtracts all the values in the slice by a scalar and then increments the incr slice
incr += a̅ - s
func IncrTransInvR ¶
IncrTransInvR subtracts all the numbers in a slice from a scalar and then increments the incr slice
incr += s - a̅
func Max ¶
func Max(a, b []float64)
Max takes two slices, a̅ + b̅, and compares them elementwise. The highest value is put into a̅.
func Min ¶
func Min(a, b []float64)
Min takes two slices, a̅ + b̅ and compares them elementwise. The lowest value is put into a̅.
func ScaleInv ¶
ScaleInv divides all values in the slice by the scalar. It performs elementwise
a̅ / s
Types ¶
This section is empty.