Boost logo

Ublas :

From: Paul C. Leopardi (leopardi_at_[hidden])
Date: 2005-05-03 05:56:47


Gunter,
Please see my response below.
Best regards
On Tue, 3 May 2005 08:29 pm, Gunter Winkler wrote:
> On Tuesday 03 May 2005 11:22, Max Weinberg wrote:
> > Well, I don't care if it's called operator==, but there definitely should
> > be a way to compare matrices. Call it equal if you like and give it a
> > functor parameter that handles the element comparison.
>
> Can you give an example, in which situation you check the equality of two
> matrices? I never needed it in my codes.
>
> BTW: Using norm_1(A-B) or norm_inf(A-B) is a O(n*m) or O(nnz) operation.
> Doing a elementwise comparison (optionally with short circuit) is O(n*m) or
> O(nnz), too. So there is no difference regarding the algorithmic
> complexity.

I can chime in here. In GluCat (in matrix_multi_imp.h), I have the following
code:

  /// Test for equality of multivectors
  template< typename Scalar_T, const index_t LO, const index_t HI >
  bool
  matrix_multi<Scalar_T,LO,HI>::
  operator== (const multivector_t& rhs) const
  {
    // Compare only within a common frame
    if (m_frame == rhs.m_frame)
      return ublas::equals(m_matrix, rhs.m_matrix);
    else
      return framed_multi_t(*this) == framed_multi_t(rhs);
  }

Naturally, there may be many cases where we have an undetected near-miss due
to rounding error, but I view this as an (important) implementation detail.
Having the abstraction available is the main purpose here, as in all of
GluCat. Also, GluCat often uses basis matrices, which are -1,0,1 matrices,
for which equality comparison does not suffer from rounding error.

Best regards, Paul Leopardi