[Genabel-commits] r980 - branches/ProbABEL-refactoring/ProbABEL/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 23 17:42:20 CEST 2012


Author: maartenk
Date: 2012-10-23 17:42:20 +0200 (Tue, 23 Oct 2012)
New Revision: 980

Modified:
   branches/ProbABEL-refactoring/ProbABEL/src/eigen_mematri1.h
   branches/ProbABEL-refactoring/ProbABEL/src/eigen_mematrix.h
Log:
made changes to successfully run the palogist test in example_bt.sh

Modified: branches/ProbABEL-refactoring/ProbABEL/src/eigen_mematri1.h
===================================================================
--- branches/ProbABEL-refactoring/ProbABEL/src/eigen_mematri1.h	2012-10-14 12:59:36 UTC (rev 979)
+++ branches/ProbABEL-refactoring/ProbABEL/src/eigen_mematri1.h	2012-10-23 15:42:20 UTC (rev 980)
@@ -1,16 +1,16 @@
 #ifndef EIGEN_MEMATRI1_H
 #define EIGEN_MEMATRI1_H
 #include "eigen_mematrix.h"
-#include <cstdlib>
+#include <Eigen/Dense>
+#include <Eigen/LU>
 #include <string>
 #include <cstdarg>
 #include <cstdio>
 #include <cstdlib>
-#include <Eigen/Dense>
-#include <Eigen/LU>
 
+
 using namespace Eigen;
-// 
+//
 // constructors
 //
 
@@ -27,12 +27,10 @@
         fprintf(stderr, "mematrix(): nc <= 0\n");
         exit(1);
     }
-    nrow = nr;
-    ncol = nc;
-    nelements = nr * nc;
-    Matrix<DT, Dynamic, Dynamic,RowMajor> data;
-
-
+    this->nrow = nr;
+    this->ncol = nc;
+    this->nelements = nr * nc;
+    this->data.resize(nr,nc);
 }
 template<class DT>
 mematrix<DT>::mematrix(const mematrix<DT> & M)
@@ -41,9 +39,8 @@
     nrow = M.nrow;
     nelements = M.nelements;
     data = M.data;
-
 }
-// 
+//
 // operators
 //
 template<class DT>
@@ -51,13 +48,10 @@
 {
     if (this != &M)
     {
-
         ncol = M.ncol;
         nrow = M.nrow;
         nelements = M.nelements;
-
         data = M.data;
-        //		fprintf(stderr,"mematrix=: can allocate memory (%d,%d)\n",M.nrow,M.ncol);
     }
     return *this;
 }
@@ -97,6 +91,9 @@
     }
     mematrix<DT> temp;
     temp.data = data + M.data;
+    temp.ncol = data.cols();
+    temp.nrow = data.rows();
+    temp.nelements = temp.nrow * temp.ncol;
 
     return temp;
 }
@@ -120,14 +117,14 @@
     }
     mematrix<DT> temp;
     temp.data = data - M.data;
-    temp.ncol=temp.data.cols();
-    temp.nrow=temp.data.rows();
-    temp.nelements=temp.nrow* temp.ncol;
+    temp.ncol = temp.data.cols();
+    temp.nrow = temp.data.rows();
+    temp.nelements = temp.nrow * temp.ncol;
     return temp;
 }
 
 template<class DT>
-mematrix<DT> mematrix<DT>::operator*( DT multiplyer)
+mematrix<DT> mematrix<DT>::operator*(DT multiplyer)
 {
 //    MatrixXd add = MatrixXd::Constant(nrow, ncol, toadd);
     mematrix<DT> temp(nrow, ncol);
@@ -142,18 +139,16 @@
     {
         fprintf(stderr, "mematrix*: ncol != nrow (%d,%d) and (%d,%d)", nrow,
                 ncol, M.nrow, M.ncol);
-
     }
     mematrix<DT> temp;
     temp.data = data * M.data;
-    temp.ncol=temp.data.cols();
-    temp.nrow=temp.data.rows();
-    temp.nelements=temp.nrow* temp.ncol;
+    temp.ncol = temp.data.cols();
+    temp.nrow = temp.data.rows();
+    temp.nelements = temp.nrow * temp.ncol;
 
     return temp;
 }
 
-
 template<class DT>
 mematrix<DT> mematrix<DT>::operator*(const mematrix<DT> *M)
 {
@@ -161,20 +156,17 @@
     {
         fprintf(stderr, "mematrix*: ncol != nrow (%d,%d) and (%d,%d)", nrow,
                 ncol, M->nrow, M->ncol);
-
     }
     mematrix<DT> temp;
     temp.data = data * M->data;
-    temp.ncol=temp.data.cols();
-    temp.nrow=temp.data.rows();
-    temp.nelements=temp.nrow* temp.ncol;
+    temp.ncol = temp.data.cols();
+    temp.nrow = temp.data.rows();
+    temp.nelements = temp.nrow * temp.ncol;
 
     return temp;
 }
 
-
-
-// 
+//
 // operations
 //
 template<class DT>
@@ -199,7 +191,6 @@
 
     data.resize(nr, nc);
     data.setZero();
-
 }
 template<class DT>
 DT mematrix<DT>::get(int nr, int nc)
@@ -222,6 +213,9 @@
 template<class DT>
 void mematrix<DT>::put(DT value, int nr, int nc)
 {
+//    printf("put val:%f  nr=%i nc=%i \n", value, nr, nc);
+//     printf("mat  nr=%i nc=%i \n", data.rows(),data.cols());
+//     printf("mat  nr=%i nc=%i \n", nrow,ncol);
     if (nc < 0 || nc > ncol)
     {
         fprintf(stderr,
@@ -250,7 +244,7 @@
 }
 
 template<class DT>
-mematrix<DT> column_sum(mematrix<DT> &M)
+mematrix<DT> column_sum(const mematrix<DT> &M)
 {
     mematrix<DT> out;
     out.reinit(1, M.ncol);
@@ -269,32 +263,27 @@
             cout << data.data()[i * ncol + j] << "\t";
         cout << "\n";
     }
-
-
-
-
 }
-
-// 
 // other functions
 //
 
 template<class DT>
-mematrix<DT> transpose(mematrix<DT> &M)
+mematrix<DT> transpose(const mematrix<DT> &M)
 {
-//    cout << "[DEBUG TRANSPOSE PRE]nrow=" << M.nrow << "; ncol=" << M.ncol << "; nelements=" << M.nelements;
+//cout << "[DEBUG TRANSPOSE PRE]nrow=" << M.nrow << "; ncol=" << M.ncol << "; nelements=" << M.nelements;
 
     mematrix<DT> temp;
-    temp.data=M.data.transpose();
-    temp.ncol=M.nrow;
-    temp.nrow=M.ncol;
-//    cout << "[DEBUG TRANSPOSE post]nrow=" << temp.nrow << "; ncol=" << temp.ncol << "; nelements=" << temp.nelements;
+    temp.data = M.data.transpose();
+    temp.ncol = M.nrow;
+    temp.nrow = M.ncol;
+    temp.nelements = M.nelements;
+//cout << "[DEBUG TRANSPOSE post]nrow=" << temp.nrow << "; ncol=" << temp.ncol << "; nelements=" << temp.nelements;
 
     return temp;
 }
 
 template<class DT>
-mematrix<DT> reorder(mematrix<DT> &M, mematrix<int> order)
+mematrix<DT> reorder(const mematrix<DT> &M, const mematrix<int> order)
 {
     if (M.nrow != order.nrow)
     {
@@ -302,7 +291,7 @@
         exit(1);
     }
     mematrix<DT> temp(M.nrow, M.ncol);
-//FIXME: commented out to get compilation running
+//FIXME(maarten): commented out to get compilation running
 //    for (int i = 0; i < temp.nrow; i++)
 //        for (int j = 0; j < temp.ncol; j++)
 //            temp.data[order[i] * temp.ncol + j] = M.data[i * M.ncol + j];
@@ -323,7 +312,7 @@
 //
 
 template<class DT>
-mematrix<DT> invert(mematrix<DT> &M)
+mematrix<DT> invert(const mematrix<DT> &M)
 {
     if (M.ncol != M.nrow)
     {
@@ -338,7 +327,7 @@
 }
 
 template<class DT>
-mematrix<DT> productMatrDiag(mematrix<DT> &M, mematrix<DT> &D)
+mematrix<DT> productMatrDiag( const mematrix<DT> &M,  const mematrix<DT> &D)
 {
     //multiply all rows of M by value of first row of D
     if (M.ncol != D.nrow)
@@ -347,11 +336,12 @@
         exit(1);
     }
     mematrix<DT> temp = M;
-//    mematrix<DT> temp(M.nrow, M.ncol);
+    //make a array of the first row of D in the same way orientation as M.data.row(i).array()
+    Array<DT,Dynamic,Dynamic> row=D.data.block(0,0,M.ncol,1).transpose();
 
     for (int i = 0; i < temp.nrow; i++)
     {
-        temp.data.row(i) = M.data.row(i).array() * D.data.row(0).array();
+       temp.data.row(i) = M.data.row(i).array() * row;
     }
     return temp;
 }

Modified: branches/ProbABEL-refactoring/ProbABEL/src/eigen_mematrix.h
===================================================================
--- branches/ProbABEL-refactoring/ProbABEL/src/eigen_mematrix.h	2012-10-14 12:59:36 UTC (rev 979)
+++ branches/ProbABEL-refactoring/ProbABEL/src/eigen_mematrix.h	2012-10-23 15:42:20 UTC (rev 980)
@@ -1,10 +1,9 @@
 #ifndef __EIGEN_MEMATRIX_H__
 #define __EIGEN_MEMATRIX_H__
-#include <iostream>
 #include <Eigen/Dense>
+#include <iostream>
 
 using namespace Eigen;
-
 using namespace std;
 
 template<class DT> class mematrix
@@ -13,7 +12,7 @@
     int nrow;
     int ncol;
     int nelements;
-    Matrix<DT, Dynamic, Dynamic,RowMajor> data;
+    Matrix<DT, Dynamic, Dynamic, RowMajor> data;
 
     mematrix()
     {
@@ -31,7 +30,7 @@
     }
 
     mematrix & operator=(const mematrix &M);
-     DT &  operator[]( int i);
+    DT & operator[](int i);
 //    mematrix operator+(DT toadd);
     mematrix operator+(const mematrix &M);
     mematrix operator-(DT toadd);
@@ -40,7 +39,6 @@
     mematrix operator*(const mematrix &M);
     mematrix operator*(const mematrix *M);
 
-
     void reinit(int nr, int nc);
 
     unsigned int getnrow(void)
@@ -55,9 +53,7 @@
     void put(DT value, int nr, int nc);
     DT column_mean(int nc);
     DT column_sum(int nc);
-   void print(void);
-
-
+    void print(void);
 };
 
 //mematrix transpose(mematrix M);



More information about the Genabel-commits mailing list