@@ -20,7 +20,8 @@ static inline bsp_matrix_t bsp_convert_matrix(bsp_matrix_t matrix,
2020 // *Convert to COO* from another format.
2121 if (matrix .format == BSP_CSR ) {
2222 // Convert CSR -> COOR
23- bsp_matrix_t result = bsp_construct_default_matrix_t ();
23+ bsp_matrix_t result ;
24+ bsp_construct_default_matrix_t (& result );
2425
2526 result .format = BSP_COOR ;
2627
@@ -40,7 +41,9 @@ static inline bsp_matrix_t bsp_convert_matrix(bsp_matrix_t matrix,
4041 bsp_error_t error =
4142 bsp_copy_construct_array_t (& result .values , matrix .values );
4243 if (error != BSP_SUCCESS ) {
43- return bsp_construct_default_matrix_t ();
44+ bsp_matrix_t empty_result ;
45+ bsp_construct_default_matrix_t (& empty_result );
46+ return empty_result ;
4447 }
4548
4649 // There is a corner case with tall and skinny matrices where we need a
@@ -51,14 +54,18 @@ static inline bsp_matrix_t bsp_convert_matrix(bsp_matrix_t matrix,
5154 error = bsp_copy_construct_array_t (& result .indices_1 , matrix .indices_1 );
5255 if (error != BSP_SUCCESS ) {
5356 bsp_destroy_array_t (& result .values );
54- return bsp_construct_default_matrix_t ();
57+ bsp_matrix_t empty_result ;
58+ bsp_construct_default_matrix_t (& empty_result );
59+ return empty_result ;
5560 }
5661 } else {
5762 error = bsp_construct_array_t (& result .indices_1 , matrix .indices_1 .size ,
5863 index_type );
5964 if (error != BSP_SUCCESS ) {
6065 bsp_destroy_array_t (& result .values );
61- return bsp_construct_default_matrix_t ();
66+ bsp_matrix_t empty_result ;
67+ bsp_construct_default_matrix_t (& empty_result );
68+ return empty_result ;
6269 }
6370
6471 for (size_t i = 0 ; i < matrix .indices_1 .size ; i ++ ) {
@@ -72,7 +79,9 @@ static inline bsp_matrix_t bsp_convert_matrix(bsp_matrix_t matrix,
7279 if (error != BSP_SUCCESS ) {
7380 bsp_destroy_array_t (& result .values );
7481 bsp_destroy_array_t (& result .indices_1 );
75- return bsp_construct_default_matrix_t ();
82+ bsp_matrix_t empty_result ;
83+ bsp_construct_default_matrix_t (& empty_result );
84+ return empty_result ;
7685 }
7786
7887 for (size_t i = 0 ; i < matrix .nrows ; i ++ ) {
@@ -95,13 +104,14 @@ static inline bsp_matrix_t bsp_convert_matrix(bsp_matrix_t matrix,
95104 if (matrix .format != BSP_COOR ) {
96105 bsp_matrix_t intermediate = bsp_convert_matrix (matrix , BSP_COOR );
97106 bsp_matrix_t result = bsp_convert_matrix (intermediate , format );
98- bsp_destroy_matrix_t (intermediate );
107+ bsp_destroy_matrix_t (& intermediate );
99108 return result ;
100109 } else {
101110 if (format == BSP_CSR ) {
102111 // Convert COOR -> CSR
103112
104- bsp_matrix_t result = bsp_construct_default_matrix_t ();
113+ bsp_matrix_t result ;
114+ bsp_construct_default_matrix_t (& result );
105115
106116 result .format = BSP_CSR ;
107117
@@ -130,22 +140,28 @@ static inline bsp_matrix_t bsp_convert_matrix(bsp_matrix_t matrix,
130140 bsp_error_t error =
131141 bsp_copy_construct_array_t (& result .values , matrix .values );
132142 if (error != BSP_SUCCESS ) {
133- return bsp_construct_default_matrix_t ();
143+ bsp_matrix_t empty_result ;
144+ bsp_construct_default_matrix_t (& empty_result );
145+ return empty_result ;
134146 }
135147
136148 if (index_type == matrix .indices_1 .type ) {
137149 error =
138150 bsp_copy_construct_array_t (& result .indices_1 , matrix .indices_1 );
139151 if (error != BSP_SUCCESS ) {
140152 bsp_destroy_array_t (& result .values );
141- return bsp_construct_default_matrix_t ();
153+ bsp_matrix_t empty_result ;
154+ bsp_construct_default_matrix_t (& empty_result );
155+ return empty_result ;
142156 }
143157 } else {
144158 error =
145159 bsp_construct_array_t (& result .indices_1 , matrix .nnz , index_type );
146160 if (error != BSP_SUCCESS ) {
147161 bsp_destroy_array_t (& result .values );
148- return bsp_construct_default_matrix_t ();
162+ bsp_matrix_t empty_result ;
163+ bsp_construct_default_matrix_t (& empty_result );
164+ return empty_result ;
149165 }
150166
151167 for (size_t i = 0 ; i < matrix .nnz ; i ++ ) {
@@ -160,7 +176,9 @@ static inline bsp_matrix_t bsp_convert_matrix(bsp_matrix_t matrix,
160176 if (error != BSP_SUCCESS ) {
161177 bsp_destroy_array_t (& result .values );
162178 bsp_destroy_array_t (& result .indices_1 );
163- return bsp_construct_default_matrix_t ();
179+ bsp_matrix_t empty_result ;
180+ bsp_construct_default_matrix_t (& empty_result );
181+ return empty_result ;
164182 }
165183
166184 bsp_array_t rowptr = result .pointers_to_1 ;
0 commit comments