Linear algebra on iPhone (python/numpy?) [closed]
Asked Answered
J

4

10

This semester, I'm implementing a compressed-sensing algorithm as an iPhone app. To do this, I'll need some good matrix/linear algebra libraries. I'm a little new to both iOS and Python, and am looking for some help at evaluating my options.

I know the iPhone has the Accelerate framework, which includes vecLib, BLAS, and LAPACK, but I'm not familiar with their API's (and they seem fairly confusing).

I've played around with Python/numpy, and I really like how simple it is to use - if I have the choice, I'd prefer to use numpy over Accelerate.

I know it's possible to embed Python, but I have had little luck on my own. I tried to include Enthought's EPD.framework in an XCode project, but didn't get it to work after playing around for an hour or so. I would imagine that compiling numpy would be worse.

As another alternative, could I use Cython (http://cython.org/) to generate C files then call functions from that? I also attempted this, but ran into more issues with including a .so library and calling it. Is there any way to have Cython generate .c and .h files? Would said .c and .h files still depend on numpy?

I've read some stuff about PyInstaller and freeze.py. Could either of those help me here?

Are there any options besides Accelerate or Python+numpy? Is Python+numpy a good option, or will it be hard to compile/build? Is Cython a valid solution?

Thank you!

Julijulia answered 14/1, 2012 at 6:15 Comment(0)
J
3

The new release of the Swift programming language with iOS 8 allows for high level Python/Matlab -like code to be written. Accordingly, a framework called swix has been developed that wraps the Accelerate (/BLAS/Lapack/etc) frameworks.

Code snippet that fully utilizes the Accelerate framework:

var N = 10
var x = ones(N) * pi
var y = ones(N) * phi
var result = (x+y+4)*x

This code will can be compiled for the iPhone/iOS. Full details on installation are covered in the swix documentation.

Julijulia answered 12/5, 2015 at 6:32 Comment(0)
C
3

Take the time to learn the Accelerate commands. If your doing complex math, these are the functions you want to be using. They are much faster, infinitely more likely to continue to be supported and tuned to future hardware, and as well - they use less energy than naive solutions.

Circumnutate answered 14/1, 2012 at 9:28 Comment(2)
-1. The question(s) was, "Are there any options besides Accelerate or Python+numpy? Is Python+numpy a good option, or will it be hard to compile/build? Is Cython a valid solution?". This answer doesn't answer the question.Jonme
Oddly, the OP accepted it... not sure why.Jassy
J
3

The new release of the Swift programming language with iOS 8 allows for high level Python/Matlab -like code to be written. Accordingly, a framework called swix has been developed that wraps the Accelerate (/BLAS/Lapack/etc) frameworks.

Code snippet that fully utilizes the Accelerate framework:

var N = 10
var x = ones(N) * pi
var y = ones(N) * phi
var result = (x+y+4)*x

This code will can be compiled for the iPhone/iOS. Full details on installation are covered in the swix documentation.

Julijulia answered 12/5, 2015 at 6:32 Comment(0)
W
2

With the release of Swift, and its access to the Accelerate framework, there is little reason to go out of your way to get Python running. With the right frameworks, you can use Swift to write high-level, and performant, code for iOS with syntax similar to Python/numpy, and performance that will be significantly greater than running numpy on iOS.

As other people have already posted, there are various libraries that attempt to 'wrap' the Accelerate framework to provide high-performance with an accessible API. As an alternative to the swix library in another answer, I have had great success with the Upsurge framework. For the kinds of operations that you are probably going to use, Upsurge may have everything that you need.

It provides an easy and detailed interface to a variety of Accelerate functions; matrices, convolution, FFT, linear algebra, mathematics etc. It also supports a lot of these operations on its own custom tensor type. The big advantage that I found over swix when I was deciding between them, was that Upsurge didn't have a dependency on OpenCV and didn't require any bridging headers (it is written in pure swift) which made debugging easier for me.

That being said, they are both great frameworks and either one will cover your needs. I would have a look at both and see which one better fits your needs.

Wonky answered 7/3, 2016 at 16:56 Comment(0)
J
1

There are libraries to include Python on iOS. These libraries are Kivy and Beeware. These are libraries that have the entire app written in Python.

Kivy

  • does not have a native GUI -- the app looks "Kivy"
  • can not make native system API calls
  • this is a more mature project than Beeware

Beeware

  • has a native looking GUI
  • can call native system APIs
  • (a newer project; less mature)

For Kivy, look at kivy-ios and the GitHub project and for Beeware look at python-ios-template.

Julijulia answered 3/6, 2016 at 17:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.