[Getfem-commits] (no subject)

2019-06-06 Thread Andriy Andreykiv
branch: csr_matrix_and_memory_fixes
commit 06165410f54c1c82ee82903906c6497cd535ce83
Author: Andriy.Andreykiv 
Date:   Thu Jun 6 14:26:43 2019 +0200

allowing gmm::csc_matrix and gmm::csr_matrix to be also templetized by 
index type. This was necessary to interface them with Intel's MKL, which 
requires int for indexes.
---
 src/gmm/gmm_inoutput.h | 42 +++---
 src/gmm/gmm_matrix.h   | 94 --
 2 files changed, 66 insertions(+), 70 deletions(-)

diff --git a/src/gmm/gmm_inoutput.h b/src/gmm/gmm_inoutput.h
index cca7027..ea2c277 100644
--- a/src/gmm/gmm_inoutput.h
+++ b/src/gmm/gmm_inoutput.h
@@ -124,12 +124,12 @@ namespace gmm {
 /** open filename and reads header */
 void open(const char *filename);
 /** read the opened file */
-template  void read(csc_matrix& A);
+template  void 
read(csc_matrix& A);
 template  void read(MAT ) IS_DEPRECATED;
-template 
-static void write(const char *filename, const csc_matrix& A);
-template 
-static void write(const char *filename, const csc_matrix& A,
+template 
+static void write(const char *filename, const csc_matrix& A);
+template 
+static void write(const char *filename, const csc_matrix& A,
  const std::vector );
 template  
 static void write(const char *filename,
@@ -324,8 +324,8 @@ namespace gmm {
   }
 
   /* only valid for double and complex csc matrices */
-  template  void
-  HarwellBoeing_IO::read(csc_matrix& A) {
+  template  void
+  HarwellBoeing_IO::read(csc_matrix& A) {
 
 // typedef typename csc_matrix::IND_TYPE IND_TYPE;
 
@@ -531,17 +531,17 @@ namespace gmm {
 return 1;
   }
   
-  template  void
+  template  void
   HarwellBoeing_IO::write(const char *filename,
- const csc_matrix& A) {
+ const csc_matrix& A) {
 write(filename, csc_matrix_ref
  ([0], [0], [0], A.nr, A.nc));
   }
 
-  template  void
+  template  void
   HarwellBoeing_IO::write(const char *filename,
- const csc_matrix& A,
+ const csc_matrix& A,
  const std::vector ) {
 write(filename, csc_matrix_ref
@@ -593,9 +593,9 @@ namespace gmm {
   /** save a "double" or "std::complex" csc matrix into a
   HarwellBoeing file
   */
-  template  inline void
+  template  inline void
   Harwell_Boeing_save(const std::string ,
- const csc_matrix& A)
+ const csc_matrix& A)
   { HarwellBoeing_IO::write(filename.c_str(), A); }
 
   /** save a reference on "double" or "std::complex" csc matrix
@@ -631,8 +631,8 @@ namespace gmm {
   /** load a "double" or "std::complex" csc matrix from a
   HarwellBoeing file
   */
-  template  void
-  Harwell_Boeing_load(const std::string , csc_matrix& A) {
+  template  void
+  Harwell_Boeing_load(const std::string , csc_matrix& A) {
 HarwellBoeing_IO h(filename.c_str()); h.read(A);
   }
 
@@ -1022,8 +1022,8 @@ namespace gmm {
 /* read opened file */
 template  void read(Matrix );
 /* write a matrix */
-template  static void 
-write(const char *filename, const csc_matrix& A);  
+template  static void 
+write(const char *filename, const csc_matrix& A);  
 template  static void 
 write(const char *filename,
  const csc_matrix_ref& A);  
@@ -1038,8 +1038,8 @@ namespace gmm {
 mm.read(A);
   }
   /** write a matrix-market file */
-  template  void
-  MatrixMarket_save(const char *filename, const csc_matrix& A) {
+  template  void
+  MatrixMarket_save(const char *filename, const csc_matrix& A) {
 MatrixMarket_IO mm; mm.write(filename, A);
   }
 
@@ -1106,8 +1106,8 @@ namespace gmm {
 }
   }
 
-  template  void 
-  MatrixMarket_IO::write(const char *filename, const csc_matrix& A) {
+  template  void 
+  MatrixMarket_IO::write(const char *filename, const csc_matrix& A) {
 write(filename, csc_matrix_ref
  ([0], [0], [0], A.nr, A.nc));
diff --git a/src/gmm/gmm_matrix.h b/src/gmm/gmm_matrix.h
index 3b133bb..634019c 100644
--- a/src/gmm/gmm_matrix.h
+++ b/src/gmm/gmm_matrix.h
@@ -497,9 +497,8 @@ namespace gmm
   /*  */
   /*  */
 
-  template 
+  template 
   struct csc_matrix {
-typedef unsigned int IND_TYPE;
 
 std::vector pr;
 std::vector ir;
@@ -519,7 +518,7 @@ namespace gmm
 void init_with(const csc_matrix_ref& B)
 { init_with_good_format(B); }
 template 
-void init_with(const csc_matrix& B)
+void init_with(const csc_matrix& B)
 { init_with_good_format(B); }
 
 void init_with_identity(size_type n);
@@ -529,7 +528,7 @@ namespace gmm
 
 size_type nrows(void) const { return nr; }
 size_type ncols(void) const { return nc; }
-void swap(csc_matrix ) {
+void swap(csc_matrix ) {
   

[Getfem-commits] (no subject)

2019-06-06 Thread Andriy Andreykiv
branch: csr_matrix_and_memory_fixes
commit f222414c84e8294857a5f1e7975b2ef06a024a01
Author: Andriy.Andreykiv 
Date:   Thu Jun 6 14:25:09 2019 +0200

preventing container out of bound access
---
 src/getfem/getfem_accumulated_distro.h |  4 ++--
 src/gmm/gmm_vector.h   | 34 ++
 2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/src/getfem/getfem_accumulated_distro.h 
b/src/getfem/getfem_accumulated_distro.h
index f323809..ebf8226 100644
--- a/src/getfem/getfem_accumulated_distro.h
+++ b/src/getfem/getfem_accumulated_distro.h
@@ -213,8 +213,8 @@ namespace detail {
   }
 )
 //erase every second item , as it was already added
-for (auto it = begin(to_add);
- next(it) < end(to_add);
+for (auto it = begin(to_add), ite = end(to_add);
+ it != end(to_add) && next(it) != end(to_add);
  it = to_add.erase(next(it)));
   }
 }
diff --git a/src/gmm/gmm_vector.h b/src/gmm/gmm_vector.h
index dbc4029..19b4a27 100644
--- a/src/gmm/gmm_vector.h
+++ b/src/gmm/gmm_vector.h
@@ -1212,15 +1212,33 @@ namespace gmm {
 
 v2.base_resize(nbc);
 it3 = v2.begin() + old_nbc;
-it2 = v2.end(); ite2 = v2.begin();
-it1 = vect_end(v1); ite1 = vect_const_begin(v1);
-while (it1 != ite1 && it3 != ite2) {
-  --it3; --it1; --it2;
-  if (it3->c > it1.index()) { *it2 = *it3; ++it1; }
-  else if (it3->c == it1.index()) { *it2=*it3; it2->e+=*it1; }
-  else { it2->c = it1.index(); it2->e = *it1; ++it3; }
+it2 = v2.end();
+ite2 = v2.begin();
+it1 = vect_end(v1);
+ite1 = vect_const_begin(v1);
+while (it1 != ite1 && it2 != ite2 && it3 != ite2){
+  --it3;
+  --it1;
+  --it2;
+  if (it3->c > it1.index()) {
+*it2 = *it3;
+++it1;
+  }
+  else if (it3->c == it1.index()) {
+*it2=*it3;
+it2->e+=*it1;
+  }
+  else {
+it2->c = it1.index();
+it2->e = *it1; ++it3;
+  }
+}
+while (it1 != ite1 && it2 != ite2) {
+  --it1;
+  --it2;
+  it2->c = it1.index();
+  it2->e = *it1;
 }
-while (it1 != ite1) { --it1; --it2; it2->c = it1.index(); it2->e = *it1; }
   }
 
   template  void copy(const V , rsvector ) {



[Getfem-commits] csr_matrix_and_memory_fixes merge request

2019-06-06 Thread Andriy Andreykiv
Dear Yves and Kostas,

Kind request to review and merge csr_matrix_and_memory_fixes.
Here I made small fixes for out of bound array access and allow
templatesation of index type for GMM CSR and CSC matrices.
We needed this to interface those matrix types with Intel MKL, that
requires integer as index type.

Thank you in advance,
  Andriy


[Getfem-commits] [getfem-commits] branch csr_matrix_and_memory_fixes created (now 0616541)

2019-06-06 Thread Andriy Andreykiv
andrico pushed a change to branch csr_matrix_and_memory_fixes.

at  0616541   allowing gmm::csc_matrix and gmm::csr_matrix to be also 
templetized by index type. This was necessary to interface them with Intel's 
MKL, which requires int for indexes.

This branch includes the following new commits:

   new  f222414   preventing container out of bound access
   new  0616541   allowing gmm::csc_matrix and gmm::csr_matrix to be also 
templetized by index type. This was necessary to interface them with Intel's 
MKL, which requires int for indexes.