Anonymous avatar Anonymous committed d3747b8

added mzd_density()

Comments (0)

Files changed (4)

 
 #include "grayflex.h"
 
+
 /* blocks of memory we like to keep around for later re-use */
 mm_block m4ri_mmc_cache[M4RI_MMC_NBLOCKS];
 
  * \param i Integer.
  */ 
 
-#define TWOPOW(i) (1<<(i))
+#define TWOPOW(i) (ONE<<(i))
 
 /**
  * \brief Pretty for unsigned char.

src/packedmatrix.c

 }
 
 
+#define MASK(c)    (((word)(-1)) / (TWOPOW(TWOPOW(c)) + ONE))
+#define COUNT(x,c) ((x) & MASK(c)) + (((x) >> (TWOPOW(c))) & MASK(c))
+
+static inline int m4ri_bitcount(word n)  {
+   n = COUNT(n, 0);
+   n = COUNT(n, 1);
+   n = COUNT(n, 2);
+   n = COUNT(n, 3);
+   n = COUNT(n, 4);
+   n = COUNT(n, 5);
+   return n ;
+}
+
+double mzd_density(packedmatrix *A, int res) {
+  long count = 0;
+  long total = 0;
+  
+  if(res == 0)
+    res = (A->width/100.0);
+  if (res < 1)
+    res = 1;
+
+  if(A->width == 1) {
+    for(size_t i=0; i<A->nrows; i++)
+      for(size_t j=0; j<A->ncols; j++)
+        if(mzd_read_bit(A, i, j))
+          count++;
+    return ((double)count)/(A->ncols * A->nrows);
+  } else {
+    for(size_t i=0; i<A->nrows; i++) {
+      size_t truerow = A->rowswap[i];
+      for(size_t j = A->offset; j<RADIX; j++)
+        if(mzd_read_bit(A, i, j))
+          count++;
+      total += (long)RADIX - A->offset;
+      for(size_t j=1; j<A->width-1; j+=res) {
+        count += m4ri_bitcount(A->values[truerow + j]);
+        total += RADIX;
+      }
+      for(size_t j = 0; j < (A->offset + A->ncols)%RADIX; j++)
+        if(mzd_read_bit(A, i, j))
+          count++;
+      total += (A->offset + A->ncols)%RADIX;
+    }
+  }
+  return ((double)count)/(total);
+}

src/packedmatrix.h

 int mzd_find_pivot(packedmatrix *M, size_t start_row, size_t start_col, size_t *r, size_t *c);
 
 
+/**
+ * \brief Return the number of nonzero entries divided by nrows *
+ * nclos
+ *
+ * If res = 0 then 100 samples per row are made, if res > 0 the
+ * function takes res sized steps within each row (res = 1 uses every
+ * word).
+ *
+ * \param A Matrix
+ * \param res Resolution of sampling
+ */
+
+double mzd_density(packedmatrix *A, int res);
+
 #endif //PACKEDMATRIX_H
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.