mirror of
				https://github.com/gonum/gonum.git
				synced 2025-11-01 02:52:49 +08:00 
			
		
		
		
	lapack,mat: rename SVDInPlace constant to SVDStore
This commit is contained in:
		 Vladimir Chalupecky
					Vladimir Chalupecky
				
			
				
					committed by
					
						 Vladimír Chalupecký
						Vladimír Chalupecký
					
				
			
			
				
	
			
			
			 Vladimír Chalupecký
						Vladimír Chalupecký
					
				
			
						parent
						
							ac10ac454b
						
					
				
				
					commit
					3a1f3daf9f
				
			| @@ -26,7 +26,7 @@ const noSVDO = "dgesvd: not coded for overwrite" | |||||||
| // jobU and jobVT are options for computing the singular vectors. The behavior | // jobU and jobVT are options for computing the singular vectors. The behavior | ||||||
| // is as follows | // is as follows | ||||||
| //  jobU == lapack.SVDAll       All m columns of U are returned in u | //  jobU == lapack.SVDAll       All m columns of U are returned in u | ||||||
| //  jobU == lapack.SVDInPlace   The first min(m,n) columns are returned in u | //  jobU == lapack.SVDStore     The first min(m,n) columns are returned in u | ||||||
| //  jobU == lapack.SVDOverwrite The first min(m,n) columns of U are written into a | //  jobU == lapack.SVDOverwrite The first min(m,n) columns of U are written into a | ||||||
| //  jobU == lapack.SVDNone      The columns of U are not computed. | //  jobU == lapack.SVDNone      The columns of U are not computed. | ||||||
| // The behavior is the same for jobVT and the rows of V^T. At most one of jobU | // The behavior is the same for jobVT and the rows of V^T. At most one of jobU | ||||||
| @@ -40,12 +40,12 @@ const noSVDO = "dgesvd: not coded for overwrite" | |||||||
| // values in decreasing order. | // values in decreasing order. | ||||||
| // | // | ||||||
| // u contains the left singular vectors on exit, stored column-wise. If | // u contains the left singular vectors on exit, stored column-wise. If | ||||||
| // jobU == lapack.SVDAll, u is of size m×m. If jobU == lapack.SVDInPlace u is | // jobU == lapack.SVDAll, u is of size m×m. If jobU == lapack.SVDStore u is | ||||||
| // of size m×min(m,n). If jobU == lapack.SVDOverwrite or lapack.SVDNone, u is | // of size m×min(m,n). If jobU == lapack.SVDOverwrite or lapack.SVDNone, u is | ||||||
| // not used. | // not used. | ||||||
| // | // | ||||||
| // vt contains the left singular vectors on exit, stored row-wise. If | // vt contains the left singular vectors on exit, stored row-wise. If | ||||||
| // jobV == lapack.SVDAll, vt is of size n×m. If jobVT == lapack.SVDInPlace vt is | // jobV == lapack.SVDAll, vt is of size n×m. If jobVT == lapack.SVDStore vt is | ||||||
| // of size min(m,n)×n. If jobVT == lapack.SVDOverwrite or lapack.SVDNone, vt is | // of size min(m,n)×n. If jobVT == lapack.SVDOverwrite or lapack.SVDNone, vt is | ||||||
| // not used. | // not used. | ||||||
| // | // | ||||||
| @@ -61,12 +61,12 @@ func (impl Implementation) Dgesvd(jobU, jobVT lapack.SVDJob, m, n int, a []float | |||||||
| 	checkMatrix(m, n, a, lda) | 	checkMatrix(m, n, a, lda) | ||||||
| 	if jobU == lapack.SVDAll { | 	if jobU == lapack.SVDAll { | ||||||
| 		checkMatrix(m, m, u, ldu) | 		checkMatrix(m, m, u, ldu) | ||||||
| 	} else if jobU == lapack.SVDInPlace { | 	} else if jobU == lapack.SVDStore { | ||||||
| 		checkMatrix(m, minmn, u, ldu) | 		checkMatrix(m, minmn, u, ldu) | ||||||
| 	} | 	} | ||||||
| 	if jobVT == lapack.SVDAll { | 	if jobVT == lapack.SVDAll { | ||||||
| 		checkMatrix(n, n, vt, ldvt) | 		checkMatrix(n, n, vt, ldvt) | ||||||
| 	} else if jobVT == lapack.SVDInPlace { | 	} else if jobVT == lapack.SVDStore { | ||||||
| 		checkMatrix(minmn, n, vt, ldvt) | 		checkMatrix(minmn, n, vt, ldvt) | ||||||
| 	} | 	} | ||||||
| 	if jobU == lapack.SVDOverwrite && jobVT == lapack.SVDOverwrite { | 	if jobU == lapack.SVDOverwrite && jobVT == lapack.SVDOverwrite { | ||||||
| @@ -83,13 +83,13 @@ func (impl Implementation) Dgesvd(jobU, jobVT lapack.SVDJob, m, n int, a []float | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	wantua := jobU == lapack.SVDAll | 	wantua := jobU == lapack.SVDAll | ||||||
| 	wantus := jobU == lapack.SVDInPlace | 	wantus := jobU == lapack.SVDStore | ||||||
| 	wantuas := wantua || wantus | 	wantuas := wantua || wantus | ||||||
| 	wantuo := jobU == lapack.SVDOverwrite | 	wantuo := jobU == lapack.SVDOverwrite | ||||||
| 	wantun := jobU == lapack.SVDNone | 	wantun := jobU == lapack.SVDNone | ||||||
|  |  | ||||||
| 	wantva := jobVT == lapack.SVDAll | 	wantva := jobVT == lapack.SVDAll | ||||||
| 	wantvs := jobVT == lapack.SVDInPlace | 	wantvs := jobVT == lapack.SVDStore | ||||||
| 	wantvas := wantva || wantvs | 	wantvas := wantva || wantvs | ||||||
| 	wantvo := jobVT == lapack.SVDOverwrite | 	wantvo := jobVT == lapack.SVDOverwrite | ||||||
| 	wantvn := jobVT == lapack.SVDNone | 	wantvn := jobVT == lapack.SVDNone | ||||||
|   | |||||||
| @@ -108,10 +108,10 @@ const ( | |||||||
| type SVDJob byte | type SVDJob byte | ||||||
|  |  | ||||||
| const ( | const ( | ||||||
| 	SVDAll       SVDJob = 'A' // Compute all singular vectors | 	SVDAll       SVDJob = 'A' // Compute all columns of the matrix U or V. | ||||||
| 	SVDInPlace   SVDJob = 'S' // Compute the first singular vectors and store them in provided storage. | 	SVDStore     SVDJob = 'S' // Compute the singular vectors and store them in the matrix U or V. | ||||||
| 	SVDOverwrite SVDJob = 'O' // Compute the singular vectors and store them in input matrix | 	SVDOverwrite SVDJob = 'O' // Compute the singular vectors and overwrite them on the input matrix A. | ||||||
| 	SVDNone      SVDJob = 'N' // Do not compute singular vectors | 	SVDNone      SVDJob = 'N' // Do not compute singular vectors. | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // GSVDJob specifies the singular vector computation type for Generalized SVD. | // GSVDJob specifies the singular vector computation type for Generalized SVD. | ||||||
|   | |||||||
| @@ -152,7 +152,7 @@ func Gelqf(a blas64.General, tau, work []float64, lwork int) { | |||||||
| // jobU and jobVT are options for computing the singular vectors. The behavior | // jobU and jobVT are options for computing the singular vectors. The behavior | ||||||
| // is as follows | // is as follows | ||||||
| //  jobU == lapack.SVDAll       All m columns of U are returned in u | //  jobU == lapack.SVDAll       All m columns of U are returned in u | ||||||
| //  jobU == lapack.SVDInPlace   The first min(m,n) columns are returned in u | //  jobU == lapack.SVDStore     The first min(m,n) columns are returned in u | ||||||
| //  jobU == lapack.SVDOverwrite The first min(m,n) columns of U are written into a | //  jobU == lapack.SVDOverwrite The first min(m,n) columns of U are written into a | ||||||
| //  jobU == lapack.SVDNone      The columns of U are not computed. | //  jobU == lapack.SVDNone      The columns of U are not computed. | ||||||
| // The behavior is the same for jobVT and the rows of V^T. At most one of jobU | // The behavior is the same for jobVT and the rows of V^T. At most one of jobU | ||||||
| @@ -166,12 +166,12 @@ func Gelqf(a blas64.General, tau, work []float64, lwork int) { | |||||||
| // values in decreasing order. | // values in decreasing order. | ||||||
| // | // | ||||||
| // u contains the left singular vectors on exit, stored columnwise. If | // u contains the left singular vectors on exit, stored columnwise. If | ||||||
| // jobU == lapack.SVDAll, u is of size m×m. If jobU == lapack.SVDInPlace u is | // jobU == lapack.SVDAll, u is of size m×m. If jobU == lapack.SVDStore u is | ||||||
| // of size m×min(m,n). If jobU == lapack.SVDOverwrite or lapack.SVDNone, u is | // of size m×min(m,n). If jobU == lapack.SVDOverwrite or lapack.SVDNone, u is | ||||||
| // not used. | // not used. | ||||||
| // | // | ||||||
| // vt contains the left singular vectors on exit, stored rowwise. If | // vt contains the left singular vectors on exit, stored rowwise. If | ||||||
| // jobV == lapack.SVDAll, vt is of size n×m. If jobVT == lapack.SVDInPlace vt is | // jobV == lapack.SVDAll, vt is of size n×m. If jobVT == lapack.SVDStore vt is | ||||||
| // of size min(m,n)×n. If jobVT == lapack.SVDOverwrite or lapack.SVDNone, vt is | // of size min(m,n)×n. If jobVT == lapack.SVDOverwrite or lapack.SVDNone, vt is | ||||||
| // not used. | // not used. | ||||||
| // | // | ||||||
|   | |||||||
| @@ -111,16 +111,16 @@ func DgesvdTest(t *testing.T, impl Dgesvder) { | |||||||
| 		svdCheck(t, false, errStr, m, n, s, a, u, ldu, vt, ldvt, aCopy, lda) | 		svdCheck(t, false, errStr, m, n, s, a, u, ldu, vt, ldvt, aCopy, lda) | ||||||
| 		svdCheckPartial(t, impl, lapack.SVDAll, errStr, uAllOrig, vtAllOrig, aCopy, m, n, a, lda, s, u, ldu, vt, ldvt, work, false) | 		svdCheckPartial(t, impl, lapack.SVDAll, errStr, uAllOrig, vtAllOrig, aCopy, m, n, a, lda, s, u, ldu, vt, ldvt, work, false) | ||||||
|  |  | ||||||
| 		// Test InPlace | 		// Test SVDStore | ||||||
| 		jobU = lapack.SVDInPlace | 		jobU = lapack.SVDStore | ||||||
| 		jobVT = lapack.SVDInPlace | 		jobVT = lapack.SVDStore | ||||||
| 		copy(a, aCopy) | 		copy(a, aCopy) | ||||||
| 		copy(u, uAllOrig) | 		copy(u, uAllOrig) | ||||||
| 		copy(vt, vtAllOrig) | 		copy(vt, vtAllOrig) | ||||||
|  |  | ||||||
| 		impl.Dgesvd(jobU, jobVT, m, n, a, lda, s, u, ldu, vt, ldvt, work, len(work)) | 		impl.Dgesvd(jobU, jobVT, m, n, a, lda, s, u, ldu, vt, ldvt, work, len(work)) | ||||||
| 		svdCheck(t, true, errStr, m, n, s, a, u, ldu, vt, ldvt, aCopy, lda) | 		svdCheck(t, true, errStr, m, n, s, a, u, ldu, vt, ldvt, aCopy, lda) | ||||||
| 		svdCheckPartial(t, impl, lapack.SVDInPlace, errStr, uAllOrig, vtAllOrig, aCopy, m, n, a, lda, s, u, ldu, vt, ldvt, work, false) | 		svdCheckPartial(t, impl, lapack.SVDStore, errStr, uAllOrig, vtAllOrig, aCopy, m, n, a, lda, s, u, ldu, vt, ldvt, work, false) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								mat/svd.go
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								mat/svd.go
									
									
									
									
									
								
							| @@ -26,15 +26,14 @@ type SVD struct { | |||||||
| // | // | ||||||
| // The full singular value decomposition (kind == SVDFull) deconstructs A as | // The full singular value decomposition (kind == SVDFull) deconstructs A as | ||||||
| //  A = U * Σ * V^T | //  A = U * Σ * V^T | ||||||
| // where Σ is an m×n diagonal matrix of singular vectors, U is an m×m unitary | // where Σ is an m×n diagonal matrix of singular values, U is an m×m unitary | ||||||
| // matrix of left singular vectors, and V is an n×n matrix of right singular vectors. | // matrix of left singular vectors, and V is an n×n matrix of right singular vectors. | ||||||
| // | // | ||||||
| // It is frequently not necessary to compute the full SVD. Computation time and | // It is frequently not necessary to compute the full SVD. Computation time and | ||||||
| // storage costs can be reduced using the appropriate kind. Only the singular | // storage costs can be reduced using the appropriate kind. Only the singular | ||||||
| // values can be computed (kind == SVDNone), or a "thin" representation of the | // values can be computed (kind == SVDNone), or a "thin" representation of the | ||||||
| // singular vectors (kind = SVDThin). The thin representation can save a significant | // singular vectors (kind = SVDThin). The thin representation can save a significant | ||||||
| // amount of memory if m >> n. See the documentation for the lapack.SVDKind values | // amount of memory if m >> n. | ||||||
| // for more information. |  | ||||||
| // | // | ||||||
| // Factorize returns whether the decomposition succeeded. If the decomposition | // Factorize returns whether the decomposition succeeded. If the decomposition | ||||||
| // failed, routines that require a successful factorization will panic. | // failed, routines that require a successful factorization will panic. | ||||||
| @@ -81,8 +80,8 @@ func (svd *SVD) Factorize(a Matrix, kind SVDKind) (ok bool) { | |||||||
| 			Stride: n, | 			Stride: n, | ||||||
| 			Data:   use(svd.vt.Data, min(m, n)*n), | 			Data:   use(svd.vt.Data, min(m, n)*n), | ||||||
| 		} | 		} | ||||||
| 		jobU = lapack.SVDInPlace | 		jobU = lapack.SVDStore | ||||||
| 		jobVT = lapack.SVDInPlace | 		jobVT = lapack.SVDStore | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// A is destroyed on call, so copy the matrix. | 	// A is destroyed on call, so copy the matrix. | ||||||
| @@ -119,7 +118,7 @@ func (svd *SVD) Cond() float64 { | |||||||
| // Values returns the singular values of the factorized matrix in decreasing order. | // Values returns the singular values of the factorized matrix in decreasing order. | ||||||
| // If the input slice is non-nil, the values will be stored in-place into the slice. | // If the input slice is non-nil, the values will be stored in-place into the slice. | ||||||
| // In this case, the slice must have length min(m,n), and Values will panic with | // In this case, the slice must have length min(m,n), and Values will panic with | ||||||
| // matrix.ErrSliceLengthMismatch otherwise. If the input slice is nil, | // ErrSliceLengthMismatch otherwise. If the input slice is nil, | ||||||
| // a new slice of the appropriate length will be allocated and returned. | // a new slice of the appropriate length will be allocated and returned. | ||||||
| // | // | ||||||
| // Values will panic if the receiver does not contain a successful factorization. | // Values will panic if the receiver does not contain a successful factorization. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user