mirror of
				https://github.com/gonum/gonum.git
				synced 2025-10-31 10:36:30 +08:00 
			
		
		
		
	Added aux file for testing and moved other functions there
This commit is contained in:
		| @@ -139,6 +139,83 @@ func (b Blas) Dgemv(o blas.Order, tA blas.Transpose, m, n int, alpha float64, a | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // Dger   performs the rank 1 operation | ||||||
|  | //    A := alpha*x*y**T + A, | ||||||
|  | // where alpha is a scalar, x is an m element vector, y is an n element | ||||||
|  | // vector and A is an m by n matrix. | ||||||
|  | func (Blas) Dger(o blas.Order, m, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int) { | ||||||
|  | 	// Check inputs | ||||||
|  | 	if o != blas.RowMajor && o != blas.ColMajor { | ||||||
|  | 		panic(badOrder) | ||||||
|  | 	} | ||||||
|  | 	if m < 0 { | ||||||
|  | 		panic("m < 0") | ||||||
|  | 	} | ||||||
|  | 	if n < 0 { | ||||||
|  | 		panic(negativeN) | ||||||
|  | 	} | ||||||
|  | 	if incX == 0 { | ||||||
|  | 		panic(zeroInc) | ||||||
|  | 	} | ||||||
|  | 	if incY == 0 { | ||||||
|  | 		panic(zeroInc) | ||||||
|  | 	} | ||||||
|  | 	if o == blas.RowMajor { | ||||||
|  | 		if lda > 1 && lda > n { | ||||||
|  | 			panic(badLda) | ||||||
|  | 		} | ||||||
|  | 	} else { | ||||||
|  | 		if lda > 1 && lda > m { | ||||||
|  | 			panic(badLda) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	// Quick return if possible | ||||||
|  | 	if m == 0 || n == 0 || alpha == 0 { | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	var jy, kx int | ||||||
|  | 	if incY > 0 { | ||||||
|  | 		jy = 1 | ||||||
|  | 	} else { | ||||||
|  | 		jy = -(n - 1) * incY | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	if incY > 0 { | ||||||
|  | 		kx = 1 | ||||||
|  | 	} else { | ||||||
|  | 		kx = -(m - 1) * incX | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	switch o { | ||||||
|  | 	default: | ||||||
|  | 		panic("should not be here") | ||||||
|  | 	case blas.RowMajor: | ||||||
|  | 		// TODO: Switch this to looping the other way | ||||||
|  | 		for j := 0; j < n; j++ { | ||||||
|  | 			if y[jy] != 0 { | ||||||
|  | 				tmp := alpha * y[jy] | ||||||
|  | 				ix := kx | ||||||
|  | 				for i := 0; i < m; i++ { | ||||||
|  | 					a[i*lda+j] += x[ix] * tmp | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			jy += incY | ||||||
|  | 		} | ||||||
|  | 	case blas.ColMajor: | ||||||
|  | 		for j := 0; j < n; j++ { | ||||||
|  | 			if y[jy] != 0 { | ||||||
|  | 				tmp := alpha * y[jy] | ||||||
|  | 				ix := kx | ||||||
|  | 				for i := 0; i < m; i++ { | ||||||
|  | 					a[j*lda+i] += x[ix] * tmp | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			jy += incY | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
| // DTRMV  performs one of the matrix-vector operations | // DTRMV  performs one of the matrix-vector operations | ||||||
| // 		x := A*x,   or   x := A**T*x, | // 		x := A*x,   or   x := A**T*x, | ||||||
| // where x is an n element vector and  A is an n by n unit, or non-unit, | // where x is an n element vector and  A is an n by n unit, or non-unit, | ||||||
| @@ -448,83 +525,6 @@ func (b Blas) Dsymv(o blas.Order, ul blas.Uplo, n int, alpha float64, a []float6 | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| // Dger   performs the rank 1 operation |  | ||||||
| //    A := alpha*x*y**T + A, |  | ||||||
| // where alpha is a scalar, x is an m element vector, y is an n element |  | ||||||
| // vector and A is an m by n matrix. |  | ||||||
| func (Blas) Dger(o blas.Order, m, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int) { |  | ||||||
| 	// Check inputs |  | ||||||
| 	if o != blas.RowMajor && o != blas.ColMajor { |  | ||||||
| 		panic(badOrder) |  | ||||||
| 	} |  | ||||||
| 	if m < 0 { |  | ||||||
| 		panic("m < 0") |  | ||||||
| 	} |  | ||||||
| 	if n < 0 { |  | ||||||
| 		panic(negativeN) |  | ||||||
| 	} |  | ||||||
| 	if incX == 0 { |  | ||||||
| 		panic(zeroInc) |  | ||||||
| 	} |  | ||||||
| 	if incY == 0 { |  | ||||||
| 		panic(zeroInc) |  | ||||||
| 	} |  | ||||||
| 	if o == blas.RowMajor { |  | ||||||
| 		if lda > 1 && lda > n { |  | ||||||
| 			panic(badLda) |  | ||||||
| 		} |  | ||||||
| 	} else { |  | ||||||
| 		if lda > 1 && lda > m { |  | ||||||
| 			panic(badLda) |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	// Quick return if possible |  | ||||||
| 	if m == 0 || n == 0 || alpha == 0 { |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	var jy, kx int |  | ||||||
| 	if incY > 0 { |  | ||||||
| 		jy = 1 |  | ||||||
| 	} else { |  | ||||||
| 		jy = -(n - 1) * incY |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	if incY > 0 { |  | ||||||
| 		kx = 1 |  | ||||||
| 	} else { |  | ||||||
| 		kx = -(m - 1) * incX |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	switch o { |  | ||||||
| 	default: |  | ||||||
| 		panic("should not be here") |  | ||||||
| 	case blas.RowMajor: |  | ||||||
| 		// TODO: Switch this to looping the other way |  | ||||||
| 		for j := 0; j < n; j++ { |  | ||||||
| 			if y[jy] != 0 { |  | ||||||
| 				tmp := alpha * y[jy] |  | ||||||
| 				ix := kx |  | ||||||
| 				for i := 0; i < m; i++ { |  | ||||||
| 					a[i*lda+j] += x[ix] * tmp |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 			jy += incY |  | ||||||
| 		} |  | ||||||
| 	case blas.ColMajor: |  | ||||||
| 		for j := 0; j < n; j++ { |  | ||||||
| 			if y[jy] != 0 { |  | ||||||
| 				tmp := alpha * y[jy] |  | ||||||
| 				ix := kx |  | ||||||
| 				for i := 0; i < m; i++ { |  | ||||||
| 					a[j*lda+i] += x[ix] * tmp |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 			jy += incY |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| /* | /* | ||||||
| // Level 2 routines. | // Level 2 routines. | ||||||
|         Dgbmv(o Order, tA Transpose, m, n, kL, kU int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) |         Dgbmv(o Order, tA Transpose, m, n, kL, kU int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) | ||||||
|   | |||||||
							
								
								
									
										79
									
								
								testblas/aux.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								testblas/aux.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,79 @@ | |||||||
|  | package testblas | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"math" | ||||||
|  | 	"testing" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | // throwPanic will throw unexpected panics if true, or will just report them as errors if false | ||||||
|  | const throwPanic = true | ||||||
|  |  | ||||||
|  | func dTolEqual(a, b float64) bool { | ||||||
|  | 	m := math.Max(math.Abs(a), math.Abs(b)) | ||||||
|  | 	if m > 1 { | ||||||
|  | 		a /= m | ||||||
|  | 		b /= m | ||||||
|  | 	} | ||||||
|  | 	if math.Abs(a-b) < 1e-14 { | ||||||
|  | 		return true | ||||||
|  | 	} | ||||||
|  | 	return false | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func dSliceTolEqual(a, b []float64) bool { | ||||||
|  | 	if len(a) != len(b) { | ||||||
|  | 		return false | ||||||
|  | 	} | ||||||
|  | 	for i := range a { | ||||||
|  | 		if !dTolEqual(a[i], b[i]) { | ||||||
|  | 			return false | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return true | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func dSliceEqual(a, b []float64) bool { | ||||||
|  | 	if len(a) != len(b) { | ||||||
|  | 		return false | ||||||
|  | 	} | ||||||
|  | 	for i := range a { | ||||||
|  | 		if !(a[i] == b[i]) { | ||||||
|  | 			return false | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	return true | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func dCopyTwoTmp(x, xTmp, y, yTmp []float64) { | ||||||
|  | 	if len(x) != len(xTmp) { | ||||||
|  | 		panic("x size mismatch") | ||||||
|  | 	} | ||||||
|  | 	if len(y) != len(yTmp) { | ||||||
|  | 		panic("y size mismatch") | ||||||
|  | 	} | ||||||
|  | 	for i, val := range x { | ||||||
|  | 		xTmp[i] = val | ||||||
|  | 	} | ||||||
|  | 	for i, val := range y { | ||||||
|  | 		yTmp[i] = val | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // returns true if the function panics | ||||||
|  | func panics(f func()) (b bool) { | ||||||
|  | 	defer func() { | ||||||
|  | 		err := recover() | ||||||
|  | 		if err != nil { | ||||||
|  | 			b = true | ||||||
|  | 		} | ||||||
|  | 	}() | ||||||
|  | 	f() | ||||||
|  | 	return | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func testpanics(f func(), name string, t *testing.T) { | ||||||
|  | 	b := panics(f) | ||||||
|  | 	if !b { | ||||||
|  | 		t.Errorf("%v should panic and does not", name) | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @@ -9,76 +9,6 @@ import ( | |||||||
| 	"testing" | 	"testing" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func dTolEqual(a, b float64) bool { |  | ||||||
| 	m := math.Max(math.Abs(a), math.Abs(b)) |  | ||||||
| 	if m > 1 { |  | ||||||
| 		a /= m |  | ||||||
| 		b /= m |  | ||||||
| 	} |  | ||||||
| 	if math.Abs(a-b) < 1e-14 { |  | ||||||
| 		return true |  | ||||||
| 	} |  | ||||||
| 	return false |  | ||||||
| } |  | ||||||
|  |  | ||||||
| func dSliceTolEqual(a, b []float64) bool { |  | ||||||
| 	if len(a) != len(b) { |  | ||||||
| 		return false |  | ||||||
| 	} |  | ||||||
| 	for i := range a { |  | ||||||
| 		if !dTolEqual(a[i], b[i]) { |  | ||||||
| 			return false |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	return true |  | ||||||
| } |  | ||||||
|  |  | ||||||
| func dSliceEqual(a, b []float64) bool { |  | ||||||
| 	if len(a) != len(b) { |  | ||||||
| 		return false |  | ||||||
| 	} |  | ||||||
| 	for i := range a { |  | ||||||
| 		if !(a[i] == b[i]) { |  | ||||||
| 			return false |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	return true |  | ||||||
| } |  | ||||||
|  |  | ||||||
| func dCopyTwoTmp(x, xTmp, y, yTmp []float64) { |  | ||||||
| 	if len(x) != len(xTmp) { |  | ||||||
| 		panic("x size mismatch") |  | ||||||
| 	} |  | ||||||
| 	if len(y) != len(yTmp) { |  | ||||||
| 		panic("y size mismatch") |  | ||||||
| 	} |  | ||||||
| 	for i, val := range x { |  | ||||||
| 		xTmp[i] = val |  | ||||||
| 	} |  | ||||||
| 	for i, val := range y { |  | ||||||
| 		yTmp[i] = val |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // returns true if the function panics |  | ||||||
| func panics(f func()) (b bool) { |  | ||||||
| 	defer func() { |  | ||||||
| 		err := recover() |  | ||||||
| 		if err != nil { |  | ||||||
| 			b = true |  | ||||||
| 		} |  | ||||||
| 	}() |  | ||||||
| 	f() |  | ||||||
| 	return |  | ||||||
| } |  | ||||||
|  |  | ||||||
| func testpanics(f func(), name string, t *testing.T) { |  | ||||||
| 	b := panics(f) |  | ||||||
| 	if !b { |  | ||||||
| 		t.Errorf("%v should panic and does not", name) |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| type DoubleOneVectorCase struct { | type DoubleOneVectorCase struct { | ||||||
| 	Name       string | 	Name       string | ||||||
| 	X          []float64 | 	X          []float64 | ||||||
|   | |||||||
| @@ -6,9 +6,6 @@ import ( | |||||||
| 	"github.com/gonum/blas" | 	"github.com/gonum/blas" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // throwPanic will throw unexpected panics if true, or will just report them as errors if false |  | ||||||
| const throwPanic = true |  | ||||||
|  |  | ||||||
| type DgemvCase struct { | type DgemvCase struct { | ||||||
| 	Name  string | 	Name  string | ||||||
| 	m     int | 	m     int | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 btracey
					btracey