예제 #1
0
파일: cgo_double.go 프로젝트: jvlmdr/linalg
// void dgeqrf_(int *m, int *n, double *a, int *lda, double *tau,
//		double *work, int *lwork, int *info);
func dgeqrf(M, N int, A []float64, lda int, tau []float64) int {
	var info int = 0
	var lwork int = -1
	var work float64

	// calculate work buffer size
	C.dgeqrf_((*C.int)(unsafe.Pointer(&M)),
		(*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)))

	lwork = int(work)
	wbuf := make([]float64, lwork)
	C.dgeqrf_((*C.int)(unsafe.Pointer(&M)),
		(*C.int)(unsafe.Pointer(&N)),
		(*C.double)(unsafe.Pointer(&A[0])),
		(*C.int)(unsafe.Pointer(&lda)),
		(*C.double)(unsafe.Pointer(&tau[0])),
		(*C.double)(unsafe.Pointer(&wbuf[0])),
		(*C.int)(unsafe.Pointer(&lwork)),
		(*C.int)(unsafe.Pointer(&info)))
	return info
}
예제 #2
0
파일: cgo_dgeqrf.go 프로젝트: jvlmdr/lin-go
func dgeqrfHelper(m, n int, a []float64, lda int, tau, work []float64, lwork int) error {
	var (
		m_     = C.integer(m)
		n_     = C.integer(n)
		a_     = ptrFloat64(a)
		lda_   = C.integer(lda)
		tau_   = ptrFloat64(tau)
		work_  = ptrFloat64(work)
		lwork_ = C.integer(lwork)
	)
	var info_ C.integer

	C.dgeqrf_(&m_, &n_, a_, &lda_, tau_, work_, &lwork_, &info_)

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