示例#1
0
// void dsytrf_(char *uplo, int *n, double *A, int *lda, int *ipiv,
//		double *work, int *lwork, int *info);
func dsytrf(uplo string, N int, A []float64, lda int, ipiv []int32) int {
	var info int = 0
	var lwork int = -1
	var work float64
	cuplo := C.CString(uplo)
	defer C.free(unsafe.Pointer(cuplo))

	// pre-calculate work buffer size
	C.dsytrf_(cuplo, (*C.int)(unsafe.Pointer(&N)),
		nil, (*C.int)(unsafe.Pointer(&lda)), nil,
		(*C.double)(unsafe.Pointer(&work)), (*C.int)(unsafe.Pointer(&lwork)),
		(*C.int)(unsafe.Pointer(&info)))

	// allocate work area
	lwork = int(work)
	wbuf := make([]float64, lwork)

	C.dsytrf_(cuplo, (*C.int)(unsafe.Pointer(&N)),
		(*C.double)(unsafe.Pointer(&A[0])), (*C.int)(unsafe.Pointer(&lda)),
		(*C.int)(unsafe.Pointer(&ipiv[0])),
		(*C.double)(unsafe.Pointer(&wbuf[0])), (*C.int)(unsafe.Pointer(&lwork)),
		(*C.int)(unsafe.Pointer(&info)))
	return info
}
示例#2
0
func dsytrfHelper(uplo Triangle, n int, a []float64, lda int, ipiv []C.integer, work []float64, lwork int) error {
	var (
		uplo_  = C.char(uplo)
		n_     = C.integer(n)
		a_     = ptrFloat64(a)
		lda_   = C.integer(lda)
		ipiv_  = ptrInt(ipiv)
		work_  = ptrFloat64(work)
		lwork_ = C.integer(lwork)
	)
	var info_ C.integer

	C.dsytrf_(&uplo_, &n_, a_, &lda_, ipiv_, work_, &lwork_, &info_)

	info := int(info_)
	switch {
	case info < 0:
		return errInvalidArg(-info)
	case info > 0:
		return errSingular(info)
	default:
		return nil
	}
}