Skip to content
This repository has been archived by the owner on Jul 26, 2020. It is now read-only.
Scott S. edited this page Jun 18, 2014 · 16 revisions

Functions

  • mathematical functions
    • trig, abs, log, pow, sqrt, sum, avg, variance, std, l0/1/2norm, diag
  • init'ing
    • ones, zeros, arange
    • use ones((N,N)) for two dimensions and ones(N) for one dimension.
  • FFT
    • y = fft(x) returns a basic c-type array, accessible through for-loops. use y[i].real or y[i].imag.

There are all functions that are very similar to NumPy's functions, if not clones. These are very simple functions: they can't handle all of the safety checks that NumPy has. They are very very rough -- expect bugs.

But if you have a function that operates on a single element, you can call apply_function(single_element_function, array).

Operators

+-*/ all work element-wise. That is, zeros(3)+4 = [4,4,4]. Note that * is not a dot product operator. ones((4,4)) * ones((4,4)) == ones((4,4)). This is playing off Python's example.

*! is the dot product operator. I was going to use @ (as PEP 465 suggests), but that's not in the list of allowable custom operator characters.

~== is the "about equal" 1D operator, and ~~ is the 2D equivalent.

== works like expected

Complex numbers

I've integrated swift-complex, meaning that a range of functions are available for single elements. This should probably be extended further (and by someone that knows more OO programming than me).

abs(1+1.i) == sqrt(2)
(1+1.i).conj == 1-1.i

The full documentation can be found on swift-complex

Number convenience elements

Float(3.14).int == 3, likewise for double/float/int.

This library uses the data type Double as the standard type. Functions you call may complain may fail on compile and complain about "function not found for input". Use N.double (and that may change on the function).

Clone this wiki locally