Numo::Linalg Alternative
Numo::Linalg Alternative (numo-linalg-alt) is an alternative to Numo::Linalg. Unlike Numo::Linalg, numo-linalg-alt depends on Numo::NArray Alterntive.
Please note that this gem was forked from Numo::TinyLinalg, not Numo::Linalg, and therefore it does not support changing backend libraries for BLAS and LAPACK. In addition, the version numbering rule is not compatible with that of Numo::Linalg.
The project owner has the utmost respect for Numo::Linalg and its creator, Prof. Masahiro Tanaka. This project is in no way intended to adversely affect the development of the original Numo::Linalg.
Installation
Unlike Numo::Linalg, numo-linalg-alt only supports OpenBLAS as a backend library.
Install the OpenBLAS.
macOS:
$ brew install openblas
Ubuntu:
$ sudo apt-get install libopenblas-dev liblapacke-dev
Install the gem and add to the application's Gemfile by executing.
macOS:
$ bundle config build.numo-linalg-alt "--with-opt-dir=/opt/homebrew/opt/openblas"
$ bundle add numo-linalg-alt
Ubuntu:
$ bundle add numo-linalg-alt
If bundler is not being used to manage dependencies, install the gem by executing.
macOS:
$ gem install numo-linalg-alt -- --with-opt-dir=/opt/homebrew/opt/openblas
Ubuntu:
$ gem install numo-linalg-alt
Usage
An example of singular value decomposition.
require 'numo/linalg'
x = Numo::DFloat.new(5, 2).rand.dot(Numo::DFloat.new(2, 3).rand)
# =>
# Numo::DFloat#shape=[5,3]
# [[0.104945, 0.0284236, 0.117406],
# [0.862634, 0.210945, 0.922135],
# [0.324507, 0.0752655, 0.339158],
# [0.67085, 0.102594, 0.600882],
# [0.404631, 0.116868, 0.46644]]
s, u, vt = Numo::Linalg.svd(x, job: 'S')
z = u.dot(s.diag).dot(vt)
# =>
# Numo::DFloat#shape=[5,3]
# [[0.104945, 0.0284236, 0.117406],
# [0.862634, 0.210945, 0.922135],
# [0.324507, 0.0752655, 0.339158],
# [0.67085, 0.102594, 0.600882],
# [0.404631, 0.116868, 0.46644]]
puts (x - z).abs.max
# => 4.440892098500626e-16
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/numo-linalg-alt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
Code of Conduct
Everyone interacting in the Numo::Linalg Alternative project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
License
The gem is available as open source under the terms of the BSD-3-Clause License.