~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/serialise/matrix.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <stdio.h>
  2 #include <stdlib.h>
  3 #include <tina/sys.h>
  4 #include <tina/sysfuncs.h>
  5 #include <tina/math.h>
  6 #include <tina/mathfuncs.h>
  7 
  8 void    nvector_ts_free(Varptr d, int l, int h, Vartype type);
  9 void    nvector_ts_print(Varptr d, int l, int h, Vartype type);
 10 List   *nvector_ts_serialise(List * lg, Varptr d, int l, int h, Vartype type);
 11 List   *nvector_ts_deserialise(List * lg, Varptr * d, int l, int h, Vartype type);
 12 
 13 static void format_header(Matrix * mat)
 14 {
 15   /*    format("matrix  ");*/
 16   format_shape(mat->shape);
 17   format(" %d by %d  of ", mat->m, mat->n);
 18   format_vtype(mat->vtype);
 19   format(";");
 20 }
 21 void    Matrix_ts_print(Matrix * m)
 22 {
 23   int i;
 24   mprintf("struct matrix { ");
 25   if(m)
 26    {
 27      Varptr  v;
 28      
 29      /* format_header(m);*/
 30      if (m->el.char_v)  /* data for this row? */
 31       {
 32         v.ptr_v = (void **) m->el.char_v;
 33         for (i = 0; i < m->m; i++)
 34          {
 35            v.char_v = m->el.char_v[i];
 36            switch (m->shape)
 37             {
 38             case matrix_symmetric:
 39             case matrix_lower:
 40               nvector_ts_print(v, 0, i + 1, m->vtype);
 41               break;
 42             case matrix_upper:  /* must handle offset array */
 43               nvector_ts_print(v, i, m->m, m->vtype);
 44               break;
 45             case matrix_full:
 46             default:
 47               nvector_ts_print(v, 0, m->n, m->vtype);
 48               break;
 49             }
 50          }
 51       }
 52    }
 53   mprintf("} matrix;");
 54 }
 55 
 56 List   *Matrix_ts_serialise(List * lg, Matrix * m)
 57 {
 58   int     i;
 59   
 60   if (serialise_tagged_item(&lg, m, sizeof(Matrix)) == 1)
 61    {
 62      if (m->el.char_v)  /* data for this row? */
 63       {
 64         /* void **vpp;
 65            vpp = (void**)(m->el.char_v);*/
 66         /* dont follow ptrs */
 67         /* lg = nvector_ts_serialise(lg, (Varptr)vpp, 0, m->m, int_v); */
 68         for (i = 0; i < m->m; i++)
 69          {
 70            Varptr vp;
 71            vp.char_v = m->el.char_v[i];
 72            switch (m->shape)
 73             {
 74             case matrix_symmetric:
 75             case matrix_lower:
 76               lg = nvector_ts_serialise(lg, vp, 0, i + 1, m->vtype);
 77               break;
 78             case matrix_upper:  /* must handle offset array */
 79               lg = nvector_ts_serialise(lg, vp, i, m->m, m->vtype);
 80               break;
 81             case matrix_full:
 82             default:
 83               lg = nvector_ts_serialise(lg, vp, 0, m->n, m->vtype);
 84               break;
 85             }
 86          }
 87       }
 88    }
 89   return lg;
 90   }
 91 List   *Matrix_ts_deserialise(List * lg, Matrix ** mp)
 92 {
 93   int     i;
 94   
 95   if (deserialise_tagged_item(&lg, (void **) mp) == 1)
 96    {
 97      Matrix *m = *mp;
 98      
 99      if (m->m && m->n && m->el.char_v)  /* was there any data here? */
100       {
101         /* Varptrptr *vpp;
102            vpp = &(m->el.char_v); */
103         /* dont follow ptrs */
104         /* lg = nvector_ts_deserialise(lg, (Varptr*)vpp, 0, m->m, int_v);*/
105         m->el.char_v=nvector_alloc(0,m->m,sizeof(void*));
106         for (i = 0; i < m->m; i++)
107          {
108            Varptr *vp;
109            vp = (Varptr *) &(m->el.char_v[i]);
110            switch (m->shape)
111             {
112             case matrix_symmetric:
113             case matrix_lower:
114               lg = nvector_ts_deserialise(lg, vp, 0, i + 1, m->vtype);
115               break;
116             case matrix_upper:
117               lg = nvector_ts_deserialise(lg, vp, i, m->m, m->vtype);
118               break;
119             case matrix_full:
120             default:
121               lg = nvector_ts_deserialise(lg, vp, 0, m->n, m->vtype);
122               break;
123             }
124          }
125       }
126    }
127   return lg;
128 }
129 void    Matrix_ts_free(Matrix * m)
130 {
131   int     i;
132   
133   if (m->el.char_v)     /* data for this row? */
134     {
135       for (i = 0; i < m->m; i++)
136         {
137           Varptr vp;
138           vp.char_v = m->el.char_v[i];
139           switch (m->shape)
140             {
141             case matrix_symmetric:
142             case matrix_lower:
143               nvector_ts_free(vp, 0, i + 1, m->vtype);
144               break;
145             case matrix_upper:  /* must handle offset array */
146               nvector_ts_free(vp, i, m->m, m->vtype);
147               break;
148             case matrix_full:
149             default:
150               nvector_ts_free(vp, 0, m->n, m->vtype);
151               break;
152             }
153         }
154       rfree(m->el.char_v);
155     }
156   rfree(m);
157 }
158 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.