Is it possible that the "m. file" code is converted from the double precision to the single precision??
Show older comments
I have "sqp.m" file which is attached here.
Is there anyway to convert this "m. file" from the double precision to the single precision??
(I found the below document and tried it, but it doesn't work.)
I wish that a result is "m.file" with 'single precision variables'
Thank you very much.
6 Comments
John D'Errico
on 29 Nov 2021
Edited: John D'Errico
on 29 Nov 2021
Unless you are good enough to have written that code yourself, having sufficient knowledge and understanding to have written that code, then wanting to change it as you wish is just dangerous.
Yes, I know (from your previous questions) that you need code to run in a single precision environment. But this is just asking for trouble, strange failures, that you then won't understand.
Changwoo Lee
on 29 Nov 2021
Edited: Changwoo Lee
on 29 Nov 2021
dpb
on 29 Nov 2021
So, what was the result of trying converttosingle?
Did it just fail to produce an output piece of code because was too complex for the function or did it produce SP code but that code didn't give expected results?
Briefly reading the description, sounds like it tries to ensure the numerics still work after converting double-->single; if it gives you an error about that sort of thing, as John implies above, "There be dragons!" in assuming that an algorithm implemented and successful in double precision will work in double precision just by reducing precision.
In particular, this being an optimization code, things like computing derivatives, particularly if it uses numerical methods instead of evaluating functional forms (the requirement for which would greatly reduce the field of possible applications of the routine to those for whom analytic expressions are available).
Changwoo Lee
on 29 Nov 2021
A geezer story on single vs double precision -- way back in the dark ages in the mid 70s I attended a conference of American Nuclear Society at which a MS candidate presented a point kernel model of neutron flux distribution in a power reactor to estimate flux at excore detector locations. It just so happened I was in the process of building a model for the same problem at the time so I requested and received a copy of his code for comparison/help in completing the work I was doing.
When I compiled and ran the code on the CDC Cyber76, I got results signficantly different from those he had produced and, unfortunately, on which his MS thesis conclusions were based(*). On exploration for the cause, it turned out he had relied on single precision and run his code on a 32-bit IBM mainframe. The CDC machines were 60-bit so single precision floating point on them was nearly as precise as double precision on the IBM.
The problem was that he accumulated summations from the the various nodes within the reactor at the external locations in a geometrical pattern (logically), but owing to the limited precision, many of the contributions to the total response from the inner assemblies were sufficiently small as to underflow the summation although the aggregation was sufficient overall to modify the response enough as to be in substantial error.
"There be dragons!" that you can't predict without extensive testing and quite likely major rewrites to solve. In the above case the solution could be obtained relatively easily without DP, but it was still much easier to just recompile, of course.
(*) Fortunately, his research thesis topic corporate sponsor and the university were flexible enough as to allow him to go ahead and receive his diploma and resubmit the work results and a revision/errata section to his thesis. It was a little dicey for a while for him, however...
dpb
on 29 Nov 2021
I don't have the coder so can't test/experiment, but looks to me by the error messages it spit out like there are further input parameters to the conversion routine you could specify to let it know the data types of the input arguments and other refinements that could be tried before completely giving up on the conversion process.
Accepted Answer
More Answers (1)
Andy Bartlett
on 6 Dec 2021
Edited: Andy Bartlett
on 6 Dec 2021
0 votes
Hi,
The tools for converting double precision floating-point to single precision for MATLAB code and Simulink models work best at converting designs that (aside from numeric efficiency needs like data types) are close to ready for a "specific" embedded usage.
General purpose MATLAB code based on default doubles and designed to handle a very wide set of situations, such as your SQP function, is much less likely to convert well as compared to a design that has been narrowed down to a specific embedded real-time need.
Since the example you provided, sqp, is doing Quadratic Programming, my answer to your other question might be helpful. That answer refers to the Model Predictive Controller that I believe uses Quadratic Programming on the inside and supports single precision sim and code generation.
Andy
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!