
Swift Numerics - hiraki9
https://swift.org/blog/numerics/
======
jph00
You may find this article I wrote useful background for understanding the
capabilities of numerical computing in Swift, including details about a
library which provides features overlapping with the new Swift package:
[https://www.fast.ai/2019/01/10/swift-
numerics/](https://www.fast.ai/2019/01/10/swift-numerics/)

~~~
Cybiote
Thanks, it is a well written article. The only part which tarnishes an
otherwise excellent article is the language comparisons portion. Such things
are best avoided as they almost always reflect the biases of or where the
author has the most experience.

As you acknowledge, you were unfair to Julia. Julia has excellent support for
general purpose programming. It has support for multiple dispatch, a quite
powerful organizational construct rarely found in other languages, for
example. Where it might fall short is in the number of general purpose
libraries but that shouldn’t matter as much for ML. It certainly isn’t lacking
for numeric libraries.

For Java, it’s unclear what you mean by JVM issues but with GraalVM and Scala
or Kotlin, I fail to identify any major issues.

F# on .net core can be distributed without installing a runtime nor does
garbage collection limit its expressiveness. It is among the fastest, in the
Go/Java/Ocaml/Swift tier, which is next fastest after C/C++/Rust/Fortran.
Compare [https://benchmarksgame-
team.pages.debian.net/benchmarksgame/...](https://benchmarksgame-
team.pages.debian.net/benchmarksgame/fastest/fsharpcore-java.html) to
[https://benchmarksgame-
team.pages.debian.net/benchmarksgame/...](https://benchmarksgame-
team.pages.debian.net/benchmarksgame/fastest/swift.html). Setting aside the
problems of microbenchmarks and unidiomatic code, they’re both within spitting
distance of each other, both wining and losing with no significant margin.
Their runtime also recently introduced SIMD and fine-grained memory management
support.

I'd say practically speaking, Swift's current great weakness is its cross
platform support, when compared to Julia, Kotlin/Scala or C#/F#.

Swift is an excellent language and it’s great a numeric programming ecosystem
is being built for it. There’s no need to justify its existence by
misrepresenting or downplaying the capabilities of competing ecosystems. I
also saw this occur for why differentiable programming in Swift and not Julia.
The more the merrier, I say. Let the various communities collaborate and share
ideas in order to better explore the space of possibilities and ideas.

~~~
zelly
> JVM issues

stop the world GC (my car ran you over because of a random unpredictable
pause!)

its bytecode is object-oriented

impossible at the moment to do CUDA style GPU programming without horrible JNI
calls

> F# on .net core can be distributed without installing a runtime nor does
> garbage collection limit its expressiveness

F# has two big crippling factors: (1) the .NET at the end of its name and (2)
functional programming, which is a huge barrier for 99% of developers (and
it's not functional enough for the other 1%). F# is dead in the water--I mean
that respectfully. To replace Python for deep learning, you need a language
that other people will actually use, not should.

~~~
fulafel
Is Swift's GC real-time, then? I thought it's just normal refcounting with
unbounded stop times.

~~~
zelly
No, but ARC does not have to pause all threads. Also this exists:

[https://developer.apple.com/documentation/swift/unsafemutabl...](https://developer.apple.com/documentation/swift/unsafemutablerawpointer/2949656-deallocate)

~~~
fulafel
So your scenario there is a separate thread that doesn't generate or free
garbage? Because if it does, there will be synchronization inside malloc/free
and your thread will pause. Also the Swift compiler is unpredictable about
when it will use the heap instead of stack, allocations are not explicit. So
it might be hard to accomplish in practice.

I agree that this special case could be more realtime with ARC, but on other
GCs such an isolated worker can be implemented as a separate program instance
(separate process or separate VM instance in same process) that has memory
allocation and GC disabled after init.

In the other cases where you keep whe GC on, I think the low-pause GCs of
today should be suitable for tasks like computer vision in cars because the
pause times are so short (sub-millisecond) vs the processing time for a frame.
And the generally higher performance of non-rc GC should more than make up for
it.

------
wnissen
I am also happy to see that sometime in the last several years slices of
arrays became views rather than copies.
[https://developer.apple.com/documentation/swift/arrayslice](https://developer.apple.com/documentation/swift/arrayslice)

~~~
ericlewis
Yes, and it makes working with Data so fast and easy.

------
zelly
Does anyone use Swift (in production) for backend services not related at all
to the Apple ecosystem? It seems like a better Golang to me, but the tooling
space only targets Apple stuff.

~~~
todd3834
I recently tried to use Swift for a UDP server that was meant to run on Linux.
I quickly realized the Network Framework is for iOS/MacOS/iPadOS only.

I ended up using Go and I'm happy with it. I really wanted to do full stack
Swift though. Just so I could become better at the language.

~~~
favorited
Honestly that's no different than realizing that AVFoundation or CoreGraphics
is Apple-platform-only...

Network.framework is an Objective-C framework (I'm honestly surprised I don't
seen any C++ symbols in the binary) – it was never supposed to be a cross-
platform framework.

SwiftNIO is the official base of the OSS Swift cross-platform networking
toolchain. It's the equivalent of Java's Jetty package.

~~~
ynx
Netty, not Jetty.

~~~
favorited
Right, thanks!

------
coldcode
Really looking forward to ShapedArray. Eventually a lot of what one might do
with Python may be available in Swift.

~~~
xvilka
You can already use Julia language for more "native" experience and more
computational syntax.

------
xvilka
I wonder what it can offer vs Julia language for HPC.

------
artfulhippo
Awesome. Now who wants to make a hypercomplex numbers library (quaternions,
Clifford, Cayley-Dixon...) in Swift?

------
bsder
Personally, I'd rather get the Swift equivalent of java.util.concurrent.

~~~
vyshane
How about the equivalent of RxJava instead:
[https://developer.apple.com/documentation/combine](https://developer.apple.com/documentation/combine)

Unfortunately not available on Linux, so server side is out :(

~~~
mbroncano
There’s an open source implementation that can be worth exploring:

[https://github.com/broadwaylamb/OpenCombine](https://github.com/broadwaylamb/OpenCombine)

