octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to check for equality between 2 octave_value objects?


From: John W. Eaton
Subject: Re: How to check for equality between 2 octave_value objects?
Date: Thu, 07 Aug 2008 10:43:16 -0400

On  7-Aug-2008, Michael Goffioul wrote:

| On Thu, Aug 7, 2008 at 3:46 PM, John W. Eaton <address@hidden> wrote:
| > On  7-Aug-2008, Michael Goffioul wrote:
| >
| > | Is there a function in the current API that allows to check
| > | that 2 octave_value objects are equals. The only assumption
| > | I can make is that both objects are numeric (isnumeric returns
| > | true), but can be of any size and any element-type. I don't mean
| > | an element-by-element equality, just a global equality: same
| > | element-type, same dims, same elements.
| >
| > Does either isequal or isequalwithequalnans do what you want?
| > Currently, they are both wrappers around __isequal__, which is also
| > implemented in a .m file.
| 
| Yes, it is what I mean, but I need it from C++ and I'd rather avoid
| a feval call.

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.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]