SciRuby/daru

Problem with has_index method with multi-index vector.

IdeoConcepts opened this issue · 1 comments

Hi,

When creating a vector with multi-index, the method "has_index?" will return true even if the given index has no match:-

Example:-

> v = Daru::Vector.new([100, 200], index: [['a', 'b'], ['c', 'd']])
 => #<Daru::Vector(2)>
   a   b 100
   c   d 200
> v.has_index?([['a', 'd']])
 => true
> v[['a', 'd']]
IndexError: Specified index ["a", "d"] do not exist
        from /home/wharf/.bundler/ruby/2.0.0/daru-92ed46eba37b/lib/daru/index/multi_index.rb:139:in `rescue in []'
        from /home/wharf/.bundler/ruby/2.0.0/daru-92ed46eba37b/lib/daru/index/multi_index.rb:136:in `[]'
        from /home/wharf/.bundler/ruby/2.0.0/daru-92ed46eba37b/lib/daru/index/multi_index.rb:165:in `pos'
        from /home/wharf/.bundler/ruby/2.0.0/daru-92ed46eba37b/lib/daru/vector.rb:217:in `[]'
        from (irb):44
        from /usr/local/rvm/gems/ruby-2.0.0-p598/gems/railties-3.2.16/lib/rails/commands/console.rb:47:in `start'
        from /usr/local/rvm/gems/ruby-2.0.0-p598/gems/railties-3.2.16/lib/rails/commands/console.rb:8:in `start'
        from /usr/local/rvm/gems/ruby-2.0.0-p598/gems/railties-3.2.16/lib/rails/commands.rb:41:in `<top (required)>'
        from ./script/rails:6:in `require'
        from ./script/rails:6:in `<main>'
> v[['a', 'b']]
 => 100

Many thanks!

Hey @IdeoConcepts , thanks for spotting the bug, can you make changes locally as per PR #455 and check whether it helps?