matrix 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/matrix.rb +29 -0
- data/lib/matrix/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1e195d010464fa1a56516e22f62671ab98829059b850cb960407e20d6e99834
|
4
|
+
data.tar.gz: 3bd6e8d34d46d7704eba6d8f5eb2010f000541c14fd373de009b50472ed0b409
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa4026329141ac7ee02166b5e847512ee2325ddf107e72d0c0d82c25d80b19bf5c0173a01bdf7217cd43dbaa16bbdf4c2123b1fcca7b6efe9b8adc50be82db85
|
7
|
+
data.tar.gz: c905e4cd30d275ee1a74d6fabca5507331edfdcbf6f2665dc2869f7d1547c6919b4eb872358676a24e032017628caef4a9e61c3f086424ffeff9a1ddab95d082
|
data/lib/matrix.rb
CHANGED
@@ -1458,6 +1458,35 @@ class Matrix
|
|
1458
1458
|
rank
|
1459
1459
|
end
|
1460
1460
|
|
1461
|
+
#
|
1462
|
+
# Returns a new matrix with rotated elements.
|
1463
|
+
# The argument specifies the rotation (defaults to `:clockwise`):
|
1464
|
+
# * :clockwise, 1, -3, etc.: "turn right" - first row becomes last column
|
1465
|
+
# * :half_turn, 2, -2, etc.: first row becomes last row, elements in reverse order
|
1466
|
+
# * :counter_clockwise, -1, 3: "turn left" - first row becomes first column
|
1467
|
+
# (but with elements in reverse order)
|
1468
|
+
#
|
1469
|
+
# m = Matrix[ [1, 2], [3, 4] ]
|
1470
|
+
# r = m.rotate_entries(:clockwise)
|
1471
|
+
# # => Matrix[[3, 1], [4, 2]]
|
1472
|
+
#
|
1473
|
+
def rotate_entries(rotation = :clockwise)
|
1474
|
+
rotation %= 4 if rotation.respond_to? :to_int
|
1475
|
+
|
1476
|
+
case rotation
|
1477
|
+
when 0
|
1478
|
+
dup
|
1479
|
+
when 1, :clockwise
|
1480
|
+
new_matrix @rows.transpose.each(&:reverse!), row_count
|
1481
|
+
when 2, :half_turn
|
1482
|
+
new_matrix @rows.map(&:reverse).reverse!, column_count
|
1483
|
+
when 3, :counter_clockwise
|
1484
|
+
new_matrix @rows.transpose.reverse!, row_count
|
1485
|
+
else
|
1486
|
+
raise ArgumentError, "expected #{rotation.inspect} to be one of :clockwise, :counter_clockwise, :half_turn or an integer"
|
1487
|
+
end
|
1488
|
+
end
|
1489
|
+
|
1461
1490
|
# Returns a matrix with entries rounded to the given precision
|
1462
1491
|
# (see Float#round)
|
1463
1492
|
#
|
data/lib/matrix/version.rb
CHANGED