Feature #10072
closed
[PATCH] Implement Vector.basis
Added by gogotanaka (Kazuki Tanaka) over 10 years ago.
Updated about 10 years ago.
Description
Standard basis vectors are really important in linear algebra.
And we usually need this when we use matrix or vector. (base conversion, principal component analysis...
This is why I implemented.
But I recognize Ruby should be not for mathematician but rubyist.
Ruby doesn't need too academic method.
So If you think it is too academic you can ignore my patches.
gogo.
Files
We can build standard euclidean space easily with this method.
[Vector.basis(3, 0), Vector.basis(3, 1), Vector.basis(3, 2)]
=> [Vector[1, 0, 0], Vector[0, 1, 0], Vector[1, 0, 1]]
This patch is needed in https://bugs.ruby-lang.org/issues/10074
gogo.
- Category set to lib
- Status changed from Open to Assigned
- Assignee set to marcandre (Marc-Andre Lafortune)
- Target version set to 2.2.0
Looks good, but I'm wondering if we should use named arguments as it's really difficult to remember the order without looking it up.
Vector.basis(3, 0)
# or
Vector.basis(size: 3, index: 0)
Not sure.
@Marc-Andre Lafortune
I get your point. I admire your taste.
After some agonizing, I come up with implementing Vector.new
(like Array.new
) also.
And implement Vector#basis
as for index
.
So I mean, how about using Vector.new(3).basis(0)
instead of Vector.basis(3, 0)
?
Just idea.
Interesting idea, but it has issues, like private new currently requiring an array, and it being two steps, the first one not too clear.
I think it's best to pick between the two possibilities I gave.
On 2014/10/03 05:51, ruby-core@marc-andre.ca wrote:
Issue #10072 has been updated by Marc-Andre Lafortune.
Looks good, but I'm wondering if we should use named arguments as it's really difficult to remember the order without looking it up.
Vector.basis(3, 0)
# or
Vector.basis(size: 3, index: 0)
Not sure.
Why not allow both? Ruby is flexible.
Regards, Martin.
- Status changed from Assigned to Closed
Martin Dürst wrote:
Why not allow both? Ruby is flexible.
Indeed.
In this case though, it would be a bit of an overkill I think.
Let's use named arguments. If basis
becomes really popular and we want to make a shortcut we still can.
@Martin Dürst @Marc-Andre Lafortune
I agree it. Thank you so much.
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0