-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
Scalar fields now rely on an internal offset to properly manage double/large values #116
Conversation
…e values (as long as the min and max values are not too far from each other!)
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.
Thinking to myself: would it be worht/intereseting to go as far as removing the inheritance of std::vector of ScalarField, and have the vector be a member ?
using std::vector<float>::shrink_to_fit; | ||
//! Shortcut to the (protected) std::vector::empty() method | ||
using std::vector<float>::empty; | ||
|
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.
Should also add one for resize
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.
I prefer/want the user to use 'resizeSafe', especially if a default value is provided for new elements (the offset wouldn't be taken into account with the resize function input - which would also be casted to float)
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.
And I agree about making the std::vector as a member, I hesitated quite a lot.
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.
Got it for resizeSafe,
I would personally put std::vector as a member, but it has worked for CC for years so its not that bit of a deal I think
inline void setValue(std::size_t index, ScalarType value) | ||
{ | ||
if (m_offsetHasBeenSet) | ||
{ | ||
// use the already set offset | ||
(*this)[index] = static_cast<float>(value - m_offset); | ||
} | ||
else if (std::isfinite(value)) | ||
{ | ||
// if the offset has not been set yet, we use the | ||
// first finite value as offset by default | ||
setOffset(value); | ||
(*this)[index] = 0.0f; | ||
} | ||
else | ||
{ | ||
// we can't set an offset | ||
(*this)[index] = static_cast<float>(value); // NaN/-inf/+inf should be maintained | ||
} | ||
} |
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.
Hum I wonder if this is ok in the general case:
If ScalarType is float and I have some big value stored on a double, calling setValue
will first cast my double into a float, so the loss of precision already happenned, its too late to apply the offset
The same thing goes for getValue which returns a ScalarType
Unlesss scalar type is no longer meant to be a float
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.
Indeed, ScalarType is double and should not be changed anymore (this would kill the purpose of all this code). I don't think we need to support the float case.
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.
In that case I think ScalarType should be removed (replaced with double) globally, or at least in these function, so its explicit that only double are expected
…e strange things when setting the first non-zero value later!
No description provided.