function TestP3
% Benchmarking test script and WinogradCVL
clc
randn('seed',0);
A = randn(100,50); B = randn(50,100);
fprintf('ErrorEvenCase = %10.3e\n',norm(A*B-Winograd(A,B)))
A = randn(100,51); B = randn(51,100);
fprintf('ErrorOddCase  = %10.3e\n',norm(A*B-Winograd(A,B)))
A = randn(500,400); B = rand(400,300);
tic 
C = Winograd(A,B);
tYOU = toc;
tic 
C = WinogradCVL(A,B);
tCVL = toc;
fprintf('tYOU/tCVL = %6.3f\n',tYOU/tCVL)

 

function C = WinogradCVL(A,B)
% A is m-by-r, B is r-by-n, and C = A*B
[m,r] = size(A); 
[r,n] = size(B);  

% Zero padding to ensure that r is even...
if rem(r,2)==1
    r = r+1;
    A = [A zeros(m,1)];
    B = [B;zeros(1,n)];
end

% Compute the f-values for each row of A and each column of B...
Aodd = A(:,1:2:r); Aeven = A(:,2:2:r); fA = (Aodd.*Aeven)*ones(r/2,1);
Bodd = B(1:2:r,:); Beven = B(2:2:r,:); fB = ones(1,r/2)*(Bodd.*Beven);

C = zeros(m,n);
% Column orientation helps in accessing the A-data...
Aodd = Aodd'; Aeven = Aeven';

for j=1:n
    % Compute the j-th column of C
    v = Beven(:,j); w = Bodd(:,j);
    for i=1:m
        C(i,j) = (Aodd(:,i)+v)'*(Aeven(:,i)+w) - fA(i) - fB(j);
    end
end
 
%Grading:
% full credit if within tYou/tCVL <= 10
% -1 if 10 < tYou/tCVL < 20
% -2 if 20 < tYou/tCVL  (usually mans no vectorization
% -1 or -2 for incorrectness of C

