From d26b835afc723532bf3c78e7349cd56078563665 Mon Sep 17 00:00:00 2001
From: Mathieu Faverge <mathieu.faverge@inria.fr>
Date: Tue, 25 Oct 2016 18:26:04 +0200
Subject: [PATCH] Rename colmajor field in layout

---
 CMakeLists.txt    |  1 -
 spm.c             | 46 ++++++++++++++++++-------------
 spm.h             | 55 ++++++++++++++++++-------------------
 z_spm.h           |  4 +--
 z_spm_dofs2flat.c | 12 ++++----
 z_spm_expand.c    | 70 ++++++++++++++++++++++++++++-------------------
 6 files changed, 104 insertions(+), 84 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 64804a36..8faf7143 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,7 +18,6 @@ precisions_rules_py(generated_headers
 set(SOURCES
   z_spm.c
   z_spm_2dense.c
-  z_spm_convert_col_row_major.c
   z_spm_convert_to_csc.c
   z_spm_convert_to_csr.c
   z_spm_convert_to_ijv.c
diff --git a/spm.c b/spm.c
index d8f954ef..a5a062b8 100644
--- a/spm.c
+++ b/spm.c
@@ -98,9 +98,9 @@ spmInit( pastix_spm_t *spm )
     spm->gnnzexp = 0;
     spm->nnzexp  = 0;
 
-    spm->dof       = 1;
-    spm->dofs      = NULL;
-    spm->colmajor  = 1;
+    spm->dof      = 1;
+    spm->dofs     = NULL;
+    spm->layout   = PastixColMajor;
 
     spm->colptr   = NULL;
     spm->rowptr   = NULL;
@@ -334,30 +334,36 @@ double
 spmNorm( int ntype,
          const pastix_spm_t *spm )
 {
-    double tmp;
+    pastix_spm_t *spmtmp;
+    double norm = -1.;
 
     if ( spm->dof != 1 ) {
         fprintf(stderr, "WARNING: spm expanded due to non implemented norm for non-expanded spm\n");
-        spm = spmExpand( spm );
+        spmtmp = spmExpand( spm );
     }
     switch (spm->flttype) {
     case PastixFloat:
-        tmp = (double)s_spmNorm( ntype, spm );
-        return tmp;
+        norm = (double)s_spmNorm( ntype, spmtmp );
+        break;
 
     case PastixDouble:
-        return d_spmNorm( ntype, spm );
+        norm = d_spmNorm( ntype, spmtmp );
+        break;
 
     case PastixComplex32:
-        tmp = (double)c_spmNorm( ntype, spm );
-        return tmp;
+        norm = (double)c_spmNorm( ntype, spmtmp );
+        break;
 
     case PastixComplex64:
-        return z_spmNorm( ntype, spm );
+        norm = z_spmNorm( ntype, spmtmp );
+        break;
 
+    case PastixPattern:
     default:
-        return -1.;
+        ;
     }
+
+    return norm;
 }
 
 /**
@@ -688,24 +694,26 @@ spmCopy( const pastix_spm_t *spm )
  *          The copy of the sparse matrix.
  *
  *******************************************************************************/
-void
-spmExpand(pastix_spm_t* spm)
+pastix_spm_t *
+spmExpand(const pastix_spm_t* spm)
 {
     switch(spm->flttype)
     {
+    case PastixPattern:
+        return p_spmExpand(spm);
+        break;
     case PastixFloat:
-        s_spmExpand(spm);
+        return s_spmExpand(spm);
         break;
     case PastixComplex32:
-        c_spmExpand(spm);
+        return c_spmExpand(spm);
         break;
     case PastixComplex64:
-        z_spmExpand(spm);
+        return z_spmExpand(spm);
         break;
     case PastixDouble:
     default:
-        d_spmExpand(spm);
-        break;
+        return d_spmExpand(spm);
     }
 }
 
diff --git a/spm.h b/spm.h
index 24a092ae..96f92194 100644
--- a/spm.h
+++ b/spm.h
@@ -60,33 +60,32 @@ typedef enum pastix_driver_e {
  *
  */
 struct pastix_spm_s {
-    int           mtxtype;   /**< Matrix structure: PastixGeneral, PastixSymmetric
-                                  or PastixHermitian.                                         */
-    int           flttype;   /**< avals datatype: PastixPattern, PastixFloat, PastixDouble,
-                                  PastixComplex32 or PastixComplex64                          */
-    int           fmttype;   /**< Matrix storage format: PastixCSC, PastixCSR, PastixIJV      */
-
-    pastix_int_t  gN;        /**< Global number of vertices in the compressed graph           */
-    pastix_int_t  n;         /**< Local number of vertices in the compressed graph            */
-    pastix_int_t  gnnz;      /**< Global number of non zeroes in the compressed graph         */
-    pastix_int_t  nnz;       /**< Local number of non zeroes in the compressed graph          */
-
-    pastix_int_t  gNexp;     /**< Global number of vertices in the compressed graph           */
-    pastix_int_t  nexp;      /**< Local number of vertices in the compressed graph            */
-    pastix_int_t  gnnzexp;   /**< Global number of non zeroes in the compressed graph         */
-    pastix_int_t  nnzexp;    /**< Local number of non zeroes in the compressed graph          */
-
-    pastix_int_t  dof;       /**< Number of degrees of freedom per unknown,
-                                  if > 0, constant degree of freedom
-                                  otherwise, irregular degree of freedom (refer to dofs)      */
-    pastix_int_t *dofs;      /**< Number of degrees of freedom per unknown (NULL, if dof > 0) */
-    int           colmajor;  /**< If > 0, column major with dofs
-                                  otherwise, row major                                        */
-
-    pastix_int_t *colptr;    /**< List of indirections to rows for each vertex                */
-    pastix_int_t *rowptr;    /**< List of edges for each vertex                               */
-    pastix_int_t *loc2glob;  /**< Corresponding numbering from local to global                */
-    void         *values;    /**< Values stored in the matrix                                 */
+    int                mtxtype;/**< Matrix structure: PastixGeneral, PastixSymmetric
+                                    or PastixHermitian.                                         */
+    pastix_coeftype_t flttype; /**< avals datatype: PastixPattern, PastixFloat, PastixDouble,
+                                    PastixComplex32 or PastixComplex64                          */
+    pastix_fmttype_t  fmttype; /**< Matrix storage format: PastixCSC, PastixCSR, PastixIJV      */
+
+    pastix_int_t      gN;      /**< Global number of vertices in the compressed graph           */
+    pastix_int_t      n;       /**< Local number of vertices in the compressed graph            */
+    pastix_int_t      gnnz;    /**< Global number of non zeroes in the compressed graph         */
+    pastix_int_t      nnz;     /**< Local number of non zeroes in the compressed graph          */
+
+    pastix_int_t      gNexp;   /**< Global number of vertices in the compressed graph           */
+    pastix_int_t      nexp;    /**< Local number of vertices in the compressed graph            */
+    pastix_int_t      gnnzexp; /**< Global number of non zeroes in the compressed graph         */
+    pastix_int_t      nnzexp;  /**< Local number of non zeroes in the compressed graph          */
+
+    pastix_int_t      dof;     /**< Number of degrees of freedom per unknown,
+                                    if > 0, constant degree of freedom
+                                    otherwise, irregular degree of freedom (refer to dofs)      */
+    pastix_int_t     *dofs;    /**< Number of degrees of freedom per unknown (NULL, if dof > 0) */
+    pastix_order_t    layout;  /**< PastixColMajor, or PastixRowMajor                           */
+
+    pastix_int_t     *colptr;  /**< List of indirections to rows for each vertex                */
+    pastix_int_t     *rowptr;  /**< List of edges for each vertex                               */
+    pastix_int_t     *loc2glob;/**< Corresponding numbering from local to global                */
+    void             *values;  /**< Values stored in the matrix                                 */
 };
 
 int
@@ -136,7 +135,7 @@ pastix_int_t  spmSymmetrize( pastix_spm_t *spm );
 
 pastix_spm_t *spmCheckAndCorrect( pastix_spm_t *spm );
 
-void spmExpand(pastix_spm_t* spm);
+pastix_spm_t *spmExpand(const pastix_spm_t* spm);
 
 int spmReadDriver( pastix_driver_t  driver,
                    char            *filename,
diff --git a/z_spm.h b/z_spm.h
index db747408..0ac21a69 100644
--- a/z_spm.h
+++ b/z_spm.h
@@ -63,7 +63,7 @@ void z_spmDensePrint( pastix_int_t m, pastix_int_t n, pastix_complex64_t *A, pas
 void z_spmPrint( const pastix_spm_t *spm );
 
 
-int  z_spmExpand(pastix_spm_t *spm);
-void z_spmDofs2Flat(pastix_spm_t *spm);
+pastix_spm_t *z_spmExpand(const pastix_spm_t *spm);
+void          z_spmDofs2Flat(pastix_spm_t *spm);
 
 #endif /* _z_spm_H_ */
diff --git a/z_spm_dofs2flat.c b/z_spm_dofs2flat.c
index b4db59f6..e196ea9c 100644
--- a/z_spm_dofs2flat.c
+++ b/z_spm_dofs2flat.c
@@ -119,9 +119,9 @@ z_spmDofs2Flat(pastix_spm_t *spm)
         spm->gnnz = spm->gnnzexp;
         spm->nnz  = spm->nnzexp;
 
-        spm->dof       = 1;
-        spm->dofs      = NULL;
-        spm->colmajor  = 1;
+        spm->dof      = 1;
+        spm->dofs     = NULL;
+        spm->layout   = PastixColMajor;
 
         spm->colptr   = new_col;
         spm->rowptr   = new_row;
@@ -218,9 +218,9 @@ z_spmDofs2Flat(pastix_spm_t *spm)
         spm->gnnzexp = nnz;
         spm->nnzexp  = nnz;
 
-        spm->dof       = 1;
-        spm->dofs      = NULL;
-        spm->colmajor  = 1;
+        spm->dof      = 1;
+        spm->dofs     = NULL;
+        spm->layout   = PastixColMajor;
 
         spm->colptr   = new_col;
         spm->rowptr   = new_row;
diff --git a/z_spm_expand.c b/z_spm_expand.c
index 672b9222..445e1a09 100644
--- a/z_spm_expand.c
+++ b/z_spm_expand.c
@@ -20,46 +20,60 @@
 /**
  * TODO: This function is incorrect
  */
-int
-z_spmExpand(pastix_spm_t *spm)
+pastix_spm_t *
+z_spmExpand(const pastix_spm_t *spm)
 {
+    pastix_spm_t *newspm;
     pastix_int_t i, col, row, cpt, dofj, dofi, baseval;
+#if !defined(PRECISION_p)
     pastix_complex64_t *oldvalptr;
     pastix_complex64_t *newvalptr;
+#endif
+
+    if (spm->dof == 1) {
+        return spm;
+    }
 
     if (1) {
-        return PASTIX_ERR_NOTIMPLEMENTED;
+        return NULL;
     }
 
-    baseval = spmFindBase( spm );
+    
+/*     baseval = spmFindBase( spm ); */
 
-    oldvalptr = (pastix_complex64_t*)spm->values;
-    spm->values = malloc( spm->nnzexp * sizeof(pastix_complex64_t) );
-    newvalptr = (pastix_complex64_t*)spm->values;
+/* #if !defined(PRECISION_p) */
+/*     oldvalptr = (pastix_complex64_t*)spm->values; */
+/*     spm->values = malloc( spm->nnzexp * sizeof(pastix_complex64_t) ); */
+/*     newvalptr = (pastix_complex64_t*)spm->values; */
+/* #endif */
 
-    cpt = 0;
-    dofi = spm->dof;
-    dofj = spm->dof;
+/*     cpt = 0; */
+/*     dofi = spm->dof; */
+/*     dofj = spm->dof; */
 
-    for( col=0; col<spm->n; col++)
-    {
-        if ( spm->dof <= 0 ) {
-            dofi = spm->dofs[col+1] - spm->dofs[col];
-        }
+/*     for( col=0; col<spm->n; col++) */
+/*     { */
+/*         if ( spm->dof <= 0 ) { */
+/*             dofi = spm->dofs[col+1] - spm->dofs[col]; */
+/*         } */
 
-        for( row=spm->colptr[col]-baseval; row<spm->colptr[col+1]-baseval; row++)
-        {
-            if ( spm->dof <= 0 ) {
-                dofj = spm->dofs[spm->rowptr[row]-baseval+1] - spm->dofs[spm->rowptr[row]-baseval];
-            }
+/*         for( row=spm->colptr[col]-baseval; row<spm->colptr[col+1]-baseval; row++) */
+/*         { */
+/*             if ( spm->dof <= 0 ) { */
+/*                 dofj = spm->dofs[spm->rowptr[row]-baseval+1] - spm->dofs[spm->rowptr[row]-baseval]; */
+/*             } */
 
-            for( i=0; i<dofi*dofj; i++)
-            {
-                newvalptr[cpt] = oldvalptr[row] / ((i/dofj) + (i%dofj) + 2); // Col major
-                cpt++;
-            }
-        }
-    }
+/*             for( i=0; i<dofi*dofj; i++) */
+/*             { */
+/* #if !defined(PRECISION_p) */
+/*                 newvalptr[cpt] = oldvalptr[row] / ((i/dofj) + (i%dofj) + 2); // Col major */
+/*                 cpt++; */
+/* #endif */
+/*             } */
+/*         } */
+/*     } */
 
-    free( oldvalptr );
+/* #if !defined(PRECISION_p) */
+/*     free( oldvalptr ); */
+/* #endif */
 }
-- 
GitLab