function y = hygepdf(x,m,k,n)
%HYGEPDF Hypergeometric probability density function optimized for GPU.
%   Y = HYGEPDF(X,M,K,N)
%
%   See also HYGECDF, HYGEINV, HYGERND, HYGESTAT, PDF.

%   See toolbox/stats/stats/hygepdf for implementation details.

%   Copyright 2019 The MathWorks, Inc.


if nargin < 4
    error(message('stats:hygepdf:TooFewInputs'));
end

[errorcode, x, m, k, n] = distchck(4,x,m,k,n);

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

% Make sure all parameters are floating point
if ~isfloat(x)
    x = double(x);
end
if ~isfloat(m)
    m = double(m);
end
if ~isfloat(k)
    k = double(k);
end
if ~isfloat(n)
    n = double(n);
end

% Process each element independently using arrayfun. This causes the
% function to be compiled into an optimised GPU kernel.
outProto = zeros(1,"like",internal.stats.dominantType(x,m,k,n));
y = arrayfun( @hygepdf_scalar, x, m, k, n, outProto );
