NDArray: a multidimensional array library written in Swift

Hey Swift Community!

I was attracted to Swift a few months ago thanks to the TensorFlow project, since I dedicate myself to Machine Learning I was impressed by a talk by @Chris_Lattner3 . Data science is a relatively new topic for the Swift community but I have a strong feeling that Swift could excel at it given how easy it is to wrap C libraries and write efficient parallel code (good-bye GIL).

I am happy to share with you NDArray, a multidimensional array library (like Numpy) for Swift. I've been taking strong queues from TensorFlow Tensor API, Numpys documentation and some other attempts at the problem that Swifters have used in the past. I've learned a lot and the journey just started!

Link: GitHub - cgarciae/NDArray: A Multidimensional Array library for Swift

NDArray

NDArray is a multidimensional array library written in Swift that aims to become the equivalent of numpy in Swift's emerging data science ecosystem. This project is in a very early stage and has a long but exciting road ahead!

Goals

  1. Have an efficient multidimensional array interface with common things like indexing, slicing, broadcasting, etc.
  2. Create specialized implementations of linear algebra operations for NDArrays containing numeric types using libraries like BLAS and LAPACK.
  3. Make NDArray and its operations differentiable so its usable along with Swift for TensorFlow.
7 Likes

Looks cool. Have you considered conforming to ExpressibleByArrayLiteral? Also, what's the difference between NDArray._shape.dimensionLengths and NDArray.data.map { $0.count }?

Thanks Alexander!

  • ExpressibleByArrayLiteral: definitely! Tensor does it, I think copying their implementation strategy could be useful.
  • NDArray.data: NDArray, Numpy and many (most?) libraries implement the multidimensional array structure as a flat / long unidimensional array with shape information, so infact the type of data is [Scalar], not [[Scalar]] or [[[Scalar]]] and all it possible nested combinations. So _shape actually contains informations about the dimensions, and data pretty much sits unchanged and can be shared with multiple NDArray which reference the same data but can have different "views" of it.
1 Like

@scanon This is an initial attempt to what was discussed in another post. You seem to have a lot of knowledge on this domain, if you have the time it would be helpful if you had a look, would really appreciate it.