function [throughput,latency] = systolicQRBlockTiming(A,B)
%SYSTOLICQRBLOCKTIMING compute the throughput and latency of Systolic QR
%Decomposition block.
    %   This computation is based on the datatype, complexity, and
    %   dimension of sample matrices A and B.
    %   Throughput is the clock cycles between adjacent ready signals.
    %   Latency is the clock cycles between the input and corresponding output.
    %   Example:
    %   A = fi(complex(randn(4,4),randn(4,4)),1,17,10)
    %   B = fi(complex(randn(4,1),randn(4,1)),1,17,10)
    %   [throughput,latency] = embblk.latency.systolicQRBlockTiming(A,B)
    
    %   Copyright 2023 The MathWorks, Inc.
    if ~isequal(size(A,1),size(B,1))
        error(message('fixed:emblib:SameNumberOfRows','A','B'));
    end
    
    m = size(A,1);
    n = size(A,2);
    
    % If any input is complex, assume both A and B are complex
    input = [A B];

    [UA,~] = fixed.internal.type.upcastWordlength(input(1),input(2));
    if isreal(UA)
        complexity = 'real';
    else
        complexity = 'complex';
    end
    if isfi(UA) && (isfixed(UA) || isscaleddouble(UA))
        wl = UA.WordLength;
    else
        switch class(UA)
            case 'double'
                wl = 53;
            case 'single'
                wl = 24;
            otherwise
                error(message('fixed:fi:invalidDataType', class(A),'A and B',mfilename));
        end
    end
        throughput = wl + 3;
        pairs = fixed.emblib.internal.qr.systolicQRPattern(m,n,complexity);
        nStages = numel(pairs);
        latency = (wl+2)*nStages;
end
