University of Wisconsin-Madison
twitter @mikolalysenko | github @mikolalysenko | blog: 0fps.net
"Arrays of nested arrays"
var array = [ [ 1, 0, 0 ],
[ 0, 1, 0 ],
[ 0, 0, 1 ] ]
var x = array[1][2]
*Sometimes optimized by v8 in special cases
"Lexicographic ordering"
var array = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ]
var x = array[ 1*3 + 2 ]
Con: Fixed size, slicing expensive
*Can be less for special kinds of slices
"Affine map from ℤn to ℤ"
var stride = [3, 1]
var offset = 0
var array = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ]
var x = array[stride[0]*1+stride[1]*2+offset]
Shape:
Stride:
Offset:
array.lo(222,215).hi(40,40) //Edit me!
data can be any array-like object or data structure with .get/.set
var hash = {}
var hashStore = {
get: function(i) {
return +hash[i]
},
set: function(i,v) {
return hash[i]=v
},
length: Infinity
}
var array = ndarray(hashStore, [1000,1000,1000])
Useful for implementing sparse arrays, interfacing to other data structures
ndarray-ops
.
Generates cache efficient array operations
Very fast
Thin, modular WebGL wrappers using ndarrays
var str="BANANA
"+"\0"
00000
10101
00110
var ndstring = require("ndarray-string")
var n = str.length
var x = ndstring(str+str,[n,n],[1,1])
00000
10101
00110
var ndsort = require("ndarray-sort")
var scratch = require("ndarray-scratch")
var y = ndsort(scratch.clone(x))
foo
var result = ndstring.toString(y.pick(-1, n-1))
scratch.free(y)
var x = ndstring("", [n,n], [1,0])
var y = scratch.clone(x)
for(var i=n-1; i>=0; --i) {
ndsort(y.lo(0, i))
}
var result = ndstring.toString(y.pick(0).lo(1))
scratch.free(y)
return result