Skip to content
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

Add support for float16 datatypes #179

Merged
merged 17 commits into from
May 3, 2024
Merged

Conversation

byrnHDF
Copy link
Collaborator

@byrnHDF byrnHDF commented Apr 18, 2024

Still need tests

@byrnHDF byrnHDF added Type - Improvement Improvements that don't add a new feature or functionality Component - Object Library Improvements to the object library Component - HDFView Improvements to the visual interface layer Type - New Feature Add a new API call, functionality, or tool Priority - 1. High 🔼 These are important issues that should be resolved in the next release labels Apr 18, 2024
@byrnHDF byrnHDF self-assigned this Apr 18, 2024
{
Object theValue = newValue;
if (isFLT16)
theValue = Short.toString(Float.floatToFloat16(Float.parseFloat((String)newValue)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this set as a string here rather than a real data value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be an artifact before the Display/Converter changes?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be. I never created one, but it'd be useful to have a test file with a float16 member inside a compound, since this seems like editing one of those values would convert it to a String and either fail on write or cause weird issues later during read.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did test a change value and it worked - will need to check into container types.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see the other setDataValue calls below return Float.float16ToFloat((short)bufObject) rather than a string. This almost certainly doesn't need the Short.toString( part and I'm surprised it doesn't cause problems.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe - I know not having it failed the first time I tried - will try again since changing other code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be a string - fails without it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then something is wrong elsewhere. For numerical values the DataProvider should be setting actual values and not strings. The only time numerical data should be working on a String is when converting to displayable formats in the DataDisplayConverters.

Copy link
Collaborator Author

@byrnHDF byrnHDF Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trouble is that float16 is a Short underneath and everything was triggering on that type.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I understand, but it shouldn't be a string. It's unfortunate that the implementation chose to encode the value in a short, because it forces us to implement "wrapper" setDataValue functions just to check if a value is a float16 value so that we can convert it from a short to a real float type, but I suppose it is what it is. But, the data array we work with should always be in terms of either short or float and then converted to String in the DataDisplayConverters and float elsewhere where we need a real value (if we didn't already choose to convert it to a float for the data array).

else
strValue = Float.toString(Float.float16ToFloat((short)value));

if (count > 0 && strValue.length() > count)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this line is trying to do. count must always be > 0 at this point and count seems to refer to some limit on the maximum number of items to return, so I'm not sure why the length of the string is being compared to count here, unless count is in terms of characters here. If that's the case, it also seems like the sb.append call above needs to account for count, but that code's commented out. However, I think this whole thing can be simplified into just a loop that starts at index 0, rather than getting a single element and then having a loop to look for other elements.

In fact, it seems like all the other cases above can and should be simplified the same way, but that's completely separate to this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you convert this comment to an issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a cut-n-paste issue

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like that is copied from the else clause, which also had that commented out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setDataValue is definitely passing in a string.
The others might need to be fixed.

* @param bufObject the data object
* @param newValue the new data object
*/
public void setDataValue(int columnIndex, int rowIndex, Object bufObject, Object newValue)
Copy link
Collaborator

@jhendersonHDF jhendersonHDF Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that we actually need to implement this setDataValue variant here, and it may actually be problematic to do so, based on my old comment in the Javadoc above: "this method should, in general, not be called by atomic type DataProviders.".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but container types will need the same method if I'm correct. Will need a test file.

if (isFLT16)
newbufObject = Float.float16ToFloat((short)bufObject);
try {
setDataValue(index, newbufObject, newValue);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this setDataValue call is just recursively calling itself, which will lead to a stack overflow when editing float16 values inside an array type. I do believe we need this setDataValue variant though to support array types.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, exactly what happened.

@byrnHDF byrnHDF merged commit a4394b0 into HDFGroup:master May 3, 2024
4 checks passed
@byrnHDF byrnHDF deleted the master-float16 branch May 20, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - HDFView Improvements to the visual interface layer Component - Object Library Improvements to the object library Priority - 1. High 🔼 These are important issues that should be resolved in the next release Type - Improvement Improvements that don't add a new feature or functionality Type - New Feature Add a new API call, functionality, or tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants