#!../src/tops  -s ../sys  -u ../usr

"cmpySSL" missing
IF
    "tops not compiled with LAPACK or ESSL; cannot run basic_math" nl .
    halt
THEN



define: cmcm_mult_test ( n --- )
    \ Complex Matrix-matrix multiplication tester.
    \ Creates two matrices with random sizes i x j and j x k,
    \ where i,j,k <= n, then multiplies them together.  The
    \ product is compared against separate products of the
    \ real and imaginary parts.
    
    dup dup
    rand * integer 1 + into rA       \ rows of [A]
    rand * integer 1 + into cArB     \ columns of [A] and rows of [B]
    rand * integer 1 + into cB       \ columns of [B]
    rA   "%3.0f x " format . cArB "%3.0f" format . " times " .  
    cArB "%3.0f x " format . cB   "%3.0f" format . 
    rA cArB random into Ar           \
    rA cArB random into Ai           \
    cArB cB random into Br           \
    cArB cB random into Bi           \
    Ar Ai Br Bi cmpySSL into Ci into Cr \  [C] = [A] * [B]
    Ar Br * Ai Bi * - into myCr         \
    Ar Bi * Ai Br * + into myCi         \

    Cr myCr - maxfetch drop drop abs  \  ( --- |delta_Re| )
    Ci myCi - maxfetch drop drop abs  \  (|delta_Re| --- |delta_Re| |delta_Im| )
    +                                 \  ( --- |sum abs max error|) 
    dup .
    1.0e-13 > 
    IF  
        " cmpySSL ERROR " . 
        quit
    ELSE  
        " cmpySSL OK    " . 
    THEN
    nl
    xx
    ;

define: n_cmcm_mult_test ( nIter nSize  --- )
    \ Invokes cmcm_mult_test nIter times for a random sized systems up to nSize
    into nSize
    1 DO I nSize 
        I "%5.0f.  " format .
        cmcm_mult_test
    LOOP
    ;

time seedset
5 20 n_cmcm_mult_test
# 20000 100 n_sparse_tests
