On Wed, 11 Apr 2012 06:38:12 +0000 (UTC), "Bruno Luong"
<b.luong@fogale.findmycountry> wrote:
>Dick Startz <@> wrote in message <dhd8o71n7hkrvi13j0l4siiuqf0jc0sjro@4ax.com>...
>> On Tue, 10 Apr 2012 07:29:20 +0000 (UTC), "Bruno Luong"
>> <b.luong@fogale.findmycountry> wrote:
>>
>> >Dick Startz <@> wrote in message <4607o7d2jscoen21hf7l227n1lt24d1rrh@4ax.com>...
>> >> I recently asked for some help with vectorization and received very
>> >> helpful answers. Now I have what I thought would only be a very slight
>> >> twist...but I'm not seeing how to do it. Here's the Matlab program.
>> >>
>> >> n = 500;
>> >> q=6;
>> >> k = 2;
>> >> X = randn(k,q,n);
>> >> H = randn(k,k);
>> >> result = zeros(q,q);
>> >>
>> >> for i=1:n
>> >> result = result + squeeze(X(:,:,i))'*H*squeeze(X(:,:,i));
>> >> end
>> >>
>> >> result
>> >>
>> >> Guidance would be much appreciated.
>> >
>> >This is ALMOST like before. If you permute the first and second dimension of X, it will be like before.
>> >
>> >Sum = sum(mtimesx(permute(X, [2 1 3]), reshape(H*reshape(X, k, []), [k q n])),3)
>> >
>> >Bruno
>>
>> Bruno:
>> The (repeated) help is much appreciated. I didn't use your mtimesx
>> solution before because the documentation says mtimesx requires a C
>> compiler and I want to be able to distribute the code without
>> complication. (I don't regard requiring the user to get mtimesx to
>> itself be a complication.)
>>
>> I see that mtimesx has a number of "modes." (By the way, your 2009
>> contribution on the FileExchange was quite helpful.) Do any of the
>> modes eliminate the need for the C compiler? Or if not, is there
>> another way to vectorize?
>
>You can replace mtimesx by pure Matlab code:
>http://www.mathworks.com/matlabcentral/fileexchange/24260
>
>Sum = sum(SliceMultiProd(permute(X, [2 1 3]), reshape(H*reshape(X, k, []), [k q n])),3)
>
>% Bruno
I put SliceMultiProd into my program, replacing a for loop. The speed
of the entire program roughly tripled!
Thanks Bruno!
Dick Startz
