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

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

[Octave-bug-tracker] [bug #39735] printf behaviour is inconsistent for m


From: anonymous
Subject: [Octave-bug-tracker] [bug #39735] printf behaviour is inconsistent for matrix arguments
Date: Fri, 09 Aug 2013 09:16:15 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:21.0) Gecko/20100101 Firefox/21.0

URL:
  <http://savannah.gnu.org/bugs/?39735>

                 Summary: printf behaviour is inconsistent for matrix
arguments
                 Project: GNU Octave
            Submitted by: None
            Submitted on: Fri 09 Aug 2013 09:16:14 AM UTC
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Inaccurate Result
                  Status: None
             Assigned to: None
         Originator Name: Michael Leitner
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 3.6.2
        Operating System: GNU/Linux

    _______________________________________________________

Details:

Consider:


~:10> printf("a %d b\n",ones(2,1))
a 1 b
a 1 b
~:11> printf("a %d b\n",ones(1,1))
a 1 b
~:12> printf("a %d b\n",ones(0,1))
a ~:13> 


For me, this is inconsistent behaviour, I would expect the last command to
give empty output. It seems that this is connect to the feature of being able
to output matrices that "are not exact multiples of the number of conversions
in the format template": 


~:13> printf("a %d %d b\n",ones(3,1))
a 1 1 b
a 1 ~:14> 


Without looking into the code, I cannot imagine the logic leading to these
results, for me the most obvious implementation would be to integer-divide the
number of supplied elements by the number of conversions in the output string,
call C's printf accordingly and special-case the remaining elements (by
cutting the output string and pass it once more to C's printf). This would
give my expected behaviour. By the way, what does MATLAB do?

At the very least, the observed behaviour is a documentation bug. In 14.2.5 it
says "If more than one value is to be printed in a single call, the output
functions do not return to the beginning of the format template when moving on
from one value to the next. This can lead to confusing output if the number of
elements in the matrices are not exact multiples of the number of conversions
in the format template." But here it is not more than one value that is to be
printed, and also the number of elements is an exact (should say: integer)
multiple of the number of output conversions.

Going a step further, I would find an added feature useful: add m and v as
type modifier characters, which in the hitherto syntax are being ignored. The
output should be:


~:14> printf("a %vd b\n",ones(2,1))
a 1 1 b
~:15> printf("a %vd b\n",ones(1,1))
a 1 b
~:16> printf("a %vd b\n",ones(0,1))
a  b
~:17> printf("a %md b\n",ones(2,2))
a 1 1 
1 1 b
~:18> printf("a %md b\n",ones(2,1))
a 1
1 b


Initial and trailing spaces/newlines would be left to debate, but I would keep
them at a minimum, as the user can supply them in the format string. This
could be implemented rather easily by a pass over the output conversion string
looking for v or d in a conversion and generating a new string, substituting a
%*v* by the corresponding sequence of %**, given by length(corresponding
argument)). Obviously, mixing a %d with a %vd in a single call with both
vector arguments would give an awkward situation.




    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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