-
-
Notifications
You must be signed in to change notification settings - Fork 13
FEAT: Adding Byte support to QuadPrecision scalar constructor #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SwayamInSync
wants to merge
7
commits into
numpy:main
Choose a base branch
from
SwayamInSync:bytes_support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+248
−57
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3375e70
byte support to scalar
SwayamInSync c7fc8b3
refactor
SwayamInSync d0bfe6a
adding tests
SwayamInSync 81d3bfc
addressing edges
SwayamInSync 05203e2
refactor
SwayamInSync ea0a489
adding ehader
SwayamInSync 25f0338
error handling
SwayamInSync File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #include "lock.h" | ||
|
|
||
| #if PY_VERSION_HEX < 0x30d00b3 | ||
| PyThread_type_lock sleef_lock = NULL; | ||
| #else | ||
| PyMutex sleef_lock = {0}; | ||
| #endif | ||
|
|
||
| void init_sleef_locks(void) | ||
| { | ||
| #if PY_VERSION_HEX < 0x30d00b3 | ||
| sleef_lock = PyThread_allocate_lock(); | ||
| if (!sleef_lock) { | ||
| PyErr_NoMemory(); | ||
| } | ||
| #endif | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #ifndef _QUADDTYPE_LOCK_H | ||
| #define _QUADDTYPE_LOCK_H | ||
|
|
||
| #include <Python.h> | ||
|
|
||
| #if PY_VERSION_HEX < 0x30d00b3 | ||
| extern PyThread_type_lock sleef_lock; | ||
| #define LOCK_SLEEF PyThread_acquire_lock(sleef_lock, WAIT_LOCK) | ||
| #define UNLOCK_SLEEF PyThread_release_lock(sleef_lock) | ||
| #else | ||
| extern PyMutex sleef_lock; | ||
| #define LOCK_SLEEF PyMutex_Lock(&sleef_lock) | ||
| #define UNLOCK_SLEEF PyMutex_Unlock(&sleef_lock) | ||
| #endif | ||
|
|
||
| void init_sleef_locks(void); | ||
|
|
||
| #endif // _QUADDTYPE_LOCK_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #include "utilities.h" | ||
| #include <stdlib.h> | ||
|
|
||
| int cstring_to_quad(const char *str, QuadBackendType backend, quad_value *out_value, | ||
| char **endptr, bool require_full_parse) | ||
| { | ||
| if(backend == BACKEND_SLEEF) { | ||
| out_value->sleef_value = Sleef_strtoq(str, endptr); | ||
| } else { | ||
| out_value->longdouble_value = strtold(str, endptr); | ||
| } | ||
| if(*endptr == str) | ||
| return -1; // parse error - nothing was parsed | ||
|
|
||
| // If full parse is required | ||
| if(require_full_parse && **endptr != '\0') | ||
| return -1; // parse error - characters remain to be converted | ||
|
|
||
| return 0; // success | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #ifndef QUAD_UTILITIES_H | ||
| #define QUAD_UTILITIES_H | ||
|
|
||
| #include "quad_common.h" | ||
| #include <sleef.h> | ||
| #include <sleefquad.h> | ||
| #include <stdbool.h> | ||
|
|
||
| int cstring_to_quad(const char *str, QuadBackendType backend, quad_value *out_value, char **endptr, bool require_full_parse); | ||
|
|
||
| #endif |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this function return int, do the error-handling, and return -1 on error and 0 on success? Unless it was intentional for some reason to leave the error handling different at all the call sites, I don't think it was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually for
NPY_DT_PyArray_ArrFuncs_fromstrNumPy passes its ownendptrand we use exactly that in parsing, this way NumPy checks if*endptrmoved forward (if not, it throws the "unmatched data" error). Here is the declaration link in NumPy linkThat's why I thought to keep it like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So there are 2 cases, where we check the exceptions by defninig our own
endptrand some whereNumPykeeps trackThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you handle that with a boolean flag or something?
partial_conversion_check?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be possible as
Both
endptrandrequire_full_parseneed to be coming from the calling context can decide passingtrueorfalsefor example inNPY_DT_PyArray_ArrFuncs_fromstrshould passfalseand otherstrueLet me know @ngoldbaum if you want something like this then I can proceed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that's better than scattering the error checking throughout the code. Either way you need to know which kind of error checking you need to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done