Changeset 516


Ignore:
Timestamp:
Feb 20, 2006, 7:37:42 PM (16 years ago)
Author:
Peter
Message:

added function generating weight matrix with respect to not-a-number vs number

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/gslapi/matrix.cc

    r444 r516  
    137137
    138138
     139  matrix matrix::nan(void) const
     140  {
     141    matrix m(rows(),columns(),1.0);
     142    for (size_t i=0; i<rows(); i++)
     143      for (size_t j=0; j<columns(); j++)
     144        if (std::isnan(operator()(i,j)))
     145          m(i,j)=0;
     146    return m;
     147  }
     148
     149
     150
    139151  // Jari, checkout GSL transpose support in GSL manual 8.4.9
    140152  void matrix::transpose(void)
  • trunk/lib/gslapi/matrix.h

    r434 r516  
    225225
    226226    ///
     227    /// @return matrix containing 1 and 0 only. 1 means element in
     228    /// matrix is valid and a zero means element is a NaN.
     229    ///
     230    matrix nan(void) const;
     231
     232    ///
    227233    /// Multiply the elements of matrix \a b with the elements of the
    228234    /// calling matrix ,\f$a_{ij} = a_{ij} * b_{ij} \; \forall
  • trunk/test/matrix_test.cc

    r420 r516  
    194194  }
    195195
     196  *error << "\tmatrix::nan()" << std::endl;
     197  is.open("data/sorlie_centroids.txt");
     198  gslapi::matrix* m_nan = new gslapi::matrix(is,'\t');
     199  gslapi::matrix m_weight = m_nan->nan();
     200  is.close();
     201  if (m_weight(0,0)!=1){
     202    *error << "error in matrix::nan(): element(0,0) is " << m_weight(0,0)
     203           << " expected 1." << std::endl;
     204    ok=false;
     205  }
     206  if (m_weight(3,2)!=0){
     207    *error << "error in matrix::nan(): element(3,2) is " << m_weight(3,2)
     208           << " expected 0." << std::endl;
     209    ok=false;
     210  }
     211  delete m_nan;
     212
    196213  if (error!=&std::cerr)
    197214    delete error;
Note: See TracChangeset for help on using the changeset viewer.