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
Extend the meta-language to support keyword arguments #4128
Conversation
@karlnapf Can we get a real example of this instead of my |
Ah this is great, thanks for that! I will review a bit in my phone as I am travelling |
As for real examples, keep in mind that the kwargs.sg file is translated and executed. I think creating a few objects, mimicking their constructors, in your file should re real enough? |
Can’t see the travis logs but all jobs failed which is due to the putting Parameter c of a Gaussian kernel |
You can both cover the current constructors and a factory method |
Yeah I know, but they would fail anyway since I've only added Python support for now. Will update with a real example and see how it goes |
Sweet! I would start with making an existing ctor work and then do the factory method next |
examples/meta/generator/parse.py
Outdated
@@ -201,6 +192,25 @@ def p_argumentList(self, p): | |||
|
|||
p[0] = {"ArgumentList": arguments} | |||
|
|||
def p_argumentList_nonEmpty(self, p): |
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.
Not sure about this capitalisation underscore mix
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.
haha yeah you're right. Will make this consistent
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.
Initial underscores t_
and p_
are enforced by the parsing library, that's why there is some confusion in this file
2f5b3e3
to
47f3f98
Compare
This piece of python code
Throws the following error
while this piece of C++ code is fine
|
d67a7f6
to
491a0e6
Compare
@lisitsyn here is someone using tags, so maybe you can help? |
Similarly, as the only language octave is complaining about:
throwing this error:
while the equivalent code in all other languages works fine |
@lisitsyn Here's an issue related to the SWIG interfaces and the parameter framework. In python, I can't see what the parameters of an object is:
Which means I have to dig around in C++ code to find the parameter names. Can this be fixed? |
I reckon a .i include missing in our swig descriptors for typemapping std::set
… On 29 Jan 2018, at 19:17, Esben Sørig ***@***.***> wrote:
@lisitsyn Here's an issue related to the SWIG interfaces and the parameter framework. In python, I can't see what the parameters of an object is:
In [1]: from shogun import GaussianKernel
In [2]: k = GaussianKernel()
In [3]: k.parameter_names()
Out[3]: <Swig Object of type 'std::set< std::string > *' at 0x11408e458>
Which means I have to dig around in C++ code to find the parameter names. Can this be fixed?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
491a0e6
to
4f60a64
Compare
@sorig i've just tried to do that what i said above.... it's not working... i'll let u know if i have found a solution |
@sorig ok i've managed to do this:
i guess this is what you would like to have right? :) |
4f60a64
to
e3d98d9
Compare
@vigsterkr Amazing, thanks! Crucial functionality for people working from the swig interfaces |
@sorig lemme push it to develop |
3cc0e37 is the patch that gets u the above mentioned functionality |
we have actually a problem: std::set isn't supported in the following interfaces: lua, java, set, r, octave, c#. |
Yeah, it looks like those interfaces just broke with the change. Is it really necessary to have |
@sorig if we wanna switch we should then switch the interface to use |
@lisitsyn what do you think? custom |
@vigsterkr std::vector for sure! |
@lisitsyn do you have any clue why
is surrounded by
? |
commit 5423ead
one would hope that there's no more compiler error, or? :D |
Who knows.. :) |
e3d98d9
to
5ea4097
Compare
Great, thanks a lot! |
All green except for Octave (see error description above) which seems to be a bug with the octave interface and float types. I'm not currently able to install octave on my macine to figure out what the issue is. Is there a server somewhere where I can test all the interfaces? It looks like there are issues with basic types in several of the interface languages. Would be good to write a thorough test case once this PR is merged. |
examples/meta/src/meta_api/kwargs.sg
Outdated
|
||
GaussianKernel k(log_width=2.0) | ||
|
||
GaussianKernel k2(log_width=14.0) |
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.
why two kernels?
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.
One of them had a boolean keyword argument earlier, but that fails in python. I’ll revert it and comment it out
examples/meta/src/meta_api/kwargs.sg
Outdated
#kernel_machine("GaussianKernel", a=glob_fun(kw=123)) | ||
|
||
|
||
# REAL EXAMPLE |
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.
Real example
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.
Cool!
I suggest you comment out everything in the API example that currently fails, and then we merge this.
Then I can take over and fix the interface issues ...
5ea4097
to
c888459
Compare
OK, included last review changes. This is ready to be merged |
…ructors and factory functions
c888459
to
c71feba
Compare
Excellent, thanks! |
changes are described in shogun-toolbox#4128: Changing from translation type A) to B)
* added remaining factory functions to Python API * add factory wrapper in loop * fixes error handling inside _swig_monkey_patch * simplified adding factory functions * fixed string check logic * changed python.json to accept kwargs as is, changes are described in #4128: Changing from translation type A) to B) * minor changes to pipeline example to work with new python API * keep track of getters automatically
* added remaining factory functions to Python API * add factory wrapper in loop * fixes error handling inside _swig_monkey_patch * simplified adding factory functions * fixed string check logic * changed python.json to accept kwargs as is, changes are described in shogun-toolbox#4128: Changing from translation type A) to B) * minor changes to pipeline example to work with new python API * keep track of getters automatically
* added remaining factory functions to Python API * add factory wrapper in loop * fixes error handling inside _swig_monkey_patch * simplified adding factory functions * fixed string check logic * changed python.json to accept kwargs as is, changes are described in shogun-toolbox#4128: Changing from translation type A) to B) * minor changes to pipeline example to work with new python API * keep track of getters automatically
Allows keyword arguments in class constructors and factory functions (when the factory function is called to set the value of a newly initialised variable).
The update in meta-language allows translation of statements like these (meta-language):
A) To something like this (python)
B) Or something like this (python):
Changing from translation type A) to B)
To get A), the
targets/python.json
file should contain:And to get B), the
targets/python.json
should contain:Where do keyword arguments not work?
Keywords arguments cannot be used anywhere else than in class constructors to initiliase variables and global functions to initialise variables. See the following examples: