3

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

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 文档中没有看到上述错误的描述,请帮助我解决这个错误。

现在根据建议,我尝试使用 bundle install 并再次出现错误:-(我不知道如何解决这个问题

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

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

4

2 回答 2

1

这里的问题是pretty_print 需要一个论点。较旧的 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

希望这可以帮助!抱歉,文档已过时。

于 2013-09-26T15:20:42.403 回答
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
于 2013-09-05T05:44:51.863 回答