NoMethodError:NMatrix的私有方法`pp'

时间:2013-09-05 05:35:54

标签: ruby-on-rails ruby-on-rails-3 matrix ruby-on-rails-3.2 nmatrix

我在我的项目中使用NMatrix,现在当我在控制台中运行follwing命令以查看它是否正在创建矩阵时

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> 

但是当我尝试使用另外的输出时,我得到了以下错误:

 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>'

我不知道为什么会这样,因为我在NMatrix文档中没有看到上述错误的描述,请帮我解决这个错误。

现在根据建议我尝试使用捆绑安装,我再次收到错误:-(我不知道如何解决此问题

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

任何人都可以有更好的建议来解决这个问题。

2 个答案:

答案 0 :(得分:1)

请以这种方式尝试

在Gemfile中

gem "nmatrix", "~> 0.0.8"

然后

1)bundle install

2)rails c

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

 require 'nmatrix'  
 m= N[ [2, 3], [0, 1, 2, 3, 4, 5] ] 
 m.pp

答案 1 :(得分:1)

此处的问题是pretty_print requires an argument。较旧的NMatrix版本未正确定义pretty_print

我建议您安装最新版本的NMatrix,然后使用pry控制台而不是irb

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

希望这有帮助!很抱歉,文档已经过时了。