From: Matt J on 5 Aug 2010 16:52 But mightn't one be better off not summing the Kronecker products? What if instead, you evaluate y=A*x by first applying all the Kronecker products to x and then sum the result? I created the following FEX tools to allow this kind of thing to be done in an object-oriented way. http://www.mathworks.com/matlabcentral/fileexchange/25969-efficient-object-oriented-kronecker-product-manipulation http://www.mathworks.com/matlabcentral/fileexchange/26611-on-the-fly-definition-of-custom-matrix-objects which I use in the following short test, with L=2. As shown, the memory saving is considerable. I also get considerable speed-up, although that could depend generally on L and how many operations y=A*x you're going to perform... %data n=50; K1=rand(n); K2=rand(n); x=rand(n^2,1); %Numeric representation of A tic; A=kron(conj(K1),K1) + kron(conj(K2),K2); y1=A*x; toc %Elapsed time is 0.388593 seconds. tic; %Object-oriented representation of A (as Aobj); Kobj1=KronProd({conj(K1),K1},[1,2]); Kobj2=KronProd({conj(K2),K2},[1,2]); Aobj=MatrixObj; Aobj.Ops.mtimes=@(A,x) Kobj1*x + Kobj2*x; y2=Aobj*x; toc%Elapsed time is 0.147291 seconds. Error=max(abs(y1-y2))./max(abs(y1)) %3.7477e-015 whos A Aobj %{ Name Size Bytes Class Attributes A 2500x2500 50000000 double Aobj 1x1 8458 MatrixObj %}
First
|
Prev
|
Pages: 1 2 Prev: Really need help to speed up piece of code Next: Really need help to speed up piece of code |