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

More user-friendly SVD interface #609

Open
v0dro opened this issue Feb 22, 2018 · 8 comments
Open

More user-friendly SVD interface #609

v0dro opened this issue Feb 22, 2018 · 8 comments

Comments

@v0dro
Copy link
Member

v0dro commented Feb 22, 2018

Currently to calculate SVD we need to call a function like gesvd. Having a simple Ruby wrapper over this called svd would be nicer.

@translunar translunar changed the title More humane SVD More user-friendly SVD interface Feb 26, 2018
@wlevine
Copy link

wlevine commented Feb 28, 2018

I think our current gesvd method actually has a pretty friendly interface (see http://sciruby.com/nmatrix/docs/NMatrix.html#method-i-gesvd ). The only thing unfriendly about it is the name. Is there anything else you had in mind?

@v0dro
Copy link
Member Author

v0dro commented Feb 28, 2018

Just the name actually. And in case we support sparse matrices in the future it should also call the respective sparse method via svd.

@gavrieltal
Copy link

Hi, I'm new to Ruby and SciRuby and looking to get involved in an open source project, so sorry if I lack a concept of the organization of the files here. Right now, I just know that the gesvd function comes from lapack and atlas.

Would it be enough to add alias :gesvd :svdin lib/nmatrix/lapack_core.rb, lib/nmatrix/cruby/math.rb, lib/nmatrix/atlas.rb, and lib/nmatrix/lapacke.rb? There is no gesvd definition in the hyperlinked file lib/nmatrix/math.rb.

Also, would you expect Spec tests to demonstrate that the alias works?

Thanks

@translunar
Copy link
Member

translunar commented Mar 2, 2018

I don't think you'd add it in all of those places. Probably just lib/nmatrix/math.rb, or perhaps the math.rb in cruby/ (which place depends on whether there's a gesvd in the JRuby NMatrix or not). It's also possible JRuby has a different svd interface (I hope not), in which case you'd want to write a function in each of the two (C and J) math.rb files which provides a common interface.

Does that make sense?

Also, welcome. :)

@gavrieltal
Copy link

gavrieltal commented Mar 2, 2018

Based on github repo searches, gesvd is not defined in either lib/nmatrix/math.rb or lib/nmatrix/jruby/math.rb, only under cruby. So I suppose I would just add it under cruby?

Also, would you want to have spec tests checking that the alias works?

And, would you also like aliases for gesvd!, gesdd, and gesdd!?

Thanks for the welcome.

@translunar
Copy link
Member

So, gesvd is in cruby because it's an interface for lapack/atlas/etc., which only exists on the C side. We should really have a common SVD interface for both JRuby and MRI (cruby), and that would go in lib/nmatrix/math.rb. Does that make sense?

It sounds like, though, it's going to be more than a simple alias — it's about coming up with an SVD interface that works for both JRuby and MRI and allows both to be executed as efficiently as possible. And yes, you would need specs for it.

Whether the ! functions are included just depends on whether there's an in-place JRuby SVD. There probably is, in which case, yes, you'd use svd!. If not, you'd raise a NotImplementedError when jruby? is true.

@gavrieltal
Copy link

I'm trying to figure out how to install nmatrix JRuby for the first time to try my work. Perhaps it's just inexperience with JRuby, but it seems hard to figure out. In addition to following the standard README instructions up until rake jruby, here is what I've tried:

gavriel@stockholm:~/Desktop/ruby/local.nmatrix$ rake jruby
x86_64-linux-gnu
Please run with JRuby

gavriel@stockholm:~/Desktop/ruby/local.nmatrix$ jruby -S rake jruby
Your bundle is locked to rake (10.5.0), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of rake (10.5.0) has removed it. You'll need to update your bundle to a different version of rake (10.5.0) that hasn't been removed in order to install.
Run `bundle install` to install missing gems

gavriel@stockholm:~/Desktop/ruby/local.nmatrix$ jruby -S rake
Your bundle is locked to rake (10.5.0), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of rake (10.5.0) has removed it. You'll need to update your bundle to a different version of rake (10.5.0) that hasn't been removed in order to install.
Run `bundle install` to install missing gems

gavriel@stockholm:~/Desktop/ruby/local.nmatrix$ sudo jruby -S bundle install
LoadError: no such file to load -- /usr/share/rubygems-integration/all/gems/bundler-1.13.6/exe/bundle
    load at org/jruby/RubyKernel.java:1059
  (root) at /usr/local/bin/bundle:22

gavriel@stockholm:~/Desktop/ruby/local.nmatrix$ sudo jruby -S bundle install rake
LoadError: no such file to load -- /usr/share/rubygems-integration/all/gems/bundler-1.13.6/exe/bundle
    load at org/jruby/RubyKernel.java:1059
  (root) at /usr/local/bin/bundle:22

gavriel@stockholm:~/Desktop/ruby/local.nmatrix$ sudo jruby -S gem install nmatrix
Building native extensions.  This could take a while...
ERROR:  Error installing nmatrix:
        ERROR: Failed to build gem native extension.

    /usr/share/jruby/bin/jruby -r ./siteconf20180820-9892-b6ltlv.rb extconf.rb
NotImplementedError: C extension support is not enabled. Pass -Xcext.enabled=true to JRuby or set JRUBY_OPTS.

   (root) at /usr/share/jruby/lib/ruby/shared/mkmf.rb:8
  require at org/jruby/RubyKernel.java:1040
   (root) at /usr/share/jruby/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:1
  require at /usr/share/jruby/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:54
  require at org/jruby/RubyKernel.java:1040
   (root) at /usr/share/jruby/lib/ruby/gems/shared/gems/nmatrix-0.2.4/lib/nmatrix/mkmf.rb:1
   (root) at extconf.rb:28

extconf failed, uncaught signal 1

Gem files will remain installed in /usr/share/jruby/lib/ruby/gems/shared/gems/nmatrix-0.2.4 for inspection.
Results logged to /usr/share/jruby/lib/ruby/gems/shared/extensions/universal-java-1.8/1.9/nmatrix-0.2.4/gem_make.out


gavriel@stockholm:~/Desktop/ruby/local.nmatrix$ sudo jruby -Xcext.enabled=true -S gem install nmatrix
Building native extensions.  This could take a while...
ERROR:  Error installing nmatrix:
        ERROR: Failed to build gem native extension.

    /usr/share/jruby/bin/jruby -r ./siteconf20180820-9969-4u2l4a.rb extconf.rb
NotImplementedError: C extension support is not enabled. Pass -Xcext.enabled=true to JRuby or set JRUBY_OPTS.

   (root) at /usr/share/jruby/lib/ruby/shared/mkmf.rb:8
  require at org/jruby/RubyKernel.java:1040
   (root) at /usr/share/jruby/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:1
  require at /usr/share/jruby/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:54
  require at org/jruby/RubyKernel.java:1040
   (root) at /usr/share/jruby/lib/ruby/gems/shared/gems/nmatrix-0.2.4/lib/nmatrix/mkmf.rb:1
   (root) at extconf.rb:28

extconf failed, uncaught signal 1

Gem files will remain installed in /usr/share/jruby/lib/ruby/gems/shared/gems/nmatrix-0.2.4 for inspection.
Results logged to /usr/share/jruby/lib/ruby/gems/shared/extensions/universal-java-1.8/1.9/nmatrix-0.2.4/gem_make.out
gavriel@stockholm:~/Desktop/ruby/local.nmatrix$ 

@translunar
Copy link
Member

@gavrieltal I'm not sure how your comment relates to this issue. Can you please open a separate issue if you want help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants