use Array: all; use SimplePrint: all; use SimpleFibre: all; use Math: all; #include "mscalar.sac" #include "dscalar.sac" #include "stdlib.sac" #define toB(x) tob((x)) #define toI(x) toi((x)) #define toD(x) tod((x)) #define toC(x) toc((x)) 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) { /* First axis reverse on anything; vector reverse */ 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,toB(0)); if (0 != size[0]) { /* real work to do */ z[[0]] = BtoB(y); /* Not sure about the coercion... */ for ( i=1; i count) /* Element reuse case */ for (i=count; i