@@ -37,25 +37,43 @@ static inline bsp_matrix_t bsp_convert_matrix(bsp_matrix_t matrix,
37
37
38
38
bsp_type_t index_type = bsp_pick_integer_type (max_dim );
39
39
40
- result .values = bsp_copy_construct_array_t (matrix .values );
40
+ bsp_error_t error =
41
+ bsp_copy_construct_array_t (& result .values , matrix .values );
42
+ if (error != BSP_SUCCESS ) {
43
+ return bsp_construct_default_matrix_t ();
44
+ }
41
45
42
46
// There is a corner case with tall and skinny matrices where we need a
43
47
// higher width for rowind. In order to keep rowind/colind the same type,
44
48
// we might upcast.
45
49
46
50
if (index_type == matrix .indices_1 .type ) {
47
- result .indices_1 = bsp_copy_construct_array_t (matrix .indices_1 );
51
+ error = bsp_copy_construct_array_t (& result .indices_1 , matrix .indices_1 );
52
+ if (error != BSP_SUCCESS ) {
53
+ bsp_destroy_array_t (& result .values );
54
+ return bsp_construct_default_matrix_t ();
55
+ }
48
56
} else {
49
- result .indices_1 =
50
- bsp_construct_array_t (matrix .indices_1 .size , index_type );
57
+ error = bsp_construct_array_t (& result .indices_1 , matrix .indices_1 .size ,
58
+ index_type );
59
+ if (error != BSP_SUCCESS ) {
60
+ bsp_destroy_array_t (& result .values );
61
+ return bsp_construct_default_matrix_t ();
62
+ }
63
+
51
64
for (size_t i = 0 ; i < matrix .indices_1 .size ; i ++ ) {
52
65
size_t index ;
53
66
bsp_array_read (matrix .indices_1 , i , index );
54
67
bsp_array_write (result .indices_1 , i , index );
55
68
}
56
69
}
57
70
58
- result .indices_0 = bsp_construct_array_t (matrix .nnz , index_type );
71
+ error = bsp_construct_array_t (& result .indices_0 , matrix .nnz , index_type );
72
+ if (error != BSP_SUCCESS ) {
73
+ bsp_destroy_array_t (& result .values );
74
+ bsp_destroy_array_t (& result .indices_1 );
75
+ return bsp_construct_default_matrix_t ();
76
+ }
59
77
60
78
for (size_t i = 0 ; i < matrix .nrows ; i ++ ) {
61
79
size_t row_begin , row_end ;
@@ -109,12 +127,26 @@ static inline bsp_matrix_t bsp_convert_matrix(bsp_matrix_t matrix,
109
127
// indices can be copied exactly. Values' type will not change, but
110
128
// column indices might, thus the extra branch.
111
129
112
- result .values = bsp_copy_construct_array_t (matrix .values );
130
+ bsp_error_t error =
131
+ bsp_copy_construct_array_t (& result .values , matrix .values );
132
+ if (error != BSP_SUCCESS ) {
133
+ return bsp_construct_default_matrix_t ();
134
+ }
113
135
114
136
if (index_type == matrix .indices_1 .type ) {
115
- result .indices_1 = bsp_copy_construct_array_t (matrix .indices_1 );
137
+ error =
138
+ bsp_copy_construct_array_t (& result .indices_1 , matrix .indices_1 );
139
+ if (error != BSP_SUCCESS ) {
140
+ bsp_destroy_array_t (& result .values );
141
+ return bsp_construct_default_matrix_t ();
142
+ }
116
143
} else {
117
- result .indices_1 = bsp_construct_array_t (matrix .nnz , index_type );
144
+ error =
145
+ bsp_construct_array_t (& result .indices_1 , matrix .nnz , index_type );
146
+ if (error != BSP_SUCCESS ) {
147
+ bsp_destroy_array_t (& result .values );
148
+ return bsp_construct_default_matrix_t ();
149
+ }
118
150
119
151
for (size_t i = 0 ; i < matrix .nnz ; i ++ ) {
120
152
size_t index ;
@@ -123,8 +155,13 @@ static inline bsp_matrix_t bsp_convert_matrix(bsp_matrix_t matrix,
123
155
}
124
156
}
125
157
126
- result .pointers_to_1 =
127
- bsp_construct_array_t (matrix .nrows + 1 , index_type );
158
+ error = bsp_construct_array_t (& result .pointers_to_1 , matrix .nrows + 1 ,
159
+ index_type );
160
+ if (error != BSP_SUCCESS ) {
161
+ bsp_destroy_array_t (& result .values );
162
+ bsp_destroy_array_t (& result .indices_1 );
163
+ return bsp_construct_default_matrix_t ();
164
+ }
128
165
129
166
bsp_array_t rowptr = result .pointers_to_1 ;
130
167
0 commit comments