rdx 0.9.0.pre

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.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/.rdx +20 -0
  3. data/README +19 -0
  4. data/bin/rdx +7 -0
  5. data/examples/minimal/.rdx +8 -0
  6. data/examples/minimal/README +10 -0
  7. data/examples/minimal/lib/other_conventions.rb +64 -0
  8. data/examples/minimal/lib/the_basics.rb +94 -0
  9. data/examples/minimal/lib/using_directives.rb +66 -0
  10. data/examples/minimal/rakefile +27 -0
  11. data/examples/ruby-2.0.0-p0/README +7 -0
  12. data/examples/ruby-2.0.0-p0/install/core/.rdx +6 -0
  13. data/examples/ruby-2.0.0-p0/install/core/README +19 -0
  14. data/examples/ruby-2.0.0-p0/install/core/Rakefile +61 -0
  15. data/examples/ruby-2.0.0-p0/install/core/diffs/array.c.diff +166 -0
  16. data/examples/ruby-2.0.0-p0/install/core/diffs/bignum.c.diff +11 -0
  17. data/examples/ruby-2.0.0-p0/install/core/diffs/class.c.diff +36 -0
  18. data/examples/ruby-2.0.0-p0/install/core/diffs/compar.c.diff +11 -0
  19. data/examples/ruby-2.0.0-p0/install/core/diffs/complex.c.diff +301 -0
  20. data/examples/ruby-2.0.0-p0/install/core/diffs/cont.c.diff +65 -0
  21. data/examples/ruby-2.0.0-p0/install/core/diffs/dir.c.diff +147 -0
  22. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/re.rdoc.diff +328 -0
  23. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/security.rdoc.diff +8 -0
  24. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/standard_library.rdoc.diff +0 -0
  25. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax.rdoc.diff +0 -0
  26. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/assignment.rdoc.diff +160 -0
  27. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/calling_methods.rdoc.diff +130 -0
  28. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/control_expressions.rdoc.diff +254 -0
  29. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/exceptions.rdoc.diff +0 -0
  30. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/literals.rdoc.diff +54 -0
  31. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/methods.rdoc.diff +157 -0
  32. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/miscellaneous.rdoc.diff +91 -0
  33. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/modules_and_classes.rdoc.diff +161 -0
  34. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/precedence.rdoc.diff +8 -0
  35. data/examples/ruby-2.0.0-p0/install/core/diffs/doc/syntax/refinements.rdoc.diff +146 -0
  36. data/examples/ruby-2.0.0-p0/install/core/diffs/encoding.c.diff +276 -0
  37. data/examples/ruby-2.0.0-p0/install/core/diffs/enum.c.diff +281 -0
  38. data/examples/ruby-2.0.0-p0/install/core/diffs/enumerator.c.diff +479 -0
  39. data/examples/ruby-2.0.0-p0/install/core/diffs/error.c.diff +143 -0
  40. data/examples/ruby-2.0.0-p0/install/core/diffs/eval.c.diff +47 -0
  41. data/examples/ruby-2.0.0-p0/install/core/diffs/eval_jump.c.diff +23 -0
  42. data/examples/ruby-2.0.0-p0/install/core/diffs/file.c.diff +752 -0
  43. data/examples/ruby-2.0.0-p0/install/core/diffs/gc.c.diff +195 -0
  44. data/examples/ruby-2.0.0-p0/install/core/diffs/hash.c.diff +84 -0
  45. data/examples/ruby-2.0.0-p0/install/core/diffs/iseq.c.diff +354 -0
  46. data/examples/ruby-2.0.0-p0/install/core/diffs/load.c.diff +53 -0
  47. data/examples/ruby-2.0.0-p0/install/core/diffs/marshal.c.diff +98 -0
  48. data/examples/ruby-2.0.0-p0/install/core/diffs/math.c.diff +110 -0
  49. data/examples/ruby-2.0.0-p0/install/core/diffs/numeric.c.diff +103 -0
  50. data/examples/ruby-2.0.0-p0/install/core/diffs/object.c.diff +295 -0
  51. data/examples/ruby-2.0.0-p0/install/core/diffs/pack.c.diff +18 -0
  52. data/examples/ruby-2.0.0-p0/install/core/diffs/parse.y.diff +23 -0
  53. data/examples/ruby-2.0.0-p0/install/core/diffs/proc.c.diff +155 -0
  54. data/examples/ruby-2.0.0-p0/install/core/diffs/random.c.diff +126 -0
  55. data/examples/ruby-2.0.0-p0/install/core/diffs/range.c.diff +49 -0
  56. data/examples/ruby-2.0.0-p0/install/core/diffs/rational.c.diff +312 -0
  57. data/examples/ruby-2.0.0-p0/install/core/diffs/re.c.diff +207 -0
  58. data/examples/ruby-2.0.0-p0/install/core/diffs/ruby.c.diff +21 -0
  59. data/examples/ruby-2.0.0-p0/install/core/diffs/signal.c.diff +67 -0
  60. data/examples/ruby-2.0.0-p0/install/core/diffs/sprintf.c.diff +29 -0
  61. data/examples/ruby-2.0.0-p0/install/core/diffs/string.c.diff +73 -0
  62. data/examples/ruby-2.0.0-p0/install/core/diffs/struct.c.diff +20 -0
  63. data/examples/ruby-2.0.0-p0/install/core/diffs/time.c.diff +691 -0
  64. data/examples/ruby-2.0.0-p0/install/core/diffs/transcode.c.diff +435 -0
  65. data/examples/ruby-2.0.0-p0/install/core/diffs/variable.c.diff +62 -0
  66. data/examples/ruby-2.0.0-p0/install/core/diffs/vm_backtrace.c.diff +164 -0
  67. data/examples/ruby-2.0.0-p0/install/core/diffs/vm_eval.c.diff +99 -0
  68. data/examples/ruby-2.0.0-p0/install/core/diffs/vm_method.c.diff +17 -0
  69. data/examples/ruby-2.0.0-p0/install/core/diffs/vm_trace.c.diff +393 -0
  70. data/examples/ruby-2.0.0-p0/install/stdlib/.rdx +6 -0
  71. data/examples/ruby-2.0.0-p0/install/stdlib/README +19 -0
  72. data/examples/ruby-2.0.0-p0/install/stdlib/Rakefile +53 -0
  73. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/abbrev.rb.diff +77 -0
  74. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/base64.rb.diff +42 -0
  75. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/benchmark.rb.diff +144 -0
  76. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/cmath.rb.diff +52 -0
  77. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/forwardable.rb.diff +150 -0
  78. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/mathn.rb.diff +58 -0
  79. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/matrix.rb.diff +657 -0
  80. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/observer.rb.diff +31 -0
  81. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/optparse.rb.diff +147 -0
  82. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/ostruct.rb.diff +78 -0
  83. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/prime.rb.diff +52 -0
  84. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/pstore.rb.diff +110 -0
  85. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/scanf.rb.diff +100 -0
  86. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/securerandom.rb.diff +144 -0
  87. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/set.rb.diff +637 -0
  88. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/shellwords.rb.diff +66 -0
  89. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/singleton.rb.diff +37 -0
  90. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/tempfile.rb.diff +104 -0
  91. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/thread.rb.diff +38 -0
  92. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/time.rb.diff +140 -0
  93. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/tmpdir.rb.diff +52 -0
  94. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/uri.rb.diff +39 -0
  95. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/uri/common.rb.diff +237 -0
  96. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/weakref.rb.diff +36 -0
  97. data/examples/ruby-2.0.0-p0/install/stdlib/diffs/lib/yaml/store.rb.diff +27 -0
  98. data/examples/ruby-2.0.0-p0/rakefile +165 -0
  99. data/lib/rdx.rb +331 -0
  100. data/lib/rdx/assertions.rb +484 -0
  101. data/lib/rdx/binding.rb +151 -0
  102. data/lib/rdx/code_object.rb +598 -0
  103. data/lib/rdx/comment.rb +338 -0
  104. data/lib/rdx/convention.rb +1174 -0
  105. data/lib/rdx/directive.rb +1432 -0
  106. data/lib/rdx/example.rb +679 -0
  107. data/lib/rdx/generator.rb +112 -0
  108. data/lib/rdx/generator/rdoc.rb +1006 -0
  109. data/lib/rdx/options.rb +359 -0
  110. data/lib/rdx/plain_text.rb +65 -0
  111. data/lib/rdx/reporter.rb +421 -0
  112. data/lib/rdx/ruby_lex.rb +324 -0
  113. data/lib/rdx/runner.rb +309 -0
  114. data/lib/rdx/source_file.rb +94 -0
  115. data/lib/rdx/specification.rb +194 -0
  116. data/lib/rdx/statement.rb +248 -0
  117. data/lib/rdx/store.rb +119 -0
  118. data/lib/rdx/task.rb +361 -0
  119. data/lib/rdx/text.rb +688 -0
  120. data/lib/rdx/version.rb +15 -0
  121. data/rakefile +64 -0
  122. metadata +203 -0
@@ -0,0 +1,58 @@
1
+ --- stdlib/orig/lib/mathn.rb 2015-06-11 07:51:45 +0000
2
+ +++ stdlib/patched/lib/mathn.rb 2015-06-25 15:53:50 +0000
3
+ @@ -10,16 +10,18 @@
4
+ # operations, then mathn is the right tool.
5
+ #
6
+ # Without mathn:
7
+ +# :rdx: before_require
8
+ #
9
+ -# 3 / 2 => 1 # Integer
10
+ +# 3 / 2 # => 1 # Integer
11
+ #
12
+ # With mathn:
13
+ #
14
+ -# 3 / 2 => 3/2 # Rational
15
+ +# 3 / 2 # => 3/2 # Rational
16
+ #
17
+ # mathn features late rounding and lacks truncation of intermediate results:
18
+ #
19
+ # Without mathn:
20
+ +# :rdx: before_require
21
+ #
22
+ # 20 / 9 * 3 * 14 / 7 * 3 / 2 # => 18
23
+ #
24
+ @@ -55,8 +57,10 @@
25
+ ##
26
+ # When mathn is required, Fixnum's division and exponentiation are enhanced to
27
+ # return more precise values from mathematical expressions.
28
+ -#
29
+ +#
30
+ +# :rdx: before_require
31
+ # 2/3*3 # => 0
32
+ +# :rdx:
33
+ # require 'mathn'
34
+ # 2/3*3 # => 2
35
+
36
+ @@ -119,8 +123,9 @@
37
+ # operations.
38
+ #
39
+ # Normal behaviour:
40
+ +# :rdx: before_require
41
+ #
42
+ -# Rational.new!(1,3) ** 2 # => Rational(1, 9)
43
+ +# Rational(1,3) ** 2 # => Rational(1, 9)
44
+ # (1 / 3) ** 2 # => 0
45
+ #
46
+ # require 'mathn' behaviour:
47
+ @@ -201,9 +206,10 @@
48
+ # When mathn is required, the Math module changes as follows:
49
+ #
50
+ # Standard Math module behaviour:
51
+ +# :rdx: before_require
52
+ # Math.sqrt(4/9) # => 0.0
53
+ # Math.sqrt(4.0/9.0) # => 0.666666666666667
54
+ -# Math.sqrt(- 4/9) # => Errno::EDOM: Numerical argument out of domain - sqrt
55
+ +# Math.sqrt(- 4/9) # raises Math::DomainError: Numerical argument is out of domain - "sqrt"
56
+ #
57
+ # After require 'mathn', this is changed to:
58
+ #
@@ -0,0 +1,657 @@
1
+ --- stdlib/orig/lib/matrix.rb 2015-06-11 07:51:45 +0000
2
+ +++ stdlib/patched/lib/matrix.rb 2015-06-25 16:11:40 +0000
3
+ @@ -119,6 +119,14 @@
4
+ # String representations:
5
+ # * #to_s
6
+ # * #inspect
7
+ +#
8
+ +# We define for convenience a few matrixes that will be used in the following examples:
9
+ +# :rdx: setup
10
+ +# m_int = Matrix[[1,2,3], [4,5,6]]
11
+ +# m_int2 = Matrix[[1,2,3], [4,5,6]] # same content as m_int, but different object
12
+ +# m_int_clone = m_int.clone
13
+ +# m_flt = Matrix[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
14
+ +# n_int = Matrix[[2,3,4], [5,6,7]]
15
+ #
16
+ class Matrix
17
+ include Enumerable
18
+ @@ -134,8 +142,14 @@
19
+ #
20
+ # Creates a matrix where each argument is a row.
21
+ # Matrix[ [25, 93], [-1, 66] ]
22
+ - # => 25 93
23
+ - # -1 66
24
+ + # # => Matrix[
25
+ + # # [25, 93],
26
+ + # # [-1, 66]
27
+ + # # ]
28
+ + # Matrix[Object.new] # raises TypeError
29
+ + # o = Object.new
30
+ + # def o.to_ary; [1,2,3]; end
31
+ + # Matrix[o] #=> Matrix[[1,2,3]]
32
+ #
33
+ def Matrix.[](*rows)
34
+ rows(rows, false)
35
+ @@ -146,8 +160,10 @@
36
+ # of the matrix. If the optional argument +copy+ is false, use the given
37
+ # arrays as the internal structure of the matrix without copying.
38
+ # Matrix.rows([[25, 93], [-1, 66]])
39
+ - # => 25 93
40
+ - # -1 66
41
+ + # # => Matrix[
42
+ + # # [25, 93],
43
+ + # # [-1, 66]
44
+ + # # ]
45
+ #
46
+ def Matrix.rows(rows, copy = true)
47
+ rows = convert_to_array(rows)
48
+ @@ -164,8 +180,10 @@
49
+ #
50
+ # Creates a matrix using +columns+ as an array of column vectors.
51
+ # Matrix.columns([[25, 93], [-1, 66]])
52
+ - # => 25 -1
53
+ - # 93 66
54
+ + # # => Matrix[
55
+ + # # [25, -1],
56
+ + # # [93, 66]
57
+ + # # ]
58
+ #
59
+ def Matrix.columns(columns)
60
+ rows(columns, false).transpose
61
+ @@ -178,9 +196,16 @@
62
+ # Returns an enumerator if no block is given.
63
+ #
64
+ # m = Matrix.build(2, 4) {|row, col| col - row }
65
+ - # => Matrix[[0, 1, 2, 3], [-1, 0, 1, 2]]
66
+ - # m = Matrix.build(3) { rand }
67
+ - # => a 3x3 matrix with random elements
68
+ + # # => Matrix[
69
+ + # # [ 0, 1, 2, 3],
70
+ + # # [-1, 0, 1, 2]
71
+ + # # ]
72
+ + # m = Matrix.build(3) { rand(10) }
73
+ + # # -> Matrix[
74
+ + # # [7, 1, 3],
75
+ + # # [2, 3, 6],
76
+ + # # [8, 2, 1]
77
+ + # # ]
78
+ #
79
+ def Matrix.build(row_count, column_count = row_count)
80
+ row_count = CoercionHelper.coerce_to_int(row_count)
81
+ @@ -198,9 +223,11 @@
82
+ #
83
+ # Creates a matrix where the diagonal elements are composed of +values+.
84
+ # Matrix.diagonal(9, 5, -3)
85
+ - # => 9 0 0
86
+ - # 0 5 0
87
+ - # 0 0 -3
88
+ + # # => Matrix[
89
+ + # # [9, 0, 0],
90
+ + # # [0, 5, 0],
91
+ + # # [0, 0,-3]
92
+ + # # ]
93
+ #
94
+ def Matrix.diagonal(*values)
95
+ size = values.size
96
+ @@ -216,8 +243,10 @@
97
+ # Creates an +n+ by +n+ diagonal matrix where each diagonal element is
98
+ # +value+.
99
+ # Matrix.scalar(2, 5)
100
+ - # => 5 0
101
+ - # 0 5
102
+ + # # => Matrix[
103
+ + # # [5, 0],
104
+ + # # [0, 5]
105
+ + # # ]
106
+ #
107
+ def Matrix.scalar(n, value)
108
+ diagonal(*Array.new(n, value))
109
+ @@ -226,8 +255,10 @@
110
+ #
111
+ # Creates an +n+ by +n+ identity matrix.
112
+ # Matrix.identity(2)
113
+ - # => 1 0
114
+ - # 0 1
115
+ + # # => Matrix[
116
+ + # # [1, 0],
117
+ + # # [0, 1]
118
+ + # # ]
119
+ #
120
+ def Matrix.identity(n)
121
+ scalar(n, 1)
122
+ @@ -240,8 +271,10 @@
123
+ #
124
+ # Creates a zero matrix.
125
+ # Matrix.zero(2)
126
+ - # => 0 0
127
+ - # 0 0
128
+ + # # => Matrix[
129
+ + # # [0, 0],
130
+ + # # [0, 0]
131
+ + # # ]
132
+ #
133
+ def Matrix.zero(row_count, column_count = row_count)
134
+ rows = Array.new(row_count){Array.new(column_count, 0)}
135
+ @@ -252,7 +285,9 @@
136
+ # Creates a single-row matrix where the values of that row are as given in
137
+ # +row+.
138
+ # Matrix.row_vector([4,5,6])
139
+ - # => 4 5 6
140
+ + # # => Matrix[
141
+ + # # [4, 5, 6]
142
+ + # # ]
143
+ #
144
+ def Matrix.row_vector(row)
145
+ row = convert_to_array(row)
146
+ @@ -263,9 +298,11 @@
147
+ # Creates a single-column matrix where the values of that column are as given
148
+ # in +column+.
149
+ # Matrix.column_vector([4,5,6])
150
+ - # => 4
151
+ - # 5
152
+ - # 6
153
+ + # # => Matrix[
154
+ + # # [4],
155
+ + # # [5],
156
+ + # # [6]
157
+ + # # ]
158
+ #
159
+ def Matrix.column_vector(column)
160
+ column = convert_to_array(column)
161
+ @@ -278,12 +315,12 @@
162
+ #
163
+ # m = Matrix.empty(2, 0)
164
+ # m == Matrix[ [], [] ]
165
+ - # => true
166
+ + # # => true
167
+ # n = Matrix.empty(0, 3)
168
+ # n == Matrix.columns([ [], [], [] ])
169
+ - # => true
170
+ + # # => true
171
+ # m * n
172
+ - # => Matrix[[0, 0, 0], [0, 0, 0]]
173
+ + # # => Matrix[[0, 0, 0], [0, 0, 0]]
174
+ #
175
+ def Matrix.empty(row_count = 0, column_count = 0)
176
+ raise ArgumentError, "One size must be 0" if column_count != 0 && row_count != 0
177
+ @@ -310,6 +347,10 @@
178
+
179
+ #
180
+ # Returns element (+i+,+j+) of the matrix. That is: row +i+, column +j+.
181
+ + # m = Matrix[ [1,2,3], [4,5,6] ]
182
+ + # m[0,0] #=> 1
183
+ + # m[1,0] #=> 4
184
+ + # m[1,2] #=> 6
185
+ #
186
+ def [](i, j)
187
+ @rows.fetch(i){return nil}[j]
188
+ @@ -341,6 +382,10 @@
189
+ #
190
+ # Returns row vector number +i+ of the matrix as a Vector (starting at 0 like
191
+ # an array). When a block is given, the elements of that vector are iterated.
192
+ + # m_int.row(0) #=> Vector[1, 2, 3]
193
+ + # a = []
194
+ + # m_int.row(0) {|x| a << x }
195
+ + # a #=> [1, 2, 3]
196
+ #
197
+ def row(i, &block) # :yield: e
198
+ if block_given?
199
+ @@ -355,6 +400,10 @@
200
+ # Returns column vector number +j+ of the matrix as a Vector (starting at 0
201
+ # like an array). When a block is given, the elements of that vector are
202
+ # iterated.
203
+ + # m_int.column(0) #=> Vector[1, 4]
204
+ + # a = []
205
+ + # m_int.column(0) {|x| a << x }
206
+ + # a #=> [1, 4]
207
+ #
208
+ def column(j) # :yield: e
209
+ if block_given?
210
+ @@ -376,8 +425,10 @@
211
+ # Returns a matrix that is the result of iteration of the given block over all
212
+ # elements of the matrix.
213
+ # Matrix[ [1,2], [3,4] ].collect { |e| e**2 }
214
+ - # => 1 4
215
+ - # 9 16
216
+ + # # => Matrix[
217
+ + # # [1, 4],
218
+ + # # [9,16]
219
+ + # # ]
220
+ #
221
+ def collect(&block) # :yield: e
222
+ return to_enum(:collect) unless block_given?
223
+ @@ -398,9 +449,10 @@
224
+ # * :strict_upper: yields only elements above the diagonal
225
+ # * :upper: yields only elements on or above the diagonal
226
+ #
227
+ - # Matrix[ [1,2], [3,4] ].each { |e| puts e }
228
+ - # # => prints the numbers 1 to 4
229
+ - # Matrix[ [1,2], [3,4] ].each(:strict_lower).to_a # => [3]
230
+ + # Matrix[ [1,2], [3,4] ].each { |e| print e }
231
+ + # # prints: 1234
232
+ + # Matrix[ [1,2], [3,4] ].each(:strict_lower).to_a
233
+ + # # => [3]
234
+ #
235
+ def each(which = :all) # :yield: e
236
+ return to_enum :each, which unless block_given?
237
+ @@ -457,11 +509,11 @@
238
+ # Matrix[ [1,2], [3,4] ].each_with_index do |e, row, col|
239
+ # puts "#{e} at #{row}, #{col}"
240
+ # end
241
+ - # # => Prints:
242
+ - # # 1 at 0, 0
243
+ - # # 2 at 0, 1
244
+ - # # 3 at 1, 0
245
+ - # # 4 at 1, 1
246
+ + # produces:
247
+ + # 1 at 0, 0
248
+ + # 2 at 0, 1
249
+ + # 3 at 1, 0
250
+ + # 4 at 1, 1
251
+ #
252
+ def each_with_index(which = :all) # :yield: e, row, column
253
+ return to_enum :each_with_index, which unless block_given?
254
+ @@ -549,8 +601,13 @@
255
+ # * row_range, col_range
256
+ #
257
+ # Matrix.diagonal(9, 5, -3).minor(0..1, 0..2)
258
+ - # => 9 0 0
259
+ - # 0 5 0
260
+ + # # => Matrix[
261
+ + # # [9, 0, 0],
262
+ + # # [0, 5, 0]
263
+ + # # ]
264
+ + # m_int.minor(0, 2, 0, 2)
265
+ + # # => Matrix[[1, 2], [4, 5]]
266
+ + # m_int.minor(0) # raises ArgumentError
267
+ #
268
+ # Like Array#[], negative indices count backward from the end of the
269
+ # row or column (-1 is the last element). Returns nil if the starting
270
+ @@ -695,6 +752,8 @@
271
+
272
+ #
273
+ # Returns +true+ if this is a regular (i.e. non-singular) matrix.
274
+ + # Matrix[[1, 0], [0, 1]].regular? #=> true
275
+ + # Matrix[[1, 0, 0], [0, 0, 1], [0, 0, 1]].regular? #=> false
276
+ #
277
+ def regular?
278
+ not singular?
279
+ @@ -702,6 +761,8 @@
280
+
281
+ #
282
+ # Returns +true+ is this is a singular matrix.
283
+ + # Matrix[[1, 0], [0, 1]].singular? #=> false
284
+ + # Matrix[[1, 0, 0], [0, 0, 1], [0, 0, 1]].singular? #=> true
285
+ #
286
+ def singular?
287
+ determinant == 0
288
+ @@ -709,6 +770,8 @@
289
+
290
+ #
291
+ # Returns +true+ is this is a square matrix.
292
+ + # Matrix[[1, 0], [0, 1]].square? #=> true
293
+ + # Matrix[[1, 0, 0], [0, 1, 0]].square? #=> false
294
+ #
295
+ def square?
296
+ column_count == row_count
297
+ @@ -762,8 +825,19 @@
298
+ # OBJECT METHODS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
299
+ #++
300
+
301
+ + #
302
+ + # test identity
303
+ + # :rdx: skip improve nested comments
304
+ + # m_int.equal? m_int2 #=> false
305
+ + # m_int.equal? m_int_clone #=> false
306
+ + # m_int.equal? m_flt #=> false
307
+ + # m_int.equal? n_int #=> false
308
+ + #
309
+ +
310
+ #
311
+ # Returns +true+ if and only if the two matrices contain equal elements.
312
+ + # m_int == m_int #=> true
313
+ + # m_int == m_flt #=> true
314
+ #
315
+ def ==(other)
316
+ return false unless Matrix === other &&
317
+ @@ -771,6 +845,16 @@
318
+ rows == other.rows
319
+ end
320
+
321
+ + #-- rdx
322
+ + # test hash equality
323
+ + # m_int.eql? m_int #=> true
324
+ + # m_int.eql? m_flt #=> false
325
+ + #
326
+ + # hash = { m_int => :value }
327
+ + # hash.key?(m_int2) #=> true
328
+ + # hash.key?(m_int_clone) #=> true
329
+ + # hash.key?(n_int) #=> false
330
+ + #
331
+ def eql?(other)
332
+ return false unless Matrix === other &&
333
+ column_count == other.column_count # necessary for empty matrices
334
+ @@ -781,13 +865,20 @@
335
+ # Returns a clone of the matrix, so that the contents of each do not reference
336
+ # identical objects.
337
+ # There should be no good reason to do this since Matrices are immutable.
338
+ - #
339
+ + # m_int == m_int_clone #=> true
340
+ + # m_int.equal? m_int_clone #=> false
341
+ + # m_int.equal? m_int #=> true
342
+ + #
343
+ def clone
344
+ new_matrix @rows.map(&:dup), column_count
345
+ end
346
+
347
+ #
348
+ # Returns a hash-code for the matrix.
349
+ + #-- rdx
350
+ + # m_int.hash #=> m_int.hash
351
+ + # m_int.hash #=> m_int2.hash
352
+ + # m_int.hash #=> m_int_clone.hash
353
+ #
354
+ def hash
355
+ @rows.hash
356
+ @@ -800,8 +891,13 @@
357
+ #
358
+ # Matrix multiplication.
359
+ # Matrix[[2,4], [6,8]] * Matrix.identity(2)
360
+ - # => 2 4
361
+ - # 6 8
362
+ + # # => Matrix[
363
+ + # # [2, 4],
364
+ + # # [6, 8]
365
+ + # # ]
366
+ + # Matrix[[2,4],[6,8]] * 2 #=> Matrix[[4,8],[12,16]]
367
+ + # 2 * Matrix[[2,4],[6,8]] #=> Matrix[[4,8],[12,16]]
368
+ + # m_int * Vector[1,2,3] #=> Vector[14,32]
369
+ #
370
+ def *(m) # m is matrix or vector or number
371
+ case(m)
372
+ @@ -833,8 +929,13 @@
373
+ #
374
+ # Matrix addition.
375
+ # Matrix.scalar(2,5) + Matrix[[1,0], [-4,7]]
376
+ - # => 6 0
377
+ - # -4 12
378
+ + # # => Matrix[
379
+ + # # [ 6, 0],
380
+ + # # [-4, 12]
381
+ + # # ]
382
+ + # Matrix.scalar(2,5) + Matrix[[1,0],[-4,7]] #=> Matrix[[6,0],[-4,12]]
383
+ + # Matrix[[1],[2],[3]] + Vector[1,2,3] #=> Matrix[[2],[4],[6]]
384
+ + # m_int + 1 # raises Matrix::ErrOperationNotDefined
385
+ #
386
+ def +(m)
387
+ case m
388
+ @@ -860,8 +961,13 @@
389
+ #
390
+ # Matrix subtraction.
391
+ # Matrix[[1,5], [4,2]] - Matrix[[9,3], [-4,1]]
392
+ - # => -8 2
393
+ - # 8 1
394
+ + # # => Matrix[
395
+ + # # [-8, 2],
396
+ + # # [ 8, 1]
397
+ + # # ]
398
+ + # Matrix.scalar(2,5) - Matrix[[1,0],[-4,7]] #=> Matrix[[4,0],[4,-2]]
399
+ + # Matrix[[1],[2],[3]] - Vector[1,2,3] #=> Matrix[[0],[0],[0]]
400
+ + # m_int - 1 # raises Matrix::ErrOperationNotDefined
401
+ #
402
+ def -(m)
403
+ case m
404
+ @@ -887,8 +993,11 @@
405
+ #
406
+ # Matrix division (multiplication by the inverse).
407
+ # Matrix[[7,6], [3,9]] / Matrix[[2,9], [3,1]]
408
+ - # => -7 1
409
+ - # -3 -6
410
+ + # # => Matrix[
411
+ + # # [Rational(11,25), Rational(51,25)],
412
+ + # # [Rational(24,25), Rational( 9,25)]
413
+ + # # ]
414
+ + # Matrix[[2,2],[2,2]] / Matrix.scalar(2,2) #=> Matrix[[1,1],[1,1]]
415
+ #
416
+ def /(other)
417
+ case other
418
+ @@ -907,8 +1016,10 @@
419
+ #
420
+ # Returns the inverse of the matrix.
421
+ # Matrix[[-1, -1], [0, -1]].inverse
422
+ - # => -1 1
423
+ - # 0 -1
424
+ + # # => Matrix[
425
+ + # # [-1, 1],
426
+ + # # [ 0, -1]
427
+ + # # ]
428
+ #
429
+ def inverse
430
+ Matrix.Raise ErrDimensionMismatch unless square?
431
+ @@ -967,8 +1078,12 @@
432
+ # Non integer exponents will be handled by diagonalizing the matrix.
433
+ #
434
+ # Matrix[[7,6], [3,9]] ** 2
435
+ - # => 67 96
436
+ - # 48 99
437
+ + # # => Matrix[
438
+ + # # [67, 96],
439
+ + # # [48, 99]
440
+ + # # ]
441
+ + # Matrix.I(5) ** -1 #=> Matrix.I(5)
442
+ + # Matrix.I(5) ** Object.new # raises Matrix::ErrOperationNotDefined
443
+ #
444
+ def ** (other)
445
+ case other
446
+ @@ -1005,7 +1120,9 @@
447
+ # Consider using exact types like Rational or BigDecimal instead.
448
+ #
449
+ # Matrix[[7,6], [3,9]].determinant
450
+ - # => 45
451
+ + # # => 45
452
+ + # Matrix[[2,0,1],[0,-2,2],[1,2,3]].determinant
453
+ + # # => -18
454
+ #
455
+ def determinant
456
+ Matrix.Raise ErrDimensionMismatch unless square?
457
+ @@ -1101,8 +1218,11 @@
458
+ # because of their lack of precision.
459
+ # Consider using exact types like Rational or BigDecimal instead.
460
+ #
461
+ - # Matrix[[7,6], [3,9]].rank
462
+ - # => 2
463
+ + # Matrix[[0]].rank #=> 0
464
+ + # Matrix[[0],[0]].rank #=> 0
465
+ + # Matrix[[7,6], [3,9]].rank
466
+ + # # => 2
467
+ + # Matrix[[0,0,1],[0,7,6],[1,3,9]].rank #=> 3
468
+ #
469
+ def rank
470
+ # We currently use Bareiss' multistep integer-preserving gaussian elimination
471
+ @@ -1150,7 +1270,8 @@
472
+ #
473
+ # Returns the trace (sum of diagonal elements) of the matrix.
474
+ # Matrix[[7,6], [3,9]].trace
475
+ - # => 16
476
+ + # # => 16
477
+ + # Matrix[[1,2,3],[4,5,6],[7,8,9]].trace #=> 1+5+9
478
+ #
479
+ def trace
480
+ Matrix.Raise ErrDimensionMismatch unless square?
481
+ @@ -1162,13 +1283,15 @@
482
+
483
+ #
484
+ # Returns the transpose of the matrix.
485
+ - # Matrix[[1,2], [3,4], [5,6]]
486
+ - # => 1 2
487
+ - # 3 4
488
+ - # 5 6
489
+ - # Matrix[[1,2], [3,4], [5,6]].transpose
490
+ - # => 1 3 5
491
+ - # 2 4 6
492
+ + # Matrix[
493
+ + # [1,2],
494
+ + # [3,4],
495
+ + # [5,6]
496
+ + # ].transpose
497
+ + # # => Matrix[
498
+ + # # [ 1, 3, 5],
499
+ + # # [ 2, 4, 6]
500
+ + # # ]
501
+ #
502
+ def transpose
503
+ return self.class.empty(column_count, 0) if row_count.zero?
504
+ @@ -1201,7 +1324,7 @@
505
+ # u.upper_triangular? # => true
506
+ # p.permutation? # => true
507
+ # l * u == p * a # => true
508
+ - # a.lup.solve([2, 5]) # => Vector[(1/1), (1/2)]
509
+ + # a.lup.solve([2, 5]) # => Vector[1, Rational(1,2)]
510
+ #
511
+ def lup
512
+ LUPDecomposition.new(self)
513
+ @@ -1214,12 +1337,14 @@
514
+
515
+ #
516
+ # Returns the conjugate of the matrix.
517
+ - # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]
518
+ - # => 1+2i i 0
519
+ - # 1 2 3
520
+ - # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].conjugate
521
+ - # => 1-2i -i 0
522
+ - # 1 2 3
523
+ + # Matrix[
524
+ + # [Complex(1,2), Complex(0,1), 0],
525
+ + # [1, 2, 3]
526
+ + # ].conjugate
527
+ + # # => Matrix[
528
+ + # # [1-2.i, -1.i, 0],
529
+ + # # [ 1 , 2 , 3]
530
+ + # # ]
531
+ #
532
+ def conjugate
533
+ collect(&:conjugate)
534
+ @@ -1228,12 +1353,14 @@
535
+
536
+ #
537
+ # Returns the imaginary part of the matrix.
538
+ - # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]
539
+ - # => 1+2i i 0
540
+ - # 1 2 3
541
+ - # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].imaginary
542
+ - # => 2i i 0
543
+ - # 0 0 0
544
+ + # Matrix[
545
+ + # [Complex(1,2), Complex(0,1), 0],
546
+ + # [1, 2, 3]
547
+ + # ].imaginary
548
+ + # # => Matrix[
549
+ + # # [ 2, 1, 0],
550
+ + # # [ 0, 0, 0]
551
+ + # # ]
552
+ #
553
+ def imaginary
554
+ collect(&:imaginary)
555
+ @@ -1242,12 +1369,14 @@
556
+
557
+ #
558
+ # Returns the real part of the matrix.
559
+ - # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]
560
+ - # => 1+2i i 0
561
+ - # 1 2 3
562
+ - # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].real
563
+ - # => 1 0 0
564
+ - # 1 2 3
565
+ + # Matrix[
566
+ + # [Complex(1,2), Complex(0,1), 0],
567
+ + # [1, 2, 3]
568
+ + # ].real
569
+ + # # => Matrix[
570
+ + # # [ 1, 0, 0],
571
+ + # # [ 1, 2, 3]
572
+ + # # ]
573
+ #
574
+ def real
575
+ collect(&:real)
576
+ @@ -1256,8 +1385,12 @@
577
+ #
578
+ # Returns an array containing matrices corresponding to the real and imaginary
579
+ # parts of the matrix
580
+ - #
581
+ - # m.rect == [m.real, m.imag] # ==> true for all matrices m
582
+ + #
583
+ + # For all matrices +m+:
584
+ + #-- rdx
585
+ + # m = Matrix.build(rand(10), rand(10)){ Complex( rand(10), rand(10)) }
586
+ + #++
587
+ + # m.rect == [m.real, m.imag] # => true
588
+ #
589
+ def rect
590
+ [real, imag]
591
+ @@ -1286,6 +1419,7 @@
592
+
593
+ #
594
+ # Returns an array of the row vectors of the matrix. See Vector.
595
+ + # m_int.row_vectors #=> [ Vector[1,2,3], Vector[4,5,6] ]
596
+ #
597
+ def row_vectors
598
+ Array.new(row_count) {|i|
599
+ @@ -1295,6 +1429,7 @@
600
+
601
+ #
602
+ # Returns an array of the column vectors of the matrix. See Vector.
603
+ + # m_int.column_vectors #=> [ Vector[1,4], Vector[2,5], Vector[3,6] ]
604
+ #
605
+ def column_vectors
606
+ Array.new(column_count) {|i|
607
+ @@ -1330,6 +1465,9 @@
608
+
609
+ #
610
+ # Overrides Object#to_s
611
+ + # m_int.to_s #=> "Matrix[[1, 2, 3], [4, 5, 6]]"
612
+ + # Matrix[].to_s #=> "Matrix.empty(0, 0)"
613
+ + # Matrix[[]].to_s #=> "Matrix.empty(1, 0)"
614
+ #
615
+ def to_s
616
+ if empty?
617
+ @@ -1550,7 +1688,7 @@
618
+
619
+ #
620
+ # Creates a Vector from a list of elements.
621
+ - # Vector[7, 4, ...]
622
+ + # Vector[7, 4, 5]
623
+ #
624
+ def Vector.[](*array)
625
+ new convert_to_array(array, false)
626
+ @@ -1745,7 +1883,7 @@
627
+
628
+ #
629
+ # Returns the inner product of this vector with the other.
630
+ - # Vector[4,7].inner_product Vector[10,1] => 47
631
+ + # Vector[4,7].inner_product Vector[10,1] #=> 47
632
+ #
633
+ def inner_product(v)
634
+ Vector.Raise ErrDimensionMismatch if size != v.size
635
+ @@ -1769,7 +1907,7 @@
636
+
637
+ #
638
+ # Returns the modulus (Pythagorean distance) of the vector.
639
+ - # Vector[5,8,2].r => 9.643650761
640
+ + # Vector[5,8,2].r #=> 9.643650761
641
+ #
642
+ def magnitude
643
+ Math.sqrt(@elements.inject(0) {|v, e| v + e.abs2})
644
+ @@ -1790,9 +1928,10 @@
645
+ end
646
+ #
647
+ # Returns a new vector with the same direction but with norm 1.
648
+ - # v = Vector[5,8,2].normalize
649
+ - # # => Vector[0.5184758473652127, 0.8295613557843402, 0.20739033894608505]
650
+ - # v.norm => 1.0
651
+ + # v = Vector[5,8,2]
652
+ + # v_normalized = Vector[0.5184758473652127, 0.8295613557843402, 0.20739033894608505]
653
+ + # (v.normalize - v_normalized).map{ |e| e.round(5) } #=> Vector[0, 0, 0]
654
+ + # v_normalized.norm # => 1.0
655
+ #
656
+ def normalize
657
+ n = magnitude