Feature #10072
closed[PATCH] Implement Vector.basis
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
Updated by gogotanaka (Kazuki Tanaka) over 10 years ago
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.
Updated by hsbt (Hiroshi SHIBATA) over 10 years ago
- Category set to lib
- Status changed from Open to Assigned
- Assignee set to marcandre (Marc-Andre Lafortune)
- Target version set to 2.2.0
Updated by marcandre (Marc-Andre Lafortune) about 10 years ago
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.
Updated by gogotanaka (Kazuki Tanaka) about 10 years ago
@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.
Updated by marcandre (Marc-Andre Lafortune) about 10 years ago
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.
Updated by duerst (Martin Dürst) about 10 years ago
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.
Updated by marcandre (Marc-Andre Lafortune) about 10 years ago
- 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.
Updated by gogotanaka (Kazuki Tanaka) about 10 years ago
@Martin Dürst @Marc-Andre Lafortune
I agree it. Thank you so much.