Problem 921. REPMAT Enhancement - Faster for Large Row Replication of Vector
The Challenge is to modify repmat.m to maintain all of its normal functionality and enhance its performance for large row replication for both N=1 and N>1 cases, B=repmat(A,M,N). The size of A for enhancement cases is [1,n].
For cases of M> 12,288,000 and n<128 or N*n<256 it is possible to perform an enhanced repmat in 40% of the time of repmat. The standard repmat takes 150% longer than repmatLV in certain cases on Cody (2.5 sec / 1 sec).
Input: [A,M,N] standard input for repmat
- A: Vector (row or column) or an array
- M: row duplication factor of A
- N: column replication factor of A
Output: B, Array of size [M*m,N*n] where [m,n]=size(A)
Score: Performance is based upon time(msec) to execute four large row replications
Test Cases include normal arrays for which the function must still maintain repmat capability and also the large test cases:
- 1: r [1,12] of uint32, M=6144000, N=4
- 2: r [1,12] of uint8, M=6144000, N=16
- 3: r [1,48] of uint32, M=6144000, N=1
- 4: r [1,48] of uint8, M=12288000, N=1
- Test cases are sized to not hit the memory limit and clears are implemented.
I suggest replicating repmat.m to a local folder and name it repmatLV.m. Create a shell that calls repmatLV as if it was repmat. Implement calls of the stressing test cases from the shell. Use the Profiler Tool to analyze where time is being consumed and devise alternative speed enhancements.
- command window; open repmat
- file: save as: to local folder with new name
- Create Shell calling function
- From the Editor/Shell; Tools: Open Profiler
- From Profiler Window: Start Profiling (Fourth row top left)
- Explore the results of the profiler windows
Note: The above cases assume a 3GB system or better. Reduce M as necessary.
The overall goal of this challenge is to show that matlab built-in functions are excellent resources for methods, optimization of functions is possible depending on individual needs, and profiling is fun.
A follow-up Challenge will demonstrate an optimization of ismember, for the 'sortrows' option with many rows, when both arrays have many rows vs columns and have low commonality(< 10%). Processing time can be reduced by more than 90% for these large row dominant arrays compared to the standard ismember time.
Solution CommentsShow comments
Problem Recent Solvers13