![]() On my W10圆4 machine this returns the following timings: ![]() Tic ismembc(d,c) fprintf('%.3f sec (ismembc, sorted a)n',toc) Tic ismembc(d,c) fprintf('%.3f sec, ',toc) Tic ismembc(a,c) fprintf('%.3f sec (ismembc, unsorted a)n',toc) Tic ismembc(a,c) fprintf('%.3f sec, ',toc) Tic ismembc(a,sort(b)) fprintf('%.3f sec (ismembc and sort)n',toc) Tic ismembc(a,sort(b)) fprintf('%.3f sec, ',toc) Tic ismember(a,b) fprintf('%.3f sec (ismember)n',toc) Tic ismember(a,b) fprintf('%.3f sec, ',toc) Tic ismembc (d,c ) fprintf ( '%.3f sec (ismembc, sorted a)n', toc ) Ĭlc,n=2e6 a=ceil(n*rand(n,1)) b=ceil(n*rand(n,1)) c=sort(b) d=sort(a) Tic ismembc (d,c ) fprintf ( '%.3f sec, ', toc ) Tic ismembc (a,c ) fprintf ( '%.3f sec (ismembc, unsorted a)n', toc ) Tic ismembc (a,c ) fprintf ( '%.3f sec, ', toc ) Tic ismembc (a, sort (b ) ) fprintf ( '%.3f sec (ismembc and sort)n', toc ) Tic ismembc (a, sort (b ) ) fprintf ( '%.3f sec, ', toc ) Tic ismember (a,b ) fprintf ( '%.3f sec (ismember)n', toc ) Tic ismember (a,b ) fprintf ( '%.3f sec, ', toc ) Whereas ismembc returns an array of logical values, ismembc2 returns the index locations of the found members.Ĭlc,n=2e6 a= ceil (n* rand (n, 1 ) ) b= ceil (n* rand (n, 1 ) ) c= sort (b ) d= sort (a ) Readers interested in ismembc might also be interested in its sibling help function, ismembc2, which is also a mex file located (with source-code) in the same folder as ismembc. The nice thing about ismembc is that its source code (ismembc.cpp) is included, so even if future Matlab releases stop using this function, you can always mex-compile the source code and use it. In the general case we should either ensure this programmatically (as done in setxor) or use ismember, which handles this for us. Ismembc should not be used carelessly: as noted, its inputs must be sorted non-sparse non-NaN values. From the source code comments we learn that the comment in setxor about ismembc usage is misleading: that comment stated that the inputs must be real, but the source-code indicates that imaginary numbers are also accepted and that only the real-part should be sorted. Its source code is included in the same folder (%matlabroot%\toolbox\matlab\ops\ismembc.cpp) and is actually very readable. Ismembc is actually a MEX file (%matlabroot%\toolbox\matlab\ops\xw32). > % Run ismember several times, to rule-out JIT compilation overheads The performance improvement may be significant: In a recent post, MathWorks’ Loren Shure presented different approaches for fast data retrieval, highlighting the ismember function. ismembc uses the same interface (two inputs, single logical output) as ismember and can be a drop-in replacement for ismember for these “regular” cases. In such cases, ismembc can be used directly, saving ismember‘s sanity-checks overhead. ![]() This function is used within the stock Matlab ismember and setxor functions for fast processing of the core ismember functionality in “regular” cases: arrays of sorted, non-sparse, non-NaN data in which we’re only interested in the logical membership information (not the index locations of the found members). In this post I want to present Matlab’s built-in ismembc helper function. Some of these helper functions are undocumented and unsupported, but may be helpful in their own right – not just as internal support functions. ![]() Matlab has a variety of internal helper functions which are used by the main (documented) functions.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |