matrix 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/matrix.rb +29 -0
  3. data/lib/matrix/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfd415fd47ead13b790454f50a6959b76bdc68da569efefd53bf11424ad9c93f
4
- data.tar.gz: 78f73f4aed336e4903b48dc1de5a8835dbe019015f9f6d534bd89b380d0d6d16
3
+ metadata.gz: d1e195d010464fa1a56516e22f62671ab98829059b850cb960407e20d6e99834
4
+ data.tar.gz: 3bd6e8d34d46d7704eba6d8f5eb2010f000541c14fd373de009b50472ed0b409
5
5
  SHA512:
6
- metadata.gz: efe3e7cb0fcce4e68c58530a8f290df1b0ea4bfe94d92b0a0310e537b8bfa4c19f468128e2b505ad33e10a522ed366a996b384c4f7528f111ac5b8982693c99b
7
- data.tar.gz: cd798bc7bac9fdaa7586b25691bb2e69402b70a36bf66c821dc7ff406dd2b2f5e7d221535b7516ae809c29ea960cd04bd31072549db8150aebba33d3ef10f95d
6
+ metadata.gz: fa4026329141ac7ee02166b5e847512ee2325ddf107e72d0c0d82c25d80b19bf5c0173a01bdf7217cd43dbaa16bbdf4c2123b1fcca7b6efe9b8adc50be82db85
7
+ data.tar.gz: c905e4cd30d275ee1a74d6fabca5507331edfdcbf6f2665dc2869f7d1547c6919b4eb872358676a24e032017628caef4a9e61c3f086424ffeff9a1ddab95d082
@@ -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
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Matrix
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc-Andre Lafortune