Post

Replies

Boosts

Views

Activity

Reply to A new message 'Answered by forumsContributor in' with a link to nowhere
While investigating, here is another bug I noticed: I received an email notifying that my answer was recommended by Apple. Going to the thread https://developer.apple.com/forums//thread/758452?answerId=793464022#793464022, I noticed that the correct answer was, logically, the DTS's answer, not mine which was just for asking for more information. Filed a bug report: FB14172207
Jul ’24
Reply to Peculiar EXC_BAD_ACCESS, involving sparse matrices
as soon as I try it out with other matrices, the function crashes with this error: 'Matrix is structurally singular'. Could you show examples of Matrix that cause crash ? It would be surprising that any other matrix be singular. Unless it is not the original matrix but some derived one.   However, the other leastSquaresSolution-method that I initially wrote also returns zero's Did you post this method, to see the difference ?
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’24
Reply to Peculiar EXC_BAD_ACCESS, involving sparse matrices
The article does not give complete code, so you probably had to complete for your own code. If I understood it correctly, the SparseSolve function changes x, which in turn changes xPtr and xValues. x is passed as a parameter (and const) to the function, so it is not modified by SparseSolve. To be clear, I did not analyse nor understand the details of how SparseSolve works, but I looked at the doc for SparseSolve (however I did not find one that returns a status), and it seems to be a bit different: let xValues = [Double](unsafeUninitializedCapacity: n) { buffer, count in bValues.withUnsafeMutableBufferPointer { bPtr in let b = DenseVector_Double(count: 3, data: bPtr.baseAddress!) let x = DenseVector_Double(count: 3, data: buffer.baseAddress!) SparseSolve(factorization, b, x) count = n } } On return, xValues contains the values [1.0, 2.0, 3.0]. Here, xValues is changed in the completion handler. Could you try to replicate this ?
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’24
Reply to Peculiar EXC_BAD_ACCESS, involving sparse matrices
Much better with the comments. However, I still do not catch where xValues is modified (initialised as zeros). It should be in this part, correct ? bValues.withUnsafeMutableBufferPointer { bPtr in xValues.withUnsafeMutableBufferPointer { xPtr in // Construct the matrices B and x in Ax = B let b = DenseVector_Double( count: Int32(B.count), data: bPtr.baseAddress! ) let x = DenseVector_Double( count: Int32(A.transpose().count), data: xPtr.baseAddress! ) // Try to find X with SparseSolve (this is where it seems to go wrong) let status = SparseSolve(SparseLSMR(), a, b, x, SparsePreconditionerDiagScaling) if status != SparseIterativeConverged { fatalError("Failed to converge. Returned with error \(status).") } } } through the change of xPtr. Correct ? But where is xPtr modified ?
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’24
Reply to BUG: **** YOU APPLE
**** I hope it is to hide a compliment… Otherwise it would be absolutely inappropriate, and not the best way to ask for help.
Jul ’24
Reply to Peculiar EXC_BAD_ACCESS, involving sparse matrices
Welcome to the forum. This code may be readable for you, but without any comment, it is a headache, at least for me, to really understand … So I may miss something in your code. If I understand what you are doing in static func leastSquaresSolution(A: [[Double]], B: [Double]) -> [Double] { you are computing and return xValues This should be done by manipulating xPtr. Correct ? xValues.withUnsafeMutableBufferPointer { xPtr in xValues is initialised with 0.0 values. Where do you update xPtr, which would modify xValues before you return it ?
Topic: Programming Languages SubTopic: Swift Tags:
Jun ’24
Reply to How on earth do I get the actual dimensions of a presented modal view on iPad?
Could you show the complete code so that we can better understand what happens (it would even be better to have a reproductible example) ? Maybe self in self.view.frame.size.width is just referring to the parent view and not settingsView. You could also try const int viewWidth = settingsView.view.frame.size.width; or get the width in the completion handler, to be sure you refer to the correct object.
Topic: UI Frameworks SubTopic: UIKit
Jun ’24