I am trying to get my code to use MPSMatrixDecompositionCholesky correctly but it is giving me an incorrect matrix result.
Any help would be greatly appreciated!
let device = MTLCreateSystemDefaultDevice()!
let commandQueue = device.makeCommandQueue()
let M = 2
let row = M * MemoryLayout<Float>.stride
let matlength = M * row
let mdesc = MPSMatrixDescriptor(
dimensions: M, columns: M, rowBytes: row, dataType: MPSDataType.float32)
let arrayA: [Float] = [ 2.0 , 1.0 , 1.0 , 2.0 ]
let buffA = device.makeBuffer(bytes: arrayA, length: matlength)
let matA = MPSMatrix(buffer: buffA!, descriptor: mdesc)
let arrayB: [Float] = [ 1.0 , 0.0 , 0.0 , 0.0 ]
let buffB = device.makeBuffer(bytes: arrayB, length: matlength)
let matB = MPSMatrix(buffer: buffB!, descriptor: mdesc)
let arrayX: [Float] = [ 0.0 , 0.0 , 0.0 , 0.0 ]
let buffX = device.makeBuffer(bytes: arrayX, length: matlength)
let matX = MPSMatrix(buffer: buffX!, descriptor: mdesc)
let arrayL: [Float] = [ 0.0 , 0.0 , 0.0 , 0.0 ]
let buffL = device.makeBuffer(bytes: arrayL, length: matlength)
let matL = MPSMatrix(buffer: buffL!, descriptor: mdesc)
let decomp = MPSMatrixDecompositionCholesky(device: device, lower: true, order: M )
let commandBuffer = commandQueue?.makeCommandBuffer()
decomp.encode(commandBuffer: commandBuffer!,
sourceMatrix: matA, resultMatrix: matL, status: buffX)
commandBuffer?.commit()
let rawPointerL = matL.data.contents()
let countL = matL.rows * matL.columns
let typedPointerL = rawPointerL.bindMemory(to: Float.self, capacity: countL)
let bufferedPointerL = UnsafeBufferPointer(start: typedPointerL, count: countL)
print(" ")
print(" ",bufferedPointerL[0], bufferedPointerL[1])
print(" ",bufferedPointerL[2], bufferedPointerL[3])
print(" ")