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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
//------------------------------------------------------------------------------
// GB_transpose_ix: transpose the values and pattern of a matrix
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
// The values of A are typecasted to C->type, the type of the C matrix.
// If A is sparse or hypersparse
// The pattern of C is constructed. C is sparse.
// Workspaces and A_slice are non-NULL.
// This method is parallel, but not highly scalable. It uses only
// nthreads = nnz(A)/(A->vlen) threads.
// If A is full or as-if-full:
// The pattern of C is not constructed. C is full.
// Workspaces and A_slice are NULL.
// This method is parallel and fully scalable.
// If A is bitmap:
// C->b is constructed. C is bitmap.
// Workspaces and A_slice are NULL.
// This method is parallel and fully scalable.
#include "transpose/GB_transpose.h"
#include "unaryop/GB_unop.h"
#include "jitifyer/GB_stringify.h"
#ifndef GBCOMPACT
#include "FactoryKernels/GB_uop__include.h"
#endif
GrB_Info GB_transpose_ix // transpose the pattern and values of a matrix
(
GrB_Matrix C, // output matrix
const GrB_Matrix A, // input matrix
// for sparse case:
void **Workspaces, // Workspaces, size nworkspaces
const int64_t *restrict A_slice, // how A is sliced, size nthreads+1
int nworkspaces, // # of workspaces to use
// for all cases:
int nthreads // # of threads to use
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
ASSERT (!GB_ZOMBIES (A)) ;
ASSERT (GB_JUMBLED_OK (A)) ;
ASSERT (!GB_PENDING (A)) ;
GrB_Info info = GrB_NO_VALUE ;
GrB_Type ctype = C->type ;
GB_Type_code code1 = ctype->code ; // defines ztype
GB_Type_code code2 = A->type->code ; // defines atype
size_t asize = A->type->size ;
bool Cp_is_32 = C->p_is_32 ;
#define GB_Cp_IS_32 Cp_is_32
//--------------------------------------------------------------------------
// built-in worker: transpose and typecast
//--------------------------------------------------------------------------
if (C->iso)
{
//----------------------------------------------------------------------
// via the iso kernel
//----------------------------------------------------------------------
// A and C are iso: Cx [0] = (ctype) Ax [0]
GB_cast_scalar (C->x, code1, A->x, code2, asize) ;
// C = pattern of A transposed
#define GB_ISO_TRANSPOSE
#include "transpose/template/GB_transpose_template.c"
info = GrB_SUCCESS ;
}
else
{
//----------------------------------------------------------------------
// via the factory kernel
//----------------------------------------------------------------------
#ifndef GBCOMPACT
GB_IF_FACTORY_KERNELS_ENABLED
{
//------------------------------------------------------------------
// define the worker for the switch factory
//------------------------------------------------------------------
#define GB_uop_tran(zname,aname) \
GB (_uop_tran__identity ## zname ## aname)
#define GB_WORKER(ignore1,zname,ztype,aname,atype) \
{ \
info = GB_uop_tran (zname,aname) \
(C, A, Workspaces, A_slice, nworkspaces, nthreads) ; \
} \
break ;
//------------------------------------------------------------------
// launch the switch factory
//------------------------------------------------------------------
#include "apply/factory/GB_twotype_factory.c"
}
#endif
//----------------------------------------------------------------------
// via the JIT or PreJIT kernel
//----------------------------------------------------------------------
if (info == GrB_NO_VALUE)
{
struct GB_UnaryOp_opaque op_header ;
GrB_Type ctype = C->type ;
GB_Operator op = GB_unop_identity (ctype, &op_header) ;
ASSERT_OP_OK (op, "identity op for transpose_ix", GB0) ;
info = GB_transpose_unop_jit (C, op, A, Workspaces,
A_slice, nworkspaces, nthreads) ;
}
//----------------------------------------------------------------------
// via the generic kernel
//----------------------------------------------------------------------
if (info == GrB_NO_VALUE)
{
GB_BURBLE_MATRIX (A, "(generic transpose) ") ;
size_t csize = C->type->size ;
GB_cast_function cast_A_to_X = GB_cast_factory (code1, code2) ;
// Cx [pC] = (ctype) Ax [pA]
#define GB_APPLY_OP(pC,pA) \
cast_A_to_X (Cx +((pC)*csize), Ax +((pA)*asize), asize) ;
#define GB_A_TYPE GB_void
#define GB_C_TYPE GB_void
#include "transpose/template/GB_transpose_template.c"
info = GrB_SUCCESS ;
}
}
return (info) ;
}
|