1 //------------------------------------------------------------------------------
2 // GB_transpose_ix: transpose the values and pattern of a matrix
3 //------------------------------------------------------------------------------
4 
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7 
8 //------------------------------------------------------------------------------
9 
10 // The values of A are typecasted to C->type, the type of the C matrix.
11 
12 // If A is sparse or hypersparse
13 //      The pattern of C is constructed.  C is sparse.
14 //      Workspaces and A_slice are non-NULL.
15 //      This method is parallel, but not highly scalable.  It uses only
16 //      nthreads = nnz(A)/(A->vlen) threads.
17 
18 // If A is full or packed:
19 //      The pattern of C is not constructed.  C is full.
20 //      Workspaces and A_slice are NULL.
21 //      This method is parallel and fully scalable.
22 
23 // If A is bitmap:
24 //      C->b is constructed.  C is bitmap.
25 //      Workspaces and A_slice are NULL.
26 //      This method is parallel and fully scalable.
27 
28 #include "GB_transpose.h"
29 #ifndef GBCOMPACT
30 #include "GB_unop__include.h"
31 #endif
32 
GB_transpose_ix(GrB_Matrix C,const GrB_Matrix A,int64_t * restrict * Workspaces,const int64_t * restrict A_slice,int nworkspaces,int nthreads)33 void GB_transpose_ix            // transpose the pattern and values of a matrix
34 (
35     GrB_Matrix C,                       // output matrix
36     const GrB_Matrix A,                 // input matrix
37     // for sparse case:
38     int64_t *restrict *Workspaces,   // Workspaces, size nworkspaces
39     const int64_t *restrict A_slice, // how A is sliced, size nthreads+1
40     int nworkspaces,                    // # of workspaces to use
41     // for all cases:
42     int nthreads                        // # of threads to use
43 )
44 {
45 
46     //--------------------------------------------------------------------------
47     // check inputs
48     //--------------------------------------------------------------------------
49 
50     ASSERT (!GB_ZOMBIES (A)) ;
51     ASSERT (GB_JUMBLED_OK (A)) ;
52     ASSERT (!GB_PENDING (A)) ;
53 
54     GrB_Info info ;
55     GrB_Type ctype = C->type ;
56     GB_Type_code code1 = ctype->code ;          // defines ztype
57     GB_Type_code code2 = A->type->code ;        // defines atype
58 
59     //--------------------------------------------------------------------------
60     // built-in worker: transpose and typecast
61     //--------------------------------------------------------------------------
62 
63     #ifndef GBCOMPACT
64 
65         //----------------------------------------------------------------------
66         // define the worker for the switch factory
67         //----------------------------------------------------------------------
68 
69         #define GB_unop_tran(zname,aname)                               \
70             GB (_unop_tran__identity ## zname ## aname)
71 
72         #define GB_WORKER(ignore1,zname,ztype,aname,atype)              \
73         {                                                               \
74             info = GB_unop_tran (zname,aname)                           \
75                 (C, A, Workspaces, A_slice, nworkspaces, nthreads) ;    \
76             if (info == GrB_SUCCESS) return ;                           \
77         }                                                               \
78         break ;
79 
80         //----------------------------------------------------------------------
81         // launch the switch factory
82         //----------------------------------------------------------------------
83 
84         #include "GB_2type_factory.c"
85 
86     #endif
87 
88     //--------------------------------------------------------------------------
89     // generic worker: transpose and typecast
90     //--------------------------------------------------------------------------
91 
92     GB_BURBLE_MATRIX (A, "(generic transpose) ") ;
93 
94     size_t asize = A->type->size ;
95     size_t csize = C->type->size ;
96     GB_cast_function cast_A_to_X = GB_cast_factory (code1, code2) ;
97 
98     // Cx [pC] = (ctype) Ax [pA]
99     #define GB_CAST_OP(pC,pA)  \
100         cast_A_to_X (Cx +((pC)*csize), Ax +((pA)*asize), asize) ;
101 
102     #define GB_ATYPE GB_void
103     #define GB_CTYPE GB_void
104 
105     #include "GB_unop_transpose.c"
106 }
107 
108