1 //------------------------------------------------------------------------------
2 // gb_by_col: ensure a matrix is stored by column
3 //------------------------------------------------------------------------------
4
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: GPL-3.0-or-later
7
8 //------------------------------------------------------------------------------
9
10 // The return value A is set to either the input matrix A_input, or the A_copy
11 // matrix.
12
13 #include "gb_matlab.h"
14
gb_by_col(GrB_Matrix * A_copy_handle,GrB_Matrix A_input)15 GrB_Matrix gb_by_col // return the matrix by column
16 (
17 GrB_Matrix *A_copy_handle, // copy made of A, stored by column, or NULL
18 GrB_Matrix A_input // input matrix, by row or column
19 )
20 {
21
22 // get the format of A_input
23 GxB_Format_Value fmt ;
24 OK (GxB_Matrix_Option_get (A_input, GxB_FORMAT, &fmt)) ;
25
26 GrB_Matrix A_copy = NULL, A ;
27
28 if (fmt == GxB_BY_ROW)
29 {
30 // make a deep copy of A_input and change it to be stored by column
31 OK (GrB_Matrix_dup (&A_copy, A_input)) ;
32 OK1 (A_copy, GxB_Matrix_Option_set (A_copy, GxB_FORMAT, GxB_BY_COL)) ;
33 OK1 (A_copy, GrB_Matrix_wait (&A_copy)) ;
34 A = A_copy ;
35 }
36 else
37 {
38 // A is just A_input, with no change
39 A = A_input ;
40 }
41
42 // return results
43 (*A_copy_handle) = A_copy ;
44 return (A) ;
45 }
46
47