epitools 0.5.31 → 0.5.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/epitools/autoloads.rb +1 -1
- data/lib/epitools/core_ext/matrix.rb +73 -0
- data/lib/epitools/core_ext/misc.rb +0 -68
- data/spec/core_ext_spec.rb +8 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0b663423844dcefe3e743a90a86cbcaab0ab460
|
4
|
+
data.tar.gz: 9a874aa31d99c415751afaed0b29542ae520cf1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1509cff967e02c20eaa9779f8608f86c3d97ffd7f84d8d1910dc492b6d0ff5eacbb655ba7af647f9dfb4b5cbdcf484f07336714344f61b22d9d7afb8bedc47a2
|
7
|
+
data.tar.gz: 06244532a2aa98d81bb1b1d6a243e2dc09e4855e8b04a5af4d71a537cf27d5fec0bddef7fc6e766c46e1ed07fd3fd6abbb314ac0546215d702a7dca29ca264ab
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.32
|
data/lib/epitools/autoloads.rb
CHANGED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'matrix'
|
2
|
+
|
3
|
+
#
|
4
|
+
# Matrix extensions
|
5
|
+
#
|
6
|
+
class Matrix
|
7
|
+
|
8
|
+
alias_class_method :zeros, :zero
|
9
|
+
alias_class_method :zeroes, :zero
|
10
|
+
|
11
|
+
#
|
12
|
+
# Create a matrix of the specified size full of random numbers.
|
13
|
+
#
|
14
|
+
def self.random(*dims)
|
15
|
+
build(*dims) { rand }
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
#
|
20
|
+
# The size of the matrix, returned as `[rows, columns]`.
|
21
|
+
#
|
22
|
+
def size
|
23
|
+
[row_size, column_size]
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Print the matrix to the STDOUT.
|
28
|
+
#
|
29
|
+
def print(header=true, separator=" ")
|
30
|
+
max_width = map {|num| num.to_s.size }.max
|
31
|
+
|
32
|
+
case first
|
33
|
+
when Integer
|
34
|
+
justify = :rjust
|
35
|
+
when Float
|
36
|
+
justify = :ljust
|
37
|
+
else
|
38
|
+
raise "Unknown matrix element type: #{first.class}"
|
39
|
+
end
|
40
|
+
|
41
|
+
# print it!
|
42
|
+
puts "#{size.join("x")} matrix:" if header
|
43
|
+
|
44
|
+
rows.each do |row|
|
45
|
+
puts " " + row.map { |n| n.to_s.send(justify, max_width) }.join(separator)
|
46
|
+
end
|
47
|
+
|
48
|
+
puts
|
49
|
+
end
|
50
|
+
|
51
|
+
alias_method :draw, :print
|
52
|
+
|
53
|
+
#
|
54
|
+
# Allow mathematical operations (*, /, +, -) with a regular number on the right side.
|
55
|
+
#
|
56
|
+
# eg: Matrix.zero(3) + 5
|
57
|
+
#
|
58
|
+
%w[* / + -].each do |op|
|
59
|
+
class_eval %{
|
60
|
+
def #{op}(other)
|
61
|
+
case other
|
62
|
+
when Fixnum, Float
|
63
|
+
map { |e| e #{op} other }
|
64
|
+
else
|
65
|
+
super(other)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
public :[]=
|
72
|
+
|
73
|
+
end
|
@@ -243,74 +243,6 @@ module ObjectSpace
|
|
243
243
|
|
244
244
|
end
|
245
245
|
|
246
|
-
|
247
|
-
#
|
248
|
-
# Matrix extensions
|
249
|
-
#
|
250
|
-
class Matrix
|
251
|
-
|
252
|
-
#
|
253
|
-
# Create a matrix of the specified size full of random numbers.
|
254
|
-
#
|
255
|
-
def self.random(*dims)
|
256
|
-
build(*dims) { rand }
|
257
|
-
end
|
258
|
-
|
259
|
-
|
260
|
-
#
|
261
|
-
# The size of the matrix, returned as `[rows, columns]`.
|
262
|
-
#
|
263
|
-
def size
|
264
|
-
[row_size, column_size]
|
265
|
-
end
|
266
|
-
|
267
|
-
#
|
268
|
-
# Print the matrix to the STDOUT.
|
269
|
-
#
|
270
|
-
def print(header=true, separator=" ")
|
271
|
-
max_width = map {|num| num.to_s.size }.max
|
272
|
-
|
273
|
-
case first
|
274
|
-
when Integer
|
275
|
-
justify = :rjust
|
276
|
-
when Float
|
277
|
-
justify = :ljust
|
278
|
-
else
|
279
|
-
raise "Unknown matrix element type: #{first.class}"
|
280
|
-
end
|
281
|
-
|
282
|
-
# print it!
|
283
|
-
puts "#{size.join("x")} matrix:" if header
|
284
|
-
|
285
|
-
rows.each do |row|
|
286
|
-
puts " " + row.map { |n| n.to_s.send(justify, max_width) }.join(separator)
|
287
|
-
end
|
288
|
-
|
289
|
-
puts
|
290
|
-
end
|
291
|
-
|
292
|
-
alias_method :draw, :print
|
293
|
-
|
294
|
-
#
|
295
|
-
# Allow mathematical operations (*, /, +, -) with a regular number on the right side.
|
296
|
-
#
|
297
|
-
# eg: Matrix.zero(3) + 5
|
298
|
-
#
|
299
|
-
%w[* / + -].each do |op|
|
300
|
-
class_eval %{
|
301
|
-
def #{op}(other)
|
302
|
-
case other
|
303
|
-
when Fixnum, Float
|
304
|
-
map { |e| e #{op} other }
|
305
|
-
else
|
306
|
-
super(other)
|
307
|
-
end
|
308
|
-
end
|
309
|
-
}
|
310
|
-
end
|
311
|
-
|
312
|
-
end
|
313
|
-
|
314
246
|
#
|
315
247
|
# Flush standard input's buffer.
|
316
248
|
#
|
data/spec/core_ext_spec.rb
CHANGED
@@ -645,6 +645,14 @@ describe Matrix do
|
|
645
645
|
(m / 2.0).to_a.should == [[0.5,1,1.5]]
|
646
646
|
end
|
647
647
|
|
648
|
+
it "lets you set things" do
|
649
|
+
m = Matrix.zeros(1,3)
|
650
|
+
m.to_a.should == [[0,0,0]]
|
651
|
+
m[0,0].should == 0
|
652
|
+
m[0,2] = 5
|
653
|
+
m.to_a.should == [[0,0,5]]
|
654
|
+
end
|
655
|
+
|
648
656
|
end
|
649
657
|
|
650
658
|
describe "truthiness" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.32
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/epitools/core_ext/array.rb
|
54
54
|
- lib/epitools/core_ext/enumerable.rb
|
55
55
|
- lib/epitools/core_ext/hash.rb
|
56
|
+
- lib/epitools/core_ext/matrix.rb
|
56
57
|
- lib/epitools/core_ext/misc.rb
|
57
58
|
- lib/epitools/core_ext/numbers.rb
|
58
59
|
- lib/epitools/core_ext/object.rb
|