Exemplo n.º 1
0
func testScaling(t *testing.T, u Scaler, data *mat64.Dense, scaledData *mat64.Dense, name string) {
	// Copy data

	r, c := data.Dims()
	origData := mat64.NewDense(r, c, nil)
	for i := 0; i < r; i++ {
		for j := 0; j < c; j++ {
			origData.Set(i, j, data.At(i, j))
		}
	}

	err := ScaleData(u, data)
	if err != nil {
		t.Errorf("Error found in ScaleData for case " + name + ": " + err.Error())
	}
	/*
		for i := range data {
			if !floats.EqualApprox(data[i], scaledData[i], 1e-14) {
				t.Errorf("Improper scaling for case"+name+". Expected: %v, Found: %v", data[i], scaledData[i])
			}
		}
	*/

	if !data.EqualsApprox(scaledData, 1e-14) {
		t.Errorf("Improper scaling for case"+name+". Expected: %v, Found: %v", scaledData, data)
	}

	err = UnscaleData(u, data)
	if err != nil {
		t.Errorf("Error found in UnscaleData for case " + name + ": " + err.Error())
	}

	if !data.EqualsApprox(origData, 1e-14) {
		t.Errorf("Improper unscaling for case"+name+". Expected: %v, Found: %v", origData, data)
	}
}