1function C = hypot (A, B)
2%HYPOT robust computation of the square root of sum of squares.
3% C = hypot (A,B) computes sqrt (abs (A).^2 + abs (B).^2) accurately.
4% If A and B are matrices, the pattern of C is the set union of A and B.
5% If one of A or B is a nonzero scalar, the scalar is expanded into a
6% full matrix the size of the other matrix, and the result is a full
7% matrix.
8%
9% See also GrB/abs, GrB/norm, GrB/sqrt, GrB/plus, GrB.eadd.
10
11% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
12% SPDX-License-Identifier: GPL-3.0-or-later
13
14% FUTURE: hypot(A,B) for two matrices A and B is slower than it could be.
15% See comments in gb_union_op.
16
17if (isobject (A))
18    A = A.opaque ;
19end
20
21if (isobject (B))
22    B = B.opaque ;
23end
24
25atype = gbtype (A) ;
26btype = gbtype (B) ;
27
28if (contains (atype, 'complex'))
29    A = gbapply ('abs', A) ;
30elseif (~gb_isfloat (atype))
31    A = gbnew (A, 'double') ;
32end
33
34if (contains (btype, 'complex'))
35    B = gbapply ('abs', B) ;
36elseif (~gb_isfloat (btype))
37    B = gbnew (B, 'double') ;
38end
39
40C = GrB (gbapply ('abs', gb_eadd (A, 'hypot', B))) ;
41
42