function y = unifpdf(x,a,b)
%UNIFPDF Uniform (continuous) probability density function optimized for GPU.
%   Y = UNIFPDF(X,A,B)
%
%   See also UNIFPDF, GPUARRAY.

%   Copyright 2019 The MathWorks, Inc. 

% Keep in-sync with toolbox/stats/stats/unifpdf

if nargin < 1
    error(message('stats:unifpdf:TooFewInputs')); 
end

if nargin == 1
    a = 0;
    b = 1;
end

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

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

% Process each element using arrayfun so that it gets compiled into a single GPU kernel
outProto = zeros(1,"like",internal.stats.dominantType(x,a,b));
y = arrayfun(@unifpdf_scalar, x, a, b, outProto);
end
