I'm experimenting with a new Ndarray class and while creating a class method add_element, I took a look at how the add_rows method was coded for the Matrix class, and I noticed that it wasn't modifying the object, but was returning a new one.
Instinctively, I would expect that I could do:
matrix = Crystalla::Matrix.new([1.0, 2.0, 2.0, 3.0], 2, 2)
p matrix
>> Matrix[[ 1.0, 2.0 ],
[ 2.0, 3.0 ]]
matrix.add_rows(1, Crystalla::Matrix.new([4.5, 3.0], 1,2))
p matrix
>> Matrix[[ 1.0, 2.0 ],
[ 4.5, 3.0 ],
[ 2.0, 3.0 ]]
Instead, I need to assign it to a new instance to get the modified matrix:
matrix2 = matrix.add_rows(1, Crystalla::Matrix.new([4.5, 3.0], 1,2))
Is there a particular reason why you made this choice ?
For Ndarrays, it would seem more natural to do:
array = Crystalla::Ndarray.new([1.0, 2.0, 2.0, 3.0])
array.add_element(6.0, 1)
p array
>> Ndarray [1.0, 6.0, 2.0, 2.0, 3.0]
Let me know what you think !
I'm experimenting with a new Ndarray class and while creating a class method
add_element, I took a look at how theadd_rowsmethod was coded for the Matrix class, and I noticed that it wasn't modifying the object, but was returning a new one.Instinctively, I would expect that I could do:
Instead, I need to assign it to a new instance to get the modified matrix:
matrix2 = matrix.add_rows(1, Crystalla::Matrix.new([4.5, 3.0], 1,2))Is there a particular reason why you made this choice ?
For Ndarrays, it would seem more natural to do:
Let me know what you think !