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

added list initialisation #4606

Merged
merged 6 commits into from
Apr 17, 2019
Merged

added list initialisation #4606

merged 6 commits into from
Apr 17, 2019

Conversation

gf712
Copy link
Member

@gf712 gf712 commented Apr 11, 2019

list initialisation to replace starting empty vector and the replace elements

@@ -12,7 +12,6 @@
"InitialSeperatorWhenArgs>0": false
},
"string": "$name = $arguments",
"CharVector": "$name = zeros(1, $arguments, 'char')",
Copy link
Member Author

Choose a reason for hiding this comment

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

this doesn't work in octave (4.4.1)

"RealVector": "$name = NArray['float', [$arguments])",
"LongRealVector": "$name = NArray['float', [$arguments])",
"ComplexVector": "NArray['scomplex', [$arguments])"
},
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 tested this out with the most recent numo/NArray version

Copy link
Member Author

Choose a reason for hiding this comment

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

ah actually, what type are the zero constructors? I can't find it anywhere

Copy link
Member

Choose a reason for hiding this comment

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

what do you mean?

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry, this was when I was confused as to how to construct with a list of args in ruby. was simpler than I thought! :D

# custom SGType construction
if typeKey == "ShogunSGType"\
and init[0][typeKey] in self.targetDict["ListInit"]:
template = Template(self.targetDict["ListInit"][init[0][typeKey]])
Copy link
Member Author

Choose a reason for hiding this comment

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

This should probably be moved out of the condition. This substitution only works if there is an implementation of the list initialiser of the target language

@@ -38,6 +38,18 @@
"RealMatrix": "DoubleMatrix $name = new DoubleMatrix($arguments)",
"LongRealMatrix": "DoubleMatrix $name = new DoubleMatrix($arguments)"
},
"ListInit": {
"BoolVector": "BoolVector $name = new BoolVector({$arguments})",
Copy link
Member Author

Choose a reason for hiding this comment

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

not sure how to do this one

Copy link
Member

Choose a reason for hiding this comment

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

Don’t know either, last resort would be to translate it to explicit assignment although that would suck

Copy link
Member

@karlnapf karlnapf left a comment

Choose a reason for hiding this comment

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

Like it! I guess now it’s done work to make it work with all the langs...

It would be cool if you could also try to make it work with R and ruby. While those meta examples are currently disabled in the build, they in principle work (r doesn’t have static calls, ruby doesn’t have overloaded methods/functions) since both support list inits. I think it would be sufficient to look at generates output and locally try it that works

@gf712
Copy link
Member Author

gf712 commented Apr 12, 2019

Like it! I guess now it’s done work to make it work with all the langs...

It would be cool if you could also try to make it work with R and ruby. While those meta examples are currently disabled in the build, they in principle work (r doesn’t have static calls, ruby doesn’t have overloaded methods/functions) since both support list inits. I think it would be sufficient to look at generates output and locally try it that works

OK, I can have a look into R. With ruby I am not sure how it would work, as the old NArray doesn't seem to have a list initialiser? The new NArray library does seem to have it though. But I am not sure which one shogun supports?

OLD: https://github.com/masa16/narray
NEW: https://github.com/ruby-numo/numo-narray

I figured out how to make it work, but there is no support for bools in ruby's old NArray library, so it might be worth upgrading to numo-array

@@ -34,10 +34,22 @@
"IntMatrix": "DoubleMatrix $name = new DoubleMatrix($arguments)",
"LongIntMatrix": "DoubleMatrix $name = new DoubleMatrix($arguments)",
"ULongIntMatrix": "DoubleMatrix $name = new DoubleMatrix($arguments)",
"ShortRealMatrix": "DoubleMatrix $name = new DoubleMatrix($arguments)",
"ShortRealMatrix": "FloatMatrix $name = new FloatMatrix($arguments)",
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 am assuming this should be FloatMatrix?

Copy link
Member

Choose a reason for hiding this comment

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

not sure what the typemap exactly does...but I think our current Java bindings treat everything as double matrix. Might be worth cleaning that up at some point soon

@karlnapf
Copy link
Member

I figured out how to make it work, but there is no support for bools in ruby's old NArray library, so it might be worth upgrading to numo-array

Shogun still uses the old one and we have an issue for upgrading here. It is some work as the typemaps will have to be re-written. That is cumbersome as ruby is currently disabled due to #4177.
So don't loose your sleep over this I'd say. Or

@gf712
Copy link
Member Author

gf712 commented Apr 13, 2019

Shogun still uses the old one and we have an issue for upgrading here. It is some work as the typemaps will have to be re-written. That is cumbersome as ruby is currently disabled due to #4177.
So don't loose your sleep over this I'd say. Or

I am thinking that maybe I skip boolean for now? There is still some lack of support for it in java, ruby and r (at least) so can address that separately?

@@ -1,5 +1,3 @@
BoolVector bool_vector([True, False])
Copy link
Member

Choose a reason for hiding this comment

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

ok!

@karlnapf
Copy link
Member

Soooo merge? :)

@gf712
Copy link
Member Author

gf712 commented Apr 17, 2019

Yup, seems fine to me. When there is a need I can add matrix initialisation

@karlnapf karlnapf merged commit ae09c50 into shogun-toolbox:develop Apr 17, 2019
ktiefe pushed a commit to ktiefe/shogun that referenced this pull request Jul 30, 2019
* added list initialisation

* minor fixes

* numo narray

* fix floating point

* removed boolean list init for now
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