-
Notifications
You must be signed in to change notification settings - Fork 164
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
Fix allTrue to return true on empty input vector #2888
Conversation
Make Modelica.Math.BooleanVectors.allTrue equivalent to obsolete (and to be removed) function Modelica.StateGraph.Temporary.allTrue.
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.
Looks good, but I would also highlight this in the release notes as it is a breaking change.
(Even though the previous behavior was plain weird.)
Yes, I will care for this kind of "critical" changes. They are usually listed in the release notes as, see for example ModelicaStandardLibrary/Modelica/package.mo Lines 2486 to 2487 in b020379
|
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.
With this change a valid user model might give different results without any notice or error message. Therefore, such a breaking change is critical. I would suggest to only make this change if a conversion script is provided. Having a notice in the release notes is not sufficient. An alternative is to add a second function with a different name.
I consider this as a bugfix, that will be well documented in the release notes. If we still want to keep/duplicate the current implementation to not break existing behaviour we would also need to duplicate the Modelica.Blocks.MathBoolean.{And, Nand} blocks then. Even worse, behaviour already is inconsistent between Modelica.Math.BooleanVectors.allTrue and Modelica.StateGraph.Temporary.allTrue. See for example the C++ Standard Library where std::all_of returns true if the range is empty. |
Well, it would always be possible to add an ObsoleteModelica class or similar with the old, bad functionality, right? |
Since the current implementation of
This means existing models will continue to behave like they did and users making use of the allTrue funtion from MSL will have the correct expected behaviour. |
@dietmarw wrote:
That is one possibility, and I think it is acceptable and likely the best, the downside is that existing users will have to do more work - for the many cases where the vector isn't empty. Making it conditional on the length of input seems too complicated. Another possibility would be to use convertMessage. However, assumedly there are not many uses of this function - so a simple safe conversion would do. |
Can't we just fix this corner case as proposed please? Considering that Modelica.StateGraph.Temporary.allTrue gets converted to Modelica.Math.BooleanVectors.allTrue (since we want the fixed behaviour for backward compatibility), but Modelica.Math.BooleanVectors.allTrue gets converted to ObsoleteModelica4.Math.BooleanVectors.allTrue (to retain the faulty behaviour for backward compatibility), I wonder what happens if conversion will be applied recursively. Once again, also Modelica.Blocks.MathBoolean.{And, Nand} need to be considered, since those blocks call Modelica.Math.BooleanVectors.allTrue. I also definitely do not want to introduce a new enumeration just for the backward-compatibility. type AllTrueIfEmpty = enumeration(FixedBehaviour, DoNotUse_LegacyBehaviour); |
This is not a bug-fix but a change of behaviour. The current documentation of the function states:
So, the function operates exactly as stated in the documentation and therefore this is clearly no bug fix. If the Boolean input vector is empty, then there is no input and it is an arbitrary choice what to do in this case. It can be argued that in some applications it gives nicer code if "true" is returned in case of empty vector (but this needs to be anyway analyzed in every particular case), and therefore it would be better to return true in this case. I understand that conversion scripts are not nice in this case. Therefore, I would propose to keep this function and add a second function with a different name (and use this second function in "nand"). Possible name: andTrue |
@MartinOtter If you close a PR with unmerged commits you should also change the milestone to never and add the invalid label. Otherwise the PRs will shos up in the automatically generated release notes. |
Make Modelica.Math.BooleanVectors.allTrue equivalent to obsolete (and to be removed) function Modelica.StateGraph.Temporary.allTrue.
Closes #682, #2860.