3

I am using NMatrix in my project and now when I run the follwing command in console to see whether it is creating a matrix or not

rails c
1.9.3p194 :001 > require 'nmatrix'
 => false 
1.9.3p194 :002 > m = NMatrix.new([2, 3], [0, 1, 2, 3, 4, 5], :int64)
 => [0, 1, 2, 3, 4, 5 shape:[2,3] dtype:int64 stype:dense> 

But when I try to pretty_print the out put I got the following error:

 1.9.3p194 :003 > m.pp
 NoMethodError: private method `pp' called for [0, 1, 2, 3, 4, 5 shape:[2,3] dtype:int64 stype:dense>:NMatrix
    from /home/user/my_project/nmatrix/lib/nmatrix/nmatrix.rb:438:in `method_missing'
    from (irb):2
    from /home/user/.rvm/gems/ruby-1.9.3-p194@rails3_2_9/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in `start'
    from /home/user/.rvm/gems/ruby-1.9.3-p194@rails3_2_9/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start'
    from /home/user/.rvm/gems/ruby-1.9.3-p194@rails3_2_9/gems/railties-3.2.9/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

I dont know why it is coming as I dont see the above error's description in NMatrix Documentation, Please help me in resolving this error.

Now As per suggestion I tried with bundle install and I got error again :-( i dont know how do I resolve this

user@user:~/my_project$ gem install --no-rdoc --no-ri nmatrix
Building native extensions.  This could take a while...
/home/user/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:48: warning: Insecure world writable dir 
/home/user/eclipse/plugins in PATH, mode 040777
ERROR:  Error installing nmatrix:
    ERROR: Failed to build gem native extension.

    /home/user/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for main() in -llapack... yes
checking for main() in -lcblas... yes
checking for main() in -latlas... yes
checking for clapack.h... yes
checking for cblas.h... yes
checking for clapack_dgetrf() in cblas.h,clapack.h... yes
checking for clapack_dgetri() in cblas.h,clapack.h... yes
checking for dgesvd_() in clapack.h... yes
checking for cblas_dgemm() in cblas.h... yes
using C++ standard... c++0x
g++ reports version... 4.6.1-9ubuntu3)
creating nmatrix_config.h
creating Makefile

make
linking shared-object nmatrix.so
g++: error: nmatrix.o: No such file or directory
g++: error: ruby_constants.o: No such file or directory
g++: error: data/data.o: No such file or directory
g++: error: util/io.o: No such file or directory
g++: error: math.o: No such file or directory
g++: error: util/sl_list.o: No such file or directory
g++: error: storage/common.o: No such file or directory
g++: error: storage/storage.o: No such file or directory
g++: error: storage/yale.o: No such file or directory
g++: error: storage/list.o: No such file or directory
make: *** [nmatrix.so] Error 1


Gem files will remain installed in /home/user/.rvm/gems/ruby-1.9.3-p194@rails3_2_9/gems/nmatrix-0.0.8 for inspection.
Results logged to /home/user/.rvm/gems/ruby-1.9.3-p194@rails3_2_9/gems/nmatrix-0.0.8/ext/nmatrix/gem_make.out

can any one have better suggestion to resolve this.

Carlos Agarie
  • 3,952
  • 1
  • 26
  • 38
Braham Shakti
  • 1,408
  • 4
  • 22
  • 39
  • `m = NMatrix.new([2, 3], [0, 1, 2, 3, 4, 5], :int64).pp` please try it or `m= N[ [2, 3], [0, 1, 2, 3, 4, 5] ] m.pp` – Rajarshi Das Sep 05 '13 at 05:44
  • `from /home/user/my_project/nmatrix/lib/nmatrix/nmatrix.rb:438` did you install the gem properly using `bundle install`? or do you have any other library on same name – Rajarshi Das Sep 05 '13 at 06:01
  • This is a case of the instructions not being up to date. You can't really call `pp` directly anymore. If you'd like pretty output, I suggest you use `pry` instead of `irb`. It'll automatically call NMatrix's `pretty_print` routine with the proper arguments. – Translunar Sep 26 '13 at 15:17

2 Answers2

1

please try it in this way

In Gemfile

gem "nmatrix", "~> 0.0.8"

Then

1) bundle install

2) rails c

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

or

 require 'nmatrix'  
 m= N[ [2, 3], [0, 1, 2, 3, 4, 5] ] 
 m.pp
Rajarshi Das
  • 11,778
  • 6
  • 46
  • 74
  • @BrahamShakti did you try this second one `m= N[ [2, 3], [0, 1, 2, 3, 4, 5] ] m.pp` – Rajarshi Das Sep 05 '13 at 05:48
  • Yes I tried the second one but still I am getting the same error. – Braham Shakti Sep 05 '13 at 06:00
  • ahh got it ....from `/home/user/my_project/nmatrix/lib/nmatrix/nmatrix.rb:438` ddo you have any other library on same name... in you application `lib` folder as stated...if yes then please rename it to nmatrix.rb to any other as it is taking this library instead of gems one – Rajarshi Das Sep 05 '13 at 06:02
  • What I did is I cloned the nmatrix from the git into my project directory then what the NMatrix documentation described I did the same . But why is it showing `NoMethodError: private method `pp'` I dont know. Is this related to installation issue?. – Braham Shakti Sep 05 '13 at 06:05
  • please do not clone it use `bundle install` for better in Gemfile `gem "nmatrix", "~> 0.0.8"` then `bundle install` remove the clone directory – Rajarshi Das Sep 05 '13 at 06:06
  • Okay when I tried this I got the following error `Bundler could not find compatible versions for gem "rdoc": In Gemfile: rails (= 3.2.9) ruby depends on rdoc (~> 3.4) ruby nmatrix (~> 0.0.8) ruby depends on rdoc (4.0.1)` – Braham Shakti Sep 05 '13 at 06:11
  • you need `rdoc` as well but your rails depends on 3.4 version and nmatrix depends on rdoc 4.0.1 version – Rajarshi Das Sep 05 '13 at 06:12
  • `gem install --no-rdoc --no-ri nmatrix -v 0.0.8` then `bundle install` – Rajarshi Das Sep 05 '13 at 06:15
1

The problem here is that pretty_print requires an argument. Older NMatrix versions were defining pretty_print improperly.

I suggest you install the most recent version of NMatrix and then use the pry console instead of irb:

$ gem install nmatrix pry
$ pry
> require 'nmatrix'
> NMatrix.new([2,3], [0,1,2,3], dtype: :float64)
=> # pretty output

Hope this helps! Sorry that the docs were out of date.

Translunar
  • 3,739
  • 33
  • 55