[#65451] [ruby-trunk - Feature #10333] [PATCH 3/1] optimize: "yoda literal" == string — ko1@...

Issue #10333 has been updated by Koichi Sasada.

9 messages 2014/10/07

[ruby-core:65526] [ruby-trunk - Feature #10077] [PATCH] Implement Matrix#row_merge and Matrix#column_merge

From: ruby-core@...
Date: 2014-10-08 16:09:19 UTC
List: ruby-core #65526
Issue #10077 has been updated by Marc-Andre Lafortune.


Thank you for your comments.

I want to point out that I've added both `x.hstack(y)` and `Matrix.hstack(x, y)`, so both interfaces are available now, the same way I would love for Array#product to have a corresponding Array.product (see https://bugs.ruby-lang.org/issues/8970)

Your proposed implementation using `transpose` is shorter, clever and expressive. It's very nice. I've chosen mine for efficiency:

    require 'fruity'
    m = Matrix.identity(3)
    compare do
      row_merge { m.row_merge(m) }
      hstack     { m.hstack(m) }
    end
    # => hstack is faster than row_merge by 2x 賊 0.1

For bigger matrices, the performance gap gets bigger (8x for 100x100 and 23x for 1000x1000).

----------------------------------------
Feature #10077: [PATCH] Implement Matrix#row_merge and Matrix#column_merge
https://bugs.ruby-lang.org/issues/10077#change-49297

* 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/

In This Thread

Prev Next