Created
June 14, 2013 10:49
-
-
Save xoba/5780979 to your computer and use it in GitHub Desktop.
how easy it is to use blas from go-lang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see http://www.netlib.org/clapack/cblas/dgemv.c | |
package main | |
/* | |
#cgo LDFLAGS: -L/usr/lib/libblas -lblas | |
#include <stdlib.h> | |
extern void dgemv_(char* trans, int *m, int *n, double *alpha, | |
double *A, int *lda, double *x, int *incx, double *beta, double *y, | |
int *incy); | |
*/ | |
import "C" | |
import ( | |
"fmt" | |
"unsafe" | |
) | |
/* | |
matrix-vector multiplication: | |
[1, 3] * [ 5 ] = [ 23 ] | |
[2, 4] [ 6 ] [ 34 ] | |
mra@desktop ~/Desktop $ go run blas.go | |
[23 34] | |
*/ | |
func main() { | |
a := []float64{1, 2, 3, 4} | |
x := []float64{5, 6} | |
y := make([]float64, 2) | |
Dgemv("N", 2, 2, 1.0, a, 2, x, 1, 0.0, y, 1) | |
fmt.Println(y) | |
} | |
func Dgemv(transA string, M int, N int, alpha float64, | |
A []float64, lda int, X []float64, incX int, beta float64, | |
Y []float64, incY int) { | |
ctransA := C.CString(transA) | |
defer C.free(unsafe.Pointer(ctransA)) | |
C.dgemv_(ctransA, | |
(*C.int)(unsafe.Pointer(&M)), | |
(*C.int)(unsafe.Pointer(&N)), | |
(*C.double)(unsafe.Pointer(&alpha)), | |
(*C.double)(unsafe.Pointer(&A[0])), | |
(*C.int)(unsafe.Pointer(&lda)), | |
(*C.double)(unsafe.Pointer(&X[0])), | |
(*C.int)(unsafe.Pointer(&incX)), | |
(*C.double)(unsafe.Pointer(&beta)), | |
(*C.double)(unsafe.Pointer(&Y[0])), | |
(*C.int)(unsafe.Pointer(&incY))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment