NoMethodError: private method `pp' for NMatrix

610 views Asked by At

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.

2

There are 2 answers

8
Rajarshi Das On

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
0
Translunar On

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.