narray
narray copied to clipboard
mul! behaves different to *=
It seems #mul! and #*= behave different when using ranges.
#*= correctly modifies the original array, #mul! does not.
Is this desired? (if yes -- it is not mentioned in the spec here http://narray.rubyforge.org/SPEC.en)
irb(main):017:0> a
=> NArray.float(5):
[ 0.0253152, 0.88346, 0.792297, 0.498892, 0.374336 ]
irb(main):018:0> a[1...3].mul!(-1.0)
=> NArray.float(2):
[ -0.88346, -0.792297 ]
irb(main):019:0> a
=> NArray.float(5):
[ 0.0253152, 0.88346, 0.792297, 0.498892, 0.374336 ]
but
irb(main):020:0> a[1...3] *= (-1.0)
=> NArray.float(2):
[ -0.88346, -0.792297 ]
irb(main):021:0> a
=> NArray.float(5):
[ 0.0253152, -0.88346, -0.792297, 0.498892, 0.374336 ]
This behaviour is quite natural in view of Ruby language.
In Ruby language, a[1...3] *= (-1.0) is equal to a[1...3] = a[1...3] * (-1.0)
On the other hand a[1...3].mul!(-1.0) means b = a[1...3]; b.mul!(-1.0)