
While experimenting with the Haskell PPL binding, I noticed that the C interface function "ppl_new_LinExpression_with_dimension" always creates an expression with one plus the specified dimension. The following code illustrates the problem:
#include <ppl_c.h>
main () { ppl_LinExpression_t e; ppl_dimension_type dim_in=3, dim_out;;
ppl_initialize();
ppl_new_LinExpression_with_dimension(&e, dim_in); dim_out = ppl_LinExpression_space_dimension(e); printf("%d, %d\n", dim_in, dim_out); /* 3, 4 rather than 3,3 as expected */
ppl_finalize(); }
Looking at the source code interface/C/ppl_c.cc, it becomes clear that the expression created has a single Variable(d), therefore dimension d+1:
int ppl_new_LinExpression_with_dimension(ppl_LinExpression_t* ple, ppl_dimension_type d) try { *ple = to_nonconst(new LinExpression(0*Variable(d))); /* <----- should be Variable(d-1) */ return 0; } CATCH_ALL
This is of course trivial to correct, but I thought it best to report so that it gets corrected in the newer releases.
Best regards,
Pedro

Pedro Vasconcelos wrote:
While experimenting with the Haskell PPL binding, I noticed that the C interface function "ppl_new_LinExpression_with_dimension" always creates an expression with one plus the specified dimension. The following code illustrates the problem:
#include <ppl_c.h>
main () { ppl_LinExpression_t e; ppl_dimension_type dim_in=3, dim_out;;
ppl_initialize();
ppl_new_LinExpression_with_dimension(&e, dim_in); dim_out = ppl_LinExpression_space_dimension(e); printf("%d, %d\n", dim_in, dim_out); /* 3, 4 rather than 3,3 as expected */
ppl_finalize(); }
Looking at the source code interface/C/ppl_c.cc, it becomes clear that the expression created has a single Variable(d), therefore dimension d+1:
int ppl_new_LinExpression_with_dimension(ppl_LinExpression_t* ple, ppl_dimension_type d) try { *ple = to_nonconst(new LinExpression(0*Variable(d))); /* <----- should be Variable(d-1) */ return 0; } CATCH_ALL
This is of course trivial to correct, but I thought it best to report so that it gets corrected in the newer releases.
Dear Pedro,
thanks a lot for your report. You spotted a genuine bug in the C interface. The fix is almost as you indicate, with the exception that the case where d == 0 must also be handled properly. The patch I applied to the CVS head version is the following:
http://www.cs.unipr.it/cgi-bin/cvsweb.cgi/ppl/interfaces/C/ppl_c.cc.diff?cvs...
(notice that the interface of ppl_new_LinExpression_with_dimension has changed since the release of PPL 0.6.1). All the best,
Roberto

Roberto Bagnara wrote:
(notice that the interface of ppl_new_LinExpression_with_dimension has changed since the release of PPL 0.6.1).
I meant ppl_LinExpression_space_dimension. This, as all other functions that compute dimensions, now require the caller to pass, as an extra argument, a pointer to a memory area where the result will be written. All the C interface functions now use the return value to signal the success or failure of the requested operation. All the best,
Roberto
participants (2)
-
Pedro Vasconcelos
-
Roberto Bagnara