ruby-numo / numo-narray

Ruby/Numo::NArray - New NArray class library
http://ruby-numo.github.io/narray/
BSD 3-Clause "New" or "Revised" License
415 stars 41 forks source link

at() method was rewritten in C. #138

Closed naitoh closed 4 years ago

naitoh commented 5 years ago

I rewrote the at() method using C language. The result is up to x18 times faster.

Ruby 2.5.3 (Linux)

Comparison: a.at(Array, Array)
numo-narray 0.9.2.1: 9839.8 i/s numo-narray 0.9.1.4: 546.5 i/s - 18.00x slower

         l.at(Numo::Int32(X).seq,      Numo::Int32(X).seq)
                          numo-narray 0.9.2.1:      7934.9 i/s 
                          numo-narray 0.9.1.4:      2203.2 i/s - 3.60x  slower

benchmark code

$ cat diagonal_at_fp32_diff.yaml
contexts:
  - gems: { numo-narray: 0.9.1.4 }
    require: false
    prelude: |
      require 'numo/narray'
  - gems: { numo-narray: 0.9.2.1 }
    require: false
    prelude: |
      require 'numo/narray'
loop_count: 1000
prelude: |
  require 'numo/narray'
  X = 10000
  a = Numo::SFloat.new(X, X).seq(0)
  b = Numo::SFloat.new(X, X).seq(0)
  x = Numo::Int32.new(X).seq.to_a
  y = Numo::Int32.new(X).seq
  sleep 30

benchmark:
  'a.at(Array, Array)                               '      : a.at(x, x)
  'l.at(Numo::Int32(X).seq,      Numo::Int32(X).seq)'      : b.at(y, y)
naitoh commented 4 years ago

Thanks!