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

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

[Octave-bug-tracker] [bug #63515] logical should convert char and string


From: Rik
Subject: [Octave-bug-tracker] [bug #63515] logical should convert char and strings instead of throwing an error for Matlab compatibility
Date: Tue, 13 Dec 2022 18:27:17 -0500 (EST)

Follow-up Comment #3, bug #63515 (project octave):

Everything turns into a project.  I thought this would be easy, and it mostly
is, but then there are all sorts of questions that arise.  To have "logical"
work on single-quoted strings is the easiest.  See the attached changeset. 
The tricky thing is that the function I added, bool_array_value, is probably
not correct.  The function I wrote is


+  boolNDArray bool_array_value (bool = false) const
+  { return boolNDArray (m_matrix); }


But, if I look at how it is implemented in ov-re-mat.cc, it seems like the
input "warn" needs to be used.


boolNDArray
octave_matrix::bool_array_value (bool warn) const
{
  if (m_matrix.any_element_is_nan ())
    octave::err_nan_to_logical_conversion ();
  if (warn && m_matrix.any_element_not_one_or_zero ())
    warn_logical_conversion ();

  return boolNDArray (m_matrix);
}


char arrays do not hold NaN elements so that test isn't needed, but the
function "any_element_not_one_or_zero" is.  Unfortunately, the class
charNDArray does not implement this so it would require adding it to that
class which is is a change in liboctave.  All of this is doable, but I'm
starting to wonder if I'm on the right track.  Adding jwe to the CC list so he
can comment.


(file #54088)

    _______________________________________________________

Additional Item Attachment:

File name: 63515.v1.cset                  Size:1 KB
    <https://file.savannah.gnu.org/file/63515.v1.cset?file_id=54088>



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?63515>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

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