internal/asm,blas,floats: move level 2 norm to asm

This allows sharing of the blas implementation with floats and opens the
possibility of an assembly implementation of this function.
This commit is contained in:
Dan Kortschak
2019-10-18 11:42:47 +10:30
parent 0732d350bf
commit e2ba7f0950
9 changed files with 264 additions and 94 deletions

View File

@@ -261,7 +261,7 @@ func TestDistance(t *testing.T) {
copy(tmp, test.s)
Sub(tmp, test.t)
norm := Norm(tmp, L)
if dist != norm { // Use equality because they should be identical
if !EqualWithinAbsOrRel(dist, norm, 1e-15, 1e-15) {
t.Errorf("Distance does not match norm for case %v, %v. Expected %v, Found %v.", i, j, norm, dist)
}
}
@@ -1753,3 +1753,15 @@ func BenchmarkScaleSmall(b *testing.B) { benchmarkScale(b, Small) }
func BenchmarkScaleMedium(b *testing.B) { benchmarkScale(b, Medium) }
func BenchmarkScaleLarge(b *testing.B) { benchmarkScale(b, Large) }
func BenchmarkScaleHuge(b *testing.B) { benchmarkScale(b, Huge) }
func benchmarkNorm2(b *testing.B, size int) {
s := randomSlice(size)
b.ResetTimer()
for i := 0; i < b.N; i++ {
Norm(s, 2)
}
}
func BenchmarkNorm2Small(b *testing.B) { benchmarkNorm2(b, Small) }
func BenchmarkNorm2Medium(b *testing.B) { benchmarkNorm2(b, Medium) }
func BenchmarkNorm2Large(b *testing.B) { benchmarkNorm2(b, Large) }
func BenchmarkNorm2Huge(b *testing.B) { benchmarkNorm2(b, Huge) }