cartesian 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/cartesian.rb +1 -1
- data/lib/cartesian/version.rb +2 -2
- data/lib/cartesian_iterator.rb +2 -2
- data/website/doc/CartesianIterator.html +64 -65
- data/website/doc/Iterable.html +20 -60
- data/website/doc/README_rdoc.html +1 -1
- data/website/doc/created.rid +5 -6
- data/website/doc/index.html +0 -2
- data/website/doc/lib/cartesian_iterator_rb.html +1 -3
- data/website/doc/lib/cartesian_rb.html +1 -1
- data/website/doc/lib/grid_search_rb.html +1 -1
- data/website/index.html +125 -2
- metadata +56 -69
data/History.txt
CHANGED
data/lib/cartesian.rb
CHANGED
@@ -39,7 +39,7 @@ module Cartesian
|
|
39
39
|
# Unfortunately, as of now, the version data must be replicated in ../cartesian.rb,
|
40
40
|
# due to a mix of newgem versions, each requiring a different one. Not DRY :P
|
41
41
|
#
|
42
|
-
VERSION = "0.6.
|
42
|
+
VERSION = "0.6.7"
|
43
43
|
|
44
44
|
# Produces the cartesian product of self and other.
|
45
45
|
# The result is an array of pairs (i.e. two-element arrays).
|
data/lib/cartesian/version.rb
CHANGED
data/lib/cartesian_iterator.rb
CHANGED
@@ -58,14 +58,14 @@ class CartesianIterator
|
|
58
58
|
for list in @lists
|
59
59
|
elems << list.restart_and_raw_next
|
60
60
|
end
|
61
|
-
|
61
|
+
yield(*elems.dup)
|
62
62
|
|
63
63
|
last_list_index = @lists.size-1
|
64
64
|
n = last_list_index
|
65
65
|
loop do
|
66
66
|
if !@lists[n].done?
|
67
67
|
elems[n] = @lists[n].raw_next
|
68
|
-
|
68
|
+
yield(*elems.dup)
|
69
69
|
n = last_list_index
|
70
70
|
next
|
71
71
|
elsif n > 0
|
@@ -201,13 +201,13 @@
|
|
201
201
|
<div class="method-source-code"
|
202
202
|
id="new-source">
|
203
203
|
<pre>
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
204
|
+
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 3</span>
|
205
|
+
3: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">foo</span>, <span class="ruby-identifier">bar</span>)
|
206
|
+
4: <span class="ruby-ivar">@lists</span> = []
|
207
|
+
5: <span class="ruby-ivar">@tot_iter</span> = <span class="ruby-value">1</span>
|
208
|
+
6: <span class="ruby-identifier">product!</span>(<span class="ruby-identifier">foo</span>)
|
209
|
+
7: <span class="ruby-identifier">product!</span>(<span class="ruby-identifier">bar</span>)
|
210
|
+
8: <span class="ruby-keyword kw">end</span></pre>
|
211
211
|
</div>
|
212
212
|
|
213
213
|
</div>
|
@@ -273,10 +273,10 @@
|
|
273
273
|
<div class="method-source-code"
|
274
274
|
id="dup-source">
|
275
275
|
<pre>
|
276
|
-
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line
|
277
|
-
|
278
|
-
|
279
|
-
|
276
|
+
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 10</span>
|
277
|
+
10: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dup</span>
|
278
|
+
11: <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span>(<span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-keyword kw">self</span>))
|
279
|
+
12: <span class="ruby-keyword kw">end</span></pre>
|
280
280
|
</div>
|
281
281
|
|
282
282
|
</div>
|
@@ -307,32 +307,31 @@
|
|
307
307
|
<div class="method-source-code"
|
308
308
|
id="each-source">
|
309
309
|
<pre>
|
310
|
-
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line
|
311
|
-
|
312
|
-
|
310
|
+
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 48</span>
|
311
|
+
48: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">each</span>
|
312
|
+
49: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@tot_iter</span> <span class="ruby-operator"><</span> <span class="ruby-value">1</span>
|
313
|
+
50:
|
314
|
+
51: <span class="ruby-identifier">elems</span> = []
|
315
|
+
52: <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">list</span> <span class="ruby-keyword kw">in</span> <span class="ruby-ivar">@lists</span>
|
316
|
+
53: <span class="ruby-identifier">elems</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">list</span>.<span class="ruby-identifier">restart_and_raw_next</span>
|
317
|
+
54: <span class="ruby-keyword kw">end</span>
|
318
|
+
55: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator"><=</span> <span class="ruby-value str">'1.9.1'</span>; <span class="ruby-keyword kw">yield</span>(*<span class="ruby-identifier">elems</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span> }); <span class="ruby-keyword kw">else</span>; <span class="ruby-keyword kw">yield</span>(*<span class="ruby-identifier">elems</span>); <span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt"># Yeah, v.map{|x|x} should be equal to v, but strangely it is NOT in Ruby versions prior to 1.9.2.</span>
|
313
319
|
56:
|
314
|
-
57: <span class="ruby-identifier">
|
315
|
-
58: <span class="ruby-
|
316
|
-
59:
|
317
|
-
60:
|
318
|
-
61:
|
319
|
-
62:
|
320
|
-
63:
|
321
|
-
64:
|
322
|
-
65:
|
323
|
-
66:
|
324
|
-
67:
|
325
|
-
68: <span class="ruby-keyword kw">
|
326
|
-
69:
|
327
|
-
70:
|
328
|
-
71:
|
329
|
-
72: <span class="ruby-identifier">elems</span>[<span class="ruby-identifier">n</span>] = <span class="ruby-ivar">@lists</span>[<span class="ruby-identifier">n</span>].<span class="ruby-identifier">restart_and_raw_next</span>
|
330
|
-
73: <span class="ruby-identifier">n</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
|
331
|
-
74: <span class="ruby-keyword kw">else</span>
|
332
|
-
75: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
|
333
|
-
76: <span class="ruby-keyword kw">end</span>
|
334
|
-
77: <span class="ruby-keyword kw">end</span>
|
335
|
-
78: <span class="ruby-keyword kw">end</span></pre>
|
320
|
+
57: <span class="ruby-identifier">last_list_index</span> = <span class="ruby-ivar">@lists</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>
|
321
|
+
58: <span class="ruby-identifier">n</span> = <span class="ruby-identifier">last_list_index</span>
|
322
|
+
59: <span class="ruby-identifier">loop</span> <span class="ruby-keyword kw">do</span>
|
323
|
+
60: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">elems</span>[<span class="ruby-identifier">n</span>] = <span class="ruby-ivar">@lists</span>[<span class="ruby-identifier">n</span>].<span class="ruby-identifier">raw_next</span>
|
324
|
+
61: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">RUBY_VERSION</span> <span class="ruby-operator"><=</span> <span class="ruby-value str">'1.9.1'</span>; <span class="ruby-keyword kw">yield</span>(*<span class="ruby-identifier">elems</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span> }); <span class="ruby-keyword kw">else</span>; <span class="ruby-keyword kw">yield</span>(*<span class="ruby-identifier">elems</span>); <span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt"># See previous comment.</span>
|
325
|
+
62: <span class="ruby-identifier">n</span> = <span class="ruby-identifier">last_list_index</span>
|
326
|
+
63: <span class="ruby-keyword kw">next</span>
|
327
|
+
64: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">n</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
328
|
+
65: <span class="ruby-identifier">elems</span>[<span class="ruby-identifier">n</span>] = <span class="ruby-ivar">@lists</span>[<span class="ruby-identifier">n</span>].<span class="ruby-identifier">restart_and_raw_next</span>
|
329
|
+
66: <span class="ruby-identifier">n</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
|
330
|
+
67: <span class="ruby-keyword kw">else</span>
|
331
|
+
68: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
|
332
|
+
69: <span class="ruby-keyword kw">end</span>
|
333
|
+
70: <span class="ruby-keyword kw">end</span>
|
334
|
+
71: <span class="ruby-keyword kw">end</span></pre>
|
336
335
|
</div>
|
337
336
|
|
338
337
|
</div>
|
@@ -363,13 +362,13 @@
|
|
363
362
|
<div class="method-source-code"
|
364
363
|
id="equal-source">
|
365
364
|
<pre>
|
366
|
-
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
365
|
+
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 14</span>
|
366
|
+
14: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">equal</span>(<span class="ruby-identifier">other</span>)
|
367
|
+
15: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">instance_variables</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">var_name</span><span class="ruby-operator">|</span>
|
368
|
+
16: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-identifier">var_name</span>) <span class="ruby-operator">!=</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-identifier">var_name</span>)
|
369
|
+
17: <span class="ruby-keyword kw">end</span>
|
370
|
+
18: <span class="ruby-keyword kw">true</span>
|
371
|
+
19: <span class="ruby-keyword kw">end</span></pre>
|
373
372
|
</div>
|
374
373
|
|
375
374
|
</div>
|
@@ -404,11 +403,11 @@
|
|
404
403
|
<div class="method-source-code"
|
405
404
|
id="left-product-source">
|
406
405
|
<pre>
|
407
|
-
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
406
|
+
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 43</span>
|
407
|
+
43: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">left_product</span>(<span class="ruby-identifier">other</span>)
|
408
|
+
44: (<span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">dup</span>).<span class="ruby-identifier">left_product!</span>(<span class="ruby-identifier">other</span>)
|
409
|
+
45: <span class="ruby-identifier">result</span>
|
410
|
+
46: <span class="ruby-keyword kw">end</span></pre>
|
412
411
|
</div>
|
413
412
|
|
414
413
|
</div>
|
@@ -439,12 +438,12 @@
|
|
439
438
|
<div class="method-source-code"
|
440
439
|
id="left-product--source">
|
441
440
|
<pre>
|
442
|
-
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
441
|
+
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 30</span>
|
442
|
+
30: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">left_product!</span>(<span class="ruby-identifier">other</span>)
|
443
|
+
31: <span class="ruby-ivar">@lists</span>.<span class="ruby-identifier">unshift</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">to_a</span>.<span class="ruby-identifier">dup</span>
|
444
|
+
32: <span class="ruby-ivar">@tot_iter</span> <span class="ruby-operator">*=</span> <span class="ruby-ivar">@lists</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">size</span>
|
445
|
+
33: <span class="ruby-keyword kw">self</span>
|
446
|
+
34: <span class="ruby-keyword kw">end</span></pre>
|
448
447
|
</div>
|
449
448
|
|
450
449
|
</div>
|
@@ -475,11 +474,11 @@
|
|
475
474
|
<div class="method-source-code"
|
476
475
|
id="product-source">
|
477
476
|
<pre>
|
478
|
-
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
477
|
+
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 36</span>
|
478
|
+
36: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">product</span>(<span class="ruby-identifier">other</span>)
|
479
|
+
37: (<span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">dup</span>).<span class="ruby-identifier">product!</span>(<span class="ruby-identifier">other</span>)
|
480
|
+
38: <span class="ruby-identifier">result</span>
|
481
|
+
39: <span class="ruby-keyword kw">end</span></pre>
|
483
482
|
</div>
|
484
483
|
|
485
484
|
</div>
|
@@ -514,12 +513,12 @@
|
|
514
513
|
<div class="method-source-code"
|
515
514
|
id="product--source">
|
516
515
|
<pre>
|
517
|
-
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
516
|
+
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 22</span>
|
517
|
+
22: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">product!</span>(<span class="ruby-identifier">other</span>)
|
518
|
+
23: <span class="ruby-ivar">@lists</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">to_a</span>.<span class="ruby-identifier">dup</span>
|
519
|
+
24: <span class="ruby-ivar">@tot_iter</span> <span class="ruby-operator">*=</span> <span class="ruby-ivar">@lists</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">size</span>
|
520
|
+
25: <span class="ruby-keyword kw">self</span>
|
521
|
+
26: <span class="ruby-keyword kw">end</span></pre>
|
523
522
|
</div>
|
524
523
|
|
525
524
|
</div>
|
data/website/doc/Iterable.html
CHANGED
@@ -38,8 +38,8 @@
|
|
38
38
|
<div class="section-body">
|
39
39
|
<ul>
|
40
40
|
|
41
|
-
<li><a href="./lib/
|
42
|
-
class="thickbox" title="lib/
|
41
|
+
<li><a href="./lib/cartesian_iterator_rb.html?TB_iframe=true&height=550&width=785"
|
42
|
+
class="thickbox" title="lib/cartesian_iterator.rb">lib/cartesian_iterator.rb</a></li>
|
43
43
|
|
44
44
|
</ul>
|
45
45
|
</div>
|
@@ -62,8 +62,6 @@
|
|
62
62
|
<h3 class="section-header">Methods</h3>
|
63
63
|
<ul class="link-list">
|
64
64
|
|
65
|
-
<li><a href="#method-i-done%3F">#done?</a></li>
|
66
|
-
|
67
65
|
<li><a href="#method-i-next">#next</a></li>
|
68
66
|
|
69
67
|
<li><a href="#method-i-raw_next">#raw_next</a></li>
|
@@ -147,43 +145,6 @@
|
|
147
145
|
<h3 class="section-header">Public Instance Methods</h3>
|
148
146
|
|
149
147
|
|
150
|
-
<div id="done--method" class="method-detail ">
|
151
|
-
<a name="method-i-done%3F"></a>
|
152
|
-
|
153
|
-
<div class="method-heading">
|
154
|
-
|
155
|
-
<span class="method-name">done?</span><span
|
156
|
-
class="method-args">()</span>
|
157
|
-
<span class="method-click-advice">click to toggle source</span>
|
158
|
-
|
159
|
-
</div>
|
160
|
-
|
161
|
-
<div class="method-description">
|
162
|
-
|
163
|
-
<p>
|
164
|
-
TODO: consider a module inclusion time solution to “count rescue
|
165
|
-
size”, for performance sake
|
166
|
-
</p>
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
<div class="method-source-code"
|
171
|
-
id="done--source">
|
172
|
-
<pre>
|
173
|
-
<span class="ruby-comment cmt"># File lib/iterable.rb, line 22</span>
|
174
|
-
22: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">done?</span>
|
175
|
-
23: <span class="ruby-ivar">@next_index</span> <span class="ruby-operator">&&</span> (<span class="ruby-ivar">@next_index</span> <span class="ruby-operator">==</span> (<span class="ruby-identifier">count</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-identifier">size</span>)<span class="ruby-operator">-</span><span class="ruby-value">1</span>)
|
176
|
-
24: <span class="ruby-keyword kw">end</span></pre>
|
177
|
-
</div>
|
178
|
-
|
179
|
-
</div>
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
</div>
|
185
|
-
|
186
|
-
|
187
148
|
<div id="next-method" class="method-detail ">
|
188
149
|
<a name="method-i-next"></a>
|
189
150
|
|
@@ -204,11 +165,11 @@ size”, for performance sake
|
|
204
165
|
<div class="method-source-code"
|
205
166
|
id="next-source">
|
206
167
|
<pre>
|
207
|
-
<span class="ruby-comment cmt"># File lib/
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
168
|
+
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 83</span>
|
169
|
+
83: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">next</span>
|
170
|
+
84: <span class="ruby-identifier">restart</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">defined?</span> <span class="ruby-ivar">@next_index</span>
|
171
|
+
85: <span class="ruby-identifier">raw_next</span>
|
172
|
+
86: <span class="ruby-keyword kw">end</span></pre>
|
212
173
|
</div>
|
213
174
|
|
214
175
|
</div>
|
@@ -239,11 +200,10 @@ size”, for performance sake
|
|
239
200
|
<div class="method-source-code"
|
240
201
|
id="raw-next-source">
|
241
202
|
<pre>
|
242
|
-
<span class="ruby-comment cmt"># File lib/
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
15: <span class="ruby-keyword kw">end</span></pre>
|
203
|
+
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 88</span>
|
204
|
+
88: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">raw_next</span>
|
205
|
+
89: <span class="ruby-keyword kw">self</span>[<span class="ruby-ivar">@next_index</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>]
|
206
|
+
90: <span class="ruby-keyword kw">end</span></pre>
|
247
207
|
</div>
|
248
208
|
|
249
209
|
</div>
|
@@ -274,11 +234,11 @@ size”, for performance sake
|
|
274
234
|
<div class="method-source-code"
|
275
235
|
id="restart-source">
|
276
236
|
<pre>
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
237
|
+
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 78</span>
|
238
|
+
78: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">restart</span>
|
239
|
+
79: <span class="ruby-ivar">@next_index</span> = <span class="ruby-value">1</span>
|
240
|
+
80: <span class="ruby-keyword kw">true</span>
|
241
|
+
81: <span class="ruby-keyword kw">end</span></pre>
|
282
242
|
</div>
|
283
243
|
|
284
244
|
</div>
|
@@ -309,10 +269,10 @@ size”, for performance sake
|
|
309
269
|
<div class="method-source-code"
|
310
270
|
id="restart-and-raw-next-source">
|
311
271
|
<pre>
|
312
|
-
<span class="ruby-comment cmt"># File lib/
|
313
|
-
|
314
|
-
|
315
|
-
|
272
|
+
<span class="ruby-comment cmt"># File lib/cartesian_iterator.rb, line 92</span>
|
273
|
+
92: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">restart_and_raw_next</span>
|
274
|
+
93: <span class="ruby-keyword kw">self</span>[<span class="ruby-ivar">@next_index</span> = <span class="ruby-value">0</span>]
|
275
|
+
94: <span class="ruby-keyword kw">end</span></pre>
|
316
276
|
</div>
|
317
277
|
|
318
278
|
</div>
|
@@ -183,7 +183,7 @@ sudo gem install cartesian
|
|
183
183
|
(The MIT License)
|
184
184
|
</p>
|
185
185
|
<p>
|
186
|
-
Copyright © 2006-
|
186
|
+
Copyright © 2006-2011 Adriano Mitre <adriano.mitre@gmail.com>
|
187
187
|
</p>
|
188
188
|
<p>
|
189
189
|
Permission is hereby granted, free of charge, to any person obtaining a
|
data/website/doc/created.rid
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
|
-
README.rdoc
|
3
|
-
lib/cartesian.rb
|
4
|
-
lib/cartesian_iterator.rb
|
5
|
-
lib/grid_search.rb
|
6
|
-
lib/iterable.rb Sun, 15 Apr 2012 03:31:27 -0300
|
1
|
+
Fri, 07 Jan 2011 13:53:06 -0200
|
2
|
+
README.rdoc Fri, 07 Jan 2011 02:46:43 -0200
|
3
|
+
lib/cartesian.rb Fri, 07 Jan 2011 13:53:03 -0200
|
4
|
+
lib/cartesian_iterator.rb Fri, 07 Jan 2011 02:46:43 -0200
|
5
|
+
lib/grid_search.rb Wed, 05 Jan 2011 06:07:10 -0200
|
data/website/doc/index.html
CHANGED
@@ -73,8 +73,6 @@
|
|
73
73
|
|
74
74
|
<li><a href="Cartesian.html#method-i-cartesian">#cartesian — Cartesian</a></li>
|
75
75
|
|
76
|
-
<li><a href="Iterable.html#method-i-done%3F">#done? — Iterable</a></li>
|
77
|
-
|
78
76
|
<li><a href="CartesianIterator.html#method-i-dup">#dup — CartesianIterator</a></li>
|
79
77
|
|
80
78
|
<li><a href="CartesianIterator.html#method-i-each">#each — CartesianIterator</a></li>
|
@@ -24,15 +24,13 @@
|
|
24
24
|
<div id="metadata">
|
25
25
|
<dl>
|
26
26
|
<dt class="modified-date">Last Modified</dt>
|
27
|
-
<dd class="modified-date">
|
27
|
+
<dd class="modified-date">2011-01-07 02:46:43 -0200</dd>
|
28
28
|
|
29
29
|
|
30
30
|
<dt class="requires">Requires</dt>
|
31
31
|
<dd class="requires">
|
32
32
|
<ul>
|
33
33
|
|
34
|
-
<li>iterable</li>
|
35
|
-
|
36
34
|
</ul>
|
37
35
|
</dd>
|
38
36
|
|
data/website/index.html
CHANGED
@@ -1,5 +1,128 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
7
|
+
<title>
|
8
|
+
|
9
|
+
</title>
|
10
|
+
<script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
|
11
|
+
<style>
|
1
12
|
|
13
|
+
</style>
|
14
|
+
<script type="text/javascript">
|
15
|
+
window.onload = function() {
|
16
|
+
settings = {
|
17
|
+
tl: { radius: 10 },
|
18
|
+
tr: { radius: 10 },
|
19
|
+
bl: { radius: 10 },
|
20
|
+
br: { radius: 10 },
|
21
|
+
antiAlias: true,
|
22
|
+
autoPad: true,
|
23
|
+
validTags: ["div"]
|
24
|
+
}
|
25
|
+
var versionBox = new curvyCorners(settings, document.getElementById("version"));
|
26
|
+
versionBox.applyCornersToAll();
|
27
|
+
}
|
28
|
+
</script>
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="main">
|
2
32
|
|
3
|
-
|
4
|
-
|
33
|
+
<h1></h1>
|
34
|
+
<div id="version" class="clickable" onclick='document.location = "http://github.com/adrianomitre/cartesian"; return false'>
|
35
|
+
<p>Get Version</p>
|
36
|
+
<a href="http://github.com/adrianomitre/cartesian" class="numbers">0.6.4</a>
|
37
|
+
</div>
|
38
|
+
<script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script><h1>cartesian</h1>
|
39
|
+
<h3>Cartesian products in Ruby</h3>
|
40
|
+
<h2>What</h2>
|
41
|
+
<p>Provides methods for the calculation of the cartesian producted between<br />
|
42
|
+
two or more enumerable objects. Includes grid search optimization methods.<br />
|
43
|
+
It can also be easily and conveniently mixed-in into any enumerable class.</p>
|
44
|
+
<h2>Installing</h2>
|
45
|
+
<p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">cartesian</span></pre></p>
|
46
|
+
<h2>The basics</h2>
|
47
|
+
<p><pre class='syntax'><span class="constant">Cartesian</span><span class="punct">::</span><span class="ident">product</span> <span class="punct">[</span><span class="number">1</span><span class="punct">,</span><span class="number">2</span><span class="punct">],[</span><span class="number">3</span><span class="punct">,</span><span class="number">4</span><span class="punct">]</span> <span class="comment">#=> [[1, 3], [1, 4], [2, 3], [2, 4]]</span></pre></p>
|
48
|
+
<h2>Demonstration of usage</h2>
|
49
|
+
<p>One can use the Cartesian module directly<br />
|
50
|
+
<pre class='syntax'>
|
51
|
+
<span class="ident">require</span> <span class="punct">'</span><span class="string">cartesian</span><span class="punct">'</span>
|
52
|
+
<span class="ident">foo</span> <span class="punct">=</span> <span class="punct">[</span><span class="number">1</span><span class="punct">,</span> <span class="number">2</span><span class="punct">]</span>
|
53
|
+
<span class="ident">bar</span> <span class="punct">=</span> <span class="punct">["</span><span class="string">a</span><span class="punct">",</span> <span class="punct">"</span><span class="string">b</span><span class="punct">"]</span>
|
54
|
+
<span class="constant">Cartesian</span><span class="punct">::</span><span class="ident">product</span><span class="punct">(</span><span class="ident">foo</span><span class="punct">,</span> <span class="ident">bar</span><span class="punct">)</span> <span class="comment">#=> [[1, "a"], [1, "b"], [2, "a"], [2, "b"]]</span>
|
55
|
+
</pre></p>
|
56
|
+
<p>or use the methods provided by the mixin in the Array class</p>
|
57
|
+
<p><pre class='syntax'>
|
58
|
+
<span class="ident">foo</span><span class="punct">.</span><span class="ident">cartesian</span><span class="punct">(</span><span class="ident">bar</span><span class="punct">)</span> <span class="comment">#=> [[1, "a"], [1, "b"], [2, "a"], [2, "b"]]</span>
|
59
|
+
</pre></p>
|
60
|
+
<p>which include the short’n’sweet <em>x</em> method</p>
|
61
|
+
<p><pre class='syntax'>
|
62
|
+
<span class="ident">v</span> <span class="punct">=</span> <span class="punct">[]</span> <span class="comment">#=> []</span>
|
63
|
+
<span class="keyword">for</span> <span class="ident">a</span><span class="punct">,</span> <span class="ident">b</span> <span class="keyword">in</span> <span class="punct">[</span><span class="number">1</span><span class="punct">,</span><span class="number">2</span><span class="punct">].</span><span class="ident">x</span> <span class="punct">[</span><span class="number">3</span><span class="punct">,</span><span class="number">4</span><span class="punct">]</span>
|
64
|
+
<span class="ident">v</span> <span class="punct"><<</span> <span class="punct">[</span><span class="ident">a</span><span class="punct">,</span><span class="ident">b</span><span class="punct">]</span>
|
65
|
+
<span class="keyword">end</span> <span class="comment">#=> true</span>
|
66
|
+
<span class="ident">v</span> <span class="comment">#=> [[1, 3], [1, 4], [2, 3], [2, 4]]</span>
|
67
|
+
</pre></p>
|
68
|
+
<p>The ‘**’ operator provides a convenient way of iterating multi-dimensionally over the same array or range</p>
|
69
|
+
<p><pre class='syntax'>
|
70
|
+
<span class="ident">u</span> <span class="punct">=</span> <span class="punct">[</span><span class="number">0</span><span class="punct">,</span> <span class="number">1</span><span class="punct">]**</span><span class="number">3</span> <span class="comment">#=> #<CartesianIterator:0x7f2fb8e54978 @tot_iter=8, \</span>
|
71
|
+
<span class="comment"># @lists=[[0, 1], [0, 1], [0, 1]]></span>
|
72
|
+
<span class="ident">u</span><span class="punct">.</span><span class="ident">to_a</span> <span class="comment">#=> [[0, 0, 0], [0, 0, 1], [0, 1, 0], \</span>
|
73
|
+
<span class="comment"># [0, 1, 1], [1, 0, 0], [1, 0, 1], \</span>
|
74
|
+
<span class="comment"># [1, 1, 0], [1, 1, 1]]</span>
|
75
|
+
</pre></p>
|
76
|
+
<p>Finally, the grid search methods</p>
|
77
|
+
<p><pre class='syntax'>
|
78
|
+
<span class="ident">require</span> <span class="punct">'</span><span class="string">grid_search</span><span class="punct">'</span>
|
79
|
+
<span class="punct">[-</span><span class="number">1</span><span class="punct">,</span> <span class="number">0</span><span class="punct">,</span> <span class="number">1</span><span class="punct">,</span> <span class="number">2</span><span class="punct">].</span><span class="ident">argmax</span> <span class="punct">{|</span><span class="ident">x</span><span class="punct">|</span> <span class="ident">x</span><span class="punct">**</span><span class="number">2</span> <span class="punct">}</span> <span class="comment">#=> 2</span>
|
80
|
+
<span class="punct">[-</span><span class="number">1</span><span class="punct">,</span> <span class="number">0</span><span class="punct">,</span> <span class="number">1</span><span class="punct">,</span> <span class="number">2</span><span class="punct">].</span><span class="ident">argmin</span> <span class="punct">{|</span><span class="ident">x</span><span class="punct">|</span> <span class="ident">x</span><span class="punct">.</span><span class="ident">abs</span> <span class="punct">}</span> <span class="comment">#=> 0</span></pre><br />
|
81
|
+
</pre></p>
|
82
|
+
<p>For more examples and details, see the RDoc-generated documentation <a href="doc/index.html">here</a>.</p>
|
83
|
+
<h2>How to submit patches</h2>
|
84
|
+
<p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people’s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
|
85
|
+
<p>You can fetch the source from:</p>
|
86
|
+
<ul>
|
87
|
+
<li>github: <a href="http://github.com/adrianomitre/cartesian/tree/master">http://github.com/adrianomitre/cartesian/tree/master</a></li>
|
88
|
+
</ul>
|
89
|
+
<pre>git clone git@github.com:adrianomitre/cartesian.git</pre>
|
90
|
+
<h3>Build and test instructions</h3>
|
91
|
+
<pre>cd cartesian
|
92
|
+
rake test
|
93
|
+
rake install_gem</pre>
|
94
|
+
<h2>License</h2>
|
95
|
+
<p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
|
96
|
+
<h2>Contact</h2>
|
97
|
+
<p>Comments are welcome. Send an email to <a href="mailto:adriano.mitre@gmail.com">Adriano Mitre</a>.</p>
|
98
|
+
<div align=right>
|
99
|
+
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
|
100
|
+
<input type="hidden" name="cmd" value="_s-xclick">
|
101
|
+
<input type="hidden" name="hosted_button_id" value="9ABWULT73Y7AC">
|
102
|
+
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
|
103
|
+
<p><img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></p>
|
104
|
+
</form>
|
105
|
+
</div>
|
106
|
+
<p class="coda">
|
107
|
+
<a href="http://github.com/adrianomitre">Adriano Mitre</a>, 7th January 2011<br>
|
108
|
+
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
109
|
+
</p>
|
110
|
+
</div>
|
5
111
|
|
112
|
+
<!-- insert site tracking codes here, like Google Urchin -->
|
113
|
+
<script type="text/javascript">
|
114
|
+
|
115
|
+
var _gaq = _gaq || [];
|
116
|
+
_gaq.push(['_setAccount', 'UA-20605454-1']);
|
117
|
+
_gaq.push(['_trackPageview']);
|
118
|
+
|
119
|
+
(function() {
|
120
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
121
|
+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
122
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
123
|
+
})();
|
124
|
+
|
125
|
+
</script>
|
126
|
+
|
127
|
+
</body>
|
128
|
+
</html>
|
metadata
CHANGED
@@ -1,82 +1,68 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: cartesian
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.6
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 0.6.7
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Adriano Mitre
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
date: 2013-01-06 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
15
16
|
name: rdoc
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '3.10'
|
22
|
-
type: :development
|
23
17
|
prerelease: false
|
24
|
-
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
19
|
none: false
|
26
|
-
requirements:
|
20
|
+
requirements:
|
27
21
|
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: newgem
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 1.5.3
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "3.10"
|
38
24
|
type: :development
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: newgem
|
39
28
|
prerelease: false
|
40
|
-
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
30
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
45
34
|
version: 1.5.3
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: hoe
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '3.0'
|
54
35
|
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: hoe
|
55
39
|
prerelease: false
|
56
|
-
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
41
|
none: false
|
58
|
-
requirements:
|
42
|
+
requirements:
|
59
43
|
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
|
63
|
-
|
64
|
-
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "3.4"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
description: |-
|
49
|
+
Provides methods for the calculation of the cartesian producted between two
|
65
50
|
or more enumerable objects. Includes grid search optimization methods.
|
66
|
-
|
67
|
-
|
68
|
-
email:
|
51
|
+
It can also be easily and conveniently mixed in into any enumerable class.
|
52
|
+
email:
|
69
53
|
- adriano.mitre@gmail.com
|
70
54
|
executables: []
|
55
|
+
|
71
56
|
extensions: []
|
72
|
-
|
57
|
+
|
58
|
+
extra_rdoc_files:
|
73
59
|
- History.txt
|
74
60
|
- Manifest.txt
|
75
61
|
- PostInstall.txt
|
76
62
|
- README.rdoc
|
77
63
|
- Wishlist.txt
|
78
64
|
- website/index.txt
|
79
|
-
files:
|
65
|
+
files:
|
80
66
|
- History.txt
|
81
67
|
- Manifest.txt
|
82
68
|
- PostInstall.txt
|
@@ -127,36 +113,37 @@ files:
|
|
127
113
|
- .gemtest
|
128
114
|
homepage: http://adrianomitre.github.com/cartesian/website/index.html
|
129
115
|
licenses: []
|
116
|
+
|
130
117
|
post_install_message: PostInstall.txt
|
131
|
-
rdoc_options:
|
118
|
+
rdoc_options:
|
132
119
|
- --main
|
133
120
|
- README.rdoc
|
134
|
-
require_paths:
|
121
|
+
require_paths:
|
135
122
|
- lib
|
136
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
124
|
none: false
|
138
|
-
requirements:
|
139
|
-
- -
|
140
|
-
- !ruby/object:Gem::Version
|
141
|
-
version:
|
142
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: "0"
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
130
|
none: false
|
144
|
-
requirements:
|
145
|
-
- -
|
146
|
-
- !ruby/object:Gem::Version
|
147
|
-
version:
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: "0"
|
148
135
|
requirements: []
|
136
|
+
|
149
137
|
rubyforge_project: cartesian
|
150
|
-
rubygems_version: 1.8.
|
138
|
+
rubygems_version: 1.8.24
|
151
139
|
signing_key:
|
152
140
|
specification_version: 3
|
153
|
-
summary: Provides methods for the calculation of the cartesian producted between two
|
154
|
-
|
155
|
-
test_files:
|
156
|
-
- test/test_suite.rb
|
141
|
+
summary: Provides methods for the calculation of the cartesian producted between two or more enumerable objects
|
142
|
+
test_files:
|
157
143
|
- test/test_iterable.rb
|
144
|
+
- test/test_suite.rb
|
158
145
|
- test/test_grid_search.rb
|
159
|
-
- test/test_cartesian.rb
|
160
|
-
- test/test_extensions.rb
|
161
146
|
- test/test_helper.rb
|
147
|
+
- test/test_extensions.rb
|
148
|
+
- test/test_cartesian.rb
|
162
149
|
- test/test_cartesian_iterator.rb
|