[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39091] branches/soc-2011-avocado/blender/ intern/autoseam/SparseMatrix.h: SparseMatrix class enhancement
shuvro sarker
shuvro05 at gmail.com
Sat Aug 6 06:41:25 CEST 2011
Revision: 39091
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39091
Author: shuvro
Date: 2011-08-06 04:41:19 +0000 (Sat, 06 Aug 2011)
Log Message:
-----------
SparseMatrix class enhancement
Modified Paths:
--------------
branches/soc-2011-avocado/blender/intern/autoseam/SparseMatrix.h
Modified: branches/soc-2011-avocado/blender/intern/autoseam/SparseMatrix.h
===================================================================
--- branches/soc-2011-avocado/blender/intern/autoseam/SparseMatrix.h 2011-08-06 04:19:30 UTC (rev 39090)
+++ branches/soc-2011-avocado/blender/intern/autoseam/SparseMatrix.h 2011-08-06 04:41:19 UTC (rev 39091)
@@ -35,20 +35,25 @@
#include <vector>
#include <iostream>
+#define INF 99999999
+
+
+
/**
* This class is based on compressed row storage(CRS) format.
* More info can be found at http://web.eecs.utk.edu/~dongarra/etemplates/node373.html
*/
-
template <class T>
class SparseMatrix
{
public:
+
typedef std::map<size_t, std::map<size_t , T> > mat_t;
typedef typename mat_t::iterator row_iter;
typedef std::map<size_t, T> col_t;
typedef typename col_t::iterator col_iter;
-
+
+
SparseMatrix(){};
SparseMatrix(size_t i){ m=i; n=i; }
SparseMatrix(size_t i, size_t j){ m=i; n=j; }
@@ -59,13 +64,41 @@
if(i>=m || j>=n) throw;
return mat[i][j];
}
+
+ /**
+ * This function does not create an element for
+ * an not existing key. In this case, it returns -INF
+ */
inline
T operator()(size_t i, size_t j) const
{
if(i>=m || j>=n) throw;
return mat[i][j];
+
+ /*row_iter ii;
+ col_iter jj;
+
+
+ if(mat.count(i)){
+ ii = mat.find(i);
+
+ if((*ii).count(j)){
+ jj = (*ii).find(j);
+ printf("requested value is : %lf",(*jj).second);
+ return (*jj).second;
+ }
+
+ }
+ printf("requested value is Infinity: %d",-INF);
+ return -INF;*/
}
-
+
+ inline
+ SparseMatrix* operator=(const SparseMatrix* matrix) {
+ mat = matrix;
+ return mat;
+ }
+
/**
* Multiplies vector x with matrix m and returns
* the result as a vector.
@@ -131,9 +164,49 @@
} std::cout << std::endl;
}
-
+
+ T row_sum(int row_index)
+ {
+ if( row_index >= m ) throw;
+
+ row_iter ii;
+ col_iter jj;
+ T sum = 0;
+
+ if(mat.count(row_index)){
+ ii = mat.find(row_index);
+ for( jj=(*ii).second.begin(); jj!=(*ii).second.end(); jj++)
+ sum += (*jj).second;
+ }
+
+ return sum;
+
+ }
+
+
+ int rows()
+ {
+ return m;
+ }
+
+ int cols()
+ {
+ return n;
+ }
+
+ int resize(size_t i, size_t j)
+ {
+ m=i;
+ n=j;
+ return 0;
+ }
+
+
+
+
+ mat_t mat;
private:
- mat_t mat;
+
size_t m;
size_t n;
};
More information about the Bf-blender-cvs
mailing list