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

Assigning NArray::Bit to a slice shows strange behavior #137

Closed kojix2 closed 5 years ago

kojix2 commented 5 years ago

Hello.

I found strange behavior. It may be a bug. I'm sorry if I'm mistaken.

require 'numo/narray'
include Numo

x_1 = Bit.ones(10, 10)
x_0 = Bit.zeros(10, 10)

X_0 = Bit.zeros(12, 12)

XXX_000 = NArray.dstack([X_0, X_0, X_0])
xxx_001 = NArray.dstack([x_1, x_0, x_0])

XXX_000[1..-2, 1..-2, true] = xxx_001

p xxx_001[true, true, 0]
p XXX_000[true, true, 0]

Numo::Bit(view)#shape=[10,10] [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]

Numo::Bit(view)#shape=[12,12] [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]

Thank you!

masa16 commented 5 years ago

Fixed with https://github.com/ruby-numo/numo-narray/commit/393d40f8479d170ef55f28c9aa72e801b979eb89 . Thank you for finding a serious bug.