wolffd@0
|
1 function bigT = mult_by_table2(bigT, bigdom, bigsz, smallT, smalldom, smallsz)
|
wolffd@0
|
2 % MULT_BY_TABLE
|
wolffd@0
|
3 % bigT = mult_by_table(bigT, bigdom, bigsz, smallT, smalldom, smallsz)
|
wolffd@0
|
4 %
|
wolffd@0
|
5
|
wolffd@0
|
6 %Ts = extend_domain_table(smallT, smalldom, smallsz, bigdom, bigsz);
|
wolffd@0
|
7 %bigT(:) = bigT(:) .* Ts(:); % must have bigT(:) on LHS to preserve shape
|
wolffd@0
|
8
|
wolffd@0
|
9 % extend_domain_table has a lot of overhead for small tables,
|
wolffd@0
|
10 % since it calls myreshape and myrepmat, which check for 1 dimensional case.
|
wolffd@0
|
11 % Here, we check up front.
|
wolffd@0
|
12
|
wolffd@0
|
13 if length(bigdom)==1 % vector
|
wolffd@0
|
14 bigT = bigT .* smallT; % smallT can be scalar or vector
|
wolffd@0
|
15 else
|
wolffd@0
|
16 if (length(bigsz) == length(smallsz)) & all(bigsz == smallsz)
|
wolffd@0
|
17 bigT = bigT .* smallT;
|
wolffd@0
|
18 else
|
wolffd@0
|
19 map = find_equiv_posns(smalldom, bigdom);
|
wolffd@0
|
20 sz = ones(1, length(bigdom));
|
wolffd@0
|
21 sz(map) = smallsz;
|
wolffd@0
|
22 smallT = reshape(smallT, sz); % add dimensions of size 1 for missing domain
|
wolffd@0
|
23 % we can use reshape instead of myreshape, because we know length(sz)>1
|
wolffd@0
|
24 sz = bigsz;
|
wolffd@0
|
25 sz(map) = 1; % don't replicate along small domain, which is shared
|
wolffd@0
|
26 % we can use repmat instead of myrepmat, because we know length(sz)>1
|
wolffd@0
|
27 smallT = repmat(smallT, sz(:)');
|
wolffd@0
|
28 bigT(:) = bigT(:) .* smallT(:);
|
wolffd@0
|
29 end
|
wolffd@0
|
30 end
|