Skip to content

NMatrix to_a too slow #543

@lokeshh

Description

@lokeshh

While porting Statsample-GLM form Matrix to NMatrix I found to_a is taking a lot of time than it should and in fact it is as the following benchmark shows:

require 'benchmark'
require 'matrix'
require 'nmatrix'

m = Matrix.zero 1000 ;
n = NMatrix.new [1000, 1000], [0]*10**6

Benchmark.bm do |x|
  x.report "Matrix to_a" do
    10.times { m.to_a }
  end

  x.report "NMatrix to_a" do
    10.times { n.to_a }
  end
end

       user     system      total        real
Matrix to_a  0.010000   0.000000   0.010000 (  0.009627)
NMatrix to_a  4.680000   0.080000   4.760000 (  4.777082)

Improvement in to_a might solve the issue in SciRuby/statsample-glm#36

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions