help-octave
[Top][All Lists]
Advanced

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

Re: fast hist() / histogram() implementation in C++


From: Paul Kienzle
Subject: Re: fast hist() / histogram() implementation in C++
Date: Tue, 16 Nov 2004 02:37:56 -0500

Here are the tests from hist.m in octave:

%!test
%!  [nn,xx]=hist([1:4],3);
%!  assert(xx, [1.5,2.5,3.5]);
%!  assert(nn, [2,1,1]);
%!test
%!  [nn,xx]=hist([1:4]',3);
%!  assert(xx, [1.5,2.5,3.5]');
%!  assert(nn, [2,1,1]');
%!test
%!  [nn,xx]=hist([[1:4]',[1:4]'],3);
%!  assert(xx, [[1.5,2.5,3.5]',[1.5,2.5,3.5]']);
%!  assert(nn, [[2,1,1]',[2,1,1]']);
%!assert(hist(1,1),1);
%!test
%!  for n = [10, 30, 100, 1000]
%!    assert( sum(hist([1:n], n)), n );
%!    assert( sum(hist([1:n], [2:n-1])), n);
%!    assert( sum(hist([1:n], [1:n])), n );
%!    assert( sum(hist([1:n], 29)), n);
%!    assert( sum(hist([1:n], 30)), n);
%!  endfor


Here's the result from your hist function:

>>>>> processing hist
>>>>> /Users/paulkienzle/Downloads/histc-Nov05/hist.m
  ***** test
  [nn,xx]=hist([1:4],3);
  assert(xx, [1.5,2.5,3.5]);
  assert(nn, [2,1,1]);
!!!!! test failed
error: assert (nn,[2, 1, 1]) expected
  2  1  1
but got
  1  1  2
maximum absolute error 1 exceeds tolerance 0
  ***** test
  [nn,xx]=hist([1:4]',3);
  assert(xx, [1.5,2.5,3.5]');
  assert(nn, [2,1,1]');
!!!!! test failed
error: assert (xx,[1.5, 2.5, 3.5]') expected
  1.5000
  2.5000
  3.5000
but got
  1.5000  2.5000  3.5000
Dimensions don't match
  ***** test
  [nn,xx]=hist([[1:4]',[1:4]'],3);
  assert(xx, [[1.5,2.5,3.5]',[1.5,2.5,3.5]']);
  assert(nn, [[2,1,1]',[2,1,1]']);
!!!!! test failed
error: assert (xx,[[1.5, 2.5, 3.5]', [1.5, 2.5, 3.5]']) expected
  1.5000  1.5000
  2.5000  2.5000
  3.5000  3.5000
but got
  1.5000  2.5000  3.5000
Dimensions don't match
  ***** assert(hist(1,1),1);
!!!!! test failed
error: first argument must be real vector or matrix
  ***** test
  for n = [10, 30, 100, 1000]
    assert( sum(hist([1:n], n)), n );
    assert( sum(hist([1:n], [2:n-1])), n);
    assert( sum(hist([1:n], [1:n])), n );
    assert( sum(hist([1:n], 29)), n);
    assert( sum(hist([1:n], 30)), n);
  endfor
PASSES 1 out of 5 tests

On Nov 5, 2004, at 1:30 PM, Petr Mikulik wrote:

I acknowledge the effort in improving hist.m. Is is as fast as M-language allows. Unfortunately, using it for large images (e.g. 2D detector data) like 512^2 and above goes beyond the user patiency (at least, for me). That was my move to reimplement my own favourite histogram.m into histogram.oct.
...
Thus, in average, 50x speedup is achieved for linearly spaced bins,
and 27x for logarithmically (or whichever non-linearly) spaced bins.

These improvements do appear to be impressive.

I would recommend that you contribute them to octave-forge,
probably in the main/general directory.

Additionally, you can ask jwe if he is prepared to add them to
octave.


I've implemented histogram evaluation in C++: routine histc.cc, and its
corresponding hist.m.

Get it from here:
        http://www.physics.muni.cz/~mikulik/tmp/histc-Nov05.zip

It supports histogram of a vector and 2D matrix.
I don't know how to access dimensions for N-dim matrices. Someone can
contribute the missing code?

Thus I ask -- what do you think -- could this replace hist.m, and contribute
the missing histc function in the Octave package?

Petr



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------




-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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