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

Enum class operation #2883

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

schwieni
Copy link

The original behavior was that an operation was defined in different
integer values (mostly unsigned char and casadi_int). This is a more
strict definition.
Moreover, in a debugging session reading the words is much easier than
numbers.

@schwieni schwieni force-pushed the enum_class_operation branch 3 times, most recently from bbad62f to 3ac95df Compare February 20, 2022 13:45
@schwieni
Copy link
Author

@jaeandersson and @jgillis could someone review this PR, please?
Would this PR be of interested to you?
Thanks!

@@ -33,7 +33,7 @@
namespace casadi {
/** \brief An atomic operation for the SXElem virtual machine */
struct ScalarAtomic {
int op; /// Operator index
Operation op; /// Operator index
Copy link
Member

Choose a reason for hiding this comment

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

@jaeandersson your thoughts?

Copy link
Author

Choose a reason for hiding this comment

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

Please note, that the type of Operation is controlled by the enum, see: casadi/core/calculus.hpp:60
enum class Operation : unsigned char {
So, in this PR it is set to unsigned char. This can be changed.

The original behavior was that an operation was defined in different
integer values (mostly unsigned char and casadi_int). This is a more
strict definition.
Moreover, in a debugging session reading the words is much easier than
numbers.
@schwieni
Copy link
Author

Hi @jaeandersson and @jgillis, sorry to bother you again.
Would this PR be of interested to you?
The issue is just: the more Operations are added the more work it is to merge your work again. I did a rebase twice now.
A simple feedback would be appreciated.
Thank you! :-)

@jaeandersson
Copy link
Member

Sorry for the late answer. If I recall correctly, the int data type was originally chosen for efficiency reasons after some experimenting about what ran faster in practice. I think that makes the data size of the virtual machine instruction 16 bytes on common architectures:

  • For binary operations: 4 bytes for operation id, 4 bytes for output memory location and 2x4 bytes for input memory location
  • For constants: 4 bytes for operation id, 4 bytes for output memory location and 8 bytes for double constant

I definitely think an unsigned data type or enum would be cleaner. You might want to ensure that the data type is an unsigned 4 bytes integer in that case. In general, I wouldn't touch this code however without thoroughly investigating how it impacts existing use across applications. Any change to how the SX virtual machine operates or how SXElem are stored can lead to big performance issues. See also https://github.com/casadi/casadi/blob/main/CONTRIBUTING.md

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.

None yet

3 participants