KevinCoble / AIToolbox

A toolbox of AI modules written in Swift: Graphs/Trees, Support Vector Machines, Neural Networks, PCA, K-Means, Genetic Algorithms
Apache License 2.0
793 stars 87 forks source link

Crossplattform/Linux-Support? #13

Closed ZENTRALALEX closed 7 years ago

ZENTRALALEX commented 7 years ago

It would be great if there would be a package/version/branch which we can use with Open Swift projects. For example a server with vapor and the AIToolbox could be a great project. Any thoughts on this?

KevinCoble commented 7 years ago

The framework uses only Foundation and Accelerate libraries. The Foundation use should be portable, but the Accelerate calls would not be. Most of them are simple enough to be replaced in a port (matrix multiplication, vector addition, etc.), but a couple would require use of the LAPACK library directly (matrix solutions and eigenvector finding), or searching for a Swift replacement for the linear algebra.

I would be happy to support a branch if someone wanted to spearhead that effort. I would be more than willing to make the base files work with both the Apple and Linux branches using the Swift "if #available" checking to call replacement functions for the Accelerate, or write wrappers for the new functions that mimic the vDSP calls. I'm afraid my knowledge of Linux build systems is limited.

I would like to see a port of it running on a Raspberry Pi so I can use it in a couple of my robots!

ZENTRALALEX commented 7 years ago

That is great to hear. Sadly i am also mostly on macOS. On the other side Swift has a own good package manager: https://swift.org/package-manager/ Creating packages in its basics is easy to handle. My bigger problem is that my linear algebra knowledge is pretty basic. Though i will have a look and see if i think i could be able to help.

KevinCoble commented 7 years ago

The linear algebra is not the major hold-up. I could write those - or it would likely be better to find a Swift package that does it (I have seen a couple on GitHub, but have not investigated thoroughly). It is learning the build system/package manager, etc. that has prevented me from doing it so far.

If I get some time, I'll try to start the process by looking for/writing a replacement library for the vDSP calls. That would allow about 90% of it to be ported. The remaining 10% uses LAPACK, and that will take some investigation to find a replacement that doesn't require a specific vector processor for speed.

ZENTRALALEX commented 7 years ago

You might want to look at: https://github.com/nifty-swift/Nifty

They integrate LAPACK/CBLAS like this: https://github.com/nifty-swift/Nifty/blob/master/Package.swift

Which is just a little package by itself: https://github.com/nifty-swift/Nifty-libs

KevinCoble commented 7 years ago

Created a Linux compatible Package directory. Will try to expand other classes (that require LAPACK and/or libdispatch) when I can find the time.