File: GB_positional_offset.c

package info (click to toggle)
suitesparse-graphblas 7.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,112 kB
  • sloc: ansic: 1,072,243; cpp: 8,081; sh: 512; makefile: 506; asm: 369; python: 125; awk: 10
file content (58 lines) | stat: -rw-r--r-- 2,510 bytes parent folder | download | duplicates (3)
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
//------------------------------------------------------------------------------
// GB_positional_offset: return the offset of a positional operator
//------------------------------------------------------------------------------

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

//------------------------------------------------------------------------------

#include "GB.h"

int64_t GB_positional_offset        // return the positional thunk
(
    GB_Opcode opcode,               // opcode of positional operator
    GrB_Scalar Thunk                // thunk for idxunops, or NULL
)
{
    int64_t ithunk = 0 ;
    if (Thunk != NULL)
    {
        // get the value of the thunk, for positional idxunops
        GB_cast_scalar (&ithunk, GB_INT64_code, Thunk->x, Thunk->type->code,
            Thunk->type->size) ;
    }

    switch (opcode)
    {

        // these operators are offset by one
        case GB_POSITIONI1_unop_code : // z = position_i1(A(i,j)) == i+1
        case GB_FIRSTI1_binop_code   : // z = first_i1(A(i,j),y) == i+1
        case GB_SECONDI1_binop_code  : // z = second_i1(x,A(i,j)) == i+1
        case GB_POSITIONJ1_unop_code : // z = position_j1(A(i,j)) == j+1
        case GB_FIRSTJ1_binop_code   : // z = first_j1(A(i,j),y) == j+1
        case GB_SECONDJ1_binop_code  : // z = second_j1(x,A(i,j)) == j+1
            return (1) ;

        // idxunops
        case GB_ROWINDEX_idxunop_code  :   // (i+thunk): row index - thunk
        case GB_COLINDEX_idxunop_code  :   // (j+thunk): col index - thunk
        case GB_DIAGINDEX_idxunop_code :   // (j-(i+thunk)): diag index + thunk
        case GB_FLIPDIAGINDEX_idxunop_code :   // (i-(j+thunk)), internal use
        case GB_TRIL_idxunop_code      :   // (j <= (i+thunk)): tril (A,thunk)
        case GB_TRIU_idxunop_code      :   // (j >= (i+thunk)): triu (A,thunk)
        case GB_DIAG_idxunop_code      :   // (j == (i+thunk)): diag(A,thunk)
        case GB_OFFDIAG_idxunop_code   :   // (j != (i+thunk)): offdiag(A,thunk)
        case GB_COLLE_idxunop_code     :   // (j <= thunk): A (:,0:thunk)
        case GB_COLGT_idxunop_code     :   // (j > thunk): A (:,thunk+1:ncols-1)
        case GB_ROWLE_idxunop_code     :   // (i <= thunk): A (0:thunk,:)
        case GB_ROWGT_idxunop_code     :   // (i > thunk): A (thunk+1:nrows-1,:)
            return (ithunk) ;

        // all other operators have no offset
        default:
            return (0) ;
    }
}