News for hackers. Stuff that matters.
Re:High Performance Numeric Programming with Swift: Explorat... by jph00 on Thursday January 10, 2019 @07:04PM (#18879792)
What I'm doing is essentially the same as `withUnsafeMutableBufferPointer`. However I didn't find a way to get concise abstractions using that approach.
Re:High Performance Numeric Programming with Swift: Explorat... by slowswift on Thursday January 10, 2019 @10:06PM (#18880699)
It is essentially the same, sure. We have some specialized in-house structs-of-arrays things for doing bulk geometry operations that (behind the scenes) go through `withUnsafeMutableBufferPointer` (etc.) for everything; we keep the code idiomatic, mutation only happens in methods that are marked as mutating, COW still works, and so on.

Thus we hadn't even considered just exposing the pointer and doing it C-style, whence the question as to whether you'd benchmarked the difference between the two.

The abstractions thing is hard, here, the key seems to be defining the bulk operations in terms of pointers (or Swift's "buffer pointers"), essentially what you have in your methods like `SupportsBasicMath.add` and so on. Abstraction is possible here by moving each "type signature"--destination & 1 source? destination & 2 sources? etc.--into "operation protocols", and then having fewer methods but a ton of "operation protocol implementations". Perhaps "more abstraction", definitely not concise. Very dependent on the compiler and inlining, too.

It's a good writeup nonetheless, was just asking a narrow question.

Re:High Performance Numeric Programming with Swift: Explorat... by jph00 on Thursday January 10, 2019 @11:37PM (#18881042)
The pointer approach allows for brevity and idiomatic swift at the place of use. The verbosity behind the scenes need not bother the user.

Because I couldn't find anything that provides that using the approach you are discussing, I didn't investigate its performance characteristics. For me, dev UX comes first, and I wouldn't personally be interested in reading or writing in a language that requires the "with" construct wrapping every calculation.