Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Problem 921. REPMAT Enhancement - Faster for Large Row Replication of Vector

Created by Richard Zapor

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.

Potential Path:

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.

  1. command window; open repmat
  2. file: save as: to local folder with new name
  3. Create Shell calling function
  4. From the Editor/Shell; Tools: Open Profiler
  5. From Profiler Window: Start Profiling (Fourth row top left)
  6. 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.


Problem Group

Solution Statistics

15 correct solutions 3 incorrect solutions
Last solution submitted on Sep 08, 2015