hamster-matrix 1.0.0 → 2.0.0

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
  SHA1:
3
- metadata.gz: e9c57bcfcd225a6ca7bfb04bae733b1e425bc5ed
4
- data.tar.gz: 29cf5ba08be8187bbbd61b8f04202618c6f815fd
3
+ metadata.gz: 9bc54527b6b284657666b4c78c03ed4d27d1714a
4
+ data.tar.gz: 30ea819a454e9e9e1e1732f28f11cbcfab7d3de4
5
5
  SHA512:
6
- metadata.gz: f8ac30643511bfceaab242dd3e7c77081968473d6c73f8210615b58ddd56e75c3c430513cca76f7ed72400bc188ae5b31f0705a409db5be4f03ac90af5903444
7
- data.tar.gz: fab9518ebfb0dba3f762c4cb56ae783831bb1f80a4ac4a549b49d293c611300e51df4259594be73d5220d19332e818b2a36a534161f32ad114cb9ba22cc7f6e5
6
+ metadata.gz: 00fdb59e5a2bc64efa0012907ed8dd34cf3167e185d4e7eddc1139d8f9e49b2691f5560e6b36209623c2fdc5446a2b07eac813f9761f49543b199621aaba8682
7
+ data.tar.gz: 221058ecedfe5f524b77883f306d5f860068882231cd7ad71cb839537472182ed429d61180fb54510fc179ed90e0a8c20e70eae0a97fa0e13969b930fcf3fea7
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hamster-matrix (0.9.5)
5
- hamster (~> 1.0)
4
+ hamster-matrix (2.0.0)
5
+ hamster (>= 1.0.0, < 3.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  # Hamster Matrix
4
4
 
5
- Hamster Matrix is a gem providing a persietent immutable matrix for functional programming in Ruby. It is an extension for the popular [Hamster](https://github.com/hamstergem/hamster/) gem, using Hamster [Vectors](http://www.rubydoc.info/github/hamstergem/hamster/master/Hamster/Vector) under the hood.
5
+ Hamster Matrix is a gem providing a persistent immutable matrix for functional programming in Ruby. It is an extension for the popular [Hamster](https://github.com/hamstergem/hamster/) gem. It creates a matrix by using nested Hamster [Vectors](http://www.rubydoc.info/github/hamstergem/hamster/master/Hamster/Vector).
6
6
 
7
- It's great for using as a board in 2D video games where the matrix must be modified as the game state changes while leaving references to the old state unchanged, such as when using a time-travelling debugger. It copies the interface from Ruby's [Matrix](http://ruby-doc.org/stdlib-2.0.0/libdoc/matrix/rdoc/Matrix.html) class as much as possible.
7
+ It's great for keeping the board state in 2D video games, where the state must be modified while leaving references to the old state unchanged, such as when using a time travelling debugger or implementing undo functionality. It copies the interface from Ruby's [Matrix](http://ruby-doc.org/stdlib-2.0.0/libdoc/matrix/rdoc/Matrix.html) class as much as possible.
8
8
 
9
9
 
10
10
  ## Installation
@@ -40,6 +40,48 @@ puts a
40
40
  # [0, 0, 1]]
41
41
  ```
42
42
 
43
+ Implements the following methods replicating the behavior of Ruby's [Matrix](http://ruby-doc.org/stdlib-2.0.0/libdoc/matrix/rdoc/Matrix.html) class as closely as possible
44
+
45
+ ### Class Methods
46
+ - []
47
+ - identity
48
+ - build
49
+ - column_vector
50
+ - columns
51
+ - diagonal
52
+ - I
53
+ - identity
54
+ - row_vector
55
+ - rows
56
+ - scalar
57
+ - unit
58
+
59
+ ### Instance Methods
60
+ - ==
61
+ - []
62
+ - collect
63
+ - column
64
+ - column_count
65
+ - column_size
66
+ - column_vectors
67
+ - component
68
+ - element
69
+ - empty?
70
+ - get
71
+ - hash
72
+ - inspect
73
+ - map
74
+ - row
75
+ - row_count
76
+ - row_size
77
+ - row_vectors
78
+ - set
79
+ - square?
80
+ - to_a
81
+ - to_matrix
82
+ - to_s
83
+ - zero?
84
+
43
85
  ## Contributing
44
86
 
45
87
  Bug reports and pull requests are welcome on GitHub at https://github.com/bradurani/hamster-matrix. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency 'rspec', '~> 3.0'
25
25
 
26
- spec.add_runtime_dependency 'hamster', '~> 1.0'
26
+ spec.add_runtime_dependency 'hamster', ['>= 1.0.0', '< 3.0']
27
27
  end
@@ -17,41 +17,49 @@ module Hamster
17
17
  Hamster::Matrix.new(array)
18
18
  end
19
19
 
20
+ # @return [Hamster::Matrix]
20
21
  def self.identity(n)
21
22
  return new if n == 0
22
23
  new(::Matrix.identity(n).row_vectors)
23
24
  end
24
25
 
26
+ # @return [Hamster::Matrix]
25
27
  def self.build(row_count, column_count = row_count, &block)
26
28
  matrix = ::Matrix.build(row_count, column_count, &block)
27
29
  new(matrix.row_vectors)
28
30
  end
29
31
 
32
+ # @return [Hamster::Matrix]
30
33
  def self.column_vector(array)
31
34
  matrix = ::Matrix.column_vector(array)
32
35
  new(matrix.row_vectors)
33
36
  end
34
37
 
38
+ # @return [Hamster::Matrix]
35
39
  def self.columns(array)
36
40
  matrix = ::Matrix.columns(array)
37
41
  new(matrix.row_vectors)
38
42
  end
39
43
 
44
+ # @return [Hamster::Matrix]
40
45
  def self.diagonal(*array)
41
46
  matrix = ::Matrix.diagonal(*array)
42
47
  new(matrix.row_vectors)
43
48
  end
44
49
 
50
+ # @return [Hamster::Matrix]
45
51
  def self.row_vector(row)
46
52
  matrix = ::Matrix.row_vector(row)
47
53
  new(matrix.row_vectors)
48
54
  end
49
55
 
56
+ # @return [Hamster::Matrix]
50
57
  def self.rows(row)
51
58
  matrix = ::Matrix.rows(row)
52
59
  new(matrix.row_vectors)
53
60
  end
54
61
 
62
+ # @return [Hamster::Matrix]
55
63
  def self.scalar(n, value)
56
64
  matrix = ::Matrix.scalar(n, value)
57
65
  new(matrix.row_vectors)
@@ -62,19 +70,20 @@ module Hamster
62
70
  alias_method :unit, :identity
63
71
  end
64
72
 
65
- def initialize(array = Hamster.vector)
73
+ def initialize(array = Hamster::Vector[])
66
74
  enumerable_check!(array)
67
75
  width = nil
68
- @row_vectors = Hamster.vector(*array.map do |a|
76
+ @row_vectors = Hamster::Vector[*array.map do |a|
69
77
  enumerable_check!(a)
70
78
  width ||= a.size
71
79
  unless(width == a.size)
72
80
  raise ExceptionForMatrix::ErrDimensionMismatch.new("row size differs (#{a.size} should be #{width})")
73
81
  end
74
- Hamster.vector(*a)
75
- end)
82
+ Hamster::Vector[*a]
83
+ end]
76
84
  end
77
85
 
86
+ # @return Boolean
78
87
  def ==(other)
79
88
  return false unless other.is_a? Hamster::Matrix
80
89
  self.row_vectors == other.row_vectors
@@ -101,7 +110,6 @@ module Hamster
101
110
  # # [[1, 0, 0]
102
111
  # # [0, 1, 0]
103
112
  # # [0, 0, "foo"]]
104
-
105
113
  # puts a
106
114
  # # [[1, 0, 0]
107
115
  # # [0, 1, 0]
@@ -120,16 +128,19 @@ module Hamster
120
128
  Hamster::Matrix.new(row_vectors.set(i, new_row))
121
129
  end
122
130
 
131
+ # @return [Hamster::Vector]
123
132
  def row(i)
124
133
  row_vectors[i]
125
134
  end
126
135
 
136
+ # @return [Fixnum]
127
137
  def column_count
128
138
  return 0 if row_vectors.size == 0
129
139
  return row_vectors.first.size
130
140
  end
131
141
  alias_method :column_size, :column_count
132
142
 
143
+ # @return [Fixnum]
133
144
  def row_count
134
145
  return row_vectors.size
135
146
  end
@@ -142,22 +153,27 @@ module Hamster
142
153
  end
143
154
  alias_method :map, :collect
144
155
 
156
+ # @return [Fixnum]
145
157
  def column(n)
146
158
  row_vectors.map { |row| row[n] }
147
159
  end
148
160
 
161
+ # @return [Hamster::Vector]
149
162
  def column_vectors
150
- Hamster.vector(*(0..row_vectors.size).map { |n| column(n) })
163
+ Hamster::Vector[*(0..row_vectors.size).map { |n| column(n) }]
151
164
  end
152
165
 
166
+ # @return [Boolean]
153
167
  def empty?
154
168
  row_vectors.size == 0
155
169
  end
156
170
 
171
+ # @return [Hash]
157
172
  def hash
158
173
  row_vectors.hash
159
174
  end
160
175
 
176
+ # @return [String]
161
177
  def inspect
162
178
  if empty?
163
179
  "#{self.class}.empty"
@@ -166,28 +182,34 @@ module Hamster
166
182
  end
167
183
  end
168
184
 
185
+ # @return [Boolean]
169
186
  def square?
170
187
  row_count == column_count
171
188
  end
172
189
 
190
+ # @return [Array]
173
191
  def to_a
174
192
  row_vectors.map { |row| row.to_a }.to_a
175
193
  end
176
194
 
195
+ # @return [String]
177
196
  def to_s
178
197
  row_string(1)
179
198
  end
180
199
 
200
+ # @return [::Matrix]
181
201
  def to_matrix
182
202
  ::Matrix[to_a]
183
203
  end
184
204
 
205
+ # @return [Boolean]
185
206
  def zero?
186
207
  row_vectors.all? do |row|
187
208
  row.all? { |elem| elem.is_a?(Numeric) && elem.zero? }
188
209
  end
189
210
  end
190
211
 
212
+ # @return [Hamster::Vector]
191
213
  attr_reader :row_vectors
192
214
 
193
215
  private
@@ -1,5 +1,5 @@
1
1
  module Hamster
2
2
  class Matrix
3
- VERSION = "1.0.0"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamster-matrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Urani
@@ -56,16 +56,22 @@ dependencies:
56
56
  name: hamster
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ - - "<"
60
63
  - !ruby/object:Gem::Version
61
- version: '1.0'
64
+ version: '3.0'
62
65
  type: :runtime
63
66
  prerelease: false
64
67
  version_requirements: !ruby/object:Gem::Requirement
65
68
  requirements:
66
- - - "~>"
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 1.0.0
72
+ - - "<"
67
73
  - !ruby/object:Gem::Version
68
- version: '1.0'
74
+ version: '3.0'
69
75
  description: Immutable persistent matrix using Hamster that aims to copy as much of
70
76
  the API from Ruby's native Matrix class as possible
71
77
  email:
@@ -114,3 +120,4 @@ signing_key:
114
120
  specification_version: 4
115
121
  summary: Immutable persistent matrix using Hamster
116
122
  test_files: []
123
+ has_rdoc: