This is a static copy of a profile reportHome
repmat (100930 calls, 122.019 sec)
Generated 05-Nov-2014 07:52:41 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/matlab/elmat/repmat.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
104 | B = A(subs{:}); | 2279 | 106.357 s | 87.2% |  |
84 | B = A(ones(siz(1), 1), :); | 4549 | 2.443 s | 2.0% |  |
48 | if isscalar(A) | 100930 | 1.843 s | 1.5% |  |
54 | B(nelems) = A; | 86823 | 1.542 s | 1.3% |  |
60 | B(:) = A; | 76737 | 1.512 s | 1.2% |  |
All other lines | | | 8.322 s | 6.8% |  |
Totals | | | 122.019 s | 100% | |
Children (called functions)
No childrenCode Analyzer results
No Code Analyzer messages.Coverage results
[ Show coverage for parent directory ]
Total lines in function | 105 |
Non-code lines (comments, blank lines) | 42 |
Code lines (lines that can run) | 63 |
Code lines that did run | 44 |
Code lines that did not run | 19 |
Coverage (did run/can run) | 69.84 % |
Function listing
time calls line
1 function B = repmat(A,M,N)
2 %REPMAT Replicate and tile an array.
3 % B = repmat(A,M,N) creates a large matrix B consisting of an M-by-N
4 % tiling of copies of A. The size of B is [size(A,1)*M, size(A,2)*N].
5 % The statement repmat(A,N) creates an N-by-N tiling.
6 %
7 % B = REPMAT(A,[M N]) accomplishes the same result as repmat(A,M,N).
8 %
9 % B = REPMAT(A,[M N P ...]) tiles the array A to produce a
10 % multidimensional array B composed of copies of A. The size of B is
11 % [size(A,1)*M, size(A,2)*N, size(A,3)*P, ...].
12 %
13 % REPMAT(A,M,N) when A is a scalar is commonly used to produce an M-by-N
14 % matrix filled with A's value and having A's CLASS. For certain values,
15 % you may achieve the same results using other functions. Namely,
16 % REPMAT(NAN,M,N) is the same as NAN(M,N)
17 % REPMAT(SINGLE(INF),M,N) is the same as INF(M,N,'single')
18 % REPMAT(INT8(0),M,N) is the same as ZEROS(M,N,'int8')
19 % REPMAT(UINT32(1),M,N) is the same as ONES(M,N,'uint32')
20 % REPMAT(EPS,M,N) is the same as EPS(ONES(M,N))
21 %
22 % Example:
23 % repmat(magic(2), 2, 3)
24 % repmat(uint8(5), 2, 3)
25 %
26 % Class support for input A:
27 % float: double, single
28 %
29 % See also BSXFUN, MESHGRID, ONES, ZEROS, NAN, INF.
30
31 % Copyright 1984-2010 The MathWorks, Inc.
32 % $Revision: 1.17.4.17 $ $Date: 2010/08/23 23:08:12 $
33
0.26 100930 34 if nargin < 2
35 error(message('MATLAB:repmat:NotEnoughInputs'))
36 end
37
0.36 100930 38 if nargin == 2
0.17 69624 39 if isscalar(M)
40 siz = [M M];
0.19 69624 41 else
0.22 69624 42 siz = M;
0.44 69624 43 end
0.06 31306 44 else
0.20 31306 45 siz = [M N];
0.15 31306 46 end
47
1.84 100930 48 if isscalar(A)
0.82 86823 49 nelems = prod(double(siz));
0.47 86823 50 if nelems>0 && nelems < (2^31)-1 % use linear indexing for speed.
51 % Since B doesn't exist, the first statement creates a B with
52 % the right size and type. Then use scalar expansion to
53 % fill the array. Finally reshape to the specified size.
1.54 86823 54 B(nelems) = A;
0.44 86823 55 if ~isequal(B(1), B(nelems)) || ~(isnumeric(A) || islogical(A))
56 % if B(1) is the same as B(nelems), then the default value filled in for
57 % B(1:end-1) is already A, so we don't need to waste time redoing
58 % this operation. (This optimizes the case that A is a scalar zero of
59 % some class.)
1.51 76737 60 B(:) = A;
0.30 76737 61 end
1.10 86823 62 B = reshape(B,siz);
63 elseif all(siz > 0) % use general indexing, cost of memory allocation dominates.
64 ind = num2cell(siz);
65 B(ind{:}) = A;
66 if ~isequal(B(1), B(ind{:})) || ~(isnumeric(A) || islogical(A))
67 B(:) = A;
68 end
69 else
70 B = A(ones(siz));
71 end
0.07 14107 72 elseif ismatrix(A) && numel(siz) == 2
11828 73 [m,n] = size(A);
0.02 11828 74 if (issparse(A))
75 [I, J, S] = find(A);
76 I = bsxfun(@plus, I(:), m*(0:siz(1)-1));
77 I = I(:); I = I(:,ones(1,siz(2)));
78 J = J(:); J = J(:,ones(1,siz(1)));
79 J = bsxfun(@plus, J(:), n*(0:siz(2)-1));
80 S = S(:); S = S(:,ones(1,prod(siz)));
81 B = sparse(I(:), J(:), S(:), siz(1)*m, siz(2)*n, prod(siz)*nnz(A));
0.03 11828 82 else
0.07 11828 83 if (m == 1 && siz(2) == 1)
2.44 4549 84 B = A(ones(siz(1), 1), :);
0.03 7279 85 elseif (n == 1 && siz(1) == 1)
0.28 5557 86 B = A(:, ones(siz(2), 1));
0.02 1722 87 else
0.01 1722 88 mind = (1:m)';
0.02 1722 89 nind = (1:n)';
1722 90 mind = mind(:,ones(1,siz(1)));
0.02 1722 91 nind = nind(:,ones(1,siz(2)));
0.02 1722 92 B = A(mind,nind);
1722 93 end
0.09 11828 94 end
0.01 2279 95 else
0.02 2279 96 Asiz = size(A);
0.07 2279 97 Asiz = [Asiz ones(1,length(siz)-length(Asiz))];
0.05 2279 98 siz = [siz ones(1,length(Asiz)-length(siz))];
0.02 2279 99 subs = cell(1,length(Asiz));
0.05 2279 100 for i=length(Asiz):-1:1
0.12 6837 101 ind = (1:Asiz(i))';
0.11 6837 102 subs{i} = ind(:,ones(1,siz(i)));
0.08 6837 103 end
106.36 2279 104 B = A(subs{:});
0.05 2279 105 end