示例#1
0
文件: house.go 项目: sguzwf/algorithm
/*
 * Applies a real elementary reflector H to a real m by n matrix A,
 * from either the left or the right. H is represented in the form
 *
 *       H = I - tau * ( 1 ) * ( 1 v.T )
 *                     ( v )
 *
 * where tau is a real scalar and v is a real vector.
 *
 * If tau = 0, then H is taken to be the unit matrix.
 *
 * A is /a1\   a1 := a1 - w1
 *      \A2/   A2 := A2 - v*w1
 *             w1 := tau*(a1 + A2.T*v) if side == LEFT
 *                := tau*(a1 + A2*v)   if side == RIGHT
 *
 * Intermediate work space w1 required as parameter, no allocation.
 */
func applyHHTo2x1(tau, v, a1, A2, w1 *matrix.FloatMatrix, flags Flags) {

	tval := tau.GetAt(0, 0)
	if tval == 0.0 {
		return
	}

	// maybe with Scale(0.0), Axpy(w1, a1, 1.0)
	a1.CopyTo(w1)
	if flags&LEFT != 0 {
		// w1 = a1 + A2.T*v
		MVMult(w1, A2, v, 1.0, 1.0, TRANSA)
	} else {
		// w1 = a1 + A2*v
		MVMult(w1, A2, v, 1.0, 1.0, NOTRANS)
	}

	// w1 = tau*w1
	Scale(w1, tval)

	// a1 = a1 - w1
	a1.Minus(w1)

	// A2 = A2 - v*w1
	if flags&LEFT != 0 {
		MVRankUpdate(A2, v, w1, -1.0)
	} else {
		MVRankUpdate(A2, w1, v, -1.0)
	}
}
示例#2
0
文件: house.go 项目: sguzwf/algorithm
/* From LAPACK/dlarf.f
 *
 * Applies a real elementary reflector H to a real m by n matrix A,
 * from either the left or the right. H is represented in the form
 *
 *       H = I - tau * ( 1 ) * ( 1 v.T )
 *                     ( v )
 *
 * where tau is a real scalar and v is a real vector.
 *
 * If tau = 0, then H is taken to be the unit matrix.
 *
 * A is /a1\   a1 := a1 - w1
 *      \A2/   A2 := A2 - v*w1
 *             w1 := tau*(a1 + A2.T*v) if side == LEFT
 *                := tau*(a1 + A2*v)   if side == RIGHT
 *
 * Allocates/frees intermediate work space matrix w1.
 */
func applyHouseholder(tau, v, a1, A2 *matrix.FloatMatrix, flags Flags) {

	tval := tau.GetAt(0, 0)
	if tval == 0.0 {
		return
	}
	w1 := a1.Copy()
	if flags&LEFT != 0 {
		// w1 = a1 + A2.T*v
		MVMult(w1, A2, v, 1.0, 1.0, TRANSA)
	} else {
		// w1 = a1 + A2*v
		MVMult(w1, A2, v, 1.0, 1.0, NOTRANS)
	}

	// w1 = tau*w1
	Scale(w1, tval)

	// a1 = a1 - w1
	a1.Minus(w1)

	// A2 = A2 - v*w1
	MVRankUpdate(A2, v, w1, -1.0)
}
示例#3
0
func nrmError(ref, val *matrix.FloatMatrix) (nrm float64, diff *matrix.FloatMatrix) {
	diff = ref.Minus(val)
	nrm = blas.Nrm2(diff).Float()
	return
}