Created
March 20, 2017 06:34
-
-
Save ukiyoevega/b0b9f6afc708c30e5235f31fdc61ebee to your computer and use it in GitHub Desktop.
invert matrix with Accelerate framework in Swift
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
func invert(matrix : [Double]) -> [Double] { | |
var inMatrix = matrix | |
var N = __CLPK_integer(sqrt(Double(matrix.count))) | |
var pivots = Array(repeating: 0 as __CLPK_integer, count: Int(N)) | |
var workspace = Array(repeating: 0.0 as Double, count: Int(N)) | |
var error : __CLPK_integer = 0 | |
dgetrf_(&N, &N, &inMatrix, &N, &pivots, &error) | |
dgetri_(&N, &inMatrix, &N, &pivots, &workspace, &N, &error) | |
return inMatrix | |
} | |
let matrix: [Double] = [2.0, 5.0, -3.0, -7.0] | |
let invertedMatrix = invert(matrix: matrix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to upgrade to swift 5?
![Schermata 2021-06-26 alle 11 06 11](https://user-images.githubusercontent.com/30832514/123508251-88838780-d66e-11eb-984a-b26abfe45783.png)