Floating point conversion to string precision loss fix for Chunk's du… #33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…ration
It seems that Python's %f formatting defaults to 6 digits. However, this precision is not sufficient within Chunks. str(float) uses higher precision. Specifically, a this (should) Fix #25 . This is not a fool-proof fix, but, add extra precision, and enables the Python path for the set of data I am working with. The fool proof way, for those who desire it, would be to use the C++ pathway only, or write more complex, bit-wise accurate serialization / deserialization of floats being passed around in strings across the Python and C++ interface.
#25 seems to be caused the by following control-flow:
a) QuadraticConstraints are created in Python using higher precision values of chunk durations which is used when populating constraint vectors in ComputeKinematicConstraints in TOPPPy.py. Specifically, ndiscrsteps is computed using trajectory duration.
b) The PiecewisePolynomial trajectory is serialized to string and transmitted when a TOPPInstance is created (in test code / app code written by user) -- here, currently, low precision chunk duration is used.
c) The received string is unserialized, and the trajectory duration, and the ndiscrsteps are computed in Constraints::Preprocess in TOPP.cpp. Due to precision loss, this can be different (and, even more) than ndiscrsteps computed in python code.
d) Then, TOPP::QuadraticConstraints::InterpolateDynamics uses the above computed value to index into vectors that were created in Python (avect, bvect, etc). This might cause out of bounds indexing of the array, giving =>
received signal SIGSEGV, Segmentation fault.
0x00007f600b042eb0 in TOPP::QuadraticConstraints::InterpolateDynamics
Quick check on fix:
On Python3 --
Also, https://stackoverflow.com/questions/20586011/python-precision-in-string-formatting-with-float-numbers.