wolffd@0: function bigT = mult_by_table2(bigT, bigdom, bigsz, smallT, smalldom, smallsz) wolffd@0: % MULT_BY_TABLE wolffd@0: % bigT = mult_by_table(bigT, bigdom, bigsz, smallT, smalldom, smallsz) wolffd@0: % wolffd@0: wolffd@0: %Ts = extend_domain_table(smallT, smalldom, smallsz, bigdom, bigsz); wolffd@0: %bigT(:) = bigT(:) .* Ts(:); % must have bigT(:) on LHS to preserve shape wolffd@0: wolffd@0: % extend_domain_table has a lot of overhead for small tables, wolffd@0: % since it calls myreshape and myrepmat, which check for 1 dimensional case. wolffd@0: % Here, we check up front. wolffd@0: wolffd@0: if length(bigdom)==1 % vector wolffd@0: bigT = bigT .* smallT; % smallT can be scalar or vector wolffd@0: else wolffd@0: if (length(bigsz) == length(smallsz)) & all(bigsz == smallsz) wolffd@0: bigT = bigT .* smallT; wolffd@0: else wolffd@0: map = find_equiv_posns(smalldom, bigdom); wolffd@0: sz = ones(1, length(bigdom)); wolffd@0: sz(map) = smallsz; wolffd@0: smallT = reshape(smallT, sz); % add dimensions of size 1 for missing domain wolffd@0: % we can use reshape instead of myreshape, because we know length(sz)>1 wolffd@0: sz = bigsz; wolffd@0: sz(map) = 1; % don't replicate along small domain, which is shared wolffd@0: % we can use repmat instead of myrepmat, because we know length(sz)>1 wolffd@0: smallT = repmat(smallT, sz(:)'); wolffd@0: bigT(:) = bigT(:) .* smallT(:); wolffd@0: end wolffd@0: end