1extern "C" {
2 fn malloc(_: ::std::os::raw::c_ulong) -> *mut ::std::os::raw::c_void;
3 fn calloc(_: ::std::os::raw::c_ulong, _: ::std::os::raw::c_ulong) -> *mut ::std::os::raw::c_void;
4 fn free(_: *mut ::std::os::raw::c_void);
5 fn printf(_: *const ::std::os::raw::c_char, _: ...) -> ::std::os::raw::c_int;
6 fn QDLDL_etree(
7 n: QDLDL_int,
8 Ap: *const QDLDL_int,
9 Ai: *const QDLDL_int,
10 work: *mut QDLDL_int,
11 Lnz: *mut QDLDL_int,
12 etree: *mut QDLDL_int,
13 ) -> QDLDL_int;
14 fn QDLDL_factor(
15 n: QDLDL_int,
16 Ap: *const QDLDL_int,
17 Ai: *const QDLDL_int,
18 Ax: *const QDLDL_float,
19 Lp: *mut QDLDL_int,
20 Li: *mut QDLDL_int,
21 Lx: *mut QDLDL_float,
22 D: *mut QDLDL_float,
23 Dinv: *mut QDLDL_float,
24 Lnz: *const QDLDL_int,
25 etree: *const QDLDL_int,
26 bwork: *mut QDLDL_bool,
27 iwork: *mut QDLDL_int,
28 fwork: *mut QDLDL_float,
29 ) -> QDLDL_int;
30 fn QDLDL_solve(
31 n: QDLDL_int,
32 Lp: *const QDLDL_int,
33 Li: *const QDLDL_int,
34 Lx: *const QDLDL_float,
35 Dinv: *const QDLDL_float,
36 x: *mut QDLDL_float,
37 );
38 fn amd_l_order(
39 n: ::std::os::raw::c_longlong,
40 Ap: *const ::std::os::raw::c_longlong,
41 Ai: *const ::std::os::raw::c_longlong,
42 P: *mut ::std::os::raw::c_longlong,
43 Control: *mut c_float,
44 Info: *mut c_float,
45 ) -> ::std::os::raw::c_longlong;
46 fn csc_spfree(A: *mut csc);
47 fn csc_pinv(p: *const c_int, n: c_int) -> *mut c_int;
48 fn csc_symperm(
49 A: *const csc,
50 pinv: *const c_int,
51 AtoC: *mut c_int,
52 values: c_int,
53 ) -> *mut csc;
54 fn form_KKT(
55 P: *const csc,
56 A: *const csc,
57 format: c_int,
58 param1: c_float,
59 param2: *mut c_float,
60 PtoKKT: *mut c_int,
61 AtoKKT: *mut c_int,
62 Pdiag_idx: *mut *mut c_int,
63 Pdiag_n: *mut c_int,
64 param2toKKT: *mut c_int,
65 ) -> *mut csc;
66 fn update_KKT_param2(
67 KKT: *mut csc,
68 param2: *const c_float,
69 param2toKKT: *const c_int,
70 m: c_int,
71 );
72 fn update_KKT_A(KKT: *mut csc, A: *const csc, AtoKKT: *const c_int);
73 fn update_KKT_P(
74 KKT: *mut csc,
75 P: *const csc,
76 PtoKKT: *const c_int,
77 param1: c_float,
78 Pdiag_idx: *const c_int,
79 Pdiag_n: c_int,
80 );
81}
82pub type c_int = ::std::os::raw::c_longlong;
83pub type c_float = ::std::os::raw::c_double;
84pub type QDLDL_int = ::std::os::raw::c_longlong;
85pub type QDLDL_float = ::std::os::raw::c_double;
86pub type QDLDL_bool = ::std::os::raw::c_uchar;
87pub type linsys_solver_type = ::std::os::raw::c_uint;
88pub const MKL_PARDISO_SOLVER: linsys_solver_type = 1;
89pub const QDLDL_SOLVER: linsys_solver_type = 0;
90pub type osqp_error_type = ::std::os::raw::c_uint;
91pub const OSQP_WORKSPACE_NOT_INIT_ERROR: osqp_error_type = 7;
92pub const OSQP_MEM_ALLOC_ERROR: osqp_error_type = 6;
93pub const OSQP_NONCVX_ERROR: osqp_error_type = 5;
94pub const OSQP_LINSYS_SOLVER_INIT_ERROR: osqp_error_type = 4;
95pub const OSQP_LINSYS_SOLVER_LOAD_ERROR: osqp_error_type = 3;
96pub const OSQP_SETTINGS_VALIDATION_ERROR: osqp_error_type = 2;
97pub const OSQP_DATA_VALIDATION_ERROR: osqp_error_type = 1;
98#[derive(Copy, Clone)]
99#[repr(C)]
100pub struct csc {
101 pub nzmax: c_int,
102 pub m: c_int,
103 pub n: c_int,
104 pub p: *mut c_int,
105 pub i: *mut c_int,
106 pub x: *mut c_float,
107 pub nz: c_int,
108}
109#[derive(Copy, Clone)]
110#[repr(C)]
111pub struct qdldl {
112 pub type_0: linsys_solver_type,
113 pub solve: Option::<unsafe extern "C" fn(*mut qdldl, *mut c_float) -> c_int>,
114 pub free: Option::<unsafe extern "C" fn(*mut qdldl) -> ()>,
115 pub update_matrices: Option::<
116 unsafe extern "C" fn(*mut qdldl, *const csc, *const csc) -> c_int,
117 >,
118 pub update_rho_vec: Option::<
119 unsafe extern "C" fn(*mut qdldl, *const c_float) -> c_int,
120 >,
121 pub nthreads: c_int,
122 pub L: *mut csc,
123 pub Dinv: *mut c_float,
124 pub P: *mut c_int,
125 pub bp: *mut c_float,
126 pub sol: *mut c_float,
127 pub rho_inv_vec: *mut c_float,
128 pub sigma: c_float,
129 pub polish: c_int,
130 pub n: c_int,
131 pub m: c_int,
132 pub Pdiag_idx: *mut c_int,
133 pub Pdiag_n: c_int,
134 pub KKT: *mut csc,
135 pub PtoKKT: *mut c_int,
136 pub AtoKKT: *mut c_int,
137 pub rhotoKKT: *mut c_int,
138 pub D: *mut QDLDL_float,
139 pub etree: *mut QDLDL_int,
140 pub Lnz: *mut QDLDL_int,
141 pub iwork: *mut QDLDL_int,
142 pub bwork: *mut QDLDL_bool,
143 pub fwork: *mut QDLDL_float,
144}
145pub type qdldl_solver = qdldl;
146pub const c_calloc: unsafe extern "C" fn(
147 ::std::os::raw::c_ulong,
148 ::std::os::raw::c_ulong,
149) -> *mut ::std::os::raw::c_void = calloc;
150pub const c_malloc: unsafe extern "C" fn(::std::os::raw::c_ulong) -> *mut ::std::os::raw::c_void = malloc;
151pub const c_print: unsafe extern "C" fn(*const ::std::os::raw::c_char, ...) -> ::std::os::raw::c_int = printf;
152pub const c_free: unsafe extern "C" fn(*mut ::std::os::raw::c_void) -> () = free;
153pub const OSQP_NULL: ::std::os::raw::c_int = 0 as ::std::os::raw::c_int;
154pub const AMD_INFO: ::std::os::raw::c_int = 20 as ::std::os::raw::c_int;
155#[no_mangle]
156pub unsafe extern "C" fn free_linsys_solver_qdldl(mut s: *mut qdldl_solver) {
157 if !s.is_null() {
158 if !((*s).L).is_null() {
159 csc_spfree((*s).L);
160 }
161 if !((*s).P).is_null() {
162 free((*s).P as *mut ::std::os::raw::c_void);
163 }
164 if !((*s).Dinv).is_null() {
165 free((*s).Dinv as *mut ::std::os::raw::c_void);
166 }
167 if !((*s).bp).is_null() {
168 free((*s).bp as *mut ::std::os::raw::c_void);
169 }
170 if !((*s).sol).is_null() {
171 free((*s).sol as *mut ::std::os::raw::c_void);
172 }
173 if !((*s).rho_inv_vec).is_null() {
174 free((*s).rho_inv_vec as *mut ::std::os::raw::c_void);
175 }
176 if !((*s).Pdiag_idx).is_null() {
177 free((*s).Pdiag_idx as *mut ::std::os::raw::c_void);
178 }
179 if !((*s).KKT).is_null() {
180 csc_spfree((*s).KKT);
181 }
182 if !((*s).PtoKKT).is_null() {
183 free((*s).PtoKKT as *mut ::std::os::raw::c_void);
184 }
185 if !((*s).AtoKKT).is_null() {
186 free((*s).AtoKKT as *mut ::std::os::raw::c_void);
187 }
188 if !((*s).rhotoKKT).is_null() {
189 free((*s).rhotoKKT as *mut ::std::os::raw::c_void);
190 }
191 if !((*s).D).is_null() {
192 free((*s).D as *mut ::std::os::raw::c_void);
193 }
194 if !((*s).etree).is_null() {
195 free((*s).etree as *mut ::std::os::raw::c_void);
196 }
197 if !((*s).Lnz).is_null() {
198 free((*s).Lnz as *mut ::std::os::raw::c_void);
199 }
200 if !((*s).iwork).is_null() {
201 free((*s).iwork as *mut ::std::os::raw::c_void);
202 }
203 if !((*s).bwork).is_null() {
204 free((*s).bwork as *mut ::std::os::raw::c_void);
205 }
206 if !((*s).fwork).is_null() {
207 free((*s).fwork as *mut ::std::os::raw::c_void);
208 }
209 free(s as *mut ::std::os::raw::c_void);
210 }
211}
212unsafe extern "C" fn LDL_factor(
213 mut A: *mut csc,
214 mut p: *mut qdldl_solver,
215 mut nvar: c_int,
216) -> c_int {
217 let mut sum_Lnz: c_int = 0;
218 let mut factor_status: c_int = 0;
219 sum_Lnz = QDLDL_etree((*A).n, (*A).p, (*A).i, (*p).iwork, (*p).Lnz, (*p).etree);
220 if sum_Lnz < 0 as ::std::os::raw::c_int as ::std::os::raw::c_longlong {
221 printf(
222 b"ERROR in %s: \0" as *const u8 as *const ::std::os::raw::c_char,
223 (*::std::mem::transmute::<&[u8; 11], &[::std::os::raw::c_char; 11]>(b"LDL_factor\0"))
224 .as_ptr(),
225 );
226 printf(
227 b"Error in KKT matrix LDL factorization when computing the elimination tree.\0"
228 as *const u8 as *const ::std::os::raw::c_char,
229 );
230 printf(b"\n\0" as *const u8 as *const ::std::os::raw::c_char);
231 if sum_Lnz == -(1 as ::std::os::raw::c_int) as ::std::os::raw::c_longlong {
232 printf(
233 b"ERROR in %s: \0" as *const u8 as *const ::std::os::raw::c_char,
234 (*::std::mem::transmute::<
235 &[u8; 11],
236 &[::std::os::raw::c_char; 11],
237 >(b"LDL_factor\0"))
238 .as_ptr(),
239 );
240 printf(
241 b"Matrix is not perfectly upper triangular.\0" as *const u8
242 as *const ::std::os::raw::c_char,
243 );
244 printf(b"\n\0" as *const u8 as *const ::std::os::raw::c_char);
245 } else if sum_Lnz == -(2 as ::std::os::raw::c_int) as ::std::os::raw::c_longlong {
246 printf(
247 b"ERROR in %s: \0" as *const u8 as *const ::std::os::raw::c_char,
248 (*::std::mem::transmute::<
249 &[u8; 11],
250 &[::std::os::raw::c_char; 11],
251 >(b"LDL_factor\0"))
252 .as_ptr(),
253 );
254 printf(
255 b"Integer overflow in L nonzero count.\0" as *const u8
256 as *const ::std::os::raw::c_char,
257 );
258 printf(b"\n\0" as *const u8 as *const ::std::os::raw::c_char);
259 }
260 return sum_Lnz;
261 }
262 let ref mut fresh0 = (*(*p).L).i;
263 *fresh0 = malloc(
264 (::std::mem::size_of::<c_int>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong)
265 .wrapping_mul(sum_Lnz as ::std::os::raw::c_ulonglong) as ::std::os::raw::c_ulong,
266 ) as *mut c_int;
267 let ref mut fresh1 = (*(*p).L).x;
268 *fresh1 = malloc(
269 (::std::mem::size_of::<c_float>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong)
270 .wrapping_mul(sum_Lnz as ::std::os::raw::c_ulonglong) as ::std::os::raw::c_ulong,
271 ) as *mut c_float;
272 (*(*p).L).nzmax = sum_Lnz;
273 factor_status = QDLDL_factor(
274 (*A).n,
275 (*A).p,
276 (*A).i,
277 (*A).x,
278 (*(*p).L).p,
279 (*(*p).L).i,
280 (*(*p).L).x,
281 (*p).D,
282 (*p).Dinv,
283 (*p).Lnz,
284 (*p).etree,
285 (*p).bwork,
286 (*p).iwork,
287 (*p).fwork,
288 );
289 if factor_status < 0 as ::std::os::raw::c_int as ::std::os::raw::c_longlong {
290 printf(
291 b"ERROR in %s: \0" as *const u8 as *const ::std::os::raw::c_char,
292 (*::std::mem::transmute::<&[u8; 11], &[::std::os::raw::c_char; 11]>(b"LDL_factor\0"))
293 .as_ptr(),
294 );
295 printf(
296 b"Error in KKT matrix LDL factorization when computing the nonzero elements. There are zeros in the diagonal matrix\0"
297 as *const u8 as *const ::std::os::raw::c_char,
298 );
299 printf(b"\n\0" as *const u8 as *const ::std::os::raw::c_char);
300 return factor_status;
301 } else {
302 if factor_status < nvar {
303 printf(
304 b"ERROR in %s: \0" as *const u8 as *const ::std::os::raw::c_char,
305 (*::std::mem::transmute::<
306 &[u8; 11],
307 &[::std::os::raw::c_char; 11],
308 >(b"LDL_factor\0"))
309 .as_ptr(),
310 );
311 printf(
312 b"Error in KKT matrix LDL factorization when computing the nonzero elements. The problem seems to be non-convex\0"
313 as *const u8 as *const ::std::os::raw::c_char,
314 );
315 printf(b"\n\0" as *const u8 as *const ::std::os::raw::c_char);
316 return -(2 as ::std::os::raw::c_int) as c_int;
317 }
318 }
319 return 0 as ::std::os::raw::c_int as c_int;
320}
321unsafe extern "C" fn permute_KKT(
322 mut KKT: *mut *mut csc,
323 mut p: *mut qdldl_solver,
324 mut Pnz: c_int,
325 mut Anz: c_int,
326 mut m: c_int,
327 mut PtoKKT: *mut c_int,
328 mut AtoKKT: *mut c_int,
329 mut rhotoKKT: *mut c_int,
330) -> c_int {
331 let mut info: *mut c_float = 0 as *mut c_float;
332 let mut amd_status: c_int = 0;
333 let mut Pinv: *mut c_int = 0 as *mut c_int;
334 let mut KKT_temp: *mut csc = 0 as *mut csc;
335 let mut KtoPKPt: *mut c_int = 0 as *mut c_int;
336 let mut i: c_int = 0;
337 info = malloc(
338 (AMD_INFO as ::std::os::raw::c_ulong)
339 .wrapping_mul(::std::mem::size_of::<c_float>() as ::std::os::raw::c_ulong),
340 ) as *mut c_float;
341 amd_status = amd_l_order(
342 (**KKT).n,
343 (**KKT).p as *const ::std::os::raw::c_longlong,
344 (**KKT).i as *const ::std::os::raw::c_longlong,
345 (*p).P,
346 0 as *mut c_float,
347 info,
348 );
349 if amd_status < 0 as ::std::os::raw::c_int as ::std::os::raw::c_longlong {
350 free(info as *mut ::std::os::raw::c_void);
351 return amd_status;
352 }
353 Pinv = csc_pinv((*p).P, (**KKT).n);
354 if PtoKKT.is_null() && AtoKKT.is_null() && rhotoKKT.is_null() {
355 KKT_temp = csc_symperm(
356 *KKT,
357 Pinv,
358 OSQP_NULL as *mut c_int,
359 1 as ::std::os::raw::c_int as c_int,
360 );
361 } else {
362 KtoPKPt = malloc(
363 (*((**KKT).p).offset((**KKT).n as isize) as ::std::os::raw::c_ulonglong)
364 .wrapping_mul(
365 ::std::mem::size_of::<c_int>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong,
366 ) as ::std::os::raw::c_ulong,
367 ) as *mut c_int;
368 KKT_temp = csc_symperm(*KKT, Pinv, KtoPKPt, 1 as ::std::os::raw::c_int as c_int);
369 if !PtoKKT.is_null() {
370 i = 0 as ::std::os::raw::c_int as c_int;
371 while i < Pnz {
372 *PtoKKT
373 .offset(
374 i as isize,
375 ) = *KtoPKPt.offset(*PtoKKT.offset(i as isize) as isize);
376 i += 1;
377 }
378 }
379 if !AtoKKT.is_null() {
380 i = 0 as ::std::os::raw::c_int as c_int;
381 while i < Anz {
382 *AtoKKT
383 .offset(
384 i as isize,
385 ) = *KtoPKPt.offset(*AtoKKT.offset(i as isize) as isize);
386 i += 1;
387 }
388 }
389 if !rhotoKKT.is_null() {
390 i = 0 as ::std::os::raw::c_int as c_int;
391 while i < m {
392 *rhotoKKT
393 .offset(
394 i as isize,
395 ) = *KtoPKPt.offset(*rhotoKKT.offset(i as isize) as isize);
396 i += 1;
397 }
398 }
399 free(KtoPKPt as *mut ::std::os::raw::c_void);
400 }
401 csc_spfree(*KKT);
402 *KKT = KKT_temp;
403 free(Pinv as *mut ::std::os::raw::c_void);
404 free(info as *mut ::std::os::raw::c_void);
405 return 0 as ::std::os::raw::c_int as c_int;
406}
407#[no_mangle]
408pub unsafe extern "C" fn init_linsys_solver_qdldl(
409 mut sp: *mut *mut qdldl_solver,
410 mut P: *const csc,
411 mut A: *const csc,
412 mut sigma: c_float,
413 mut rho_vec: *const c_float,
414 mut polish: c_int,
415) -> c_int {
416 let mut KKT_temp: *mut csc = 0 as *mut csc;
417 let mut i: c_int = 0;
418 let mut n_plus_m: c_int = 0;
419 let mut s: *mut qdldl_solver = 0 as *mut qdldl_solver;
420 s = calloc(
421 1 as ::std::os::raw::c_int as ::std::os::raw::c_ulong,
422 ::std::mem::size_of::<qdldl_solver>() as ::std::os::raw::c_ulong,
423 ) as *mut qdldl_solver;
424 *sp = s;
425 (*s).n = (*P).n;
426 (*s).m = (*A).m;
427 n_plus_m = (*s).n + (*s).m;
428 (*s).sigma = sigma;
429 (*s).polish = polish;
430 let ref mut fresh2 = (*s).solve;
431 *fresh2 = Some(
432 solve_linsys_qdldl
433 as unsafe extern "C" fn(*mut qdldl_solver, *mut c_float) -> c_int,
434 );
435 let ref mut fresh3 = (*s).free;
436 *fresh3 = Some(
437 free_linsys_solver_qdldl as unsafe extern "C" fn(*mut qdldl_solver) -> (),
438 );
439 let ref mut fresh4 = (*s).update_matrices;
440 *fresh4 = Some(
441 update_linsys_solver_matrices_qdldl
442 as unsafe extern "C" fn(*mut qdldl_solver, *const csc, *const csc) -> c_int,
443 );
444 let ref mut fresh5 = (*s).update_rho_vec;
445 *fresh5 = Some(
446 update_linsys_solver_rho_vec_qdldl
447 as unsafe extern "C" fn(*mut qdldl_solver, *const c_float) -> c_int,
448 );
449 (*s).type_0 = QDLDL_SOLVER;
450 (*s).nthreads = 1 as ::std::os::raw::c_int as c_int;
451 let ref mut fresh6 = (*s).L;
452 *fresh6 = malloc(::std::mem::size_of::<csc>() as ::std::os::raw::c_ulong) as *mut csc;
453 (*(*s).L).m = n_plus_m;
454 (*(*s).L).n = n_plus_m;
455 (*(*s).L).nz = -(1 as ::std::os::raw::c_int) as c_int;
456 let ref mut fresh7 = (*s).Dinv;
457 *fresh7 = malloc(
458 (::std::mem::size_of::<QDLDL_float>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong)
459 .wrapping_mul(n_plus_m as ::std::os::raw::c_ulonglong) as ::std::os::raw::c_ulong,
460 ) as *mut QDLDL_float;
461 let ref mut fresh8 = (*s).D;
462 *fresh8 = malloc(
463 (::std::mem::size_of::<QDLDL_float>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong)
464 .wrapping_mul(n_plus_m as ::std::os::raw::c_ulonglong) as ::std::os::raw::c_ulong,
465 ) as *mut QDLDL_float;
466 let ref mut fresh9 = (*s).P;
467 *fresh9 = malloc(
468 (::std::mem::size_of::<QDLDL_int>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong)
469 .wrapping_mul(n_plus_m as ::std::os::raw::c_ulonglong) as ::std::os::raw::c_ulong,
470 ) as *mut QDLDL_int;
471 let ref mut fresh10 = (*s).bp;
472 *fresh10 = malloc(
473 (::std::mem::size_of::<QDLDL_float>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong)
474 .wrapping_mul(n_plus_m as ::std::os::raw::c_ulonglong) as ::std::os::raw::c_ulong,
475 ) as *mut QDLDL_float;
476 let ref mut fresh11 = (*s).sol;
477 *fresh11 = malloc(
478 (::std::mem::size_of::<QDLDL_float>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong)
479 .wrapping_mul(n_plus_m as ::std::os::raw::c_ulonglong) as ::std::os::raw::c_ulong,
480 ) as *mut QDLDL_float;
481 let ref mut fresh12 = (*s).rho_inv_vec;
482 *fresh12 = malloc(
483 (::std::mem::size_of::<c_float>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong)
484 .wrapping_mul((*s).m as ::std::os::raw::c_ulonglong) as ::std::os::raw::c_ulong,
485 ) as *mut c_float;
486 let ref mut fresh13 = (*s).etree;
487 *fresh13 = malloc(
488 (n_plus_m as ::std::os::raw::c_ulonglong)
489 .wrapping_mul(
490 ::std::mem::size_of::<QDLDL_int>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong,
491 ) as ::std::os::raw::c_ulong,
492 ) as *mut QDLDL_int;
493 let ref mut fresh14 = (*s).Lnz;
494 *fresh14 = malloc(
495 (n_plus_m as ::std::os::raw::c_ulonglong)
496 .wrapping_mul(
497 ::std::mem::size_of::<QDLDL_int>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong,
498 ) as ::std::os::raw::c_ulong,
499 ) as *mut QDLDL_int;
500 let ref mut fresh15 = (*(*s).L).p;
501 *fresh15 = malloc(
502 ((n_plus_m + 1 as ::std::os::raw::c_int as ::std::os::raw::c_longlong) as ::std::os::raw::c_ulonglong)
503 .wrapping_mul(
504 ::std::mem::size_of::<QDLDL_int>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong,
505 ) as ::std::os::raw::c_ulong,
506 ) as *mut c_int;
507 let ref mut fresh16 = (*(*s).L).i;
508 *fresh16 = OSQP_NULL as *mut c_int;
509 let ref mut fresh17 = (*(*s).L).x;
510 *fresh17 = OSQP_NULL as *mut c_float;
511 let ref mut fresh18 = (*s).iwork;
512 *fresh18 = malloc(
513 (::std::mem::size_of::<QDLDL_int>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong)
514 .wrapping_mul(
515 (3 as ::std::os::raw::c_int as ::std::os::raw::c_longlong * n_plus_m) as ::std::os::raw::c_ulonglong,
516 ) as ::std::os::raw::c_ulong,
517 ) as *mut QDLDL_int;
518 let ref mut fresh19 = (*s).bwork;
519 *fresh19 = malloc(
520 (::std::mem::size_of::<QDLDL_bool>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong)
521 .wrapping_mul(n_plus_m as ::std::os::raw::c_ulonglong) as ::std::os::raw::c_ulong,
522 ) as *mut QDLDL_bool;
523 let ref mut fresh20 = (*s).fwork;
524 *fresh20 = malloc(
525 (::std::mem::size_of::<QDLDL_float>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong)
526 .wrapping_mul(n_plus_m as ::std::os::raw::c_ulonglong) as ::std::os::raw::c_ulong,
527 ) as *mut QDLDL_float;
528 if polish != 0 {
529 i = 0 as ::std::os::raw::c_int as c_int;
530 while i < (*A).m {
531 *((*s).rho_inv_vec).offset(i as isize) = sigma;
532 i += 1;
533 }
534 KKT_temp = form_KKT(
535 P,
536 A,
537 0 as ::std::os::raw::c_int as c_int,
538 sigma,
539 (*s).rho_inv_vec,
540 OSQP_NULL as *mut c_int,
541 OSQP_NULL as *mut c_int,
542 OSQP_NULL as *mut *mut c_int,
543 OSQP_NULL as *mut c_int,
544 OSQP_NULL as *mut c_int,
545 );
546 if !KKT_temp.is_null() {
547 permute_KKT(
548 &mut KKT_temp,
549 s,
550 OSQP_NULL as c_int,
551 OSQP_NULL as c_int,
552 OSQP_NULL as c_int,
553 OSQP_NULL as *mut c_int,
554 OSQP_NULL as *mut c_int,
555 OSQP_NULL as *mut c_int,
556 );
557 }
558 } else {
559 let ref mut fresh21 = (*s).PtoKKT;
560 *fresh21 = malloc(
561 (*((*P).p).offset((*P).n as isize) as ::std::os::raw::c_ulonglong)
562 .wrapping_mul(
563 ::std::mem::size_of::<c_int>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong,
564 ) as ::std::os::raw::c_ulong,
565 ) as *mut c_int;
566 let ref mut fresh22 = (*s).AtoKKT;
567 *fresh22 = malloc(
568 (*((*A).p).offset((*A).n as isize) as ::std::os::raw::c_ulonglong)
569 .wrapping_mul(
570 ::std::mem::size_of::<c_int>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong,
571 ) as ::std::os::raw::c_ulong,
572 ) as *mut c_int;
573 let ref mut fresh23 = (*s).rhotoKKT;
574 *fresh23 = malloc(
575 ((*A).m as ::std::os::raw::c_ulonglong)
576 .wrapping_mul(
577 ::std::mem::size_of::<c_int>() as ::std::os::raw::c_ulong as ::std::os::raw::c_ulonglong,
578 ) as ::std::os::raw::c_ulong,
579 ) as *mut c_int;
580 i = 0 as ::std::os::raw::c_int as c_int;
581 while i < (*A).m {
582 *((*s).rho_inv_vec)
583 .offset(i as isize) = 1.0f64 / *rho_vec.offset(i as isize);
584 i += 1;
585 }
586 KKT_temp = form_KKT(
587 P,
588 A,
589 0 as ::std::os::raw::c_int as c_int,
590 sigma,
591 (*s).rho_inv_vec,
592 (*s).PtoKKT,
593 (*s).AtoKKT,
594 &mut (*s).Pdiag_idx,
595 &mut (*s).Pdiag_n,
596 (*s).rhotoKKT,
597 );
598 if !KKT_temp.is_null() {
599 permute_KKT(
600 &mut KKT_temp,
601 s,
602 *((*P).p).offset((*P).n as isize),
603 *((*A).p).offset((*A).n as isize),
604 (*A).m,
605 (*s).PtoKKT,
606 (*s).AtoKKT,
607 (*s).rhotoKKT,
608 );
609 }
610 }
611 if KKT_temp.is_null() {
612 printf(
613 b"ERROR in %s: \0" as *const u8 as *const ::std::os::raw::c_char,
614 (*::std::mem::transmute::<
615 &[u8; 25],
616 &[::std::os::raw::c_char; 25],
617 >(b"init_linsys_solver_qdldl\0"))
618 .as_ptr(),
619 );
620 printf(
621 b"Error forming and permuting KKT matrix\0" as *const u8
622 as *const ::std::os::raw::c_char,
623 );
624 printf(b"\n\0" as *const u8 as *const ::std::os::raw::c_char);
625 free_linsys_solver_qdldl(s);
626 *sp = OSQP_NULL as *mut qdldl_solver;
627 return OSQP_LINSYS_SOLVER_INIT_ERROR as ::std::os::raw::c_int as c_int;
628 }
629 if LDL_factor(KKT_temp, s, (*P).n) < 0 as ::std::os::raw::c_int as ::std::os::raw::c_longlong {
630 csc_spfree(KKT_temp);
631 free_linsys_solver_qdldl(s);
632 *sp = OSQP_NULL as *mut qdldl_solver;
633 return OSQP_NONCVX_ERROR as ::std::os::raw::c_int as c_int;
634 }
635 if polish != 0 {
636 csc_spfree(KKT_temp);
637 } else {
638 let ref mut fresh24 = (*s).KKT;
639 *fresh24 = KKT_temp;
640 }
641 return 0 as ::std::os::raw::c_int as c_int;
642}
643#[no_mangle]
644pub unsafe extern "C" fn permute_x(
645 mut n: c_int,
646 mut x: *mut c_float,
647 mut b: *const c_float,
648 mut P: *const c_int,
649) {
650 let mut j: c_int = 0;
651 j = 0 as ::std::os::raw::c_int as c_int;
652 while j < n {
653 *x.offset(j as isize) = *b.offset(*P.offset(j as isize) as isize);
654 j += 1;
655 }
656}
657#[no_mangle]
658pub unsafe extern "C" fn permutet_x(
659 mut n: c_int,
660 mut x: *mut c_float,
661 mut b: *const c_float,
662 mut P: *const c_int,
663) {
664 let mut j: c_int = 0;
665 j = 0 as ::std::os::raw::c_int as c_int;
666 while j < n {
667 *x.offset(*P.offset(j as isize) as isize) = *b.offset(j as isize);
668 j += 1;
669 }
670}
671unsafe extern "C" fn LDLSolve(
672 mut x: *mut c_float,
673 mut b: *mut c_float,
674 mut L: *const csc,
675 mut Dinv: *const c_float,
676 mut P: *const c_int,
677 mut bp: *mut c_float,
678) {
679 permute_x((*L).n, bp, b, P);
680 QDLDL_solve((*L).n, (*L).p, (*L).i, (*L).x, Dinv, bp);
681 permutet_x((*L).n, x, bp, P);
682}
683#[no_mangle]
684pub unsafe extern "C" fn solve_linsys_qdldl(
685 mut s: *mut qdldl_solver,
686 mut b: *mut c_float,
687) -> c_int {
688 let mut j: c_int = 0;
689 if (*s).polish != 0 {
690 LDLSolve(b, b, (*s).L, (*s).Dinv, (*s).P, (*s).bp);
691 } else {
692 LDLSolve((*s).sol, b, (*s).L, (*s).Dinv, (*s).P, (*s).bp);
693 j = 0 as ::std::os::raw::c_int as c_int;
694 while j < (*s).n {
695 *b.offset(j as isize) = *((*s).sol).offset(j as isize);
696 j += 1;
697 }
698 j = 0 as ::std::os::raw::c_int as c_int;
699 while j < (*s).m {
700 let ref mut fresh25 = *b.offset((j + (*s).n) as isize);
701 *fresh25
702 += *((*s).rho_inv_vec).offset(j as isize)
703 * *((*s).sol).offset((j + (*s).n) as isize);
704 j += 1;
705 }
706 }
707 return 0 as ::std::os::raw::c_int as c_int;
708}
709#[no_mangle]
710pub unsafe extern "C" fn update_linsys_solver_matrices_qdldl(
711 mut s: *mut qdldl_solver,
712 mut P: *const csc,
713 mut A: *const csc,
714) -> c_int {
715 update_KKT_P((*s).KKT, P, (*s).PtoKKT, (*s).sigma, (*s).Pdiag_idx, (*s).Pdiag_n);
716 update_KKT_A((*s).KKT, A, (*s).AtoKKT);
717 return (QDLDL_factor(
718 (*(*s).KKT).n,
719 (*(*s).KKT).p,
720 (*(*s).KKT).i,
721 (*(*s).KKT).x,
722 (*(*s).L).p,
723 (*(*s).L).i,
724 (*(*s).L).x,
725 (*s).D,
726 (*s).Dinv,
727 (*s).Lnz,
728 (*s).etree,
729 (*s).bwork,
730 (*s).iwork,
731 (*s).fwork,
732 ) < 0 as ::std::os::raw::c_int as ::std::os::raw::c_longlong) as ::std::os::raw::c_int as c_int;
733}
734#[no_mangle]
735pub unsafe extern "C" fn update_linsys_solver_rho_vec_qdldl(
736 mut s: *mut qdldl_solver,
737 mut rho_vec: *const c_float,
738) -> c_int {
739 let mut i: c_int = 0;
740 i = 0 as ::std::os::raw::c_int as c_int;
741 while i < (*s).m {
742 *((*s).rho_inv_vec).offset(i as isize) = 1.0f64 / *rho_vec.offset(i as isize);
743 i += 1;
744 }
745 update_KKT_param2((*s).KKT, (*s).rho_inv_vec, (*s).rhotoKKT, (*s).m);
746 return (QDLDL_factor(
747 (*(*s).KKT).n,
748 (*(*s).KKT).p,
749 (*(*s).KKT).i,
750 (*(*s).KKT).x,
751 (*(*s).L).p,
752 (*(*s).L).i,
753 (*(*s).L).x,
754 (*s).D,
755 (*s).Dinv,
756 (*s).Lnz,
757 (*s).etree,
758 (*s).bwork,
759 (*s).iwork,
760 (*s).fwork,
761 ) < 0 as ::std::os::raw::c_int as ::std::os::raw::c_longlong) as ::std::os::raw::c_int as c_int;
762}