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