This is a static copy of a profile reportHome
tformarray>GetBlocking (1721 calls, 0.120 sec)
Generated 05-Nov-2014 07:53:15 using cpu time.
subfunction in file /usr1/opt/matlab/7.13/toolbox/images/images/tformarray.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Function Name | Function Type | Calls |
tformarray | function | 1721 |
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
422 | B = ones(1,L); | 1721 | 0.020 s | 16.7% |  |
374 | Nt = 20; % Defines target blo... | 1721 | 0.020 s | 16.7% |  |
436 | if any(D < 2^Nm) | 1721 | 0.010 s | 8.3% |  |
426 | for i = 1:N | 1721 | 0.010 s | 8.3% |  |
424 | blockingfactors = zeros(size(t... | 1721 | 0.010 s | 8.3% |  |
All other lines | | | 0.050 s | 41.7% |  |
Totals | | | 0.120 s | 100% | |
Children (called functions)
No childrenCode Analyzer results
No Code Analyzer messages.Coverage results
[ Show coverage for parent directory ]
Total lines in function | 92 |
Non-code lines (comments, blank lines) | 73 |
Code lines (lines that can run) | 19 |
Code lines that did run | 12 |
Code lines that did not run | 7 |
Coverage (did run/can run) | 63.16 % |
Function listing
time calls line
347 function blockingfactors = GetBlocking( tsize, P )
348
349 % With large input arrays, the memory used by the grid and/or map
350 % (G and M) in the main function can be substantial and may exceed
351 % the memory used by the input and output images -- depending on the
352 % number of input transform dimensions, the number of non-transform
353 % dimensions, and the storage class of the input and output arrays.
354 % So the main function may compute the map block-by-block, resample
355 % the input for just that block, and assign the result to a pre-allocated
356 % output array. We define the blocks by slicing the output transform space
357 % along lines, planes, or hyperplanes normal to each of the subscript
358 % axes. We call the number of regions created by the slicing along a
359 % given axis the 'blocking factor' for that dimension. (If no slices
360 % are made, the blocking factor is 1. If all the blocking factors are
361 % 1 (which can be tested by checking if prod(blockingfactors) == 1),
362 % then the output array is small enough to process as a single block.)
363 % The blockingfactors array created by this function has the same
364 % size as TSIZE, and its dimensions are ordered as in TSIZE.
365 %
366 % This particular implementation has the following properties:
367 % - All blocking factors are powers of 2
368 % - After excluding very narrow dimensions, it slices across the
369 % remaining dimensions to defined blocks whose dimensions tend
370 % toward equality. (Of course, for large aspect ratios and relatively
371 % few blocks, the result may not actually get very close to equality.)
372
373 % Control parameters
0.02 1721 374 Nt = 20; % Defines target block size
1721 375 Nm = 2; % Defines cut-off to avoid blocking on narrow dimensions
376 % The largest block will be on the order of 2^Nt doubles (but may be
377 % somewhat larger). Any dimensions with size less than 2^Nm (= 4)
378 % will have blocking factors of 1. They are tagged by zeros in the
379 % qDivisible array below.
380
381 % Separate the dimensions that are too narrow to divide into blocks.
0.01 1721 382 qDivisible = tsize > 2^(Nm+1);
0.01 1721 383 L = sum(qDivisible);
384
385 % The number of blocks will be 2^N. As a goal, each block will
386 % contain on the order of 2^Nt values, but larger blocks may be
387 % needed to avoid subdividing narrow dimensions too finely.
388 %
389 % If all dimensions are large, then we'd like something like
390 %
391 % (1) N = floor(log2(prod(tsize)/(2^Nt/P)));
392 %
393 % That's because we'd like prod(size(M)) / 2^N to be on the order of 2^Nt,
394 % and prod(size(M)) = prod(tsize) * P. The following slightly more complex
395 % formula is equivalent to (1), but divides out the non-divisible dimensions
396 %
397 % (2) N = floor(log2(prod(tsize(qDivisible)) / ...
398 % (2^Nt/(P*prod(tsize(~qDivisible))))));
399 %
400 % However, it is possible that we might not be able to block an image as
401 % finely as we'd like if its size is due to having many small dimensions
402 % rather than a few large ones. That's why the actual formula for N in
403 % the next line of code replaces the numerator in (2) with 2^((Nm+1)*L)
404 % if this quantity is larger. In such a case, we'd have
405 %
406 % (3) N = floor(log2(prod(tsize(qDivisible)) / 2^((Nm+1)*L)));
407 %
408 % and would have to make do with fewer blocks in order to ensure a minimum
409 % block size greater than or equal to 2^Nm. The fact that our block sizes
410 % always satisfy this constraint is proved in the comments at the end of
411 % this function.
412
1721 413 N = floor(log2(prod(tsize(qDivisible)) / ...
414 max( (2^Nt)/(P*prod(tsize(~qDivisible))), 2^((Nm+1)*L) )));
415
416 % Initialize the blocking factor for the each divisible dimensions
417 % as unity. Iterate N times, each time multiplying one of the
418 % blocking factors by 2. The choice of which to multiply is driven
419 % by the goal of making the final set of average divisible block
420 % dimensions (stored in D at the end of the iteration) as uniform
421 % as possible.
0.02 1721 422 B = ones(1,L);
1721 423 D = tsize(qDivisible);
0.01 1721 424 blockingfactors = zeros(size(tsize));
425
0.01 1721 426 for i = 1:N
427 k = find(D == max(D));
428 k = k(1); % Take the first if there is more than one maximum
429 B(k) = B(k) * 2;
430 D(k) = D(k) / 2;
431 end
1721 432 blockingfactors( qDivisible) = B;
1721 433 blockingfactors(~qDivisible) = 1;
434
435 % Assertion: After the loop is complete, all(D >= 2^Nm).
0.01 1721 436 if any(D < 2^Nm)
437 error(message('images:tformarray:blockDimsTooSmall'));
438 end
Other subfunctions in this file are not included in this listing.