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

Fix observe() method when called for SGVector/SGMatrix. #4626

Conversation

geektoni
Copy link
Contributor

@geektoni geektoni commented May 2, 2019

  • Fix observe() method when called for SGVector/SGMatrix. The given SGVector/SGMatrix was not cloned correctly (since copying them just copy the pointer to the raw data and it does not make a clone of the data itself).

I moved some useful type traits from type_case.h to base_types.h since I did not want to pollute too much SGObject.h with unnecessary headers.

Any comments on this change? @karlnapf @vigsterkr @gf712

T_SGMATRIX_INT32 = 24,
T_SGMATRIX_INT64 = 25,
T_UNDEFINED = 26
};
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it would be worth adding all the combinations of containers and primitive types, or some macro that would do that? Because right now stuff like SGVector<bool> isn't included (whether or not we actually use it is another question...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess it would make sense if we were to use it somewhere in Shogun. For instance, if we find a machine which needs to emit SGVector<bool> then we will add it.

src/shogun/base/base_types.h Outdated Show resolved Hide resolved
@geektoni geektoni force-pushed the feature/observable_framework branch from e540d7e to 42835a7 Compare May 3, 2019 10:02
src/shogun/base/SGObject.h Outdated Show resolved Hide resolved
@geektoni geektoni force-pushed the feature/observable_framework branch 2 times, most recently from 756b353 to 939c907 Compare May 9, 2019 13:37
@geektoni geektoni force-pushed the feature/observable_framework branch from c9a2064 to 4bdea29 Compare May 13, 2019 09:59
@geektoni geektoni force-pushed the feature/observable_framework branch 2 times, most recently from c8b39fe to 30ca2d6 Compare May 13, 2019 16:27
@geektoni geektoni force-pushed the feature/observable_framework branch from 30ca2d6 to d2bce30 Compare May 15, 2019 12:30
@geektoni
Copy link
Contributor Author

@karlnapf any final comments before I merge this? :)

@geektoni geektoni merged commit e8169ae into shogun-toolbox:feature/observable_framework May 15, 2019
@@ -316,6 +316,13 @@ namespace shogun
watch_method("some_method", &CMockObject::some_method);
}

virtual CSGObject* create_empty() const
Copy link
Member

Choose a reason for hiding this comment

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

curios: why did you add this here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Basically, since observe() emit a clone of the given value, we happens to call MockObject->clone(). However, the standard SGObject implementation of clone() assumes that there is a corresponding create() method, for that element, inside class_list.h. This is not true for MockObject since it is used only for testing purpose. Therefore, I needed to override create_empty such to return a new instance without relying on the class_list.h methods.

Copy link
Member

Choose a reason for hiding this comment

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

ah yep, I remember that stuff now. thanks!

@karlnapf
Copy link
Member

good!

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