ruby-numo / numo-narray

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

invalid dimension argument Hash with dot method in Ruby 3 #184

Closed ankane closed 3 years ago

ankane commented 3 years ago

Hi, I came across an error with the dot method due to the keyword argument changes in Ruby 3. Here's a minimal example to reproduce:

require "numo/narray"

a = Numo::Int64.cast([[1, 2, 3]])
b = Numo::DFloat.cast([[1]])
p a.dot(b)

And the stack trace:

/Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/numo-narray-0.9.1.9/lib/numo/narray/extra.rb:1129:in `mulsum': invalid dimension argument Hash (Numo::NArray::DimensionError)
    from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/numo-narray-0.9.1.9/lib/numo/narray/extra.rb:1129:in `mulsum'
    from /Users/user/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/numo-narray-0.9.1.9/lib/numo/narray/extra.rb:1129:in `dot'

With Ruby 2.7, there's a deprecation warning:

/Users/user/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/numo-narray-0.9.1.9/lib/numo/narray/extra.rb:1129: warning: Using the last argument as keyword parameters is deprecated
kojix2 commented 3 years ago

This issue appears to have been resolved by @yoshoku 's commit.

require "numo/narray"

a = Numo::Int64.cast([[1, 2, 3]])
b = Numo::DFloat.cast([[1]])
p a.dot(b)

ruby 2.7 or ruby 3.0

Numo::DFloat#shape=[1,1]
[[6]]
ankane commented 3 years ago

Awesome, thanks @yoshoku 🎉