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

Feature/equals with tags #4069

Merged
merged 16 commits into from Jan 9, 2018

Conversation

karlnapf
Copy link
Member

@karlnapf karlnapf commented Jan 5, 2018

@lisitsyn This almost works, and side-steps a lot of older code (will delete later).

One thing that is quite annoying is "old" parameter registrations are not covered by tags. See e.g.

m_parameters->add_vector(&m_array.array, &m_array.current_num_elements, "array",
			"Memory for dynamic array.");

in CDynamicObjectArray. This causes some tests to fail when using equals via tags. I am on it, but let me know if you have a quick fix for things like the above (reason SG_ADD is not used is since only a smaller part of the array is registered...)

@@ -153,7 +153,12 @@ namespace shogun
auto compare_impl(maybe_most_important, T* lhs, T* rhs)
-> decltype(lhs->equals(rhs))
{
return lhs->equals(rhs);
if (lhs && rhs)
Copy link
Member Author

Choose a reason for hiding this comment

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

@lisitsyn let me know if this is the right place to add those checks

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that's a good catch.

@karlnapf karlnapf requested a review from lisitsyn January 5, 2018 18:45
@@ -88,6 +88,16 @@ namespace shogun
return m_properties;
}

inline bool operator==(const AnyParameter& other)
{
return m_value == other.get_value();
Copy link
Member Author

Choose a reason for hiding this comment

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

good? not good?

Copy link
Member

Choose a reason for hiding this comment

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

Probably ok. Maybe needs a comment that it doesn't consider properties.

@@ -28,6 +28,7 @@

#include <stdlib.h>
#include <stdio.h>
#include <typeinfo>
Copy link
Member Author

Choose a reason for hiding this comment

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

good? not good?

Copy link
Member

Choose a reason for hiding this comment

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

Was it missed?

@@ -820,7 +743,7 @@ AnyParameter CSGObject::get_parameter(const BaseTag& _tag) const
const auto& parameter = self->get(_tag);
if (parameter.get_value().empty())
{
SG_ERROR("There is no parameter called \"%s\" in %s",
SG_ERROR("There is no parameter called \"%s\" in %s\n",
Copy link
Member Author

Choose a reason for hiding this comment

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

gotcha!

return false;
}

/* Assumption: can use SGObject::get_name to distinguish types */
Copy link
Member Author

Choose a reason for hiding this comment

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

good? not good?


SG_SDEBUG("Comparing parameter %s::%s.\n", this->get_name(),
tag.name().c_str());
if (own != given)
Copy link
Member Author

Choose a reason for hiding this comment

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

all the magic happens in this single line, awesome!

std::stringstream ss;
std::unique_ptr<AnyVisitor> visitor(new ToStringVisitor(&ss));

ss << "Own parameter " << this->get_name() << "::" << tag.name() << "=";
Copy link
Member Author

Choose a reason for hiding this comment

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

I would actually like to print the differences here (also for vectors which is currently shown as ...), as that was useful in unit-testing in the past

Copy link
Member

Choose a reason for hiding this comment

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

It could be a custom visitor. Or we can add another interface 'Reducer'.

@@ -88,6 +88,16 @@ namespace shogun
return m_properties;
}

inline bool operator==(const AnyParameter& other)
{
return m_value == other.get_value();
Copy link
Member

Choose a reason for hiding this comment

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

Probably ok. Maybe needs a comment that it doesn't consider properties.

@@ -28,6 +28,7 @@

#include <stdlib.h>
#include <stdio.h>
#include <typeinfo>
Copy link
Member

Choose a reason for hiding this comment

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

Was it missed?

}

/* Assumption: objects of same type have same set of tags. */
for (auto it=self->map.cbegin(); it!=self->map.cend(); it++)
Copy link
Member

Choose a reason for hiding this comment

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

Why not auto it : self->map?

std::stringstream ss;
std::unique_ptr<AnyVisitor> visitor(new ToStringVisitor(&ss));

ss << "Own parameter " << this->get_name() << "::" << tag.name() << "=";
Copy link
Member

Choose a reason for hiding this comment

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

It could be a custom visitor. Or we can add another interface 'Reducer'.

@@ -153,7 +153,12 @@ namespace shogun
auto compare_impl(maybe_most_important, T* lhs, T* rhs)
-> decltype(lhs->equals(rhs))
{
return lhs->equals(rhs);
if (lhs && rhs)
Copy link
Member

Choose a reason for hiding this comment

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

Yeah that's a good catch.

@lisitsyn
Copy link
Member

lisitsyn commented Jan 6, 2018

You might want to fix the codestyle ;)

git clang-format-3.8 --commit 6f1fd162892988e212b5ddfc6de15db3a8bf1026 --binary /usr/bin/clang-format-3.8

}

TEST(SGObject,equals_DynamicObjectArray_equal)
TEST(SGObject,DISABLED_equals_DynamicObjectArray_equal)
Copy link
Member Author

Choose a reason for hiding this comment

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

@lisitsyn I had to disable this until we fix the registration of that partly used array parameter

@karlnapf
Copy link
Member Author

karlnapf commented Jan 8, 2018

@lisitsyn ok it was green now apart form style, which I fixed. Let's wait for travis to be sure, but you can review now. And potentially merge

@@ -147,6 +154,26 @@ namespace shogun
return sg_io;
}

float64_t get_global_fequals_epsilon()
{
return sg_fequals_epsilon;
Copy link
Member Author

Choose a reason for hiding this comment

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

@vigsterkr this is fucked up, but the way it was before was even more so. We should just get rid of all of this accuracy business and rather fix the serialization, which should not be lossy (in my eyes)


// Handle this separately since NAN is unordered
if (CMath::is_nan((float64_t)a) && CMath::is_nan((float64_t)b))
return true;

// Required for JSON Serialization Tests
if (tolerant)
return CMath::fequals_abs<T>(a, b, eps);
if (get_global_fequals_tolerant())
Copy link
Member Author

Choose a reason for hiding this comment

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

@vigsterkr here the beauty is

{
// global fequals epsilon might override passed one
// hack for lossy serialization formats
float64_t eps = std::max(eps_, get_global_fequals_epsilon());
Copy link
Member Author

Choose a reason for hiding this comment

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

here it comes ...


SG_UNREF(array1);
SG_UNREF(array2);
}

TEST(SGObject,equals_DynamicObjectArray_equal_after_resize)
TEST(SGObject, DISABLED_equals_DynamicObjectArray_equal_after_resize)
Copy link
Member Author

Choose a reason for hiding this comment

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

@lisitsyn @vigsterkr I disabled this for now. With this patch, DynamicObjectArray is not serializable anymore. We need to fix the registration of the underlying array (not all of it, only used parts)

@lisitsyn
Copy link
Member

lisitsyn commented Jan 8, 2018

Ok this is deffs improvement even though accuracy business is meh :)

@karlnapf
Copy link
Member Author

karlnapf commented Jan 8, 2018

Ok baby, lets merge it, just fixed the style issues....

@karlnapf
Copy link
Member Author

karlnapf commented Jan 8, 2018

I take that back, windows is not happy, https://ci.appveyor.com/project/vigsterkr/shogun/build/1668#L16427

@karlnapf
Copy link
Member Author

karlnapf commented Jan 9, 2018

One unit test was actually broken (and under linux only passed accidentally with an invalid read memory error). Should be fixed now.

@karlnapf
Copy link
Member Author

karlnapf commented Jan 9, 2018

windows times out and travis is angry about style (even though I ran the checker, I think it is confused).
I think that means merge ... Objections?

@karlnapf
Copy link
Member Author

karlnapf commented Jan 9, 2018

I'll just do it and fix tomorrow if there are problems

@karlnapf karlnapf merged commit e4a19a2 into shogun-toolbox:develop Jan 9, 2018
@karlnapf karlnapf deleted the feature/equals_with_tags branch January 9, 2018 23:52
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

2 participants