Skip to content

Dense and sparse linear algebra library for Ruby via SciRuby

License

Notifications You must be signed in to change notification settings

blackwinter-attic/nmatrix

 
 

Repository files navigation

NMatrix

Fast Numerical Linear Algebra Library for Ruby

<img src=https://travis-ci.org/SciRuby/nmatrix.png>

<img src=“https://codeclimate.com/github/SciRuby/nmatrix.png” />

Description

NMatrix is a fast numerical linear algebra library for Ruby, with dense and sparse matrices, written mostly in C and C++. It is part of the SciRuby project.

NMatrix was inspired by NArray, by Masahiro Tanaka.

Installation

To install the latest stable version:

gem install nmatrix

However, you will need to install ATLAS with CBLAS (C interface to BLAS) first. Detailed directions can be found here. The requirements for NMatrix are:

  • ATLAS, preferably with CLAPACK (see here for details)

  • a version of GCC or clang which supports C++0x or C++11

  • Ruby 1.9.3+

  • packable 1.3.5 (used for I/O)

If you want to obtain the latest (development) code, you should generally do:

git clone https://github.com/SciRuby/nmatrix.git
cd nmatrix/
bundle install
bundle exec rake compile
bundle exec rake repackage
gem install pkg/nmatrix-0.1.0.rc5.gem

Detailed instructions are available for Mac and Linux. We are currently working on Mavericks (Mac OS X) installation instructions, but in general, you’ll need Homebrew and should probably use +brew install gcc48+ instead of using the install script.

Documentation

If you have a suggestion or want to add documentation for any class or method in NMatrix, please open an issue or send a pull request with the changes.

You can find the complete API documentation on our website.

Examples

Create a new NMatrix from a ruby Array:

>> require 'nmatrix'
>> NMatrix.new([2, 3], [0, 1, 2, 3, 4, 5], dtype: :int64)
=> [
    [0, 1, 2],
    [3, 4, 5]
   ]

Create a new NMatrix using the N shortcut:

>> m = N[ [2, 3, 4], [7, 8, 9] ]
=> [
    [2, 3, 4],
    [7, 8, 9]
   ]
>> m.inspect
=> #<NMatrix:0x007f8e121b6cf8shape:[2,3] dtype:int32 stype:dense>

The above output requires that you have a pretty-print-enabled console such as Pry; otherwise, you’ll see the output given by inspect.

If you want to learn more about how to create a matrix, read the guide in our wiki.

Again, you can find the complete API documentation on our website.

NArray Compatibility

When NArray is installed alongside NMatrix, require 'nmatrix' will inadvertently load NArray’s lib/nmatrix.rb file, usually accompanied by the following error:

uninitialized constant NArray (NameError)

To make sure NMatrix is loaded properly in the presence of NArray, use require 'nmatrix/nmatrix' instead of require 'nmatrix' in your code.

Developers

Read the instructions in CONTRIBUTING.md if you want to help NMatrix.

Features

The following features exist in the current version of NMatrix (0.1.0.rc1):

  • Matrix and vector storage containers: dense, yale, list (more to come)

  • Data types: byte (uint8), int8, int16, int32, int64, float32, float64, complex64, complex128, rational64, rational128, Ruby object

  • Interconversion between storage and data types

  • Element-wise and right-hand-scalar operations and comparisons for all matrix types

  • Matrix-matrix multiplication for dense (with and without ATLAS) and yale

  • Matrix-vector multiplication for dense (with and without ATLAS)

  • Lots of enumerators (each, each_with_indices, each_row, each_column, each_rank, map, etc.)

  • Matrix slicing by copy and reference (for dense, yale, and list)

  • Native reading and writing of dense and yale matrices

    • Optional compression for dense matrices with symmetry or triangularity: symmetric, skew, hermitian, upper, lower

  • Input/output:

    • Matlab .MAT v5 file input

    • MatrixMarket file input/output

    • Harwell-Boeing and Fortran file input

    • Point Cloud Library PCD file input

  • C and C++ API

  • BLAS internal implementations (no library) and ATLAS (with library) access:

    • Level 1: xROT, xROTG (BLAS dtypes only), xASUM, xNRM2, IxAMAX

    • Level 2: xGEMV

    • Level 3: xGEMM, xTRSM

  • LAPACK ATLAS access:

    • xGETRF, xGETRI, xGETRS, xGESV (Gaussian elimination)

    • xPOTRF, xPOTRI, xPOTRS, xPOSV (Cholesky factorization)

    • xLASWP, xSCAL, xLAUUM

  • LAPACK-less internal implementations (no LAPACK needed and working on non-BLAS dtypes):

    • xGETRF

    • xLASWP, xSCAL

    • xLAUUM (no LAPACK needed, but BLAS dtypes only)

  • LAPACK (non-ATLAS) access:

    • xGESVD, xGESDD (singular value decomposition)

    • xGEEV (eigenvalue decomposition of a asymmetric square matrices)

  • LU decomposition

  • Matrix inversions

  • Determinant calculation for BLAS dtypes

  • Traces

  • Ruby/GSL interoperability (requires SciRuby’s fork of rb-gsl)

  • slice assignments, e.g.,

    x[1..3,0..4] = some_other_matrix
    

Planned Features (Short-to-Medium Term)

See the issues tracker for a list of planned features or to request new ones.

License

Copyright © 2012–15, John Woods and the Ruby Science Foundation.

All rights reserved.

NMatrix, along with SciRuby, is licensed under the BSD 2-clause license. See LICENSE.txt for details.

Donations

Support a SciRuby Fellow:

<img src=http://pledgie.com/campaigns/15783.png?skin_name=chrome>

About

Dense and sparse linear algebra library for Ruby via SciRuby

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 61.0%
  • Ruby 30.3%
  • C 8.6%
  • Shell 0.1%