2013-03-25 46 views

回答

1

這是很容易調用例如cblas via cgo:

package main 

// #include <cblas.h> 
// #cgo LDFLAGS: -L/usr/lib64/atlas -lcblas 
import "C" 

import "fmt" 

type matrix struct { 
    rows int 
    cols int 
    elems []float32 
} 

func (a matrix) cblasmul(b matrix) (c matrix) { 
    c = matrix{a.rows, b.cols, make([]float32, a.rows*b.cols)} 
    C.cblas_sgemm(
     C.CblasRowMajor, C.CblasNoTrans, C.CblasNoTrans, 
     C.int(a.rows), C.int(b.cols), C.int(a.cols), 
     1.0, 
     (*C.float)(&a.elems[0]), C.int(a.cols), 
     (*C.float)(&b.elems[0]), C.int(b.cols), 
     0.0, 
     (*C.float)(&c.elems[0]), C.int(c.cols)) 

    return c 
} 

func main() { 
    a := matrix{100, 100, make([]float32, 100*100)} 
    b := matrix{100, 100, make([]float32, 100*100)} 
    // ... 
    c := a.cblasmul(b) 
    fmt.Println(c) 
} 
0

GSL有各種不同的cgo綁定,甚至有一些純粹的Go端口嘗試。沒有人可以有很大的認同,但(儘可能明星而言),並已閒置了幾個月,但你可能想看看代碼:

http://godoc.org/?q=gsl