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

Issue #1042 - Cross-Product for lists of kernels #1059

Merged
merged 1 commit into from
May 8, 2013
Merged

Issue #1042 - Cross-Product for lists of kernels #1059

merged 1 commit into from
May 8, 2013

Conversation

van51
Copy link
Contributor

@van51 van51 commented May 5, 2013

I haven't added a check on whether each sub-list contains kernels of the same type.
Let me know if you think it's necessary.

@karlnapf
Copy link
Member

karlnapf commented May 5, 2013

Hi,
thanks a lot for the patch!

The code is a little complicated to read (these kind of problems can be solved in a more elegant way if done recursively). However, if it works, it doesnt really matter.

My first question: Does it work? Could you create an example and post the output of it? This has to be done anyway at some point for illustration and also for unit testing.

Second question: Is it memory clean? For that you will have to run your example in valgrind.

I will also comment on some minor style issues in the code

{
CList* return_list = new CList(true);
if (!kernel_list)
{
Copy link
Member

Choose a reason for hiding this comment

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

We do single if statements without the {}

@karlnapf
Copy link
Member

karlnapf commented May 5, 2013

Okay, nice! Looking forward to your reply

@van51
Copy link
Contributor Author

van51 commented May 5, 2013

Hello, thanks for your reply!
I will go through your comments and adjust the code (and I thought I was careful)!
It is working however and it is memory-clean. I'll incorporate the example I have made in the class's unit test and
post the output I get from valgrind (unless that can be done in testing as well somehow).
Also, I agree that it is a bit confusing to read so I will try to change it.
I'll start working on it in a while and get back to you

@karlnapf karlnapf closed this May 5, 2013
@karlnapf karlnapf reopened this May 5, 2013
@van51
Copy link
Contributor Author

van51 commented May 5, 2013

The reason I have that first loop and ended up having the code written this way was because I wanted to avoid creating new CombinedKernels on the fly and then copying the already listed kernels from the old kernels to the newly created ones. I think that would also be the case in recursion. However it would probably be more intuitive and understandable as you said. Do you prefer it the second way? If yes, don't hesitate to tell me, it won't be any trouble to change it

@van51
Copy link
Contributor Author

van51 commented May 6, 2013

I 've mades the changes you said. Also I've added a unit test and added a line in another one to fix a memory leak.
I didn't add anything to the modular typemap, because I am not sure what to edit. Hopefully, that's all that's left and
if you explain it to me, I can do it tomorrow. Unless you would prefer to have it in a recursion as well, which I am fine with.
Anyway, I am looking forward to your input!

{
CList* c_list= dynamic_cast<CList* >(list);
if (!c_list)
SG_SERROR("CCombinedKernel::combine_kernels() : Failed to cast list of type "
Copy link
Member

Choose a reason for hiding this comment

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

{ }

@karlnapf
Copy link
Member

karlnapf commented May 8, 2013

Hi!
Sorry for the long delay, was travelling.
I am fine with the way you do it. Nice patch! :)
Also thanks for resolving the memory leak

karlnapf added a commit that referenced this pull request May 8, 2013
Issue #1042 - Cross-Product for lists of kernels
@karlnapf karlnapf merged commit a641e16 into shogun-toolbox:develop May 8, 2013
@karlnapf
Copy link
Member

karlnapf commented May 8, 2013

@van51 while I wanted to write an example showing how to use this for modelselection, I realised that you change the order of the kernels.

So if the input kernel list is (a, b), then the output list's combined kernels should have subkernels in the same order (a[i],b[j]). Otherwise it gets confusing.
I will shortly add the example with the way its done currently, so you will have to change the order in there (just two sub-kernels) or it will crash

Could you add a note to the documentation of the method that the caller gets a list which does ref-counting
Thanks!
Heiko

@karlnapf
Copy link
Member

karlnapf commented May 8, 2013

Here is the example that you will have to change once the ordering is fine

#1066
Should be just 4 lines (exchange 0 and 1 in kernel index)

@van51
Copy link
Contributor Author

van51 commented May 8, 2013

Hello! no worries about the delay, I hope you had a nice trip!
I have made the changes you said and I will make a new PR.
Please review it when you have the time!

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