Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FLOAT and LONG flags in code_generator.py/ codegen() #56

Open
vifr9883 opened this issue May 28, 2021 · 1 comment
Open

FLOAT and LONG flags in code_generator.py/ codegen() #56

vifr9883 opened this issue May 28, 2021 · 1 comment

Comments

@vifr9883
Copy link

Original post: OSQP Forum

It was recommended by @goulart-paul that I open an issue in GitHub.


Hello,

I am trying to generate C source code with the Python3 tool m.codegen(dir_name, **opts). I would like the resulting code to use float instead of double and to use int instead of long long. However, I believe I am not achieving these settings. The following is a description of the behavior I am experiencing.

Following the documentation, I tried running the following Python3 script:

import osqp

# Allocate problem data and src variable
... 

m = osqp.OSQP();
m.setup(P, q, A, l, u)
m.codegen(src, force_rewrite=True, parameters='matrices', FLOAT=True, LONG=False)

The result is a directory with the correct source code. In fact, I can compile the source code with the rest of my project and correctly solve the QP. However, I believe the type of c_int is long long and the type of c_float is double. I have tested this by printing, for example, as follows
printf( "Test c_int workspace->data->A->i[4] = %d, workspace->data->A->i[4]);
>> Test c_int workspace->data->A->i[4] = 467912
printf( "Test c_int workspace->data->A->i[4] = %lld, workspace->data->A->i[4]);
>> Test c_int workspace->data->A->i[4] = 1

The expected value of workspace->data->A->i[4] is 1. I can cast (int)workspace->data->A->i[4] and then I also get 1 as expected. But I believe this shows me the type of c_int is long long.

Furthermore, here are some lines in the file src/include/osqp_configure.h that seem to have auto-generated with unexpected content. I would expect #define DFLOAT for example.

/* EMBEDDED */
#define EMBEDDED (2)

/* PRINTING */
/* #undef PRINTING */

/* PROFILING */
/* #undef PROFILING */

/* CTRLC */
/* #undef CTRLC */

/* DFLOAT */
/* #undef DFLOAT */

/* DLONG */
#define DLONG

If I try to manually change this osqp_configure.h file, I get some compilation errors from the qdldl library with type mismatches.

I apologize for the long explanation. Any advice on how to correctly use the m.codegen(dir_name, **opts) Python3 method to generate code with the correct float and int typing would be appreciated.

Thank you for your time,

-Victor

@vifr9883
Copy link
Author

vifr9883 commented May 28, 2021

As a temporary solution, the following changes to the autogenerated header files achieves the desired behavior:

// osqp_configure.h
...
/* DFLOAT */
#define DFLOAT

/* DLONG */
#undef DLONG
...
// qdldl_types.h
...
//typedef long long    QDLDL_int;   /* for indices */
typedef int    QDLDL_int;   /* for indices */
//typedef double  QDLDL_float; /* for numerical values  */
typedef float  QDLDL_float; /* for numerical values  */ 
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant