-
Notifications
You must be signed in to change notification settings - Fork 54
Home
- 1d
-
x[0]
gives element,x[0..<2]
gives range of two elements,x[0...2]
gives three elements. For convince, I defined0..<2
as0|2
and0...2
as0!2
. This was chosen to be similar to NumPy's indexing.
-
- 2d
- The indexing scheme is
x[row, column]
, similar to NumPy. Why? The first object in the matrix is another one dimensional matrix.x[0][1] == x[0, 1]
is how NumPy works; I follow that example. - use
x[1, 0|2]
,x[0|2, 1]
,x[0|3, 0|3]
to access any two dimensional grid - note that
x[0|2, 0|2]
cannot equal an integer. Use x[0|2, 0|2] = zeros((2,2)) - a bug I found:
println(x[0|2, 1|3])
gives a bug butvar y:matrix2d = x[0|2, 1|3]; println(y)
works. This was found in Beta3 and is probably a Swift0.3 bug. - use
x[array(1, 2, 3, 4)]
to access the flattened array. Specifically, the flattened array stacks the rows.array("1 2 3; 4 5 6")[array(0, 1, 2, 3)] = [1 2 3 4]
. This is similar to NumPy'sx.flat
.
- The indexing scheme is
- mathematical functions
- trig, abs, log, pow, sqrt, sum, avg, variance, std, l0/1/2norm, diag
- init'ing
- ones, zeros, arange, linspace
- use array("1 2 3; 4 5 5") to create simple 2d array
- use
ones((N,N))
for two dimensions andones(N)
for one dimension.
- FFT
-
y = fft(x)
returns a basic c-type array, accessible through for-loops. usey[i].real
ory[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)
.
+-*/
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
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
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).