GMStandard.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #include <core/basics/Exception.h>
  2. #include "GMStandard.h"
  3. using namespace NICE;
  4. using namespace std;
  5. void GMStandard::multiply ( const SetType & rowSet, const SetType & columnSet, NICE::Vector & y, const NICE::Vector & x) const
  6. {
  7. if ( x.size() != columnSet.size() )
  8. fthrow(Exception, "Size of the column set is different from the size of the given input vector: " << columnSet.size() << " vs " << x.size());
  9. y.resize( rowSet.size() );
  10. // memory inefficient
  11. Matrix Asub ( rowSet.size(), columnSet.size() );
  12. int ii = 0;
  13. for ( SetType::const_iterator i = rowSet.begin(); i != rowSet.end(); i++,ii++ )
  14. {
  15. int jj = 0;
  16. for ( SetType::const_iterator j = columnSet.begin(); j != columnSet.end(); j++,jj++ )
  17. Asub ( ii, jj ) = A( *i, *j );
  18. }
  19. y.multiply ( Asub, x );
  20. }
  21. double GMStandard::getDiagonalElement ( uint i ) const
  22. {
  23. if ( (i >= A.rows()) || (i >= A.cols()) )
  24. fthrow(Exception, "Invalid index to access diagonal element: " << i << " (" << A.rows() << " x " << A.cols() << ")" );
  25. return A(i,i);
  26. }