use Array: all; use SimplePrint: all; use SimpleFibre: all; use Math: all; #define toB(x) tob((x)) #define toI(x) toi((x)) #define toD(x) tod((x)) #define toC(x) (x) #define dneCCB(XV,YV,QUADct) (XV!=YV) #define dorBBB(XV,YV) (XV||YV) inline bool[.,.] APEXTranspose(bool[.,.] y) {/* Rank 2 transpose */ return({[i,j] -> y[[j,i]]}); } inline bool[.] APEXTranspose(bool[.] y) { return(y); } inline bool[+] tob (bool[+] x) { z = with (. <= iv <= .) genarray(_shape_(x),tob(_sel_(iv,x))); return(z); } inline bool[+] tob (int[+] x) { z = with (. <= iv <= .) genarray(_shape_(x),tob(_sel_(iv,x))); return(z); } inline bool[+] tob (double[+] x) { z = with (. <= iv <= .) genarray(_shape_(x),tob(_sel_(iv,x))); return(z); } inline bool tob(bool x) { return(x); } inline bool tob(int x) { if (1 == _toi_S_(x)) z = true; else z = false; return(z); } inline bool tob(double x) { if (1 == _toi_S_(x)) z = true; else z = false; return(z); } inline bool[+] neCCBsy(char[*] x, char y , double QUADct) { /* AxS scalar function */ yel = toC(y); z = with( . <= iv <= .) { xel = toC(_sel_(iv,x)); } genarray( _shape_(x), dneCCB(xel,yel, QUADct)); return(z); } inline bool[+] orBBB(bool[+] x, bool[+] y ) { /* AxA Dyadic scalar fn, shapes unknown, shapes may or may not match */ /* Insert length error checking code here!! */ z = with( . <= iv <= .) { xel = toB(_sel_(iv,x)); yel = toB(_sel_(iv,y)); } genarray( _shape_(x), dorBBB(xel,yel)); return(z); } inline bool[+] rotrXBB(bool[+] y) { lim = _sub_SxS_(_sel_([0], _shape_(y)),1); z = with( [0] <= iv = [i] <= [lim]) modarray(y, iv,y[[_sub_SxS_(lim,i)]]); return(z); } inline int[.] takeBII(bool x, int[.] y) /* LOTS of missing code here. (x0<0 for example */ { /* Scalar take vector */ z = with( . <= iv <= .) genarray([abs(toi(x))], _sel_(iv,y)); return(z); } inline char[.,.] takeICC(int[.] x, char[.,.] y) { /* vector take matrix */ offset = where( toI(x) < 0, _shape_(y) + toI(x), 0); res = with( . <= iv <= .) genarray( abs(x), _sel_( _add_AxA_( offset, iv), y)); return( res); } inline int[2] rhoXCI(char[.,.] y) { /* Shape of matrix (rank-2) */ return(_shape_(y)); } inline int[.] comaIII(int[.] x, int y) {/* VxS catenate first (or last) axis */ return(toI(x)++[toI(y)]); } inline bool[+] orsl1XBB(bool[+] y) { /* first-axis reduce rank-2 or greater matrix */ /* This does not stop quick for Booleans... */ /* First y axis disappears from result shape */ /* Result is: transpose last-axis reduce transpose y */ yt = APEXTranspose(y); rhrank = _dim_(yt); sy = _shape_(yt); zrho = _drop_SxV_(_neg_(1), sy); z = with (. <= iv <= .) { val = with (_mul_SxA_(0,sy) <= iv < sy) fold( +, toB(0), toB(_sel_(iv, yt))); } genarray(zrho, val); return(APEXTranspose(z)); } inline bool[.] orbslXBB(bool[.] y) { /* This does the scan in the wrong direction, but since * we assume associative functions only, it should be ok. */ size = _shape_(y); z = genarray(size,false); if (0 != size[0]) { z[[0]] = toB(y[0]); for ( i=1; i count) /* Element reuse case */ for (i=count; i