function y = gampdf(x,a,b)
%GAMPDF Gamma probability density function optimized for GPU.
%   Y = GAMPDF(X,A,B)
%
%   See also GAMPDF, GPUARRAY.


%   Keep this code in sync with toolbox/stats/stats/gampdf.

%   Copyright 2019 The MathWorks, Inc.


if nargin < 2
    error(message('stats:gampdf:TooFewInputs'));
elseif nargin < 3
    b = 1;
end

[errorcode, x, a, b] = distchck(3,x,a,b);

if errorcode > 0
    error(message('stats:gampdf:InputSizeMismatch'));
end

% The algorithm now works independently on each element, so call via
% arrayfun which will convert the entire algorithm into a single GPU kernel.
outProto = zeros(1,"like",internal.stats.dominantType(x,a,b));
y = arrayfun( @gampdf_scalar, x, a, b, outProto );

end

