Speed up a lookup process
2 views (last 30 days)
I have been trying to speed up a lookup process.
A is a array of 1 million numbers. B is a array of 15 thousands numbers (no duplicated numbers in B). I am trying to do is: for every number in A, find the index of same number in B and use that index to fetch a value in array C (which is of the same size as A).
The look up process stated above has to be repeated several thousands times since I have thousands of different array B to loop up, but A and C kept always same.
I used ismember function AND gpuArray, which gave me some improvement. I wonder if there still some space for improvement. Let me know you suggestions!
Here is some testing code that I used:
for j=1:10 % e.g. 10 loops with different B (all integers) and C, but A (all integers) kept same in every loop
[~,Locb] = ismember(A,B);
Locb(Locb==0)=size(B,1)+1;%%% make all the zero in Locb to be a element that is indexable
C(size(B,1)+1,1)=0;% add zero in the end of the table;