I’d like to find non-zero elements of a matrix as fast as possible. Having CUDA \ Jacket in mind, I’ve learned that this is much slower than the “regular” CPU version of Matlab‘s find, probably due to memory allocation issues, since the size of the output is not known prior to the find function. However, using bwlabel and regionprops (both supported in Jacket) does effectively yield info regarding the non-zero elements, and much faster than Matlab‘s built in Image Processing Toolbox functions. Is there a way to harness this to get the non-zero elements? Is there instead a way to do some processing on each of the labeled objects that are found using bwlabel?
I’d like to find non-zero elements of a matrix as fast as possible. Having
Share
In my experience, the FIND implementation supported by Jacket is very fast, at least for matrices larger than 300×300 or so. I tested this on my laptop and share the results in what follows. My HW specs are:
CPU is Intel Core i7-2630QM.
I get that Jacket hits ~3X speedups on the FIND function over the CPU. Here is the benchmark code I used:
Here are the results of running this code:
I’m sure the BWLABEL and REGIONPROPS functions supported by Jacket are also very fast, but you might be able to get by with FIND itself given the benchmarks above.