osqp_tester.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Utilities for testing
  2. #ifndef EMBEDDED
  3. c_float* csc_to_dns(csc *M)
  4. {
  5. c_int i, j = 0; // Predefine row index and column index
  6. c_int idx;
  7. // Initialize matrix of zeros
  8. c_float *A = (c_float *)c_calloc(M->m * M->n, sizeof(c_float));
  9. // Allocate elements
  10. for (idx = 0; idx < M->p[M->n]; idx++)
  11. {
  12. // Get row index i (starting from 1)
  13. i = M->i[idx];
  14. // Get column index j (increase if necessary) (starting from 1)
  15. while (M->p[j + 1] <= idx) {
  16. j++;
  17. }
  18. // Assign values to A
  19. A[j * (M->m) + i] = M->x[idx];
  20. }
  21. return A;
  22. }
  23. c_int is_eq_csc(csc *A, csc *B, c_float tol) {
  24. c_int j, i;
  25. // If number of columns does not coincide, they are not equal.
  26. if (A->n != B->n) return 0;
  27. for (j = 0; j < A->n; j++) { // Cycle over columns j
  28. // if column pointer does not coincide, they are not equal
  29. if (A->p[j] != B->p[j]) return 0;
  30. for (i = A->p[j]; i < A->p[j + 1]; i++) { // Cycle rows i in column j
  31. if ((A->i[i] != B->i[i]) || // Different row indices
  32. (c_absval(A->x[i] - B->x[i]) > tol)) {
  33. return 0;
  34. }
  35. }
  36. }
  37. return 1;
  38. }
  39. #endif // #ifndef EMBEDDED