% AIM test nd.f

clear;
clc;
%%
s = RandStream('mrg32k3a');
RandStream.setGlobalStream(s);
savedState = s.State;

A(:,:,1) = [1 2; 3 4];
A(:,:,2) = eye(2);
B(:,:,1) = [5 6; 7 8];
B(:,:,2) = eye(2)*2; 
% E = A(:,:,1) ;
% F = B(:,:,1);
numPages = 100;
s = 26;
A = randn(s,s,numPages);
B = randn(s,1,numPages);
%%
tic
C1 = ndfun('mult', A, B);
t1 = toc;
tic
[C1] = ndmm2(A,B);

t2 = toc;
%%
tic
for ii = 1:size(A,3)
   C2(:,:,ii)  = A(:,:,ii) * B(:,:,ii)  ;
end
t3 = toc;
format short
disp([1 t2/t1 t3/t1] );
format short
disp(sum(sum(sum(C1 - C2))))
%%
% C =0;
% C =  nd3(E,F);
% C =  nd3(A,B);
% n = 100000;
%  tic
% for ii = 1:n
% C = nd5(A);
% end 
% toc
% tic
% for ii = 1:n
% C = nd4(E,F);
% end 
% toc
% tic
% for ii = 1:n
% C = A.*B.^2 .*B;
% D = C .* A;
% end
% toc

% x = revord('ccd')

% C = mxsetdimensionsf(A,2,4);
% C = nd(A,B);
% disp([E, F]);
% disp(C)