-
Notifications
You must be signed in to change notification settings - Fork 361
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
Automatic conversion of integers to doubles when setting parameters #2024
Conversation
Co-authored-by: jasperalbers <jasperalbers45@gmail.com>
Co-authored-by: jasperalbers <jasperalbers45@gmail.com>
Co-authored-by: jasperalbers <jasperalbers45@gmail.com>
@ackurth Could this PR be move from Draft to Open? |
The PR as it is right now does address the issue of passing integers where doubles are expected in cases like |
Change order of type checks when converting a token array to a vector
…doubles_array_test
@ackurth There seems to be some formatting errors, could you fix this? |
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.
Thanks! I included some comments in the code below.
sli/tokenutils.cc
Outdated
@@ -97,13 +106,20 @@ template <> | |||
float | |||
getValue< float >( const Token& t ) |
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 don't think we use float anywhere in NEST, could you try to remove this function and see if anything breaks?
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 removed this function from the code and everything seems to work fine, see c21eef4.
sli/tokenutils.cc
Outdated
DoubleDatum* dd = dynamic_cast< DoubleDatum* >( t.datum() ); | ||
if ( dd ) | ||
{ | ||
return ( float ) dd->get(); |
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.
Turn into proper static cast if kept.
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.
See above.
sli/tokenutils.cc
Outdated
IntegerDatum* id = dynamic_cast< IntegerDatum* >( t.datum() ); | ||
if ( id ) | ||
{ | ||
return ( float ) id->get(); |
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.
See above.
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.
See above.
sli/tokenutils.cc
Outdated
|
||
// we have to create a Datum object to get the name... | ||
DoubleDatum const d; | ||
throw TypeMismatch( d.gettypename().toString(), t.datum()->gettypename().toString() ); | ||
} | ||
|
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.
Se if setValue< float >
below can be removed as well.
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.
Same as above.
Co-authored-by: Hans Ekkehard Plesser <hans.ekkehard.plesser@nmbu.no>
Co-authored-by: Hans Ekkehard Plesser <hans.ekkehard.plesser@nmbu.no>
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.
Thanks!
Fixes #2009.
The implementation silently converts integers to doubles (both for simple and vector data) where doubles are expected.
We removed the tests that became obsolete due to this new behavior.