Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

changed types: internally (float), externally (double)

  • Loading branch information...
commit d1e07b9a057edcc8352399e50b6622bcd6c81935 1 parent 607fd66
Oliver Stegle authored
Showing with 45 additions and 6 deletions.
  1. +32 −1 array_helper.cpp
  2. +6 −2 array_helper.h
  3. +3 −0  python/peer.i
  4. +4 −3 vbfa.h
View
33 array_helper.cpp
@@ -11,6 +11,20 @@
+PMatrix array2matrix(const float32_t* matrix,int32_t rows,int32_t cols)
+{
+ //create a matrix from a double array
+ PMatrix m = PMatrix(rows,cols);
+ printf("starting copying");
+ for(int i=0;i<rows;i++)
+ for(int j=0;j<cols;j++)
+ {
+ //m(i,j) = matrix[i*cols+j];
+ m(i,j) = matrix[j*rows+i];
+ }
+ return m;
+}
+
PMatrix array2matrix(const float64_t* matrix,int32_t rows,int32_t cols)
{
//create a matrix from a double array
@@ -25,11 +39,27 @@ PMatrix array2matrix(const float64_t* matrix,int32_t rows,int32_t cols)
return m;
}
+void matrix2array(const PMatrix m,float32_t** matrix, int32_t* rows, int32_t*cols)
+{
+ int size = m.rows()*m.cols();
+ //allocate memory
+ (*matrix) = new float32_t[size];
+ //set dimensions
+ (*rows) = m.rows();
+ (*cols) = m.cols();
+ for (int i=0;i<m.rows();i++)
+ for(int j=0;j<m.cols();j++)
+ {
+ //(*matrix)[i*m.cols()+j] = m(i,j);
+ (*matrix)[j*m.rows()+i] = m(i,j);
+ }
+}
+
void matrix2array(const PMatrix m,float64_t** matrix, int32_t* rows, int32_t*cols)
{
int size = m.rows()*m.cols();
//allocate memory
- (*matrix) = new double[size];
+ (*matrix) = new float64_t[size];
//set dimensions
(*rows) = m.rows();
(*cols) = m.cols();
@@ -42,6 +72,7 @@ void matrix2array(const PMatrix m,float64_t** matrix, int32_t* rows, int32_t*col
}
+
PMatrix randn(int n, int m)
/* create a randn matrix */
{
View
8 array_helper.h
@@ -18,17 +18,21 @@ using alglib::randomreal;
//some definitions for the python interface
#define float64_t double
+#define float32_t float
#define int32_t int
//standard Matrix type to use in this project
-typedef Matrix<double, Dynamic, Dynamic> PMatrix;
-typedef Matrix<double, Dynamic, 1> PVector;
+typedef Matrix<float32_t, Dynamic, Dynamic> PMatrix;
+typedef Matrix<float32_t, Dynamic, 1> PVector;
//array 2 matrix and vice versa
+PMatrix array2matrix(const float32_t* matrix,int32_t rows,int32_t cols);
PMatrix array2matrix(const float64_t* matrix,int32_t rows,int32_t cols);
+void matrix2array(const PMatrix m,float32_t** matrix, int32_t* rows, int32_t*cols);
void matrix2array(const PMatrix m,float64_t** matrix, int32_t* rows, int32_t*cols);
+
//check for null Matrix (empty)
bool isnull(const PMatrix m);
View
3  python/peer.i
@@ -34,9 +34,12 @@
//typemap for matrix arguments
%apply (float64_t* IN_ARRAY2, int32_t DIM1, int32_t DIM2) {(float64_t* matrix, int32_t rows, int32_t cols)};
+%apply (float32_t* IN_ARRAY2, int32_t DIM1, int32_t DIM2) {(float32_t* matrix, int32_t rows, int32_t cols)};
+
//typemap for return matrix arguments
%apply (float64_t** ARGOUT2, int32_t* DIM1, int32_t* DIM2) {(float64_t** matrix, int32_t* rows, int32_t* cols)};
+%apply (float32_t** ARGOUT2, int32_t* DIM1, int32_t* DIM2) {(float32_t** matrix, int32_t* rows, int32_t* cols)};
/* Remove C Prefix */
View
7 vbfa.h
@@ -186,6 +186,7 @@ class cVBFA : public cBayesNet {
//setters
void setPhenoMean(float64_t* matrix,int32_t rows,int32_t cols)
{this->pheno_mean = array2matrix(matrix,rows,cols);is_initialized=false;}
+
void setPhenoVar(float64_t* matrix,int32_t rows,int32_t cols)
{this->pheno_var = array2matrix(matrix,rows,cols);is_initialized=false;}
void setCovariates(float64_t* matrix,int32_t rows,int32_t cols)
@@ -211,9 +212,9 @@ class cVBFA : public cBayesNet {
{return matrix2array(calc_residuals(),matrix,rows,cols);}
#else
//excludede fromo the swig interface as overloade functions do not get type mapped (and we don't port PMatrix anyway)
- void setPhenoMean(PMatrix pheno_mean) {this->pheno_mean = pheno_mean;is_initialized=false;}
- void setPhenoVar(PMatrix pheno_var) {this->pheno_var = pheno_var;is_initialized=false;}
- void setCovariates(PMatrix covs) { this->covs = covs;is_initialized=false;}
+ void setPhenoMean(const PMatrix pheno_mean) {this->pheno_mean = pheno_mean;is_initialized=false;}
+ void setPhenoVar(const PMatrix pheno_var) {this->pheno_var = pheno_var;is_initialized=false;}
+ void setCovariates(const PMatrix covs) { this->covs = covs;is_initialized=false;}
//getters
PMatrix getPhenoMean(){return this->pheno_mean;}
Please sign in to comment.
Something went wrong with that request. Please try again.