-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add meta example features-char-string #4423
Add meta example features-char-string #4423
Conversation
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.
A made a few comments.
Does this compile/execute? What about the other cpp examples, do they still work?
Also, does it work from other targets (at least python/java?). We will have our CI back to check this for you soon ...
You are right we dont really need any output here, as nothing really happens. THese outputs are for making sure that algorithms dont all of a sudden output different results. |
Our CI (before PR) is down atm. Can you confirm this example runs smooth locally (say c++, python, and maybe java)? |
Apologies for the late reply. |
Shall we update and merge this one? |
Yes, that is the plan. I have started making changes but they will be ready mid next week if that is ok with you. |
Sure of course. |
5f6cc7a
to
be01de6
Compare
An update for this one - I am working on refactoring the watch_method function to be able to register functions that take arguments. The features-char-string example needs that. I think made some progress but I need to work a bit more. @gf712 I believe you will encounter this problem when you start converting undocumented python examples. |
@avramidis we cannot really accept arguments in the watched functions. At least not with the current design, and this was a quite conscious decision. The way around this is to communicate with the classes via put get (to set parameters) and then call helper methods. Why does |
OK, thanks for the explanation. The max_string_length doesn't need it but the set_feature_vector shogun/src/shogun/features/StringFeatures.cpp Line 248 in f8a120b
|
Actually that is a method that we do not want to expose to SWIG, so rather just hide it. But in cases where we want things like this, it would be best added to the base class. |
#![create_features] | ||
Features f = string_features(words, enum EAlphabet.RAWBYTE) | ||
#![create_features] | ||
|
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.
maybe we can add some of the basic things that one would do with string features?
Like extract the string list?
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.
Good idea - I can do that.
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 am stuck. I am trying to make get_features work. However, it is overloaded and it is used in many undocumented python examples.
shogun/src/shogun/features/StringFeatures.cpp
Line 1022 in 1c9ac30
template<class ST> SGStringList<ST> CStringFeatures<ST>::get_features() |
shogun/src/shogun/features/StringFeatures.cpp
Line 1030 in 1c9ac30
template<class ST> SGString<ST>* CStringFeatures<ST>::get_features(int32_t& num_str, int32_t& max_str_len) |
shogun/src/shogun/features/StringFeatures.cpp
Line 1062 in 1c9ac30
template<class ST> void CStringFeatures<ST>::get_features(SGString<ST>** dst, int32_t* num_str) |
I don't want to put them in the base interface because they are specific to string features.
You said earlier
The way around this is to communicate with the classes via put get (to set parameters) and then call helper methods.
put and get for watched parameters is fine but what helper methods you mean?
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 just spend quite some time trying to register get_features
with watch_param
. Tricky one!
You will first need to make the method const
(both of them as one calls the other). The compiler error you see when trying to register it comes from const, not from overloading (although it looks like that).
Then you will hit another compiler error, which complains about bool shogun::any_detail::compare
not matching with the call (among others). This comes from the fact that anything that is ever any'ed in Shogun needs to be comparable and cloneable for SGObject::clone/equals
. This hasn't yet been done for SGStringList
. You will have to add equals
and clone
to SGStringList
(see SGMatrix/SGVector/ for inspiration). Then those compiler errors should vanish. I don't know what happens then, but it will bring you one step closer to making the get
work for the list of string features.
Nice, thanks for that. I have a branch for trying to watch methods with
arguments. I was working on that in the weekend. We definitely don't need
something like that, right?
…On Mon, 14 Jan 2019, 22:52 Heiko Strathmann ***@***.*** wrote:
***@***.**** commented on this pull request.
------------------------------
In examples/meta/src/features/string_char.sg
<#4423 (comment)>
:
> @@ -0,0 +1,10 @@
+File words = csv_file("../../data/words.dat")
+
+#![create_features]
+Features f = string_features(words, enum EAlphabet.RAWBYTE)
+#![create_features]
+
I just spend quite some time trying to register get_features with
watch_param. Tricky one!
You will first need to make the method const (both of them as one calls
the other). The compiler error you see when trying to register it comes
from const, not from overloading (although it looks like that).
Then you will hit another compiler error, which complains about bool
shogun::any_detail::compare not matching with the call (among others).
This comes from the fact that anything that is ever any'ed in Shogun needs
to be comparable and cloneable for SGObject::clone/equals. This hasn't
yet been done for SGStringList. You will have to add equals and clone to
SGStringList (see SGMatrix/SGVector/ for inspiration). Then those
compiler errors should vanish. I don't know what happens then, but it will
bring you one step closer to making the get work for the list of string
features.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4423 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHEjTfED3XnXqoaybFwiI2AxVl-eHts_ks5vDQojgaJpZM4Yw5h2>
.
|
I think that would be quite hard as then we would need multiple |
I also think our new API design doesn't need that (as far as I can see yet) |
I was trying to do that with variadic templates. I still get some errors
but it can be done I think.
I have to dig more into the new API because it seems I have some knowledge
gaps.
…On Mon, 14 Jan 2019, 22:59 Heiko Strathmann ***@***.*** wrote:
I also think our new API design doesn't need that (as far as I can see yet)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4423 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHEjTUFnpJ_-zHvPtxjV0tPElHtSEBQ6ks5vDQvggaJpZM4Yw5h2>
.
|
I mean sure it is possible to offer this, exactly using those flexible templates. But it obscures the BTW the new API is all moving around. We are trying to figure out what is best still. |
Any news here on this? |
yes, I am still working on it but I am close. I had to create clone/equals methods for a couple of more classes which caused some unit tests to fail. I fixed those but now it fails for python/java generated examples. I will push again for feedback. |
ah ok. Yeah just push stuff. It is easiest to discuss it here. Might save you some time if devs point out stuff. Shogun is a beast ;) |
be01de6
to
71a7f3e
Compare
The runtime error for the python string_char.sg meta example is:
|
|
||
TEST(StringFeaturesTest,equals) | ||
{ | ||
SGStringList<char> strings = generateRandomStringData(); |
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.
we would want a test for SGStringList
... all shogun objects are tested for clone and equals in here
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've seen those. These are tests for constructors without arguments, right?
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.
For now, yes
We might add a version with random content soon
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 here (remove this). I would however love to see a test for clone/equals of SGStringList
as those are very low level operations
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.
And we should probably do these tests for all legal template arguments using the googletest magic.
@gf712 can help here
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.
Yup, for this you need to define the types you want to test:
shogun/tests/unit/mathematics/linalg/operations/Eigen3_operations_unittest.cc
Lines 47 to 50 in 13961a1
typedef ::testing::Types< | |
int8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t, float32_t, | |
float64_t, floatmax_t, char> | |
AllTypes; |
Associate it to a (empty) class:
shogun/tests/unit/mathematics/linalg/operations/Eigen3_operations_unittest.cc
Lines 26 to 29 in 13961a1
template <typename T> | |
class LinalgBackendEigenAllTypesTest : public ::testing::Test | |
{ | |
}; |
TYPED_TEST_CASE(LinalgBackendEigenAllTypesTest, AllTypes); |
And then just pass the class to the TYPED_TEST macro
TYPED_TEST(LinalgBackendEigenAllTypesTest, SGVector_add) |
In the test you can access the type with
TypeParam
it seems weird that this error shows up. Are you sure you are running the same shogun version as the source shows? You could find out via printing all parameter names using |
I will work on the |
it is pretty easy to add a blacklist to the logic. You would check if the dictionary contains the blacklist key "ExcludeImport", and then assume you get a list of imports to exclude.... |
That what I was thinking too. I hope this is the last problem with this PR :) |
|
Hehehe, you will be surprised ;) |
OK the JAVA problem is fixed. Tomorrow I will take a look the octave one. |
Cool! Can you push so we can see what you did in the end? |
For octave can you paste the generated code? |
bfd1c31
to
2fbabc2
Compare
Ok. I pushed the changes. I tested octave on my pc and there are no errors. |
Cool, just checked the changes, all looks good. I will wait for the CI :) |
Great! Thank you! |
@avramidis octave failed. Could you pls post the listing of the char features example? |
Error is explained here |
Have a look at the incoming typemap....looks like we need to write an octave string list typemap to make this work. It is actually quite good that we spotted that as it means one was never ever able to execute string based algorithms from octave ... :/ |
OK no problem. I will make the change. |
2fbabc2
to
cc41340
Compare
6656e93
to
c0b5dc8
Compare
@karlnapf are the changes ok with you? |
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.
Great effort for the typemap!!
Did you do some basic checks in terms of memory errors/leaks and passing string in and out, eg out one in then retrieve it back and ensure it is the same? And all the local variables of the octave program/shogun are still valid?
Then it’s good to be merged :)
We can then later add strings as part of the testing files to ensure results don’t change, but that can be another pr
|
||
for (i = 0; i < num_strings; i++) { | ||
c(i)=std::string(str[i].string); | ||
SG_FREE(str[i].string); |
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.
Does this maybe cause problems? The original string is destroyed?
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.
Correct. I copied these from the other languages interfaces. I removed them.
c0b5dc8
to
336ce47
Compare
336ce47
to
2e81426
Compare
Very nice work! This now allows to port quite a few more examples |
A simple meta example for CStringFeatures.
I would like to make changes and add output file for an integration test but I am not sure if the current outputs are enough for that. Currently, it stores "max_string_length", "number_of_strings" and "length_of_first_string". I don't think that is possible to practically check all the values of "strings".
However, if you don't have a better idea I could add eight variables that store the value of the first vector before and after the change to "test".