Documentation ¶
Overview ¶
Package gnum provides generic numerical functions.
Index ¶
- func Abs[N Number](n N) N
- func Add[S ~[]N, N Number](a S, b ...S) S
- func Add1[S ~[]N, N Number](a S, m N) S
- func Cast[S ~[]N, T ~[]M, N Number, M Number](a S) T
- func Copy[S ~[]N, N any](a S) S
- func Corr[S ~[]N, N Number](a, b S) float64
- func Cov[S ~[]N, N Number](a, b S) float64
- func Diff[N Number](a, b N) N
- func Dot[S ~[]N, N Number](a, b S) N
- func Entropy[S ~[]N, N Number](a S) float64
- func L1[S ~[]N, N Number](a, b S) N
- func L2[S ~[]N, N Number](a, b S) float64
- func Lp[S ~[]N, N Number](p int) func(S, S) float64
- func Max[S ~[]N, N constraints.Ordered](s S) N
- func Mean[S ~[]N, N Number](a S) float64
- func Min[S ~[]N, N constraints.Ordered](s S) N
- func Mul[S ~[]N, N Number](a S, b ...S) S
- func Mul1[S ~[]N, N Number](a S, m N) S
- func Norm[S ~[]N, N constraints.Float](a S) float64
- func Ones[S ~[]N, N Number](n int) S
- func Std[S ~[]N, N Number](a S) float64
- func Sub[S ~[]N, N Number](a S, b ...S) S
- func Sub1[S ~[]N, N Number](a S, m N) S
- func Sum[S ~[]N, N Number](a S) N
- func Var[S ~[]N, N Number](a S) float64
- type Number
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
func Add[S ~[]N, N Number](a S, b ...S) S
Add adds b to a and returns a. b is unchanged. If a is nil, creates a new vector.
func Entropy ¶
Entropy returns the Shannon-entropy of a. The elements in a don't have to sum up to 1.
func L1 ¶
func L1[S ~[]N, N Number](a, b S) N
L1 returns the L1 (Manhattan) distance between a and b. Equivalent to Lp(1) but returns the same type.
func Lp ¶
Lp returns an Lp distance function. Lp is calculated as follows:
Lp(v) = (sum_i(v[i]^p))^(1/p)
func Max ¶
func Max[S ~[]N, N constraints.Ordered](s S) N
Max returns the maximal value in the slice or zero if the slice is empty.
func Min ¶
func Min[S ~[]N, N constraints.Ordered](s S) N
Min returns the maximal value in the slice or zero if the slice is empty.
func Mul ¶
func Mul[S ~[]N, N Number](a S, b ...S) S
Mul multiplies a by b and returns a. b is unchanged. If a is nil, creates a new vector.
func Mul1 ¶
func Mul1[S ~[]N, N Number](a S, m N) S
Mul1 multiplies the values of a by m and returns a.
func Norm ¶
func Norm[S ~[]N, N constraints.Float](a S) float64
Norm returns the L2 norm of the vector.
Types ¶
type Number ¶
type Number interface { constraints.Float | constraints.Integer }
Number is a constraint that contains comparable numbers.