File: gb_trig.m

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 503; asm: 369; python: 125; awk: 10
file content (64 lines) | stat: -rw-r--r-- 1,983 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function C = gb_trig (op, G)
%GB_TRIG inverse sine, cosine, log, sqrt, ... etc
% Implements C = asin (G), C = acos (G), C = atanh (G), ... etc

% SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
% SPDX-License-Identifier: Apache-2.0

type = gbtype (G) ;

if (~gb_contains (type, 'complex'))

    % determine if any entries are outside the domain for the real case
    noutside = 0 ;  % default if no switch cases apply
    switch (op)

        case { 'asin', 'acos', 'atanh' }

            % C is complex if any (abs (G) > 1)
            switch (type)
                case { 'int8', 'int16', 'int32', 'int64', 'single', 'double' }
                    noutside = gbnvals (gbselect (gbapply ('abs', G), '>', 1)) ;
                case { 'uint8', 'uint16', 'uint32', 'uint64' }
                    noutside = gbnvals (gbselect (G, '>', 1)) ;
            end

        case { 'log', 'log10', 'sqrt', 'log2' }

            % C is complex if any (G < 0)
            switch (type)
                case { 'int8', 'int16', 'int32', 'int64', 'single', 'double' }
                    noutside = gbnvals (gbselect (G, '<', 0)) ;
            end

        case { 'log1p' }

            % C is complex if any (G < -1)
            switch (type)
                case { 'int8', 'int16', 'int32', 'int64', 'single', 'double' }
                    noutside = gbnvals (gbselect (G, '<', -1)) ;
            end

        case { 'acosh' }

            % C is complex if any (G < 1)
            noutside = gbnvals (gbselect (G, '<', 1)) ;
    end

    if (noutside > 0)
        % G is real but C is complex
        if (isequal (type, 'single'))
            op = [op '.single complex'] ;
        else
            op = [op '.double complex'] ;
        end
    elseif (~gb_isfloat (type))
        % G is integer or logical; use the op.double operator
        op = [op '.double'] ;
    end
end

% if G is already complex, gbapply will select a complex operator

C = gbapply (op, G) ;