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

Idea: Support casting any object that responds to `to_a` #157

Closed ankane closed 4 years ago

ankane commented 4 years ago

Hi, small thing, but it'd be great if cast worked with any object that responds to to_a. Currently, it throws TypeError: invalid type for NArray. Here's an example with Daru:

require "daru"
require "numo/narray"

v = Daru::Vector.new([1, 2, 3])
Numo::NArray.cast(v.to_a) # success
Numo::NArray.cast(v)      # error
masa16 commented 4 years ago

Your idea is implemented: https://github.com/ruby-numo/numo-narray/commit/29c5c1340c1e52f541a8055b14a87d521e10c62b

ankane commented 4 years ago

Thanks @masa16! However, I'm still seeing TypeError: invalid type for NArray with the example above in 0.9.1.8.

ankane commented 4 years ago

Thanks @masa16, looks like that last commit fixed it!