octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #50776] Octave inconsistent with Matlab for co


From: Rik
Subject: [Octave-bug-tracker] [bug #50776] Octave inconsistent with Matlab for corner indexing case
Date: Wed, 12 Apr 2017 13:02:08 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0

Follow-up Comment #10, bug #50776 (project octave):

Very cute code:


idx_vector::idx_vector (const Array<bool>& bnda)
  : rep (0)
{
  // Convert only if it means saving at least half the memory.
  static const int factor = (2 * sizeof (octave_idx_type));
  octave_idx_type nnz = bnda.nnz ();
  if (nnz <= bnda.numel () / factor)
    rep = new idx_vector_rep (bnda, nnz);
  else
    rep = new idx_mask_rep (bnda, nnz);
}


As a side note, should idx_vector have an xelem method in analogy to the xelem
method for Array?

Right now I see only elem().  For example, your new code is



  bool is_nd_vector (void) const
  {
    int num_non_one = 0;

    for (int i = 0; i < ndims (); i++)
      {
        if (elem (i) != 1)
          {
            num_non_one++;

            if (num_non_one > 1)
              break;
          }
      }

    return num_non_one == 1;
  }


But since the loop explicitly runs over the dimensions of the idx_vector there
is no need to also run through an assert statement to check that.


  octave_idx_type elem (int i) const
  {
#if defined (OCTAVE_ENABLE_BOUNDS_CHECK)
    assert (i >= 0 && i < ndims ());
#endif
    return rep[i];
  }





    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?50776>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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