import Accelerate import TabularData // set-up reading options let options = CSVReadingOptions(hasHeaderRow: false, delimiter: " ") // read separate columns of data to rowFrame, colFrame, datFrame let rowFrame = try! DataFrame(contentsOfCSVFile: url, columns: ["Column 0"], types: ["Column 0": .integer], options: options) let colFrame = try! DataFrame(contentsOfCSVFile: url, columns: ["Column 1"], types: ["Column 1": .integer], options: options) let datFrame = try! DataFrame(contentsOfCSVFile: url, columns: ["Column 2"], types: ["Column 2": .double], options: options) // assign DataFrame optional Int data and Double data to arrays let rows = Array(rowFrame["Column 0"]) as? [Int] let cols = Array(colFrame["Column 1"]) as? [Int] let dats = Array(datFrame["Column 2"]) as? [Double] // coordinate file row count let rowcount = 23737339 let rowcountm1 = 23737339 - 1 // set up arrays for conversion to sparse format types var rows32 = Array<Int32>( repeating: 0, count: rowcount) var cols32 = Array<Int32>( repeating: 0, count: rowcount) var datsdouble = Array<Double>( repeating: 0, count: rowcount) // assign forced unwrapping for casting to appropriate arrays for index in 0...rowcountm1 { rows32[index] = Int32(rows![index]) cols32[index] = Int32(cols![index]) datsdouble[index] = Double(dats![index]) } var attributes = SparseAttributes_t() attributes.triangle = SparseLowerTriangle attributes.kind = SparseSymmetric // symmetric matrix row size let size32:Int32 = 952203 let size = 952203 let blockCount = size + size let blockSize = 1 let a = SparseConvertFromCoordinate(size32, size32, blockCount, UInt8(blockSize), attributes, &rows32, &cols32, &datsdouble) var bValues = Array<Double>( repeating: 1 , count: size) var xValues = Array<Double>( repeating: 0 , count: size) let llt: SparseOpaqueFactorization_Double = datsdouble.withUnsafeMutableBufferPointer { datsdoublePtr in return SparseFactor(SparseFactorizationCholesky, a) } bValues.withUnsafeMutableBufferPointer { bPtr in xValues.withUnsafeMutableBufferPointer { xPtr in let b = DenseVector_Double(count: size32, data: bPtr.baseAddress!) let x = DenseVector_Double(count: size32, data: xPtr.baseAddress!) SparseSolve(llt, b, x) } }