1function C = min (A, B, option)
2%MIN Maximum elements of a matrix.
3% C = min (A) is the smallest entry in the vector A.  If A is a matrix,
4% C is a row vector with C(j) = min (A (:,j)).
5%
6% C = min (A,B) is an array of the element-wise minimum of two matrices
7% A and B, which either have the same size, or one can be a scalar.
8%
9% C = min (A, [ ], 'all') is a scalar, with the smallest entry in A.
10% C = min (A, [ ], 1) is a row vector with C(j) = min (A (:,j))
11% C = min (A, [ ], 2) is a column vector with C(i) = min (A (i,:))
12%
13% The 2nd output of [C,I] = min (...) in the MATLAB built-in min
14% is not yet supported.  The min (..., nanflag) option is
15% not yet supported; only the 'omitnan' behavior is supported.
16%
17% Complex matrices are not supported.
18%
19% See also GrB/max.
20
21% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
22% SPDX-License-Identifier: GPL-3.0-or-later
23
24% FUTURE: min(A,B) for two matrices A and B is slower than it could be.
25% See comments in gb_union_op.
26
27if (isobject (A))
28    A = A.opaque ;
29end
30
31type = gbtype (A) ;
32if (contains (type, 'complex'))
33    error ('complex matrices not yet supported') ;
34elseif (isequal (type, 'logical'))
35    op = '&.logical' ;
36else
37    op = 'min' ;
38end
39
40if (nargin == 1)
41    % C = min (A)
42    C = GrB (gb_min1 (op, A)) ;
43elseif (nargin == 2)
44    % C = min (A,B)
45    if (isobject (B))
46        B = B.opaque ;
47    end
48    C = GrB (gb_min2 (op, A, B)) ;
49else
50    % C = min (A, [ ], option)
51    if (~isempty (B))
52        error ('dimension argument not allowed with 2 input matrices') ;
53    end
54    C = GrB (gb_min3 (op, A, option)) ;
55end
56
57