Remove Dependance on Foundation NSString (#177)

* Remove Dependance on Foundation NSString

* Use array to represent V for eigenDecompose
This commit is contained in:
Brett Park 2021-01-14 12:37:48 -06:00 committed by GitHub
parent 372ba2830c
commit d1eeceea6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -963,9 +963,11 @@ public func eigenDecompose(_ lhs: Matrix<Double>) throws -> MatrixEigenDecomposi
var leftEigenVectorWork = [Double](repeating: 0, count: Int(leftEigenVectorCount * matrixColCount))
var rightEigenVectorWork = [Double](repeating: 0, count: Int(rightEigenVectorCount * matrixColCount))
let decompositionJobV = UnsafeMutablePointer<Int8>(mutating: ("V" as NSString).utf8String)
var decompositionJobVL: [CChar] = [0x56, 0x00] // "V" (compute)
var decompositionJobVR: [CChar] = [0x56, 0x00] // "V" (compute)
// Call dgeev to find out how much workspace to allocate
dgeev_(decompositionJobV, decompositionJobV, &matrixRowCount, &matrixGrid, &eigenValueCount, &eigenValueRealParts, &eigenValueImaginaryParts, &leftEigenVectorWork, &leftEigenVectorCount, &rightEigenVectorWork, &rightEigenVectorCount, &workspaceQuery, &workspaceSize, &error)
dgeev_(&decompositionJobVL, &decompositionJobVR, &matrixRowCount, &matrixGrid, &eigenValueCount, &eigenValueRealParts, &eigenValueImaginaryParts, &leftEigenVectorWork, &leftEigenVectorCount, &rightEigenVectorWork, &rightEigenVectorCount, &workspaceQuery, &workspaceSize, &error)
if error != 0 {
throw EigenDecompositionError.matrixNotDecomposable
}
@ -973,7 +975,7 @@ public func eigenDecompose(_ lhs: Matrix<Double>) throws -> MatrixEigenDecomposi
// Allocate the workspace and call dgeev again to do the actual decomposition
var workspace = [Double](repeating: 0.0, count: Int(workspaceQuery))
workspaceSize = __CLPK_integer(workspaceQuery)
dgeev_(decompositionJobV, decompositionJobV, &matrixRowCount, &matrixGrid, &eigenValueCount, &eigenValueRealParts, &eigenValueImaginaryParts, &leftEigenVectorWork, &leftEigenVectorCount, &rightEigenVectorWork, &rightEigenVectorCount, &workspace, &workspaceSize, &error)
dgeev_(&decompositionJobVL, &decompositionJobVR, &matrixRowCount, &matrixGrid, &eigenValueCount, &eigenValueRealParts, &eigenValueImaginaryParts, &leftEigenVectorWork, &leftEigenVectorCount, &rightEigenVectorWork, &rightEigenVectorCount, &workspace, &workspaceSize, &error)
if error != 0 {
throw EigenDecompositionError.matrixNotDecomposable
}