octave-maintainers
[Top][All Lists]
Advanced

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

Usage of empty_arg


From: Jordi Gutiérrez Hermoso
Subject: Usage of empty_arg
Date: Wed, 28 Dec 2011 11:02:39 -0500

While engaging the Numpy developers in a discussion about empty
matrices and how to handle them, I noticed the following snippet in
src/DLD-FUNCTIONS/det.cc:

    octave_idx_type nr = arg.rows ();
    octave_idx_type nc = arg.columns ();

    if (nr == 0 && nc == 0)
      {
        retval(0) = 1.0;
        return retval;
      }

    int arg_is_empty = empty_arg ("det", nr, nc);
    if (arg_is_empty < 0)
      return retval;
    if (arg_is_empty > 0)
      return octave_value (Matrix (1, 1, 1.0));

Okay, so I understand the first part, if it's a 0x0 empty matrix, the
determinant is 1. What is the empty_arg part supposed to do? The
function is simply this:


    // Return non-zero if either NR or NC is zero.  Return -1 if this
    // should be considered fatal; return 1 if this is ok.
    int
    empty_arg (const char * /* name */, octave_idx_type nr, octave_idx_type nc)
    {
      return (nr == 0 || nc == 0);
    }

The name argument is completely ignored and it effectively returns a
bool instead of an int. Using hg annotate to see where this change was
made, I found at cset 7afd4bf05aa the following comment, from 2003:

    Behave as though propagate_empty_matrices is always 1.

So it looks like some remnant of empty matrix handling.

Would it be ok to completely get rid of this function? From what I can
tell, it's only called in a few places in src/DLD-FUNCTIONS, and it
doesn't do anything very exciting. It seems like an easy enough
simplification to the code, but I don't want to break anything by
mistake.

- Jordi G. H.


reply via email to

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