Swift Numerics

:raised_hands:.

1 Like

@scanon would GPU acceleration of the functions in this package be considered, or would that entail a separate project?

2 Likes

Swift doesn't really have a language model for thinking about heterogeneous computing (yet?), which maybe makes GPU acceleration premature (at least for the API currently in the library, which is too low-level to benefit).

Either a language-level heterogeneous compute model or higher-level API could put this in scope.

That would be very interesting! I had only considered approaching this as a higher-level API.

1 Like

The way that Julia has dealt with this is very instructive (https://github.com/JuliaGPU and related work).

5 Likes

Nice work @scanon & Team. Very exciting!

Moderator note: the negative hyperbole has been removed from this post.

Is this library using accelerate? We need some easy way to use accelerate.

this is great news!

:smiling_imp: (don‘t take my response serious)

Swift Numerics doesn't use Accelerate at present, because it doesn't yet include API that would benefit from using Accelerate. It will likely use some pieces of Accelerate in the future, but only the pieces that have alternative open-source implementations available (BLAS, LAPACK, maybe FFTs, ...), because Swift Numerics is intended to provide a uniform cross-platform API.

I should note that the vDSP, vForce, and Quadrature API in Accelerate all became vastly easier to use from Swift in macOS 10.15 / iOS 13.0 / tvOS 13.0 / watchOS 6.0. There's further work to be done, but the Accelerate team has done a great job improving them already. E.g.:

import Accelerate
let a: [Float] = // ...
let b: [Float] = // ...
// Create new array with c[i] = a[i] + b[i]
var c = vDSP.add(a, b)
// Or update a contiguous collection with the right element type in-place
// (this works out of the box with Array and UnsafeBufferPointer and a
// Slice of any conforming type, but you can add your own conforming
// types to `AccelerateBuffer` too):
vDSP.subtract(a, b, result: &c)
7 Likes

Support for arbitrary-precision String -> Real parsing probably does belong in SN.

However, parsing for specific formats (IEEE Float, Double, etc) can exploit fixed-precision arithmetic in common cases. That makes it a lot faster but limits it to specific target formats, which is useful for the standard library types.

1 Like

Hi Steve Canon

How to import swift numercis into xcode?
Can you show

Thanks

To add any swiftpm package to an existing Xcode project:

  1. Navigate to "File" > "Swift Packages" > "Add Package Dependency ..."
  2. Under "Choose Package Repository", put https://github.com/apple/swift-numerics
  3. For "Rules", the first two options are essentially equivalent for most users right now, because Swift Numerics isn't yet to version 1.0.0¹
  4. Add "Numerics" as a dependency for your target
  5. In your source file, write import Numerics

To add a dependency to a SwiftPM project, add the following to the dependencies section in Package.swift:

.package(url: "https://github.com/apple/swift-numerics", from: "0.0.5"),

and then add Numerics as a dependency for your target:

.target(name: "MyTarget", dependencies: [
  .product(name: "Numerics", package: "swift-numerics"),
  "SomeOtherDependency",
]),

¹ If you are compiling with the nightly toolchain and want to experiment with Float16, select "branch" and specify "swift-5.3" (but note: this branch will fail to compile with released versions of Swift, so do not use it for anything except for experimentation).

4 Likes

Hi Steve Canon

I tried to follow your instruction and i got an error
Can you tell what is wrong in it?

Thanks

To add, what @scanon said can also be found here.

Yes thanks

I missed the "" and s

Right now it is still error when I import it to my view controller

I’m not sure what you did, but you’re not supposed to have your own Numerics package that import Swift Numerics, which is what I see from your screenshot.

May be I did wrong

I tried to follow Steve and get lost

Delete Numeric Packages from your project and try again with the link. Pictures may help.


Hi Steve Canon

I tried two times to follow your instruction but i still got error
Here is the screen shot

Can you help me to fix it?

Thanks in advanced
Kit

Terms of Service

Privacy Policy

Cookie Policy