function  y_hat=make_insampleFit_MAIAR(B0,A,gamma,x_bul)


% INPUT :  y is nxT, 
% x_bul is nx mqp xT
% A is nxrp
[n,~,T]=size(x_bul);
r=size(B0,1);
q=length(gamma)/n;
p=size(A,2)/r;

Gammas=zeros(n,n,q);
Gammas(logical(repmat(eye(n),[1,1,q])))=gamma;

if q>p
    x_bul_p=x_bul(:,1:p,:);
    x_bul_q=x_bul;
else
    x_bul_q=x_bul(:,1:q,:);
    x_bul_p=x_bul;
end

y_hat=mtimesx(A,  reshape( mtimesx(B0,x_bul_p),[r*p,T]  )    )+...
               reshape(sum(mtimesx(Gammas, reshape(x_bul_q,[n,1,q,T])  ),3),[n,T])  ;

  


end