MATLAB: Strfind on gpu

gpustrfind

Hi there, When I try to use strfind on data which is on the gpu it gives me an error. It seems strfind cannot work on data which is on the gpu. Is there a work around?.

Best Answer

The STRFIND function is fast to find the occurrences of a sequence. The problem is that you are calling it for all possible sequences, even though I think you are only interested in using it on sequences that repeat. It is easy and quick to find repeated sequences:
First create some data that I can run quickly on my laptop
M = 1e6;
N = 6;
k = 100;
x = randi(k, 1, M);
First you need to reshape the data to get every N element sequence
y = zeros(M-N, N);
for ii = 1:(M-N)
y(ii, :) = x((0:(N-1))+ii);
end
Then find all the unique N element sequences.
[a, b, c] = unique(y, 'rows');
Some of these sequences will occur only once and we want to remove these
temp = c;
temp(b) = [];
a = a(unique(temp));
then instead of looping over every possible sequence you can do
for ii =1:size(a, 1)
strfind(x, a(ii, :));
end
I am not even sure this last step is needed since the information may already be available in "c".
I have no idea if this is faster.