You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This adds a minimal decimal capsule API. As can be seen from the patch,
adding anything to decimal while doing it properly is quite labor and
testing intensive, so the intent is to *keep* the API minimal!
That said, some functions are really necessary:
PyDec_TypeCheck() -- for obvious reasons.
PyDec_Alloc() -- create new decimals.
PyDec_Get() -- get the mpd_t, enables the use of all libmpdec functions.
PyDec_AsUint128Triple() -- export the decimal as (sign, hi, lo, exp).
PyDec_FromUint128Triple() -- create a decimal from (sign, hi, lo, exp).
and 5) have been requested by Antoine for a real world use case. (hi, lo)
is the coefficient as a __uint128_t split in two uint64_t.
Antoine, could you verify that this is sufficient for the database use case?
I probably won't try it out explicitly (it's basically cumbersome for us to test with non-release Pythons, because of our dependencies to Numpy and Cython), but reviewing the API should be enough anyway.
skrah commented on Jul 18, 2020
skrahmannequin
MannequinAuthor
More actions
It looks like the API would be usable, so the PR now has documentation.
Was expanding the C-API discussed on the mailing list or in any wider forum? It seems vstinner is working hard to reduce the public API exposure while this issue + PR makes it even larger. Please reconsider putting this in for 3.10.
For the record, this is going to be reverted at Stefan's request in bpo-43422.
dvarrazzo commented on May 10, 2021
dvarrazzomannequin
Mannequin
More actions
FYI, will try to use this API in psycopg3, which supports the PostgreSQL decimal binary format. Thank you very much: it seems exactly what needed.
Binary conversion with Python Decimal currently has disappointing performances and is slower than the text format conversion. This is likely caused by the use of Decimal.as_tuple(), which creates tuples for the return value and the digits and requires Python calls to access their values.
I have considered using libmpdec directly: personally I wouldn't be opposed to that, but the additional dependency on libmpdec-dev would earn the project no new fan :\
Activity
skrah commentedon Jul 17, 2020
This adds a minimal decimal capsule API. As can be seen from the patch,
adding anything to decimal while doing it properly is quite labor and
testing intensive, so the intent is to *keep* the API minimal!
That said, some functions are really necessary:
PyDec_TypeCheck() -- for obvious reasons.
PyDec_Alloc() -- create new decimals.
PyDec_Get() -- get the mpd_t, enables the use of all libmpdec functions.
PyDec_AsUint128Triple() -- export the decimal as (sign, hi, lo, exp).
PyDec_FromUint128Triple() -- create a decimal from (sign, hi, lo, exp).
and 5) have been requested by Antoine for a real world use case. (hi, lo)
is the coefficient as a __uint128_t split in two uint64_t.
Antoine, could you verify that this is sufficient for the database use case?
skrah commentedon Jul 17, 2020
Also as a note for Mark and Raymond: This API is for exact conversions
and avoids the use of the context except for raising ConversionSyntax.
I'll add documentation once Antoine has tried it out for his use case.
skrah commentedon Jul 17, 2020
Adding Daniele Varrazzo, in case this is useful for the PostgreSQL
adapter.
pitrou commentedon Jul 17, 2020
I probably won't try it out explicitly (it's basically cumbersome for us to test with non-release Pythons, because of our dependencies to Numpy and Cython), but reviewing the API should be enough anyway.
skrah commentedon Jul 18, 2020
It looks like the API would be usable, so the PR now has documentation.
[-]Add a minimal decimal capsule API[/-][+]En az ondalık kapsül API ekleme[/+][-]Add a minimal decimal capsule API[/-][+]En az ondalık kapsül API ekleme[/+]3 remaining items
skrah commentedon Aug 10, 2020
New changeset 39042e0 by Stefan Krah in branch 'master':
bpo-41324 Add a minimal decimal capsule API (bpo-21519)
39042e0
mattip commentedon Mar 4, 2021
Was expanding the C-API discussed on the mailing list or in any wider forum? It seems vstinner is working hard to reduce the public API exposure while this issue + PR makes it even larger. Please reconsider putting this in for 3.10.
pitrou commentedon Mar 7, 2021
@mattip, see bpo-43422
pitrou commentedon Mar 21, 2021
For the record, this is going to be reverted at Stefan's request in bpo-43422.
dvarrazzo commentedon May 10, 2021
FYI, will try to use this API in psycopg3, which supports the PostgreSQL decimal binary format. Thank you very much: it seems exactly what needed.
Binary conversion with Python Decimal currently has disappointing performances and is slower than the text format conversion. This is likely caused by the use of Decimal.as_tuple(), which creates tuples for the return value and the digits and requires Python calls to access their values.
I have considered using libmpdec directly: personally I wouldn't be opposed to that, but the additional dependency on libmpdec-dev would earn the project no new fan :\
Ref. psycopg/psycopg#54
dvarrazzo commentedon May 10, 2021
Ah, just noticed that this has been now reverted. Oh well, I'll see what to do then :(