octave-maintainers
[Top][All Lists]
Advanced

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

Re: __plt__.m redundancies


From: Daniel J Sebald
Subject: Re: __plt__.m redundancies
Date: Thu, 27 Jun 2013 14:05:58 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16

On 06/27/2013 01:50 PM, Rik wrote:
On 06/27/2013 10:31 AM, Daniel J Sebald wrote:
On 06/27/2013 11:44 AM, Rik wrote:
6/27/13

All,

I happened to be looking in scripts/plot/private/__plt__.m and found that
there is a dispatch table in the subfunction __plt2__ which checks whether
the x input is a scalar, vector, or matrix and whether the y input is a
scalar, vector, or matrix and then calls the appropriate subfunction such
as __plt2sv__ for scalar/vector plotting.

I checked in each of the 6 subfunctions and they check the number of input
arguments with nargin as well as re-checking that each of the inputs is a
scalar, vector, or matrix.  This is redundant and probably arose as the
code evolved in time.  Does anyone know why the input checks in the leaf
functions cannot be deleted in favor of the earlier checks?

--Rik

I'm not seeing this redundancy.  What line numbers or code hunks?
The dispatch table is in the __plt2__ subfunction at line 231.  Here it is
just to give the flavor:

   if (isempty (x1)&&  isempty (x2))
     retval = zeros (0, 1);
   elseif (isscalar (x1))
     if (isscalar (x2))
       retval = __plt2ss__ (h, x1, x2, options, properties);
     elseif (isvector (x2))
       retval = __plt2sv__ (h, x1, x2, options, properties);
     else
       error ("__plt2__: invalid data for plotting");
     endif
   elseif (isvector (x1))
     if (isscalar (x2))
       retval = __plt2vs__ (h, x1, x2, options, properties);
     elseif (isvector (x2))
       retval = __plt2vv__ (h, x1, x2, options, properties);
     elseif (ismatrix (x2))
       retval = __plt2vm__ (h, x1, x2, options, properties);
     else
       error ("__plt2__: invalid data for plotting");
     endif
   elseif (ismatrix (x1))
     if (isvector (x2))
       retval = __plt2mv__ (h, x1, x2, options, properties);
     elseif (ismatrix (x2))
       retval = __plt2mm__ (h, x1, x2, options, properties);
     else
       error ("__plt2__: invalid data for plotting");
     endif
   else
     error ("__plt2__: invalid data for plotting");
   endif

Each of the subfunctions is __plt2[svm][svm]__ where s is scalar, v is
vector, and m is matrix.  As an example, here is the start of __plt2ss__
which is for plotting scalar/scalar such as plot (1,1).

function retval = __plt2ss__ (h, x, y, options, properties)

   if (nargin<  3 || nargin>  5)
     print_usage ();
   endif

   if (nargin<  4 || isempty (options))
     options = __default_plot_options__ ();
   endif

   if (nargin<  5)
     properties = {};
   endif

   if (numel (options)>  1)
     options = options(1);
   endif

   if (isscalar (x)&&  isscalar (y))
     linestyle = options.linestyle;
     marker = options.marker;
     if (isempty (marker)&&  isempty (linestyle))
       ## If unspecified, marker for a single point is always "."
       linestyle = "-";
       marker = ".";
     endif
     color = options.color;
     if (isempty (color))
       color = __next_line_color__ ();
     endif

     retval = line (x, y, "color", color,
                    "linestyle", linestyle,
                    "marker", marker, properties{:});
   else
     error ("__plt2ss__: arguments must be scalars");
   endif

As you can see, there is quite a bit of option validating and this seems
unnecessary.

--Rik

Oh, I see what you are saying now. I was looking at the routine __plt2__.m. This is in the private directory, and I think JWE has not been validating the options at the lower level routines in such cases, just assuming they are properly called. The line

    else
      error ("__plt2ss__: arguments must be scalars");
    endif

will only produce an error if a developer hasn't programmed things correctly. But in all likelihood if a developer doesn't provide scalars, there will be some other type of error from within the core.

You're proposing removing

    if (isscalar (x)&&  isscalar (y))

and similar checks, right?

Dan


reply via email to

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