[英]Print a matrix stored as a SparseMatrixStructure
我正在使用 Apple 的 Accelerate 框架,使用稀疏矩陣操作。
我創建了一個稀疏矩陣,因此:
var values: Array<Double> = [0.125, 0.08, -0.01, 0.405, -0.02, 0.005]
var rowIndices: [Int32] = [0, 1, 2, // Column 0
3, 4, // Column 1
5 ] // Column 3
var columnStarts = [0, 3, 5, 6]
let structure: SparseMatrixStructure = rowIndices.withUnsafeMutableBufferPointer { rowIndicesPtr in
columnStarts.withUnsafeMutableBufferPointer { columnStartsPtr in
var attributes = SparseAttributes_t()
attributes.triangle = SparseLowerTriangle
attributes.kind = SparseSymmetric
return SparseMatrixStructure(
rowCount: 3,
columnCount: 3,
columnStarts: columnStartsPtr.baseAddress!,
rowIndices: rowIndicesPtr.baseAddress!,
attributes: attributes,
blockSize: 1
)
}
我正在打電話來分解矩陣:
let llt: SparseOpaqueFactorization_Double = values.withUnsafeMutableBufferPointer { valuesPtr in
let a = SparseMatrix_Double(
structure: structure,
data: valuesPtr.baseAddress!
)
return SparseFactor(SparseFactorizationCholesky, a)
}
我真的需要檢查分解的結果是什么 - 即打印出結果。 連得到結果的方法都看不到,更別說打印出來了。
誰能幫助我了解如何檢索結果並打印它?
最終自己解決了這個問題。 我用了:
let subfactors = SparseCreateSubfactor(SparseSubfactorL, llt)
從分解中提取一個 Subfactors 對象,然后將子因子乘以單位矩陣以獲得分解。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.