File: GB_transpose_in_place.c

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (75 lines) | stat: -rw-r--r-- 2,789 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
65
66
67
68
69
70
71
72
73
74
75
//------------------------------------------------------------------------------
// GB_transpose_in_place: in-place transpose (to change A->is_csc format)
//------------------------------------------------------------------------------

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

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

// All other uses of GB_transpose are not in-place.
// No operator is applied and no typecasting is done.
// Does nothing if A is already in the requested format.

#include "transpose/GB_transpose.h"
#define GB_FREE_ALL ;

GrB_Info GB_transpose_in_place  // A=A', to change A->is_csc
(
    GrB_Matrix A,           // input/output matrix
    const bool new_csc,     // desired format, by row (false) or by col (true)
    GB_Werk Werk
)
{

    //--------------------------------------------------------------------------
    // conform the matrix to the new by-row/by-col format
    //--------------------------------------------------------------------------

    if (A->is_csc != new_csc)
    { 

        //----------------------------------------------------------------------
        // check inputs
        //----------------------------------------------------------------------

        GrB_Info info ;
        ASSERT_MATRIX_OK (A, "A for new csc format", GB0) ;
        ASSERT (GB_PENDING_OK (A)) ;
        ASSERT (GB_ZOMBIES_OK (A)) ;
        ASSERT (GB_JUMBLED_OK (A)) ;
        GB_BURBLE_N (GB_nnz (A), "(transpose to set orientation) ") ;

        //----------------------------------------------------------------------
        // swap A->[ji]_control
        //----------------------------------------------------------------------

        int8_t j_control = A->j_control ;
        A->j_control = A->i_control ;
        A->i_control = j_control ;

        //----------------------------------------------------------------------
        // in-place A = A', with the new csc setting
        //----------------------------------------------------------------------

        GB_OK (GB_transpose (A,
            /* no change of type: */ NULL,
            /* new requested format: */ new_csc,
            /* in-place transpose: */ A,
            /* no operator: */ NULL, NULL, false, false,
            Werk)) ;

        ASSERT_MATRIX_OK (A, "A with new csc format", GB0) ;
        ASSERT (A->is_csc == new_csc) ;
        ASSERT (!GB_PENDING (A)) ;
        ASSERT (!GB_ZOMBIES (A)) ;
        ASSERT (GB_JUMBLED_OK (A)) ;
    }

    //--------------------------------------------------------------------------
    // return result
    //--------------------------------------------------------------------------

    return (GrB_SUCCESS) ;
}