[#65451] [ruby-trunk - Feature #10333] [PATCH 3/1] optimize: "yoda literal" == string — ko1@...
Issue #10333 has been updated by Koichi Sasada.
ko1@atdot.net wrote:
Eric Wong <normalperson@yhbt.net> wrote:
Eric Wong <normalperson@yhbt.net> wrote:
On 2014/10/09 11:04, Eric Wong wrote:
SASADA Koichi <ko1@atdot.net> wrote:
[#65453] [ruby-trunk - Feature #10328] [PATCH] make OPT_SUPPORT_JOKE a proper VM option — ko1@...
Issue #10328 has been updated by Koichi Sasada.
[#65559] is there a name for this? — Xavier Noria <fxn@...>
When describing stuff about constants (working in their guide), you often
On 2014/10/09 20:41, Xavier Noria wrote:
On Thu, Oct 9, 2014 at 1:59 PM, Nobuyoshi Nakada <nobu@ruby-lang.org> wrote:
[#65566] [ruby-trunk - Feature #10351] [Open] [PATCH] prevent CVE-2014-6277 — shyouhei@...
Issue #10351 has been reported by Shyouhei Urabe.
[#65741] Re: [ruby-cvs:55121] normal:r47971 (trunk): test/ruby/test_rubyoptions.rb: fix race — Nobuyoshi Nakada <nobu@...>
On 2014/10/16 10:10, normal@ruby-lang.org wrote:
Nobuyoshi Nakada <nobu@ruby-lang.org> wrote:
2014-10-16 12:48 GMT+09:00 Eric Wong <normalperson@yhbt.net>:
[#65753] [ruby-trunk - Feature #10333] [PATCH 3/1] optimize: "yoda literal" == string — ko1@...
Issue #10333 has been updated by Koichi Sasada.
[#65818] [ruby-trunk - Feature #10351] [PATCH] prevent CVE-2014-6277 — shyouhei@...
Issue #10351 has been updated by Shyouhei Urabe.
[ruby-core:65510] [ruby-trunk - Feature #10077] [PATCH] Implement Matrix#row_merge and Matrix#column_merge
Issue #10077 has been updated by gogo tanaka.
@Marc-Andre Lafortune san
It’s hard for me to say this, but I have confidence in my implementation more than merged one.
My implementation
```
def row_merge(*matrices)
if matrices.any?{|m| m.row_size != row_size}
raise ErrDimensionMismatch, "all matrices should have same row size"
end
transpose.column_merge(*matrices.map(&:transpose)).transpose
end
alias_method :merge, :row_merge
def column_merge(*matrices)
if matrices.any?{|m| m.column_size != column_size }
raise ErrDimensionMismatch, "all matrices should have same column size"
end
new_matrix [self, *matrices].map(&:to_a).flatten(1)
end
```
Merged implementation
```
def Matrix.hstack(x, *matrices)
raise TypeError, "Expected a Matrix, got a #{x.class}" unless x.is_a?(Matrix)
result = x.send(:rows).map(&:dup)
total_column_count = x.column_count
matrices.each do |m|
raise TypeError, "Expected a Matrix, got a #{m.class}" unless m.is_a?(Matrix)
if m.row_count != x.row_count
raise ErrDimensionMismatch, "The given matrices must have #{x.row_count} rows, but one has #{m.row_count}"
end
result.each_with_index do |row, i|
row.concat m.send(:rows)[i]
end
total_column_count += m.column_count
end
new result, total_column_count
end
def Matrix.vstack(x, *matrices)
raise TypeError, "Expected a Matrix, got a #{x.class}" unless x.is_a?(Matrix)
result = x.send(:rows).map(&:dup)
matrices.each do |m|
raise TypeError, "Expected a Matrix, got a #{m.class}" unless m.is_a?(Matrix)
if m.column_count != x.column_count
raise ErrDimensionMismatch, "The given matrices must have #{x.column_count} columns, but one has #{m.column_count}"
end
result.concat(m.send(:rows))
end
new result, x.column_count
end
```
I believe the interface `x.row_merge(y) is preferred to Matrix.vstack(x, y)`,
And I think my implementation is more clear and maintainability.
Of course, merged one has some better point my patch doesn't have.
But we should use symmetry between row and column at least.
How is merged implementation preferred to my implementation?
I'm so sorry, I said something trouble.
Take you time.
----------------------------------------
Feature #10077: [PATCH] Implement Matrix#row_merge and Matrix#column_merge
https://bugs.ruby-lang.org/issues/10077#change-49285
* Author: gogo tanaka
* Status: Closed
* Priority: Normal
* Assignee: Marc-Andre Lafortune
* Category: lib
* Target version:
----------------------------------------
Merge matrices horizontally and vertically.
It is useful and important when we handle linear equations, statistics and so on.
```
Matrix[[1, 2], [3, 4]].row_merge(Matrix[[5], [6]])
=> 1 2 5
3 4 6
Matrix[[1, 2], [3, 4]].column_merge(Matrix[[5, 6]])
=> 1 2
3 4
5 6
# accept more than two matrices as an argument.
Matrix[[1, 2], [3, 4]].column_merge(Matrix[[5, 6]], Matrix[[7, 8]])
=> 1 2
3 4
5 6
7 8
```
* Matrix#row_merge needs Matrix#column
---Files--------------------------------
Implement_Matrix#column_merge.patch (863 Bytes)
Add_test_for_Matrix#column_merge.patch (1.36 KB)
Add_Matrix#column_merge_to_NEWS.patch (452 Bytes)
Implement_Matrix#row_merge.patch (899 Bytes)
Add_test_for_Matrix#row_merge.patch (1.4 KB)
Add_Matrix#row_merge_to_NEWS.patch (523 Bytes)
--
https://bugs.ruby-lang.org/