ruby-on-rails - 无方法错误 : private method `pp' for NMatrix

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

我在我的项目中使用 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> 

但是当我尝试 pretty_print 输出时,出现以下错误:

 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

谁能有更好的建议来解决这个问题。

最佳答案

请这样试一下

在 Gemfile 中

gem "nmatrix", "~> 0.0.8"

然后

1) 捆绑安装

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

关于ruby-on-rails - 无方法错误 : private method `pp' for NMatrix,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18628526/

相关文章:

ruby-on-rails - Ruby on Rails:从YAML文件加载种子数据

ruby-on-rails - Rails 4 - has_one - 无法访问相关模型的属性

ruby-on-rails - mass_assignment_authorizer 的更改导致 Ruby on Rails 3.1 中的错误

matlab - 使用matlab选择矩阵中的元素

ruby-on-rails - 带有 BCrypt 的 Rails Fixtures

javascript - 如何使用 JQuery 和 Rails 创建类似 Wufoo(表单生成器)的 Web 应用程序?

ruby-on-rails - Assets 在服务器中预编译但未在 puma 和 nginx 服务器中显示

jquery - Rails accepts_nested_attributes_for 与 f.fields_for 和 AJAX

python - 来自邻接矩阵的 Dijkstra 算法

c - 堆问题,PC 卡住