Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: histc for gpu
Date: Thu, 20 Feb 2014 13:39:09 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 20
Message-ID: <le50ht$i1u$1@newscl01ah.mathworks.com>
References: <lc1a97$6tt$1@newscl01ah.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: rubyext-04-ls.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1392903549 18494 172.20.102.180 (20 Feb 2014 13:39:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Feb 2014 13:39:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:809610

"Christian " <proechri@umich.edu> wrote in message <lc1a97$6tt$1@newscl01ah.mathworks.com>...
> Hi,
> 
> I hope to use histc on CUDA, but it's not a supported function. So I tried a workaround because I'm actually just interested in the second output argument:
> 
> [~,ind] = histc(x,x_grid);
> 
> is more or less equivalent to the following code (except for points outside the grid).
> 
> ind=ones(size(x));
> for j=1:length(x_grid)-1
>     ind(x>=x_grid(j) & x<x_grid(j+1)) = j;
> end
>
 
The best way is perhaps to sort x and x_grid concatenated together, which has an O(N*log(N)) complexity where N is numel(x)+ numel(xgrid). Furthermore the histc engine is possibly programmed in C and very optimal way.

You won't beat it with the trivial for-loop, even with CUDA.

Bruno