klemenv / PyDevice

PyDevice is an EPICS device for Python interpreter. It allows to connect EPICS database with Python functions from a C-based soft IOC.
GNU General Public License v3.0
21 stars 11 forks source link

Double input arguments: converting all digits #28

Closed PierreSchnizer closed 1 year ago

PierreSchnizer commented 1 year ago

In its current state this pull request should foster some discussion: how to handle floating points.

Before input arguments are handled to python these arguments are converted to strings. From my tests I saw that std::to_string uses a fixed field of roughly 6 digits. This can result in a loss of conversion accuracy: e.g epsilon values passed as limits to an internal optimiser can be 1e-6 or 1e-8. This value would be passed as "zero" to python.

A solution could be a redirection: provide a template function

         template <typename T>
         inline std::string to_string(const T v) { return std::to_string(v); }

with special implementations for float, double and long double. These convert the number to string streaming it to a string buffer using appropriate io manipulation.

I see that this conversion similar to how python prints floating point numbers. I reckon that this conversion needs more time than using standard strings.

Alternatives to consider:

klemenv commented 1 year ago

Let's try to get the double/float conversion precision merged into the main branch. But there are 10 commits associated with this PR. Could you change the PR to only include the relevant commits?

PierreSchnizer commented 1 year ago

Dear Klemen,

I will try.

I'd like to ask also, if it would be a good idea to review if it would be a better idea to avoid the conversion:

• pydevice dbl -> string • python string -> dbl

I assume that you choice for the string conversion yielded a much slimmer simpler epics device. When it gets to large arrays or images I could imagine that the load could be rather large.

I'd like to ask you what your intend is here in a bit longer view.

Sitll I will try to simplify my pull request.

Thx for the code!

Pierre

--------------------Ursprüngliche Nachricht--------------------
Von: Klemen Vodopivec ***@***.***>
Gesendet: Montag 6. November 2023 17:00
An: klemenv/PyDevice ***@***.***>
CC: Pierre Schnizer ***@***.***>; Author
***@***.***>
Betreff: Re: [klemenv/PyDevice] Double input arguments: converting all
digits (PR #28)

Let's try to get the double/float conversion precision merged into the main
branch. But there are 10 commits associated with this PR. Could you change
the PR to only include the relevant commits?

—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: <klemenv
***@***.***>
PierreSchnizer commented 1 year ago

This PR is superseded by https://github.com/klemenv/PyDevice/pull/30