summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-03 03:38:06 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-03 03:38:06 +0000
commitf59098d1182f08594078bc458820c8ab8c972c46 (patch)
tree5835e3a4498e5f84f1f5ff722f3f812c8a4dabdf
parent1b5acebef2d447a3dbed6cf5e146fda74b81f10d (diff)
* lib/matrix.rb: Fix Matrix.rows copy bug.
Patch by Arron Mabrey. [Fix GH-707] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--lib/matrix.rb2
-rw-r--r--test/matrix/test_matrix.rb14
3 files changed, 20 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 21d35117d2d..79a3bf4a4c8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Oct 3 12:37:48 2014 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
+
+ * lib/matrix.rb: Fix Matrix.rows copy bug.
+ Patch by Arron Mabrey. [Fix GH-707]
+
Fri Oct 3 06:06:28 2014 Eric Wong <e@80x24.org>
* st.c (next_pow2): new function (from old bignum.c)
diff --git a/lib/matrix.rb b/lib/matrix.rb
index ed5390f8731..45c24d12755 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -152,7 +152,7 @@ class Matrix
# -1 66
#
def Matrix.rows(rows, copy = true)
- rows = convert_to_array(rows)
+ rows = convert_to_array(rows, copy)
rows.map! do |row|
convert_to_array(row, copy)
end
diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb
index 7c466e67fda..3e1e0db91e4 100644
--- a/test/matrix/test_matrix.rb
+++ b/test/matrix/test_matrix.rb
@@ -177,6 +177,20 @@ class TestMatrix < Test::Unit::TestCase
assert_equal(@m1, Matrix.rows([[1, 2, 3], [4, 5, 6]]))
end
+ def test_rows_copy
+ rows1 = [[1], [1]]
+ rows2 = [[1], [1]]
+
+ m1 = Matrix.rows(rows1, copy = false)
+ m2 = Matrix.rows(rows2, copy = true)
+
+ rows1.uniq!
+ rows2.uniq!
+
+ assert_equal([[1]], m1.to_a)
+ assert_equal([[1], [1]], m2.to_a)
+ end
+
def test_columns
assert_equal(@m1, Matrix.columns([[1, 4], [2, 5], [3, 6]]))
end