Skip to content

Implicit conversions for put/get - #5056

Open
gf712 wants to merge 1 commit into
shogun-toolbox:developfrom
gf712:implicit_conversions
Open

Implicit conversions for put/get#5056
gf712 wants to merge 1 commit into
shogun-toolbox:developfrom
gf712:implicit_conversions

Conversation

@gf712

@gf712 gf712 commented Jun 4, 2020

Copy link
Copy Markdown
Member

Implicit conversions as discussed in #5045. Would have to add all the primitive types, and probably come up with some better abstraction. This does the same as the Any::CastingRegistry, but by putting all this logic in SGObject we can add some very specific edge cases, like std::variant. I think this separates Any as a "type safe" type erasure abstraction from the parameters that use it.

@gf712
gf712 requested a review from vigsterkr June 4, 2020 14:58
@gf712
gf712 force-pushed the implicit_conversions branch from 96b8998 to 748be8b Compare June 4, 2020 14:59
EXPECT_THROW(obj->get<float64_t>(MockObject::kInt), ShogunException);
EXPECT_THROW(obj->get(Tag<float64_t>(MockObject::kInt)), ShogunException);
EXPECT_EQ(obj->get<float64_t>(MockObject::kInt), 10.0);
EXPECT_EQ(obj->get(Tag<float64_t>(MockObject::kInt)), 10.0);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@karlnapf so this won't throw anymore

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yep.
But everything that looses information throws?
maybe a test for some examples?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

by lose information you mean something like 1.3 becomes 1? Right now I think this function only supports checks for overflow, e.g. int -10 is converted to unsigned int.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, we wouldnt want that to happen for now I think.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@vigsterkr would it make sense to extend safe_convert to check floating point casting to integers and see if the delta is larger than fepsilon?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I always thought that the safe_convert functions would be for overflow checks, not for loss of information when going from discrete to floating?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(on the other hand, why not :) )

@gf712
gf712 force-pushed the implicit_conversions branch from 748be8b to 8efeb15 Compare June 4, 2020 16:52
@stale

stale Bot commented Dec 9, 2020

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the stale label Dec 9, 2020
@gf712 gf712 added Tag: Cleanup and removed stale labels Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants