1 // Copyright ©2015 The Gonum Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
11 "gonum.org/v1/gonum/floats"
14 type Drscler interface {
15 Drscl(n int, a float64, x []float64, incX int)
18 func DrsclTest(t *testing.T, impl Drscler) {
19 for _, test := range []struct {
24 x: []float64{1, 2, 3, 4, 5},
28 x: []float64{1, 2, 3, 4, 5},
32 x: []float64{1, 2, 3, 4, 5},
36 xcopy := make([]float64, len(test.x))
39 // Cannot test the scaling directly because of floating point scaling issues
40 // (the purpose of Drscl). Instead, check that scaling and scaling back
41 // yeilds approximately x. If overflow or underflow occurs then the scaling
43 impl.Drscl(len(test.x), test.a, xcopy, 1)
44 if floats.Equal(xcopy, test.x) {
45 t.Errorf("x unchanged during call to drscl. a = %v, x = %v.", test.a, test.x)
47 impl.Drscl(len(test.x), 1/test.a, xcopy, 1)
48 if !floats.EqualApprox(xcopy, test.x, 1e-14) {
49 t.Errorf("x not equal after scaling and unscaling. a = %v, x = %v.", test.a, test.x)