Building NMatrix on OSX

NMatrix is a Ruby library providing some linear algebra functions and sparse data-structures. Unfortunately, it’s surprisingly difficult to get running on OSX. Here’s a hackish method, using rvm and macports (I’ll show what I had to install on my system, you may need more — the documentation is rather sparse at this point).

sudo port install atlas

cd

rvm use ruby-1.9.3

gem install isolate hoe rspec rake-compiler hoe-git json packable
git clone https://github.com/mohawkjohn/nmatrix.git

cd nmatrix

rake compile

sed -i "" 's:clang\+\+:g++ -I/opt/local/include:g' tmp/x86_64-darwin11.3.0/nmatrix/1.9.3/Makefile

sed -i "" 's:clang:gcc -I/opt/local/include:g' tmp/x86_64-darwin11.3.0/nmatrix/1.9.3/Makefile

sed -i "" 's:nmatrix\.so:nmatrix\.bundle:g' lib/nmatrix.rb

rake compile

rake compile

rake newb

cd nmatrix

ln nmatrix/nmatrix.bundle .

cd

irb -I nmatrix/lib/

require 'nmatrix'

Hopefully this process will improve soon (SciRuby has Google Summer of Code support this year), but this procedure should get you started.

update: for debugging purposes, I’m running an up to date OSX 10.7.4 and macports (2.1.0), ruby-1.9.3-p125, clang version 3.1 (tags/Apple/clang-318.0.58).

Leave a Reply