[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Octave's plotting much slower than matlab
From: |
David Bateman |
Subject: |
Re: Octave's plotting much slower than matlab |
Date: |
Tue, 22 Jan 2008 01:58:34 +0100 |
User-agent: |
Thunderbird 1.5.0.7 (X11/20060921) |
Michael Goffioul wrote:
> what takes most
> of the time is the actual patch object creation (through __scatter__), which
> is
> interpreted code using for-loops. Here are some numbers (Dual P4 3.2GHz, 1GB,
> Intel 915G):
>
> octave.exe:5> tic, scatter(rand(1,1000),rand(1,1000)), toc
> Elapsed time is 0.813968 seconds.
> octave.exe:6> close
> octave.exe:8> tic, scatter(rand(1,10000),rand(1,10000)), toc
> Elapsed time is 2.53856 seconds.
> octave.exe:11> close
> octave.exe:12> tic, scatter(rand(1,100000),rand(1,100000)), toc
> Elapsed time is 21.8031 seconds.
>
> In the last test, the actual rendering takes about 0.5s.
Well the rendering in gnuplot will be a lot slower, and even for the
first case takes seconds, and the second case I gave up and used ctrl-c
to quit. Though to test your idea, I see that there is a single for-loop
in __patch__ that is called for the case in question with scatter.
Though is the user has no NaN values in the data, then this loop is
never really needed. However, that brings up two issues.
1) What should be done if the user gives NaN data in the patches?
Without matlab to check, I believe scatter should drop these points,
though I suppose they might be stored in the handle and dropped at the
time of plotting.
2) Can we vectorize the for-loop and at least get reasonable speed for
scatter with a SVN head version of JHandles? I think we can, but the
only means I saw to do it is quite messy. See the attached patch.
We need to address the issue of what the matlab scatter function stores
in xdata, etc with a point is NaN and probably adapt my patch, but this
is a good first start at addressing this. Michael, care to test it and
see if your speed with JHandles is better?
D.
>
> Michael.
*** ./scripts/plot/__scatter__.m.orig9 2008-01-22 01:47:42.155914576 +0100
--- ./scripts/plot/__scatter__.m 2008-01-22 01:46:20.158006248 +0100
***************
*** 29,36 ****
--- 29,43 ----
if (nd == 3)
z = varargin{6}(:);
+ idx = isnan(x) | isnan (y) | isnan (z);
+ x (idx) = [];
+ y (idx) = [];
+ z (idx) = [];
istart = 7;
else
+ idx = isnan(x) | isnan (y);
+ x (idx) = [];
+ y (idx) = [];
z = zeros (length (x), 0);
endif
*** ./scripts/plot/__patch__.m.orig9 2008-01-22 01:47:57.233162226 +0100
--- ./scripts/plot/__patch__.m 2008-01-22 01:49:07.724644722 +0100
***************
*** 124,136 ****
nr = size (faces, 2);
nc = size (faces, 1);
idx = faces .';
! for i = 1: nc
! t1 = isnan (idx (:,i));
! if (any (t1))
! t2 = find (t1(1:end-1) != t1(2:end))(1);
! idx(t1,i) = idx(t2,i);
! endif
! endfor
x = reshape (vert(:,1)(idx), size (idx));
y = reshape (vert(:,2)(idx), size (idx));
if (size(vert,2) > 2)
--- 124,136 ----
nr = size (faces, 2);
nc = size (faces, 1);
idx = faces .';
! t1 = isnan (idx);
! if (any (t1))
! t2 = find (t1 != t1([2:end,end],:));
! idx (t1) = idx (t2 (cell2mat (cellfun (@(x) x(1)*ones(1,x(2)),
! mat2cell ([1 : length(t2); sum(t1)], 2, ones(1,length(t2))),
! "UniformOutput", false))));
! endif
x = reshape (vert(:,1)(idx), size (idx));
y = reshape (vert(:,2)(idx), size (idx));
if (size(vert,2) > 2)