hamster-matrix 0.9.5 → 1.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: 8f6659d401677505ae8c2c64e378ccd0c30d574f
4
- data.tar.gz: d3c0811f005d505b108912fd5a86ab5f86ba483f
3
+ metadata.gz: e9c57bcfcd225a6ca7bfb04bae733b1e425bc5ed
4
+ data.tar.gz: 29cf5ba08be8187bbbd61b8f04202618c6f815fd
5
5
  SHA512:
6
- metadata.gz: cb3fbca3051385a36726d37d5c5a682a483474e99ecc2e9c71333a6e1c85d4f585d366e662aff336bf814b35054f993ddfed9ef884ec8314e300f0bb47de469d
7
- data.tar.gz: 2281e55d391c8599ada824c9037e25e9624e83af9d83e9d21abb3d67e355ade62fa2c2c123feeae7462cbfa0d92048dafb22869e299196541c51f8edf089c55a
6
+ metadata.gz: f8ac30643511bfceaab242dd3e7c77081968473d6c73f8210615b58ddd56e75c3c430513cca76f7ed72400bc188ae5b31f0705a409db5be4f03ac90af5903444
7
+ data.tar.gz: fab9518ebfb0dba3f762c4cb56ae783831bb1f80a4ac4a549b49d293c611300e51df4259594be73d5220d19332e818b2a36a534161f32ad114cb9ba22cc7f6e5
data/README.md CHANGED
@@ -25,7 +25,20 @@ Or install it yourself as:
25
25
 
26
26
  ## Usage
27
27
 
28
- ###Coming Soon!###
28
+ ```ruby
29
+ require 'hamster-matrix'
30
+ a = Hamster::Matrix[[1,0,0],[0,1,0],[0,0,1]]
31
+ b = a.set(2,2,'foo')
32
+ puts b
33
+ # [[1, 0, 0]
34
+ # [0, 1, 0]
35
+ # [0, 0, "foo"]]
36
+
37
+ puts a
38
+ #[[1, 0, 0]
39
+ # [0, 1, 0]
40
+ # [0, 0, 1]]
41
+ ```
29
42
 
30
43
  ## Contributing
31
44
 
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "hamster/matrix"
4
+ require "hamster-matrix"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -0,0 +1,2 @@
1
+ require 'hamster/matrix'
2
+ require 'hamster/version'
@@ -1,15 +1,18 @@
1
- require "hamster/version"
2
1
  require 'hamster'
3
2
  require 'matrix'
4
3
 
5
4
  module Hamster
6
-
7
- def self.matrix(array = Hamster.vector)
8
- Hamster::Matrix.new(array)
9
- end
10
-
11
5
  class Matrix
12
6
 
7
+ # Creates a new Hamster Matrix
8
+ #
9
+ # @example
10
+ # Hamster::Matrix[[1,0,0],[0,1,0],[0,0,1]]
11
+ # # => Hamster::Matrix[[1,0,0]
12
+ # # [0,1,0]
13
+ # # [0,0,1]]
14
+ #
15
+ # @return [Hamster::Matrix]
13
16
  def self.[](*array)
14
17
  Hamster::Matrix.new(array)
15
18
  end
@@ -87,6 +90,24 @@ module Hamster
87
90
  alias_method :component, :get
88
91
  alias_method :element, :get
89
92
 
93
+
94
+ # Sets the value at a certain given index, leaving
95
+ # existing references unchanged
96
+ #
97
+ # @example
98
+ # a = Hamster::Matrix[[1,0,0],[0,1,0],[0,0,1]]
99
+ # b = a.set(2,2,'foo')
100
+ # puts b
101
+ # # [[1, 0, 0]
102
+ # # [0, 1, 0]
103
+ # # [0, 0, "foo"]]
104
+
105
+ # puts a
106
+ # # [[1, 0, 0]
107
+ # # [0, 1, 0]
108
+ # # [0, 0, 1]]
109
+ #
110
+ # @return [Hamster::Matrix]
90
111
  def set(i,j,value)
91
112
  if(i >= row_vectors.size)
92
113
  raise ExceptionForMatrix::ErrDimensionMismatch.new("I index #{i} outside of array bounds")
@@ -141,7 +162,7 @@ module Hamster
141
162
  if empty?
142
163
  "#{self.class}.empty"
143
164
  else
144
- "#{self.class}#{row_string(16)}"
165
+ "#{self.class}#{row_string(19)}"
145
166
  end
146
167
  end
147
168
 
@@ -157,19 +178,28 @@ module Hamster
157
178
  row_string(1)
158
179
  end
159
180
 
181
+ def to_matrix
182
+ ::Matrix[to_a]
183
+ end
184
+
160
185
  def zero?
161
- row_vectors.all? { |row| row.all? { |elem| elem.is_a?(Numeric) && elem.zero? } }
186
+ row_vectors.all? do |row|
187
+ row.all? { |elem| elem.is_a?(Numeric) && elem.zero? }
188
+ end
162
189
  end
163
190
 
164
191
  attr_reader :row_vectors
165
192
 
166
- private
193
+ private
194
+
195
+ # @private
167
196
  def enumerable_check!(enumerable)
168
197
  unless enumerable.is_a?(::Enumerable)
169
198
  raise TypeError.new('Matrix rows must be Enumerable')
170
199
  end
171
200
  end
172
201
 
202
+ # @private
173
203
  def row_string(spaces)
174
204
  br = ''
175
205
  row_vectors.inject('[') do |acc, row|
@@ -1,5 +1,5 @@
1
1
  module Hamster
2
2
  class Matrix
3
- VERSION = "0.9.5"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hamster-matrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Urani
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-22 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,6 +86,7 @@ files:
86
86
  - bin/console
87
87
  - bin/setup
88
88
  - hamster-matrix.gemspec
89
+ - lib/hamster-matrix.rb
89
90
  - lib/hamster/matrix.rb
90
91
  - lib/hamster/version.rb
91
92
  homepage: https://github.com/bradurani/hamster-matrix