mirror of
https://github.com/photoprism/photoprism.git
synced 2026-07-18 00:59:38 +00:00
Split the catch-all values.go into one file per concept, each mirrored by its test: distance.go, norm.go, stats.go, product.go, centroid.go, plus the mean methods folded into mean.go and Copy/Dim/Sum into vector.go. Remove values.go, values_test.go, and values_more_test.go so functionality and tests live where developers expect them. Hoist the two 512-dimensional face embeddings shared by the distance, norm, and cosine tests into fixtures_test.go, removing the previous triplication, and decompose the monolithic TestVector into per-concept tests. Close pre-existing coverage gaps in the integer converters and the GeometricMean/HarmonicMean method wrappers, bringing the package to 100% statement coverage. Pure code movement; no behavior change.
28 lines
771 B
Go
28 lines
771 B
Go
package vector
|
|
|
|
import "math"
|
|
|
|
// Norm returns the vector size (magnitude),
|
|
// see https://builtin.com/data-science/vector-norms.
|
|
func (v Vector) Norm(pow float64) float64 {
|
|
return Norm(v, pow)
|
|
}
|
|
|
|
// EuclideanNorm returns the Euclidean vector size (magnitude),
|
|
// see https://builtin.com/data-science/vector-norms.
|
|
func (v Vector) EuclideanNorm() float64 {
|
|
return v.Norm(2.0)
|
|
}
|
|
|
|
// Norm returns the size of the vector (use pow = 2.0 for the Euclidean distance),
|
|
// see https://builtin.com/data-science/vector-norms. Absolute values are used so
|
|
// that odd powers (e.g. the L1 norm) stay well-defined for negative components.
|
|
func Norm(v Vector, pow float64) float64 {
|
|
s := 0.0
|
|
|
|
for _, f := range v {
|
|
s += math.Pow(math.Abs(f), pow)
|
|
}
|
|
|
|
return math.Pow(s, 1/pow)
|
|
}
|