简体   繁体   中英

Print a matrix stored as a SparseMatrixStructure

I am working with Apple's Accelerate framework, using Sparse Matrix operations.

I have created a sparse matrix thus:

    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
            )
        }

I am making a call to factorise the matrix:

 let llt: SparseOpaqueFactorization_Double = values.withUnsafeMutableBufferPointer { valuesPtr in
        let a = SparseMatrix_Double(
            structure: structure,
            data: valuesPtr.baseAddress!
        )
        
        return SparseFactor(SparseFactorizationCholesky, a)
    }

I really need to check what the result is of the factorisation - ie print out the result. Can't see any way of even getting the result, let alone print it out.

Can anyone help me understand how to retrieve the result and print it?

Solved this myself eventually. I used:

let subfactors = SparseCreateSubfactor(SparseSubfactorL, llt)

to extract a Subfactors object from the factorisation, then multiplied the subfactors by the identity matrix to get at the factorisation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM