matrix 0.3.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/matrix/version.rb +1 -1
- data/lib/matrix.rb +36 -7
- data/matrix.gemspec +2 -5
- metadata +4 -38
- data/.gitignore +0 -9
- data/Gemfile +0 -6
- data/README.md +0 -45
- data/Rakefile +0 -10
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb141efd74292651e0289eb99780e5fdc476e5bf124a1038f6240939c629a2bf
|
4
|
+
data.tar.gz: 0e2f47d4f48c2986e4a4cc71973040b9b4a44f1e4c17a0f2319d46316ec742c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86c8960e1d3878711dc34b4af96ae95a4e0a2c765ab3fd1b63cf1e868ccd6b89cbdbbf4821744202c8ad834f7b65bd7b15642383156cac78d767351085ea4997
|
7
|
+
data.tar.gz: e1f5cf5fbdfb027d80afb774c3c89ef8ea837f2c1711ee91ac4689154a24588bfa21f74f2e47a71e5be698512c0023e4649ff1dc64d9feb0fbfcefe250874694
|
data/lib/matrix/version.rb
CHANGED
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
|
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
|
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
|
-
|
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
|
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
|
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
|
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
|
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 = ["
|
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 =
|
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.
|
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-
|
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.
|
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
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# Matrix [](https://badge.fury.io/rb/matrix) [](https://stdgems.org/matrix/) [](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
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__)
|