0
我想在Swift中乘以兩個矩陣。我在這個主題中發現了一個很好的回覆:matrix multiplication in swift using Accelerate framework 32 bit vs 64 bit,其中我被告知使用cblas_dgemm來乘以兩個矩陣。 這裏是我的代碼:在Swift中使用加速框架的cblas_dgemm問題
import SpriteKit
import Accelerate
class GetMatrix {
var cols:Int, rows:Int
var matrix:[Double]
init(cols:Int, rows:Int) {
self.cols = cols
self.rows = rows
matrix = Array(count:cols*rows, repeatedValue:0.0)
}
subscript(col:Int, row:Int) -> Double {
get {
return matrix[cols * row + col]
}
set {
matrix[cols*row+col] = newValue
}
}
func colCount() -> Int {
return self.cols
}
func rowCount() -> Int {
return self.rows
}
}
class GameScene: SKScene {
var firstMatrix = GetMatrix(cols: 18, rows: 18)
var secondMatrix = GetMatrix(cols: 18, rows: 18)
var answerMatrix = GetMatrix(cols: 18, rows: 18)
override func didMoveToView(view: SKView) {
for c in 0...17 {
for r in 0...17 {
firstMatrix[r,c] = 2.0
}
}
for c in 0...17 {
for r in 0...17 {
secondMatrix[r,c] = 1.0
}
}
for c in 0...17 {
for r in 0...17 {
answerMatrix[r,c] = 0.0
}
}
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 18, 18, 18, 1.0, firstMatrix, 18, secondMatrix, 18, 0.0, answerMatrix, 18) // Error in this line
}
}
該代碼不會構建。與cblas_dgemm的行有問題。它說:「GetMatrix」是無法轉換爲‘UnsafePointer’請幫幫忙,我該如何解決這個問題?
完美地工作!謝謝 – Dman 2014-11-01 01:49:17