-
Notifications
You must be signed in to change notification settings - Fork 183
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
Changes for numpy 2.0 to fix test matrix. #1196
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -14,10 +14,61 @@ | |
See NOTICE file for details. | ||
*****************************************************************************/ | ||
#include "jpype.h" | ||
#include <math.h> | ||
#include <bitset> | ||
|
||
namespace | ||
{ | ||
|
||
template <jvalue func(void *c) > | ||
class Half | ||
{ | ||
public: | ||
static jvalue convert(void* c) | ||
{ | ||
uint16_t i = *(uint16_t*) c; | ||
uint32_t sign = (i&0x8000)>>15; | ||
uint32_t man = (i&0x7C00)>>10; | ||
uint32_t frac = (i&0x03ff); | ||
uint32_t k = sign<<31; | ||
|
||
if (man == 0) | ||
{ | ||
// subnormal numbers | ||
if (frac != 0) | ||
{ | ||
frac = frac | (frac >> 1); | ||
frac = frac | (frac >> 2); | ||
frac = frac | (frac >> 4); | ||
frac = frac | (frac >> 8); | ||
int zeros = std::bitset<32>(~frac).count(); | ||
man = 127-zeros+7; | ||
man <<= 23; | ||
frac <<= zeros-8; | ||
frac &= 0x7fffff; | ||
k |= man | frac; | ||
} | ||
} | ||
else if (man < 31) | ||
{ | ||
// normal numbers | ||
man = man-15+127; | ||
man <<= 23; | ||
frac <<= 13; | ||
k |= man | frac; | ||
} | ||
else | ||
{ | ||
// to infinity and beyond! | ||
if (frac == 0) | ||
k |= 0x7f800000; | ||
else | ||
k |= 0x7f800001 | ((frac&0x200)<<12); | ||
} | ||
return func(&k); | ||
} | ||
}; | ||
|
||
template <class T> | ||
class Convert | ||
{ | ||
|
@@ -385,6 +436,31 @@ | |
case 'd': return &Convert<double>::toD; | ||
} | ||
break; | ||
case 'e': | ||
if (reverse) switch (to[0]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if there is every a case in which a reversed byte order half floating value would be converted. Through the order of this operation is reasonable to define. Reverse the bytes, promote to float then convert to Java type. |
||
{ | ||
case 'z': return &Reverse<Half<Convert<float>::toZ>::convert>::call4; | ||
case 'b': return &Reverse<Half<Convert<float>::toB>::convert>::call4; | ||
case 'c': return &Reverse<Half<Convert<float>::toC>::convert>::call4; | ||
case 's': return &Reverse<Half<Convert<float>::toS>::convert>::call4; | ||
case 'i': return &Reverse<Half<Convert<float>::toI>::convert>::call4; | ||
case 'j': return &Reverse<Half<Convert<float>::toJ>::convert>::call4; | ||
case 'f': return &Reverse<Half<Convert<float>::toF>::convert>::call4; | ||
case 'd': return &Reverse<Half<Convert<float>::toD>::convert>::call4; | ||
} | ||
else switch (to[0]) | ||
{ | ||
case 'z': return &Half<Convert<float>::toZ>::convert; | ||
case 'b': return &Half<Convert<float>::toB>::convert; | ||
case 'c': return &Half<Convert<float>::toC>::convert; | ||
case 's': return &Half<Convert<float>::toS>::convert; | ||
case 'i': return &Half<Convert<float>::toI>::convert; | ||
case 'j': return &Half<Convert<float>::toJ>::convert; | ||
case 'f': return &Half<Convert<float>::toF>::convert; | ||
case 'd': return &Half<Convert<float>::toD>::convert; | ||
} | ||
break; | ||
|
||
case 'n': | ||
if (reverse) switch (to[0]) | ||
{ | ||
|
This file contains 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 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 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 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 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 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 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 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
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.
This is a crude implementation of the "half" floating type. There is no native type in Java to support this but it is possible that someone could pass a half floating in for promotion to either float or double. This code is exercised in the test suite.