annotate toolboxes/FullBNT-1.0.7/bnt/potentials/Tables/mult_by_table2.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function bigT = mult_by_table2(bigT, bigdom, bigsz, smallT, smalldom, smallsz)
Daniel@0 2 % MULT_BY_TABLE
Daniel@0 3 % bigT = mult_by_table(bigT, bigdom, bigsz, smallT, smalldom, smallsz)
Daniel@0 4 %
Daniel@0 5
Daniel@0 6 %Ts = extend_domain_table(smallT, smalldom, smallsz, bigdom, bigsz);
Daniel@0 7 %bigT(:) = bigT(:) .* Ts(:); % must have bigT(:) on LHS to preserve shape
Daniel@0 8
Daniel@0 9 % extend_domain_table has a lot of overhead for small tables,
Daniel@0 10 % since it calls myreshape and myrepmat, which check for 1 dimensional case.
Daniel@0 11 % Here, we check up front.
Daniel@0 12
Daniel@0 13 if length(bigdom)==1 % vector
Daniel@0 14 bigT = bigT .* smallT; % smallT can be scalar or vector
Daniel@0 15 else
Daniel@0 16 if (length(bigsz) == length(smallsz)) & all(bigsz == smallsz)
Daniel@0 17 bigT = bigT .* smallT;
Daniel@0 18 else
Daniel@0 19 map = find_equiv_posns(smalldom, bigdom);
Daniel@0 20 sz = ones(1, length(bigdom));
Daniel@0 21 sz(map) = smallsz;
Daniel@0 22 smallT = reshape(smallT, sz); % add dimensions of size 1 for missing domain
Daniel@0 23 % we can use reshape instead of myreshape, because we know length(sz)>1
Daniel@0 24 sz = bigsz;
Daniel@0 25 sz(map) = 1; % don't replicate along small domain, which is shared
Daniel@0 26 % we can use repmat instead of myrepmat, because we know length(sz)>1
Daniel@0 27 smallT = repmat(smallT, sz(:)');
Daniel@0 28 bigT(:) = bigT(:) .* smallT(:);
Daniel@0 29 end
Daniel@0 30 end