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

Scalar fields now rely on an internal offset to properly manage double/large values #116

Merged
merged 4 commits into from
Dec 8, 2024

Conversation

dgirardeau
Copy link
Member

No description provided.

Copy link
Contributor

@tmontaigu tmontaigu left a 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;

Copy link
Contributor

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

Copy link
Member Author

@dgirardeau dgirardeau Nov 24, 2024

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)

Copy link
Member Author

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.

Copy link
Contributor

@tmontaigu tmontaigu Nov 24, 2024

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

Comment on lines +173 to +192
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
}
}
Copy link
Contributor

@tmontaigu tmontaigu Nov 24, 2024

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

Copy link
Member Author

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.

Copy link
Contributor

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!
@dgirardeau dgirardeau merged commit 83732e7 into master Dec 8, 2024
16 checks passed
@dgirardeau dgirardeau deleted the double_sf branch December 8, 2024 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants