matrix 0.3.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfd415fd47ead13b790454f50a6959b76bdc68da569efefd53bf11424ad9c93f
4
- data.tar.gz: 78f73f4aed336e4903b48dc1de5a8835dbe019015f9f6d534bd89b380d0d6d16
3
+ metadata.gz: bb141efd74292651e0289eb99780e5fdc476e5bf124a1038f6240939c629a2bf
4
+ data.tar.gz: 0e2f47d4f48c2986e4a4cc71973040b9b4a44f1e4c17a0f2319d46316ec742c0
5
5
  SHA512:
6
- metadata.gz: efe3e7cb0fcce4e68c58530a8f290df1b0ea4bfe94d92b0a0310e537b8bfa4c19f468128e2b505ad33e10a522ed366a996b384c4f7528f111ac5b8982693c99b
7
- data.tar.gz: cd798bc7bac9fdaa7586b25691bb2e69402b70a36bf66c821dc7ff406dd2b2f5e7d221535b7516ae809c29ea960cd04bd31072549db8150aebba33d3ef10f95d
6
+ metadata.gz: 86c8960e1d3878711dc34b4af96ae95a4e0a2c765ab3fd1b63cf1e868ccd6b89cbdbbf4821744202c8ad834f7b65bd7b15642383156cac78d767351085ea4997
7
+ data.tar.gz: e1f5cf5fbdfb027d80afb774c3c89ef8ea837f2c1711ee91ac4689154a24588bfa21f74f2e47a71e5be698512c0023e4649ff1dc64d9feb0fbfcefe250874694
@@ -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.2"
5
5
  end
data/lib/matrix.rb CHANGED
@@ -379,7 +379,7 @@ class Matrix
379
379
  end
380
380
 
381
381
  private def set_value(row, col, value)
382
- raise ErrDimensionMismatch, "Expected a a value, got a #{value.class}" if value.respond_to?(:to_matrix)
382
+ raise ErrDimensionMismatch, "Expected a value, got a #{value.class}" if value.respond_to?(:to_matrix)
383
383
 
384
384
  @rows[row][col] = value
385
385
  end
@@ -1016,7 +1016,7 @@ class Matrix
1016
1016
  #++
1017
1017
 
1018
1018
  #
1019
- # Returns +true+ if and only if the two matrices contain equal elements.
1019
+ # Returns whether the two matrices contain equal elements.
1020
1020
  #
1021
1021
  def ==(other)
1022
1022
  return false unless Matrix === other &&
@@ -1239,7 +1239,7 @@ class Matrix
1239
1239
  when Integer
1240
1240
  case
1241
1241
  when exp == 0
1242
- _make_sure_it_is_invertible = inverse
1242
+ raise ErrDimensionMismatch unless square?
1243
1243
  self.class.identity(column_count)
1244
1244
  when exp < 0
1245
1245
  inverse.power_int(-exp)
@@ -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
  #
@@ -2105,7 +2134,7 @@ class Vector
2105
2134
  #++
2106
2135
 
2107
2136
  #
2108
- # Returns +true+ iff all of vectors are linearly independent.
2137
+ # Returns whether all of vectors are linearly independent.
2109
2138
  #
2110
2139
  # Vector.independent?(Vector[1,0], Vector[0,1])
2111
2140
  # # => true
@@ -2123,7 +2152,7 @@ class Vector
2123
2152
  end
2124
2153
 
2125
2154
  #
2126
- # Returns +true+ iff all of vectors are linearly independent.
2155
+ # Returns whether all of vectors are linearly independent.
2127
2156
  #
2128
2157
  # Vector[1,0].independent?(Vector[0,1])
2129
2158
  # # => true
@@ -2136,7 +2165,7 @@ class Vector
2136
2165
  end
2137
2166
 
2138
2167
  #
2139
- # Returns +true+ iff all elements are zero.
2168
+ # Returns whether all elements are zero.
2140
2169
  #
2141
2170
  def zero?
2142
2171
  all?(&:zero?)
@@ -2164,7 +2193,7 @@ class Vector
2164
2193
  #++
2165
2194
 
2166
2195
  #
2167
- # Returns +true+ iff the two vectors have the same elements in the same order.
2196
+ # Returns whether the two vectors have the same elements in the same order.
2168
2197
  #
2169
2198
  def ==(other)
2170
2199
  return false unless Vector === other
data/matrix.gemspec CHANGED
@@ -19,11 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.licenses = ["Ruby", "BSD-2-Clause"]
20
20
  spec.required_ruby_version = ">= 2.5.0"
21
21
 
22
- spec.files = [".gitignore", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "bin/console", "bin/setup", "lib/matrix.rb", "lib/matrix/eigenvalue_decomposition.rb", "lib/matrix/lup_decomposition.rb", "lib/matrix/version.rb", "matrix.gemspec"]
22
+ spec.files = ["LICENSE.txt", "lib/matrix.rb", "lib/matrix/eigenvalue_decomposition.rb", "lib/matrix/lup_decomposition.rb", "lib/matrix/version.rb", "matrix.gemspec"]
23
23
  spec.bindir = "exe"
24
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.executables = []
25
25
  spec.require_paths = ["lib"]
26
-
27
- spec.add_development_dependency "bundler"
28
- spec.add_development_dependency "rake"
29
26
  end
metadata CHANGED
@@ -1,43 +1,15 @@
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc-Andre Lafortune
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-16 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
11
+ date: 2021-06-18 00:00:00.000000000 Z
12
+ dependencies: []
41
13
  description: An implementation of Matrix and Vector classes.
42
14
  email:
43
15
  - ruby-core@marc-andre.ca
@@ -45,13 +17,7 @@ executables: []
45
17
  extensions: []
46
18
  extra_rdoc_files: []
47
19
  files:
48
- - ".gitignore"
49
- - Gemfile
50
20
  - LICENSE.txt
51
- - README.md
52
- - Rakefile
53
- - bin/console
54
- - bin/setup
55
21
  - lib/matrix.rb
56
22
  - lib/matrix/eigenvalue_decomposition.rb
57
23
  - lib/matrix/lup_decomposition.rb
@@ -77,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
43
  - !ruby/object:Gem::Version
78
44
  version: '0'
79
45
  requirements: []
80
- rubygems_version: 3.2.3
46
+ rubygems_version: 3.3.0.dev
81
47
  signing_key:
82
48
  specification_version: 4
83
49
  summary: An implementation of Matrix and Vector classes.
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in matrix.gemspec
6
- gemspec
data/README.md DELETED
@@ -1,45 +0,0 @@
1
- # Matrix [![Version](https://badge.fury.io/rb/matrix.svg)](https://badge.fury.io/rb/matrix) [![Default Gem](https://img.shields.io/badge/stdgem-default-9c1260.svg)](https://stdgems.org/matrix/) [![Test](https://github.com/ruby/matrix/workflows/test/badge.svg)](https://github.com/ruby/matrix/actions?query=workflow%3Atest)
2
-
3
- An implementation of `Matrix` and `Vector` classes.
4
-
5
- The `Matrix` class represents a mathematical matrix. It provides methods for creating matrices, operating on them arithmetically and algebraically, and determining their mathematical properties (trace, rank, inverse, determinant, eigensystem, etc.).
6
-
7
- The `Vector` class represents a mathematical vector, which is useful in its own right, and also constitutes a row or column of a `Matrix`.
8
-
9
- ## Installation
10
-
11
- The `matrix` library comes pre-installed with Ruby. Unless you need recent features, you can simply `require 'matrix'` directly, no need to install it.
12
-
13
- If you need features that are more recent than the version of Ruby you want to support (check the [CHANGELOG](CHANGELOG.md)), you must use the gem. To do this, add this line to your application's Gemfile or gem's gemspec:
14
-
15
- ```ruby
16
- gem 'matrix'
17
- ```
18
-
19
- And then execute:
20
-
21
- $ bundle
22
-
23
- To make sure that the gem takes precedence over the builtin library, call `bundle exec ...` (or call `gem 'matrix'` explicitly).
24
-
25
- ## Usage
26
-
27
- ```ruby
28
- require 'matrix'
29
- m = Matrix[[1, 2], [3, 4]]
30
- m.determinant # => -2
31
- ```
32
-
33
- ## Development
34
-
35
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
-
37
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
-
39
- ## Contributing
40
-
41
- Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/matrix.
42
-
43
- ## License
44
-
45
- The gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test" << "test/lib"
6
- t.libs << "lib"
7
- t.test_files = FileList['test/**/test_*.rb']
8
- end
9
-
10
- task :default => [:test]
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "matrix"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here