home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / mesch12a.zip / memtort.c < prev    next >
C/C++ Source or Header  |  1994-01-14  |  18KB  |  759 lines

  1.  
  2. /**************************************************************************
  3. **
  4. ** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  5. **
  6. **                 Meschach Library
  7. ** 
  8. ** This Meschach Library is provided "as is" without any express 
  9. ** or implied warranty of any kind with respect to this software. 
  10. ** In particular the authors shall not be liable for any direct, 
  11. ** indirect, special, incidental or consequential damages arising 
  12. ** in any way from use of the software.
  13. ** 
  14. ** Everyone is granted permission to copy, modify and redistribute this
  15. ** Meschach Library, provided:
  16. **  1.  All copies contain this copyright notice.
  17. **  2.  All modified copies shall carry a notice stating who
  18. **      made the last modification and the date of such modification.
  19. **  3.  No charge is made for this software or works derived from it.  
  20. **      This clause shall not be construed as constraining other software
  21. **      distributed on the same medium as this software, nor is a
  22. **      distribution fee considered a charge.
  23. **
  24. ***************************************************************************/
  25.  
  26.  
  27. /* 
  28.   Tests for mem_info.c functions
  29.   */
  30.  
  31. static char rcsid[] = "$Id: $";
  32.  
  33. #include        <stdio.h>
  34. #include        <math.h>
  35. #include        "matrix2.h"
  36. #include     "sparse2.h"
  37. #include      "zmatrix2.h"
  38.  
  39.  
  40. #define errmesg(mesg)   printf("Error: %s error: line %d\n",mesg,__LINE__)
  41. #define notice(mesg)    printf("# Testing %s...\n",mesg)
  42.  
  43.  
  44. /*  new types list */
  45.  
  46. extern MEM_CONNECT mem_connect[MEM_CONNECT_MAX_LISTS];
  47.  
  48. /* the number of a new list */
  49. #define FOO_LIST 1
  50.  
  51. /* numbers of types */
  52. #define TYPE_FOO_1    1
  53. #define TYPE_FOO_2    2
  54.  
  55. typedef struct {
  56.    int dim;
  57.    int fix_dim;
  58.    Real (*a)[10];
  59. } FOO_1;
  60.  
  61. typedef struct {
  62.   int dim;
  63.   int fix_dim;
  64.   Real (*a)[2];
  65. } FOO_2;
  66.  
  67.  
  68.  
  69. FOO_1 *foo_1_get(dim)
  70. int dim;
  71. {
  72.    FOO_1 *f;
  73.    
  74.    if ((f = (FOO_1 *)malloc(sizeof(FOO_1))) == NULL)
  75.      error(E_MEM,"foo_1_get");
  76.    else if (mem_info_is_on()) {
  77.       mem_bytes_list(TYPE_FOO_1,0,sizeof(FOO_1),FOO_LIST);
  78.       mem_numvar_list(TYPE_FOO_1,1,FOO_LIST);
  79.    }
  80.    
  81.    f->dim = dim;
  82.    f->fix_dim = 10;
  83.    if ((f->a = (Real (*)[10])malloc(dim*sizeof(Real [10]))) == NULL)
  84.       error(E_MEM,"foo_1_get");
  85.    else if (mem_info_is_on())
  86.      mem_bytes_list(TYPE_FOO_1,0,dim*sizeof(Real [10]),FOO_LIST); 
  87.  
  88.    return f;
  89. }
  90.  
  91.  
  92. FOO_2 *foo_2_get(dim)
  93. int dim;
  94. {
  95.    FOO_2 *f;
  96.    
  97.    if ((f = (FOO_2 *)malloc(sizeof(FOO_2))) == NULL)
  98.      error(E_MEM,"foo_2_get");
  99.    else if (mem_info_is_on()) {
  100.       mem_bytes_list(TYPE_FOO_2,0,sizeof(FOO_2),FOO_LIST);
  101.       mem_numvar_list(TYPE_FOO_2,1,FOO_LIST);
  102.    }
  103.  
  104.    f->dim = dim;
  105.    f->fix_dim = 2;
  106.    if ((f->a = (Real (*)[2])malloc(dim*sizeof(Real [2]))) == NULL)
  107.       error(E_MEM,"foo_2_get");
  108.    else if (mem_info_is_on())
  109.      mem_bytes_list(TYPE_FOO_2,0,dim*sizeof(Real [2]),FOO_LIST); 
  110.  
  111.    return f;
  112. }
  113.  
  114.  
  115.  
  116. int foo_1_free(f)
  117. FOO_1 *f;
  118. {
  119.    if ( f != NULL) {
  120.       if (mem_info_is_on()) {
  121.      mem_bytes_list(TYPE_FOO_1,sizeof(FOO_1)+
  122.             f->dim*sizeof(Real [10]),0,FOO_LIST);
  123.      mem_numvar_list(TYPE_FOO_1,-1,FOO_LIST);
  124.       }
  125.  
  126.       free(f->a);
  127.       free(f);
  128.    }
  129.    return 0;
  130. }
  131.  
  132. int foo_2_free(f)
  133. FOO_2 *f;
  134. {
  135.    if ( f != NULL) {
  136.       if (mem_info_is_on()) {
  137.      mem_bytes_list(TYPE_FOO_2,sizeof(FOO_2)+
  138.             f->dim*sizeof(Real [2]),0,FOO_LIST);
  139.      mem_numvar_list(TYPE_FOO_2,-1,FOO_LIST);
  140.       }
  141.  
  142.       free(f->a);
  143.       free(f);
  144.    }
  145.    return 0;
  146. }
  147.  
  148.  
  149.  
  150.  
  151. char *foo_type_name[] = {
  152.    "nothing",
  153.    "FOO_1",
  154.    "FOO_2"
  155. };
  156.  
  157.  
  158. #define FOO_NUM_TYPES  (sizeof(foo_type_name)/sizeof(*foo_type_name))
  159.  
  160.  
  161. int (*foo_free_func[FOO_NUM_TYPES])() = {
  162.    NULL, 
  163.    foo_1_free, 
  164.    foo_2_free
  165.   };
  166.  
  167.  
  168.  
  169. static MEM_ARRAY foo_info_sum[FOO_NUM_TYPES];
  170.  
  171.  
  172.  
  173.   /* px_rand -- generates sort-of random permutation */
  174. PERM    *px_rand(pi)
  175. PERM    *pi;
  176. {
  177.    int         i, j, k;
  178.    
  179.    if ( ! pi )
  180.      error(E_NULL,"px_rand");
  181.    
  182.    for ( i = 0; i < 3*pi->size; i++ )
  183.    {
  184.       j = (rand() >> 8) % pi->size;
  185.       k = (rand() >> 8) % pi->size;
  186.       px_transp(pi,j,k);
  187.    }
  188.    
  189.    return pi;
  190. }
  191.  
  192. #ifdef SPARSE
  193. SPMAT  *gen_non_symm(m,n)
  194. int     m, n;
  195. {
  196.     SPMAT      *A;
  197.     static      PERM    *px = PNULL;
  198.     int         i, j, k, k_max;
  199.     Real        s1;
  200.  
  201.     A = sp_get(m,n,8);
  202.     px = px_resize(px,n);
  203.     MEM_STAT_REG(px,TYPE_PERM);
  204.     for ( i = 0; i < A->m; i++ )
  205.     {
  206.         k_max = 1 + ((rand() >> 8) % 10);
  207.         for ( k = 0; k < k_max; k++ )
  208.         {
  209.             j = (rand() >> 8) % A->n;
  210.             s1 = rand()/((double)MAX_RAND);
  211.             sp_set_val(A,i,j,s1);
  212.         }
  213.     }
  214.     /* to make it likely that A is nonsingular, use pivot... */
  215.     for ( i = 0; i < 2*A->n; i++ )
  216.     {
  217.         j = (rand() >> 8) % A->n;
  218.         k = (rand() >> 8) % A->n;
  219.         px_transp(px,j,k);
  220.     }
  221.     for ( i = 0; i < A->n; i++ )
  222.         sp_set_val(A,i,px->pe[i],1.0);
  223.  
  224.     
  225.     return A;
  226. }
  227. #endif
  228.  
  229. void stat_test1(par)
  230. int par;
  231. {
  232.    static MAT *AT = MNULL;
  233.    static VEC *xt1 = VNULL, *yt1 = VNULL;
  234.    static VEC *xt2 = VNULL, *yt2 = VNULL;
  235.    static VEC *xt3 = VNULL, *yt3 = VNULL;
  236.    static VEC *xt4 = VNULL, *yt4 = VNULL;
  237.  
  238.    AT = m_resize(AT,10,10);
  239.    xt1 = v_resize(xt1,10);
  240.    yt1 = v_resize(yt1,10);
  241.    xt2 = v_resize(xt2,10);
  242.    yt2 = v_resize(yt2,10);
  243.    xt3 = v_resize(xt3,10);
  244.    yt3 = v_resize(yt3,10);
  245.    xt4 = v_resize(xt4,10);
  246.    yt4 = v_resize(yt4,10);
  247.  
  248.    MEM_STAT_REG(AT,TYPE_MAT);
  249.  
  250. #ifdef ANSI_C
  251.    mem_stat_reg_vars(0,TYPE_VEC,&xt1,&xt2,&xt3,&xt4,&yt1,
  252.              &yt2,&yt3,&yt4,NULL);
  253. #else
  254. #ifdef VARARGS
  255.    mem_stat_reg_vars(0,TYPE_VEC,&xt1,&xt2,&xt3,&xt4,&yt1,
  256.              &yt2,&yt3,&yt4,NULL);
  257. #else
  258.    MEM_STAT_REG(xt1,TYPE_VEC);
  259.    MEM_STAT_REG(yt1,TYPE_VEC);
  260.    MEM_STAT_REG(xt2,TYPE_VEC);
  261.    MEM_STAT_REG(yt2,TYPE_VEC);
  262.    MEM_STAT_REG(xt3,TYPE_VEC);
  263.    MEM_STAT_REG(yt3,TYPE_VEC);
  264.    MEM_STAT_REG(xt4,TYPE_VEC);
  265.    MEM_STAT_REG(yt4,TYPE_VEC);
  266. #endif
  267. #endif
  268.  
  269.    v_rand(xt1);
  270.    m_rand(AT);
  271.    mv_mlt(AT,xt1,yt1);
  272.    
  273. }
  274.  
  275.  
  276. void stat_test2(par)
  277. int par;
  278. {
  279.    static PERM *px = PNULL;
  280.    static IVEC *ixt = IVNULL, *iyt = IVNULL;
  281.    
  282.    px = px_resize(px,10);
  283.    ixt = iv_resize(ixt,10);
  284.    iyt = iv_resize(iyt,10);
  285.  
  286.    MEM_STAT_REG(px,TYPE_PERM);
  287.    MEM_STAT_REG(ixt,TYPE_IVEC);
  288.    MEM_STAT_REG(iyt,TYPE_IVEC);
  289.  
  290.    px_rand(px);
  291.    px_inv(px,px);
  292. }
  293.  
  294. #ifdef SPARSE
  295. void stat_test3(par)
  296. int par;
  297. {
  298.    static SPMAT *AT = (SPMAT *)NULL;
  299.    static VEC *xt = VNULL, *yt = VNULL;
  300.    static SPROW *r = (SPROW *) NULL;
  301.    
  302.    if (AT == (SPMAT *)NULL)
  303.      AT = gen_non_symm(100,100);
  304.    else
  305.      AT = sp_resize(AT,100,100);
  306.    xt = v_resize(xt,100);
  307.    yt = v_resize(yt,100);
  308.    if (r == NULL) r = sprow_get(100);
  309.  
  310.    MEM_STAT_REG(AT,TYPE_SPMAT);
  311.    MEM_STAT_REG(xt,TYPE_VEC);
  312.    MEM_STAT_REG(yt,TYPE_VEC);
  313.    MEM_STAT_REG(r,TYPE_SPROW);
  314.  
  315.    v_rand(xt);
  316.    sp_mv_mlt(AT,xt,yt);
  317.    
  318. }
  319. #endif
  320.  
  321. #ifdef COMPLEX
  322. void stat_test4(par)
  323. int par;
  324. {
  325.    static ZMAT *AT = ZMNULL;
  326.    static ZVEC *xt = ZVNULL, *yt = ZVNULL;
  327.    
  328.    AT = zm_resize(AT,10,10);
  329.    xt = zv_resize(xt,10);
  330.    yt = zv_resize(yt,10);
  331.  
  332.    MEM_STAT_REG(AT,TYPE_ZMAT);
  333.    MEM_STAT_REG(xt,TYPE_ZVEC);
  334.    MEM_STAT_REG(yt,TYPE_ZVEC);
  335.  
  336.    zv_rand(xt);
  337.    zm_rand(AT);
  338.    zmv_mlt(AT,xt,yt);
  339.    
  340. }
  341. #endif
  342.  
  343.  
  344. void main(argc, argv)
  345. int     argc;
  346. char    *argv[];
  347. {
  348.    VEC  *x = VNULL, *y = VNULL, *z = VNULL;
  349.    PERM  *pi1 = PNULL, *pi2 = PNULL, *pi3 = PNULL;
  350.    MAT   *A = MNULL, *B = MNULL, *C = MNULL;
  351. #ifdef SPARSE
  352.    SPMAT *sA, *sB;
  353.    SPROW *r;
  354. #endif
  355.    IVEC *ix = IVNULL, *iy = IVNULL, *iz = IVNULL;
  356.    int m,n,i,j,deg,k;
  357.    Real s1,s2;
  358. #ifdef COMPLEX
  359.    ZVEC        *zx = ZVNULL, *zy = ZVNULL, *zz = ZVNULL;
  360.    ZMAT        *zA = ZMNULL, *zB = ZMNULL, *zC = ZMNULL;
  361.    complex     ONE;
  362. #endif
  363.    /* variables for testing attaching new lists of types  */
  364.    FOO_1 *foo_1;
  365.    FOO_2 *foo_2;
  366.  
  367.  
  368.    mem_info_on(TRUE);
  369.  
  370. #if defined(ANSI_C) || defined(VARARGS)
  371.  
  372.    notice("vector initialize, copy & resize");
  373.    
  374.    n = v_get_vars(15,&x,&y,&z,(VEC **)NULL);
  375.    if (n != 3) {
  376.       errmesg("v_get_vars");
  377.       printf(" n = %d (should be 3)\n",n);
  378.    }
  379.  
  380.    v_rand(x);
  381.    v_rand(y);
  382.    z = v_copy(x,z);
  383.    if ( v_norm2(v_sub(x,z,z)) >= MACHEPS )
  384.      errmesg("v_get_vars");
  385.    v_copy(x,y);
  386.    n = v_resize_vars(10,&x,&y,&z,NULL);
  387.    if ( n != 3 || v_norm2(v_sub(x,y,z)) >= MACHEPS )
  388.      errmesg("VEC copy/resize");
  389.  
  390.    n = v_resize_vars(20,&x,&y,&z,NULL);
  391.    if ( n != 3 || v_norm2(v_sub(x,y,z)) >= MACHEPS )
  392.      errmesg("VEC resize"); 
  393.  
  394.    n = v_free_vars(&x,&y,&z,NULL);
  395.    if (n != 3)
  396.      errmesg("v_free_vars");
  397.    
  398.    /* IVEC */
  399.    notice("int vector initialise, copy & resize");
  400.    n = iv_get_vars(15,&ix,&iy,&iz,NULL);
  401.  
  402.    if (n != 3) {
  403.       errmesg("iv_get_vars");
  404.       printf(" n = %d (should be 3)\n",n);
  405.    }
  406.    for (i=0; i < ix->dim; i++) {
  407.       ix->ive[i] = 2*i-1;
  408.       iy->ive[i] = 3*i+2;
  409.    }
  410.    iz = iv_add(ix,iy,iz);
  411.    for (i=0; i < ix->dim; i++) 
  412.      if ( iz->ive[i] != 5*i+1)
  413.        errmesg("iv_get_vars");
  414.    
  415.    n = iv_resize_vars(10,&ix,&iy,&iz,NULL);
  416.    if ( n != 3) errmesg("IVEC copy/resize");
  417.    
  418.    iv_add(ix,iy,iz);
  419.    for (i=0; i < ix->dim; i++)
  420.      if (iz->ive[i] != 5*i+1)
  421.        errmesg("IVEC copy/resize");
  422.    
  423.    n = iv_resize_vars(20,&ix,&iy,&iz,NULL);
  424.    if ( n != 3 ) errmesg("IVEC resize");
  425.    
  426.    iv_add(ix,iy,iz);
  427.    for (i=0; i < 10; i++)
  428.      if (iz->ive[i] != 5*i+1)
  429.        errmesg("IVEC copy/resize");
  430.    
  431.    n = iv_free_vars(&ix,&iy,&iz,NULL);
  432.    if (n != 3) 
  433.      errmesg("iv_free_vars");
  434.    
  435.    /* MAT */
  436.    notice("matrix initialise, copy & resize");
  437.    n = m_get_vars(10,10,&A,&B,&C,NULL);
  438.    if (n != 3) {
  439.       errmesg("m_get_vars");
  440.       printf(" n = %d (should be 3)\n",n);
  441.    }
  442.    
  443.    m_rand(A);
  444.    m_rand(B);
  445.    C = m_copy(A,C);
  446.    if ( m_norm_inf(m_sub(A,C,C)) >= MACHEPS )
  447.      errmesg("MAT copy");
  448.    m_copy(A,B);
  449.    n = m_resize_vars(5,5,&A,&B,&C,NULL);
  450.    if ( n != 3 || m_norm_inf(m_sub(A,B,C)) >= MACHEPS )
  451.      errmesg("MAT copy/resize");
  452.    
  453.    n = m_resize_vars(20,20,&A,&B,NULL);
  454.    if ( m_norm_inf(m_sub(A,B,C)) >= MACHEPS )
  455.      errmesg("MAT resize"); 
  456.    
  457.    k = m_free_vars(&A,&B,&C,NULL);
  458.    if ( k != 3 )
  459.      errmesg("MAT free");
  460.    
  461.    /* PERM */
  462.    notice("permutation initialise, inverting & permuting vectors");
  463.    n = px_get_vars(15,&pi1,&pi2,&pi3,NULL);
  464.    if (n != 3) {
  465.       errmesg("px_get_vars");
  466.       printf(" n = %d (should be 3)\n",n);
  467.    }
  468.  
  469.    v_get_vars(15,&x,&y,&z,NULL);
  470.    
  471.    px_rand(pi1);
  472.    v_rand(x);
  473.    px_vec(pi1,x,z);
  474.    y = v_resize(y,x->dim);
  475.    pxinv_vec(pi1,z,y);
  476.    if ( v_norm2(v_sub(x,y,z)) >= MACHEPS )
  477.      errmesg("PERMute vector");
  478.    pi2 = px_inv(pi1,pi2);
  479.    pi3 = px_mlt(pi1,pi2,pi3);
  480.    for ( i = 0; i < pi3->size; i++ )
  481.      if ( pi3->pe[i] != i )
  482.        errmesg("PERM inverse/multiply");
  483.    
  484.    px_resize_vars(20,&pi1,&pi2,&pi3,NULL);
  485.    v_resize_vars(20,&x,&y,&z,NULL);
  486.    
  487.    px_rand(pi1);
  488.    v_rand(x);
  489.    px_vec(pi1,x,z);
  490.    pxinv_vec(pi1,z,y);
  491.    if ( v_norm2(v_sub(x,y,z)) >= MACHEPS )
  492.      errmesg("PERMute vector");
  493.    pi2 = px_inv(pi1,pi2);
  494.    pi3 = px_mlt(pi1,pi2,pi3);
  495.    for ( i = 0; i < pi3->size; i++ )
  496.      if ( pi3->pe[i] != i )
  497.        errmesg("PERM inverse/multiply");
  498.    
  499.    n = px_free_vars(&pi1,&pi2,&pi3,NULL);
  500.    if ( n != 3 )
  501.      errmesg("PERM px_free_vars"); 
  502.  
  503. #ifdef SPARSE   
  504.    /* set up two random sparse matrices */
  505.    m = 120;
  506.    n = 100;
  507.    deg = 5;
  508.    notice("allocating sparse matrices");
  509.    k = sp_get_vars(m,n,deg,&sA,&sB,NULL);
  510.    if (k != 2) {
  511.       errmesg("sp_get_vars");
  512.       printf(" n = %d (should be 2)\n",k);
  513.    }
  514.    
  515.    notice("setting and getting matrix entries");
  516.    for ( k = 0; k < m*deg; k++ )
  517.    {
  518.       i = (rand() >> 8) % m;
  519.       j = (rand() >> 8) % n;
  520.       sp_set_val(sA,i,j,rand()/((Real)MAX_RAND));
  521.       i = (rand() >> 8) % m;
  522.       j = (rand() >> 8) % n;
  523.       sp_set_val(sB,i,j,rand()/((Real)MAX_RAND));
  524.    }
  525.    for ( k = 0; k < 10; k++ )
  526.    {
  527.       s1 = rand()/((Real)MAX_RAND);
  528.       i = (rand() >> 8) % m;
  529.       j = (rand() >> 8) % n;
  530.       sp_set_val(sA,i,j,s1);
  531.       s2 = sp_get_val(sA,i,j);
  532.       if ( fabs(s1 - s2) >= MACHEPS ) {
  533.      printf(" s1 = %g, s2 = %g, |s1 - s2| = %g\n", 
  534.         s1,s2,fabs(s1-s2));
  535.      break;
  536.       }
  537.    }
  538.    if ( k < 10 )
  539.      errmesg("sp_set_val()/sp_get_val()");
  540.    
  541.    /* check column access paths */
  542.    notice("resizing and access paths");
  543.    k = sp_resize_vars(sA->m+10,sA->n+10,&sA,&sB,NULL);
  544.    if (k != 2) {
  545.       errmesg("sp_get_vars");
  546.       printf(" n = %d (should be 2)\n",k);
  547.    }
  548.    
  549.    for ( k = 0 ; k < 20; k++ )
  550.    {
  551.       i = sA->m - 1 - ((rand() >> 8) % 10);
  552.       j = sA->n - 1 - ((rand() >> 8) % 10);
  553.       s1 = rand()/((Real)MAX_RAND);
  554.       sp_set_val(sA,i,j,s1);
  555.       if ( fabs(s1 - sp_get_val(sA,i,j)) >= MACHEPS )
  556.     break;
  557.    }
  558.    if ( k < 20 )
  559.      errmesg("sp_resize()");
  560.    sp_col_access(sA);
  561.    if ( ! chk_col_access(sA) )
  562.    {
  563.       errmesg("sp_col_access()");
  564.    }
  565.    sp_diag_access(sA);
  566.    for ( i = 0; i < sA->m; i++ )
  567.    {
  568.       r = &(sA->row[i]);
  569.       if ( r->diag != sprow_idx(r,i) )
  570.     break;
  571.    }
  572.    if ( i < sA->m )
  573.    {
  574.       errmesg("sp_diag_access()");
  575.    }
  576.    
  577.    k = sp_free_vars(&sA,&sB,NULL);
  578.    if (k != 2)
  579.      errmesg("sp_free_vars");
  580. #endif  /* SPARSE */   
  581.  
  582.  
  583. #ifdef COMPLEX
  584.    /* complex stuff */
  585.    
  586.    ONE = zmake(1.0,0.0);
  587.    printf("# ONE = "); z_output(ONE);
  588.    printf("# Check: MACHEPS = %g\n",MACHEPS);
  589.    /* allocate, initialise, copy and resize operations */
  590.    /* ZVEC */
  591.    notice("vector initialise, copy & resize");
  592.    zv_get_vars(12,&zx,&zy,&zz,NULL);
  593.    
  594.    zv_rand(zx);
  595.    zv_rand(zy);
  596.    zz = zv_copy(zx,zz);
  597.    if ( zv_norm2(zv_sub(zx,zz,zz)) >= MACHEPS )
  598.      errmesg("ZVEC copy");
  599.    zv_copy(zx,zy);
  600.    
  601.    zv_resize_vars(10,&zx,&zy,NULL);
  602.    if ( zv_norm2(zv_sub(zx,zy,zz)) >= MACHEPS )
  603.      errmesg("ZVEC copy/resize");
  604.    
  605.    zv_resize_vars(20,&zx,&zy,NULL);
  606.    if ( zv_norm2(zv_sub(zx,zy,zz)) >= MACHEPS )
  607.      errmesg("VZEC resize");
  608.    zv_free_vars(&zx,&zy,&zz,NULL);
  609.  
  610.    
  611.    /* ZMAT */
  612.    notice("matrix initialise, copy & resize");
  613.    zm_get_vars(8,5,&zA,&zB,&zC,NULL);
  614.    
  615.    zm_rand(zA);
  616.    zm_rand(zB);
  617.    zC = zm_copy(zA,zC);
  618.    if ( zm_norm_inf(zm_sub(zA,zC,zC)) >= MACHEPS )
  619.      errmesg("ZMAT copy");
  620.    
  621.    zm_copy(zA,zB);
  622.    zm_resize_vars(3,5,&zA,&zB,&zC,NULL);
  623.    
  624.    if ( zm_norm_inf(zm_sub(zA,zB,zC)) >= MACHEPS )
  625.      errmesg("ZMAT copy/resize");
  626.    zm_resize_vars(20,20,&zA,&zB,&zC,NULL);
  627.    
  628.    if ( zm_norm_inf(zm_sub(zA,zB,zC)) >= MACHEPS )
  629.      errmesg("ZMAT resize");
  630.    
  631.    zm_free_vars(&zA,&zB,&zC,NULL);
  632. #endif /* COMPLEX */
  633.  
  634. #endif  /* if defined(ANSI_C) || defined(VARARGS) */
  635.  
  636.    printf("# test of mem_info_bytes and mem_info_numvar\n");
  637.    printf("  TYPE VEC: %ld bytes allocated, %d variables allocated\n",
  638.       mem_info_bytes(TYPE_VEC,0),mem_info_numvar(TYPE_VEC,0));
  639.  
  640.    notice("static memory test");
  641.    mem_info_on(TRUE);
  642.    mem_stat_mark(1);
  643.    for (i=0; i < 100; i++)
  644.      stat_test1(i);
  645.    mem_stat_free(1);
  646.  
  647.    mem_stat_mark(1);
  648.    for (i=0; i < 100; i++) {
  649.      stat_test1(i);
  650. #ifdef COMPLEX
  651.      stat_test4(i);
  652. #endif
  653.   }
  654.  
  655.    mem_stat_mark(2);
  656.    for (i=0; i < 100; i++)
  657.      stat_test2(i);
  658.  
  659.    mem_stat_mark(3);
  660. #ifdef SPARSE
  661.    for (i=0; i < 100; i++)
  662.      stat_test3(i);
  663. #endif
  664.  
  665.    mem_info();
  666.    mem_dump_list(stdout,0);
  667.  
  668.    mem_stat_free(1);
  669.    mem_stat_free(3);
  670.    mem_stat_mark(4);
  671.  
  672.    for (i=0; i < 100; i++) {
  673.       stat_test1(i);
  674. #ifdef COMPLEX
  675.       stat_test4(i);
  676. #endif
  677.    } 
  678.  
  679.    mem_stat_dump(stdout,0);
  680.    if (mem_stat_show_mark() != 4) {
  681.       errmesg("not 4 in mem_stat_show_mark()");
  682.    }
  683.    
  684.    mem_stat_free(2);
  685.    mem_stat_free(4);
  686.  
  687.    if (mem_stat_show_mark() != 0) {
  688.       errmesg("not 0 in mem_stat_show_mark()");
  689.    }
  690.  
  691.    /* add new list of types */
  692.  
  693.    mem_attach_list(FOO_LIST,FOO_NUM_TYPES,foo_type_name,
  694.            foo_free_func,foo_info_sum);
  695.    if (!mem_is_list_attached(FOO_LIST))
  696.      errmesg("list FOO_LIST is not attached");
  697.  
  698.    mem_dump_list(stdout,FOO_LIST);
  699.    foo_1 = foo_1_get(6);
  700.    foo_2 = foo_2_get(3);
  701.    for (i=0; i < foo_1->dim; i++)
  702.      for (j=0; j < foo_1->fix_dim; j++)
  703.        foo_1->a[i][j] = i+j;
  704.    for (i=0; i < foo_2->dim; i++)
  705.      for (j=0; j < foo_2->fix_dim; j++)
  706.        foo_2->a[i][j] = i+j;
  707.    printf(" foo_1->a[%d][%d] = %g\n",5,9,foo_1->a[5][9]);
  708.    printf(" foo_2->a[%d][%d] = %g\n",2,1,foo_2->a[2][1]);
  709.    
  710.    mem_stat_mark(5);
  711.    mem_stat_reg_list((void **)&foo_1,TYPE_FOO_1,FOO_LIST);
  712.    mem_stat_reg_list((void **)&foo_2,TYPE_FOO_2,FOO_LIST);
  713.    mem_stat_dump(stdout,FOO_LIST);
  714.    mem_info_file(stdout,FOO_LIST);
  715.    mem_stat_free_list(5,FOO_LIST);
  716.    mem_stat_dump(stdout,FOO_LIST);
  717.    if ( foo_1 != NULL )
  718.      errmesg(" foo_1 is not released");
  719.    if ( foo_2 != NULL )
  720.      errmesg(" foo_2 is not released");
  721.    mem_dump_list(stdout,FOO_LIST);
  722.    mem_info_file(stdout,FOO_LIST);
  723.  
  724.    mem_free_vars(FOO_LIST);
  725.    if ( mem_is_list_attached(FOO_LIST) )
  726.      errmesg("list FOO_LIST is not detached");
  727.  
  728.    mem_info();
  729.    
  730. #if REAL == FLOAT
  731.    printf("# SINGLE PRECISION was used\n");
  732. #elif REAL == DOUBLE
  733.    printf("# DOUBLE PRECISION was used\n");
  734. #endif
  735.  
  736. #define ANSI_OR_VAR
  737.  
  738. #ifndef ANSI_C
  739. #ifndef VARARGS
  740. #undef ANSI_OR_VAR
  741. #endif
  742. #endif
  743.  
  744. #ifdef ANSI_OR_VAR
  745.  
  746.    printf("# you should get: \n");
  747. #if (REAL == FLOAT)
  748.      printf("#   type VEC: 276 bytes allocated, 3 variables allocated\n");
  749. #elif (REAL == DOUBLE)
  750.      printf("#   type VEC: 516 bytes allocated, 3 variables allocated\n");
  751. #endif
  752.    printf("#   and other types are zeros\n");
  753.  
  754. #endif /*#if defined(ANSI_C) || defined(VARAGS) */
  755.  
  756.    printf("# Finished memory torture test\n");
  757.    return;
  758. }
  759.