use Array: all; use Numerical : all; use StdIO : all; use CommandLine: all; use String: {to_string,tochar,sscanf}; use ArrayFormat: all; use Bits: all; /* Compiled by APEX Version: /home/apex/apex2003/wss/sac3006.dws2009-07-14 16:59:09.880 */ /* % This is the APEX stdlib.sis include file. % Standard equates and constants for APL compiler % Also standard coercion functions */ #define toB(x) to_bool((x)) #define toI(x) toi((x)) #define toD(x) tod((x)) #define toC(x) (x) #define toc(x) ((x)) inline int plusIII(int x, int y) { return(toI(x)+toI(y)); } inline double barDDD(double x, double y) { return(toD(x)-toD(y)); } inline bool eqDDB(double x, double y, double QUADct) { /* A=B on doubles */ return((toD(x) == toD(y)) || APEXFUZZEQ(toD(x),toD(y),QUADct)); } inline int plusBBI(bool x, bool y) { return(toI(x)+toI(y)); } inline bool[+] neBBB(bool[+] x, bool[+] y) { /* AxA Dyadic scalar fn, shapes may or may not match */ sx = DSFLenErrorCheck(shape(x), shape(y),tochar("neBBB(bool[+],bool[+]")); z = with { ( . <= iv <= .) { xel = toB(x[iv]); yel = toB(y[iv]); } : neBBB(xel,yel); } : genarray(sx, false); return(z); } inline bool[+] andBBB(bool x, bool[+] y) { /* SxA scalar function */ xel = toB(x); z = with { ( . <= iv <= .) { yel = toB(y[iv]); } : andBBB(xel,yel); } : genarray(shape(y), false); return(z); } inline int[+] plusIII(int x, int[+] y) { /* SxA scalar function */ xel = toI(x); z = with { ( . <= iv <= .) { yel = toI(y[iv]); } : plusIII(xel,yel); } : genarray(shape(y), 0); return(z); } inline bool[+] andBBB(bool[+] x, bool[+] y) { /* AxA Dyadic scalar fn, shapes may or may not match */ sx = DSFLenErrorCheck(shape(x), shape(y),tochar("andBBB(bool[+],bool[+]")); z = with { ( . <= iv <= .) { xel = toB(x[iv]); yel = toB(y[iv]); } : andBBB(xel,yel); } : genarray(sx, false); return(z); } inline int[+] modIII(int x, int[+] y) { /* SxA scalar function */ xel = toI(x); z = with { ( . <= iv <= .) { yel = toI(y[iv]); } : modIII(xel,yel); } : genarray(shape(y), 0); return(z); } inline bool[+] eqBIB(bool x, int[+] y) { /* SxA scalar function */ xel = toI(x); z = with { ( . <= iv <= .) { yel = toI(y[iv]); } : eqIIB(xel,yel); } : genarray(shape(y), false); return(z); } inline bool[.,.] tranXBB(bool[.,.] y) { /* Transpose on rank-2 */ z = { [i,j] -> y[j,i] }; return(z); } inline bool[.] rotrXBB(bool[.] y) { /* Vector reverse */ n = shape(y); cell = false; z = with { ( . <= iv <= .) : y[(n-1)-iv]; } : genarray(n, cell); return(z); } inline bool[+] rotrXBB(bool[+] y) {/* Last axis reverse on rank>1 */ cellshape = take([-1], shape(y)); frameshape = drop([-1],shape(y)); cell = genarray(cellshape, false); z = with { ( . <= iv <= .) : rotrXBB(y[iv]); } : genarray(frameshape, cell); return(z); } inline bool[+] rot1XBB(bool[+] y) { /* First axis reverse on anything */ frameshape = take([1],shape(y)); cell = genarray(drop([1],shape(y)), false); z = with { ( . <= iv <= .) : y[(frameshape-[1])-iv]; } : genarray(frameshape, cell); return(z); } inline bool[+] tranXBB(bool[+] y) { /* General transpose */ z = TRANSPOSE(y); return(z); } inline bool[.] comaXBB(bool[+] y) { /* Ravel of anything with rank>1 */ z = reshape([prod(shape(y))],y); return(z); } inline bool[*] tranIBB(int[.] x, bool[*] y, int QUADio) { /* General case of dyadic transpose */ /* Someone has to validate x here! FIXME */ nx = toi(x) - QUADio; shpy = shape(y); wts = drop([1],shpy)++[1]; rankz = (take([-1], nx))[0]; /* times scan the hard way */ for(i=shape(shpy)[0] - 2; i>=0; i--) { wts[i] = wts[i+1]*wts[i]; rankz = max(rankz,nx[i]); } rankz = rankz + 1; shpz = genarray([rankz], 1 + prod(shape(y))); /* all overwritten */ cwts = shpz * 0; for(i=dim(y)-1; i>=0; i--){ j = nx[i]; shpz[j] = min( shpy[i], shpz[j]); cwts[j] = cwts[j]+wts[i]; } cp = CartProdPlus(cwts, shpz); ry = comaXBB(y); z = with { (. <= iv <= .) : ry[[cp[iv]]]; } : genarray(shape(cp), false); z = reshape(shpz,z); return(z); } inline int[.] CartProdPlus(int[.] weights, int[.] lengths) { /* Cartesian product, sum-like, for weights+each iota each lengths */ /* Weight and length vectors must be same length, and non-empty */ s = shape(weights)[[0]]; z = (0 == s) ? s : weights[[0]] * iotaXII(lengths[[0]],0); for(i=1; i=0; i--) weights[[i]] = weights[[i+1]]*toI(x); /* Now, we just do weights +.* y */ z = with { ([0] <= iv < ycols) : weights[iv] * toI(y[iv]); } : fold(+, 0); return(z); } inline int[*] dtakIBI(int x, bool[+] y) { /* Scalar basevalue rank>1 */ yt = TRANSPOSE(y); /* Dumb, but easy */ frameshape = drop([-1],shape(yt)); z = with { (. <= iv <= .) : dtakIBI(x, yt[iv]); } : genarray(frameshape, 0); return(TRANSPOSE(z)); } inline double dtakDBD(double x, bool[.] y) { /* Scalar basevalue vector */ ycols=shape(y); weights = genarray(ycols, toD(1)); for (i=ycols[[0]]-2; i>=0; i--) weights[[i]] = weights[[i+1]]*toD(x); /* Now, we just do weights +.* y */ z = with { ([0] <= iv < ycols) : weights[iv] * toD(y[iv]); } : fold(+, 0.0d); return(z); } inline bool[*] indr(bool[+] X, int I) { /* X[scalarI;;;] */ /* Used only in conjunction with other indexing, e.g., * X[scalarI;;j;] */ z = X[[I]]; return(z); } inline char[*] indr(char[+] X, int[+] I) { /* X[nonscalarI;;;] */ defcell = genarray(drop([1],shape(X)),' '); z = with { (. <= iv <= .) : X[[I[iv]]]; } : genarray(shape(I), defcell); return(z); } inline int[*] indr(int[+] X, int I) { /* X[scalarI;;;] */ /* Used only in conjunction with other indexing, e.g., * X[scalarI;;j;] */ z = X[[I]]; return(z); } inline bool[*] indr(bool[+] X) { /* X[;;;] */ /* Used only in conjunction with other indexing, e.g., * X[;;j;] */ return(X); } inline bool[+] inds1(bool[+] X, int [+] I0, bool Yin) { /* X[;;nonscalarI;;;]<- scalarY */ z = to_bool(X); Y = Yin; for(i0=0; i01 */ z = reshape([prod(shape(y))],y); return(z); } inline char[*] rhoICC(int[.] x, char[+] y) { /* APEX vector x reshape, with item reuse */ ix = toi(x); ry = comaXCC(y); zxrho = prod(ix); /* THIS NEEDS XRHO FOR CODE SAFETY!! */ yxrho = shape(ry)[[0]]; if( zxrho <= yxrho) { /* No element resuse case */ z = take([zxrho],ry); } else { ncopies = zxrho/yxrho; /* # complete copies of y. */ /* FIXME: y empty case !*/ z = with { (. <= [i] <= .) : ry; } : genarray( [ncopies], ry); /* Now append the leftover bits */ z = comaXCC(z) ++ take([zxrho-(ncopies*yxrho)],ry); } return(reshape(ix,z)); } inline bool[.] utakIIB(int[.] x, int y) { /* Vector-of-twos represent scalar */ /* */ cell = 0; k = shape(x)[[0]]-1; z = with { (. <= iv <= .) : BitAND(1,BitShiftRight(k-iv[0],toi(y))); } : genarray(shape(x), cell); return(to_bool(z)); } inline bool[*] indrfr(int fr, bool[+] X, int[+] I) { /* X[;;;I;;;], where I has fr (framerank) semicolons to its left */ /* This is actually "I from"fr X" */ frameshape = take([fr], shape(X)); cellshape = shape(I)++drop([fr+1], shape(X)); cell = genarray(cellshape, false); z = with { (. <= iv <= .) : indrfr0(X[iv], I); } : genarray(frameshape, cell); return(z); } inline bool[*] indrfr0(bool[+] X, int[+] I) { /* X[I;;;] or I from X */ cellshape = drop([1], shape(X)); cell = genarray(cellshape, false); z = with { (. <= iv <= .) : sel( I[iv], X); } : genarray(shape(I), cell); return(z); } inline bool[*] indrfr(int fr, bool[+] X, int I) { /* X[;;;I;;;], where I has fr (framerank) semicolons to its left */ /* This is actually "I from"fr X" */ frameshape = take([fr], shape(X)); cellshape = drop([1+fr],shape(X)); cell = genarray(cellshape,false); z = with { (. <= iv <= .) : sel( I, X[iv]); } : genarray(frameshape, cell); return(z); } inline char[*] indrfr(int fr, char[+] X, int[+] I) { /* X[;;;I;;;], where I has fr (framerank) semicolons to its left */ /* This is actually "I from"fr X" */ frameshape = take([fr], shape(X)); cellshape = shape(I)++drop([fr+1], shape(X)); cell = genarray(cellshape, ' '); z = with { (. <= iv <= .) : indrfr0(X[iv], I); } : genarray(frameshape, cell); return(z); } inline char[*] indrfr0(char[+] X, int[+] I) { /* X[I;;;] or I from X */ cellshape = drop([1], shape(X)); cell = genarray(cellshape, ' '); z = with { (. <= iv <= .) : sel( I[iv], X); } : genarray(shape(I), cell); return(z); } inline char[*] indrfr(int fr, char[+] X, int I) { /* X[;;;I;;;], where I has fr (framerank) semicolons to its left */ /* This is actually "I from"fr X" */ frameshape = take([fr], shape(X)); cellshape = drop([1+fr],shape(X)); cell = genarray(cellshape,' '); z = with { (. <= iv <= .) : sel( I, X[iv]); } : genarray(frameshape, cell); return(z); } inline int[*] indrfr(int fr, int[+] X, int[+] I) { /* X[;;;I;;;], where I has fr (framerank) semicolons to its left */ /* This is actually "I from"fr X" */ frameshape = take([fr], shape(X)); cellshape = shape(I)++drop([fr+1], shape(X)); cell = genarray(cellshape, 0); z = with { (. <= iv <= .) : indrfr0(X[iv], I); } : genarray(frameshape, cell); return(z); } inline int[*] indrfr0(int[+] X, int[+] I) { /* X[I;;;] or I from X */ cellshape = drop([1], shape(X)); cell = genarray(cellshape, 0); z = with { (. <= iv <= .) : sel( I[iv], X); } : genarray(shape(I), cell); return(z); } inline int[*] indrfr(int fr, int[+] X, int I) { /* X[;;;I;;;], where I has fr (framerank) semicolons to its left */ /* This is actually "I from"fr X" */ frameshape = take([fr], shape(X)); cellshape = drop([1+fr],shape(X)); cell = genarray(cellshape,0); z = with { (. <= iv <= .) : sel( I, X[iv]); } : genarray(frameshape, cell); return(z); } inline bool APEXFUZZEQ(double x, double y, double QUADct) { /* ISO APL Tolerant equality predicate */ absx = abs(x); absy = abs(y); tolerance = QUADct * max(absx,absy); z = abs(x-y) <= tolerance; return(z); } inline int[.] DSFLenErrorCheck(int[.] sx, int[.] sy, char[.] whodunit) { /* Dyadic scalar fn length error check */ z = sx; #ifdef GENME /* SAC bug #306 - side effect kills fold! */ if (any(sx != sy)) { /* Check that shapes match */ show(tochar("APEX dyadic scalar function length error in function")); show(whodunit); show(sx); show(sy); } #endif return(z); } inline bool[+] TRANSPOSE(bool[+] y) { /* Generic monadic transpose */ z = with { ( . <= iv <= .) : y[reverse( iv)]; }: genarray( reverse( shape(y)), false); return(z); } inline int[+] TRANSPOSE(int[+] y) { /* Generic monadic transpose */ z = with { ( . <= iv <= .) : y[reverse( iv)]; }: genarray( reverse( shape(y)), 0); return(z); } inline int ABC(int I, int Xshape) { /* Array bounds checker for indexed ref X[scalarI] and indexed assign */ z = I; #ifdef BOUNDSCHECKING /* This needs more thought... */ if ( (I < 0) || (I >= Xshape)) { print(tochar("APEX index error!")); } #endif return(z); } inline int[+] ABC(int[+] I, int Xshape) { /* Array bounds checker for indexed ref X[nonscalarI] and indexed assign */ z = I; #ifdef BOUNDSCHECKING bad = with { ((0*shape(z)) <= iv < shape(z)) : (z[iv] < 0) || (z[iv] >= Xshape); }: fold(|, false); if (bad) print(tochar("APEX index error!")); #endif return(z); } inline int plusslXBIFOLD(bool[.] y) { /* First/last axis fold-based reduction of vector */ lim = shape(y)[0]-1; z = with { (0*shape(y) <= iv < shape(y)) : toI(y[lim-iv]); } : fold( plusIII, toI(0)); return(z); } inline char[.] comaXCC(char[+] y) { /* Ravel of anything with rank>1 */ z = reshape([prod(shape(y))],y); return(z); } inline char[.] bfcrc32BCC(bool[.,.] tab, char[.] v ,int QUADio) { /* ? */ A_45=rhoIBB(8,false); z8_0=( A_45); A_47=rhoIBB(32,A_45); q_0=( A_47); A_49=quadavXXC( ); A_52=iotaCCIQUADAV(A_49,v,QUADio); A_53=utakIIB([2, 2, 2, 2, 2, 2, 2, 2],A_52); A_54=tranXBB( A_53); vb_0=( A_54); A_56=rhoXCI( v); A_58=iotaXII( A_56,QUADio); A_CTR59_= 0; A_CTR59z_ = (shape(A_58)[[0]])-1; q_2=to_bool(q_0); for(; A_CTR59_ <= A_CTR59z_; A_CTR59_++){ i_0 = A_58[[A_CTR59_]]; A_62= ABC(toi(i_0)-QUADio,shape(vb_0)[0]); A_64=vb_0[[A_62]]; A_65=takeIBB(8,q_2); /* dsf Check needed */ A_67=neBBB(A_65,A_64); A_68=dtakIBI(2,A_67); t_0=( A_68); A_71= ABC(toi(t_0)-QUADio,shape(tab)[0]); A_73=tab[[A_71]]; A_74=comaBBB(q_2,z8_0); A_75=dropIBB(8,A_74); /* dsf Check needed */ A_77=neBBB(A_75,A_73); q_2=( A_77); } A_80=rhoIBB([4, 8],q_2); A_81=tranXBB( A_80); A_82=dtakIBI(2,A_81); A_84=quadavXXC( ); A_83= ABC(toi(A_82)-QUADio,shape(A_84)[0]); A_86=indr(A_84,A_83); p_0=( A_86); return(p_0); } inline bool[.,.] table32XBB(bool[.] p ,int QUADio) { /* ? */ A_55=rotrXBB( p); A_56=takeIBB(64,A_55); p_0=( A_56); A_58=rhoIBB([1, 64],A_56); g_0=( A_58); A_61=iotaXII( 7,QUADio); A_CTR62_= 0; A_CTR62z_ = (shape(A_61)[[0]])-1; g_2=to_bool(g_0); for(; A_CTR62_ <= A_CTR62z_; A_CTR62_++){ j_0 = A_61[[A_CTR62_]]; A_65=rhoXBI( g_2); A_64= ABC(toi(false)-QUADio,shape(A_65)[0]); A_67=A_65[[A_64]]; /* dsf scalar(s) */ A_68=plusIII(-1,A_67); A_70= ABC(toi(A_68)-QUADio,shape(g_2)[0]); A_72=g_2[[A_70]]; gl_0=( A_72); A_74= ABC(toi(31)-QUADio,shape(gl_0)[0]); A_76=gl_0[[A_74]]; gl31_0=( A_76); /* dsf scalar(s) */ A_78=andBBB(gl31_0,p_0); A_79=comaBBB(false,gl_0); A_80=dropIBB(-1,A_79); /* dsf Check needed */ A_82=neBBB(A_80,A_78); A_83=combBBBLG(g_2,A_82); g_2=( A_83); } A_86=rotrXBB( g_2); A_87=rot1XBB( A_86); g_3=( A_87); A_90=iotaXII( 256,QUADio); A_91=utakIIB([2, 2, 2, 2, 2, 2, 2, 2],A_90); A_92=rhoIBB([32, 8, 256],A_91); A_93=tranXBB( A_92); i_0=( A_93); A_96=iotaXII( 32,QUADio); /* dsf scalar(s) */ A_97=plusIII(32,A_96); A_98= ABC(toi(A_97)-QUADio,shape(g_3)[1]); A_101=indrfr(1,g_3,A_98); A_102=rhoIBB([256, 8, 32],A_101); /* dsf Check needed */ A_103=andBBB(i_0,A_102); r_0=( A_103); A_106=tranIBB([0, 2, 1],r_0,QUADio); A_107=plusslXBIFOLD( A_106); /* dsf scalar(s) */ A_112=modIII(2,A_107); /* dsf scalar(s) */ A_114=eqBIB(true,A_112); r_1=( A_114); return(r_1); } inline bool[.] tobinXCB(char[.] c ,int QUADio) { /* ? */ A_23=quadavXXC( ); A_26=iotaCCIQUADAV(A_23,c,QUADio); A_27=utakIIB([2, 2, 2, 2, 2, 2, 2, 2],A_26); A_28=tranXBB( A_27); A_29=comaXBB( A_28); r_0=( A_29); return(r_0); } inline bool[.] crctestXIB(int len,int QUADio) { /* ? */ A_38=rhoIBB(33,false); crcloc32_0=( A_38); A_40= ABC(toi([0, 5, 11, 17, 23, 28, 32])-QUADio,shape(crcloc32_0)[0]); A_42=inds1(crcloc32_0,A_40,true); crcloc32_1=( A_42); A_44=quadavXXC( ); A_45=rhoICC(len,A_44); cv_0=( A_45); A_48=table32XBB( crcloc32_1,QUADio); t32_0=( A_48); A_51=bfcrc32BCC(t32_0,cv_0,QUADio); A_53=tobinXCB( A_51,QUADio); r_0=( A_53); return(r_0); } int main() { /* ? */ n=CommandLineArgvXBI( true); QUADio_0=toi(( false)); QUADct_0=( 1.0e-13); QUADpp_0=( 10); QUADpw_0=( 80); QUADrl_0=( 16807); QUADio_1=toi(( false)); QUADrl_1=( 16807); QUADpp_1=( 16); QUADpw_1=( 80); QUADct_1=( 1.0e-14); A_65=crctestXIB( n,QUADio_1); r_0=( A_65); A_69=quadXBB( A_65,QUADpp_1,QUADpw_1); /* dsf scalar(s) */ A_70=barDDD(3.5,1.5); A_71=dtakDBD(A_70,r_0); A_72=rhoCDD([:char],A_71); r_1=( A_72); A_76=quadXDD( A_72,QUADpp_1,QUADpw_1); /* dsf scalar(s) */ A_77=barDDD(3604692541.5,0.5); /* dsf scalar(s) */ A_79=eqDDB(r_1,A_77,QUADct_1); /* dsf scalar(s) */ A_80=plusBBI(true,A_79); r_2=( A_80); A_84=quadXII( A_80,QUADpp_1,QUADpw_1); return(r_2); }