[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to check for equality between 2 octave_value objects?
From: |
Michael Goffioul |
Subject: |
Re: How to check for equality between 2 octave_value objects? |
Date: |
Fri, 8 Aug 2008 11:08:01 +0200 |
On Thu, Aug 7, 2008 at 4:43 PM, John W. Eaton <address@hidden> wrote:
> It would be possible to rewrite the __isequal__ function in C++ with
> the DEFUN as a wrapper around a function like
>
> bool isequal (const octave_value&, const octave_value&)
>
> defined in ov.{h,cc}. If we do this, it might be worth having the
> isequal function do the dispatching using the same table we use for
> dispatching for other binary operators, and add an "equal" operator to
> the octave_value::binary_op enum.
>
> We can provide this same interface now by defining a function
>
> bool
> isequal (const octave_value& a, const octave_value& b,
> bool nans_compare_equal = false)
> {
> octave_value_list args;
>
> args(2) = b;
> args(1) = a;
> args(0) = nans_compare_equal;
>
> octave_value_list tmp = feval ("__isequal__", args, 1);
>
> // We expect __isequal__ to always return a single logical scalar.
> return tmp(0).bool_value ();
> }
>
> in ov.{h,cc}. I know you'd like to avoid the feval, but I think this
> is the best we can do without a fair amount of work.
No problem, I was just asking if this feature was present or
not. It might be interesting to have it on the long term, but for
the time being I can live with an ad-hoc solution (in my case,
I only want to test for equivalence between numeric arrays)
that is easy to implement with a couple of #define's.
Thinking about possible implementations, you might also
consider to add a method to the octave_value/octave_base_value
class like bool isequal (const octave_value& ov) and leave the
work of equality check to the derived class of octave_base_value.
Michael.