octave-maintainers
[Top][All Lists]
Advanced

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

Re: Speeding Up gnuplot Interface with Binary Data


From: Daniel J Sebald
Subject: Re: Speeding Up gnuplot Interface with Binary Data
Date: Wed, 08 Oct 2008 21:21:59 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041020

John W. Eaton wrote:
On  7-Oct-2008, Daniel J Sebald wrote:

| John W. Eaton wrote:
| > On  7-Oct-2008, Daniel J Sebald wrote:
| > | > | John, | > | | > | Attached is a patch using gnuplot's binary data input feature rather than ASCII data fifteen characters wide. It does appear to speed up drawing a fair amount. Less data is transmitted through the pipe, gnuplot doesn't have to input data as formated, and as I see it there is no need for handling NaN in a special way (it is just another value in IEEE format). | > | | > | Let me know what you think. | > | > This patch fails to apply cleanly to the current Octave sources. | | Sorry. I'm out of step with Mercurial. Give this patch a try...

OK, this applies cleanly to my sources.

| +    fwrite (plot_stream, data, "float32");

Why float32?  That breaks things like

  plot ([1, 2], [3, 4]*1e100)

which used to work properly.  I think we should be sending double
precision data.

OK, I replaced the float32 in the previous patch with float64 in the proper 
places.  (Is image and palette data going to need double precision as well?)

Can you notice a considerable speedup on your machine?  I have a fairly old 
machine so the change is obvious.

Dan
--- /home/sebald/Desktop/__go_draw_axes__.m     2008-10-07 21:13:46.556716731 
-0500
+++ __go_draw_axes__.m  2008-10-07 21:29:50.995195506 -0500
@@ -1154,11 +1154,11 @@
          fprintf (plot_stream, "set view %.15g, %.15g;\n", rot_x, rot_z);
        endif
       endif
-      fprintf (plot_stream, "%s \"-\" %s %s %s \\\n", plot_cmd,
-              usingclause{1}, titlespec{1}, withclause{1});
+      fprintf (plot_stream, "%s \"-\" binary record=%d format='%%float64' %s 
%s %s \\\n", plot_cmd,
+              columns(data{1}), usingclause{1}, titlespec{1}, withclause{1});
       for i = 2:data_idx
-       fprintf (plot_stream, ", \"-\" %s %s %s \\\n",
-                usingclause{i}, titlespec{i}, withclause{i});
+       fprintf (plot_stream, ", \"-\" binary record=%d format='%%float64' %s 
%s %s \\\n",
+                columns(data{i}), usingclause{i}, titlespec{i}, withclause{i});
       endfor
       fputs (plot_stream, ";\n");
       for i = 1:data_idx
@@ -1351,48 +1351,23 @@
   endif
 
   if (nd == 2)
-    nan_elts = find (sum (isnan (data)));
-    fmt = cstrcat (repmat ("%.15g ", 1, rows (data)), "\n");
-    if (isempty (nan_elts))
-      fprintf (plot_stream, fmt, data);
-    else
-      n = columns (data);
-      have_nans = true;
-      num_nan_elts = numel (nan_elts);
-      if (num_nan_elts == n)
-       fputs (plot_stream, "Inf Inf\n");
-      else
-       k = 1;
-       for i = 1:n
-         if (have_nans && i == nan_elts(k))
-           fputs (plot_stream, "\n");
-           have_nans = ++k <= num_nan_elts;
-         else
-           fprintf (plot_stream, fmt, data(:,i));
-         endif
-       endfor
-      endif
-    endif
+    fwrite (plot_stream, data, "float64");
   elseif (nd == 3)
-    ## FIXME -- handle NaNs here too?
     if (parametric)
-      fprintf (plot_stream, "%.15g %.15g %.15g\n", data);
+      fwrite (plot_stream, data, "float64");
     else
       nr = rows (data);
       if (cdata)
        for j = 1:4:nr
-         fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data(j:j+3,:));
-         fputs (plot_stream, "\n");
+         fwrite (plot_stream, data(j:j+3,:), "float64");
        endfor
       else
        for j = 1:3:nr
-         fprintf (plot_stream, "%.15g %.15g %.15g\n", data(j:j+2,:));
-         fputs (plot_stream, "\n");
+         fwrite (plot_stream, data(j:j+2,:), "float64");
        endfor
       endif
     endif
   endif
-  fputs (plot_stream, "e\n");
 
 endfunction
 

reply via email to

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