halton 0.2.1.2 → 0.2.1.4

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
  SHA256:
3
- metadata.gz: 2a65d2ef8aa05f9ff2b905cd199b67c457c22f6916be59df4fff97a92af0a48e
4
- data.tar.gz: 15b62c7f8c05f1bcc9d206d3f228012fc1839a11095d6cc67cf046996696477c
3
+ metadata.gz: 8115499e016e8c1c3ef1608ac90caed45b48ba7d34a722788b3ae4f550d35db5
4
+ data.tar.gz: c2e2f8af26707e3b486036c24b82b15df6421caaa03eb35f0cfdaa383dc5c649
5
5
  SHA512:
6
- metadata.gz: ca1ad0a5551d63dc6009b11afe17f8d792af1181564794c4a707bd9fdb08311459d73c3ff13dc76a7e067ac72fa510089a4bf8d09a093bf5f761af0d45284f8a
7
- data.tar.gz: 11ebf433af39d7047da8c1cf99404bc09eb422ebc0f4e0c532ef0fdda96a7dbf37f89b09e01ca76c258dd03566f74653af7a096ece95d39117820b247bf36e21
6
+ metadata.gz: 021dbd5d00a5045f9a02c6b3f09560305468c0f360b16dbd3acb0829db8d848457c685864edbb8427fad1a7e7d3852b242d26dfcf33ddb95bc51dc8c1d90f076
7
+ data.tar.gz: a6ece029b0b98a9f4ac3f8e8c5dc4cf604d9a13d6d2e5d4de3cdf9376925c6a480ec437635f7b52340df09c57f1f767f65f7171c2a5052a137abd7499c42d843
@@ -4,54 +4,30 @@ version = 3
4
4
 
5
5
  [[package]]
6
6
  name = "aho-corasick"
7
- version = "0.7.18"
7
+ version = "0.7.20"
8
8
  source = "registry+https://github.com/rust-lang/crates.io-index"
9
- checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
9
+ checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
10
10
  dependencies = [
11
11
  "memchr",
12
12
  ]
13
13
 
14
- [[package]]
15
- name = "ansi_term"
16
- version = "0.12.1"
17
- source = "registry+https://github.com/rust-lang/crates.io-index"
18
- checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
19
- dependencies = [
20
- "winapi",
21
- ]
22
-
23
- [[package]]
24
- name = "atty"
25
- version = "0.2.14"
26
- source = "registry+https://github.com/rust-lang/crates.io-index"
27
- checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
28
- dependencies = [
29
- "hermit-abi",
30
- "libc",
31
- "winapi",
32
- ]
33
-
34
14
  [[package]]
35
15
  name = "bindgen"
36
- version = "0.59.2"
16
+ version = "0.60.1"
37
17
  source = "registry+https://github.com/rust-lang/crates.io-index"
38
- checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8"
18
+ checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6"
39
19
  dependencies = [
40
20
  "bitflags",
41
21
  "cexpr",
42
22
  "clang-sys",
43
- "clap",
44
- "env_logger",
45
23
  "lazy_static",
46
24
  "lazycell",
47
- "log",
48
25
  "peeking_take_while",
49
26
  "proc-macro2",
50
27
  "quote",
51
28
  "regex",
52
29
  "rustc-hash",
53
30
  "shlex",
54
- "which",
55
31
  ]
56
32
 
57
33
  [[package]]
@@ -77,90 +53,15 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
77
53
 
78
54
  [[package]]
79
55
  name = "clang-sys"
80
- version = "1.3.1"
56
+ version = "1.4.0"
81
57
  source = "registry+https://github.com/rust-lang/crates.io-index"
82
- checksum = "4cc00842eed744b858222c4c9faf7243aafc6d33f92f96935263ef4d8a41ce21"
58
+ checksum = "fa2e27ae6ab525c3d369ded447057bca5438d86dc3a68f6faafb8269ba82ebf3"
83
59
  dependencies = [
84
60
  "glob",
85
61
  "libc",
86
62
  "libloading",
87
63
  ]
88
64
 
89
- [[package]]
90
- name = "clap"
91
- version = "2.34.0"
92
- source = "registry+https://github.com/rust-lang/crates.io-index"
93
- checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
94
- dependencies = [
95
- "ansi_term",
96
- "atty",
97
- "bitflags",
98
- "strsim 0.8.0",
99
- "textwrap",
100
- "unicode-width",
101
- "vec_map",
102
- ]
103
-
104
- [[package]]
105
- name = "darling"
106
- version = "0.13.1"
107
- source = "registry+https://github.com/rust-lang/crates.io-index"
108
- checksum = "d0d720b8683f8dd83c65155f0530560cba68cd2bf395f6513a483caee57ff7f4"
109
- dependencies = [
110
- "darling_core",
111
- "darling_macro",
112
- ]
113
-
114
- [[package]]
115
- name = "darling_core"
116
- version = "0.13.1"
117
- source = "registry+https://github.com/rust-lang/crates.io-index"
118
- checksum = "7a340f241d2ceed1deb47ae36c4144b2707ec7dd0b649f894cb39bb595986324"
119
- dependencies = [
120
- "fnv",
121
- "ident_case",
122
- "proc-macro2",
123
- "quote",
124
- "strsim 0.10.0",
125
- "syn",
126
- ]
127
-
128
- [[package]]
129
- name = "darling_macro"
130
- version = "0.13.1"
131
- source = "registry+https://github.com/rust-lang/crates.io-index"
132
- checksum = "72c41b3b7352feb3211a0d743dc5700a4e3b60f51bd2b368892d1e0f9a95f44b"
133
- dependencies = [
134
- "darling_core",
135
- "quote",
136
- "syn",
137
- ]
138
-
139
- [[package]]
140
- name = "either"
141
- version = "1.6.1"
142
- source = "registry+https://github.com/rust-lang/crates.io-index"
143
- checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
144
-
145
- [[package]]
146
- name = "env_logger"
147
- version = "0.9.0"
148
- source = "registry+https://github.com/rust-lang/crates.io-index"
149
- checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
150
- dependencies = [
151
- "atty",
152
- "humantime",
153
- "log",
154
- "regex",
155
- "termcolor",
156
- ]
157
-
158
- [[package]]
159
- name = "fnv"
160
- version = "1.0.7"
161
- source = "registry+https://github.com/rust-lang/crates.io-index"
162
- checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
163
-
164
65
  [[package]]
165
66
  name = "glob"
166
67
  version = "0.3.0"
@@ -172,7 +73,6 @@ name = "halton"
172
73
  version = "0.1.0"
173
74
  dependencies = [
174
75
  "halton 0.2.1",
175
- "lazy_static",
176
76
  "magnus",
177
77
  ]
178
78
 
@@ -182,27 +82,6 @@ version = "0.2.1"
182
82
  source = "registry+https://github.com/rust-lang/crates.io-index"
183
83
  checksum = "be629448e3d85a1be12868f190df524655fea8ec3f143e14d803e298f618acae"
184
84
 
185
- [[package]]
186
- name = "hermit-abi"
187
- version = "0.1.19"
188
- source = "registry+https://github.com/rust-lang/crates.io-index"
189
- checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
190
- dependencies = [
191
- "libc",
192
- ]
193
-
194
- [[package]]
195
- name = "humantime"
196
- version = "2.1.0"
197
- source = "registry+https://github.com/rust-lang/crates.io-index"
198
- checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
199
-
200
- [[package]]
201
- name = "ident_case"
202
- version = "1.0.1"
203
- source = "registry+https://github.com/rust-lang/crates.io-index"
204
- checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
205
-
206
85
  [[package]]
207
86
  name = "lazy_static"
208
87
  version = "1.4.0"
@@ -217,46 +96,37 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
217
96
 
218
97
  [[package]]
219
98
  name = "libc"
220
- version = "0.2.119"
99
+ version = "0.2.138"
221
100
  source = "registry+https://github.com/rust-lang/crates.io-index"
222
- checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
101
+ checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
223
102
 
224
103
  [[package]]
225
104
  name = "libloading"
226
- version = "0.7.3"
105
+ version = "0.7.4"
227
106
  source = "registry+https://github.com/rust-lang/crates.io-index"
228
- checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
107
+ checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
229
108
  dependencies = [
230
109
  "cfg-if",
231
110
  "winapi",
232
111
  ]
233
112
 
234
- [[package]]
235
- name = "log"
236
- version = "0.4.14"
237
- source = "registry+https://github.com/rust-lang/crates.io-index"
238
- checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
239
- dependencies = [
240
- "cfg-if",
241
- ]
242
-
243
113
  [[package]]
244
114
  name = "magnus"
245
- version = "0.1.0"
115
+ version = "0.4.3"
246
116
  source = "registry+https://github.com/rust-lang/crates.io-index"
247
- checksum = "1825dcc83398c263845f82fdf847f2599a6d51a4da6e668e5ca8e84309eea8df"
117
+ checksum = "c7d904f55da4e2b0ac7f133257af80580ff4ca17bcca67f51ea06be46aa634ac"
248
118
  dependencies = [
249
- "bindgen",
250
119
  "magnus-macros",
120
+ "rb-sys",
121
+ "rb-sys-env",
251
122
  ]
252
123
 
253
124
  [[package]]
254
125
  name = "magnus-macros"
255
- version = "0.1.0"
126
+ version = "0.2.0"
256
127
  source = "registry+https://github.com/rust-lang/crates.io-index"
257
- checksum = "27968fcabe2ef7e35b8331d71a62882282996f6222c133c0255cf7f33b8d9b48"
128
+ checksum = "acc8ba6908cb0f67a4e75cb48fc81a1f0e6a6dd1501936e0c9e2c7c8f9f18e05"
258
129
  dependencies = [
259
- "darling",
260
130
  "proc-macro2",
261
131
  "quote",
262
132
  "syn",
@@ -264,9 +134,9 @@ dependencies = [
264
134
 
265
135
  [[package]]
266
136
  name = "memchr"
267
- version = "2.4.1"
137
+ version = "2.5.0"
268
138
  source = "registry+https://github.com/rust-lang/crates.io-index"
269
- checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
139
+ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
270
140
 
271
141
  [[package]]
272
142
  name = "minimal-lexical"
@@ -276,13 +146,12 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
276
146
 
277
147
  [[package]]
278
148
  name = "nom"
279
- version = "7.1.0"
149
+ version = "7.1.1"
280
150
  source = "registry+https://github.com/rust-lang/crates.io-index"
281
- checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109"
151
+ checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36"
282
152
  dependencies = [
283
153
  "memchr",
284
154
  "minimal-lexical",
285
- "version_check",
286
155
  ]
287
156
 
288
157
  [[package]]
@@ -293,27 +162,53 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
293
162
 
294
163
  [[package]]
295
164
  name = "proc-macro2"
296
- version = "1.0.36"
165
+ version = "1.0.47"
297
166
  source = "registry+https://github.com/rust-lang/crates.io-index"
298
- checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
167
+ checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
299
168
  dependencies = [
300
- "unicode-xid",
169
+ "unicode-ident",
301
170
  ]
302
171
 
303
172
  [[package]]
304
173
  name = "quote"
305
- version = "1.0.15"
174
+ version = "1.0.21"
306
175
  source = "registry+https://github.com/rust-lang/crates.io-index"
307
- checksum = "864d3e96a899863136fc6e99f3d7cae289dafe43bf2c5ac19b70df7210c0a145"
176
+ checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
308
177
  dependencies = [
309
178
  "proc-macro2",
310
179
  ]
311
180
 
181
+ [[package]]
182
+ name = "rb-sys"
183
+ version = "0.9.46"
184
+ source = "registry+https://github.com/rust-lang/crates.io-index"
185
+ checksum = "b9f1cfd225389bd9333d93d393d0feeeacd191d97f9b1c881528ac1233c67f0f"
186
+ dependencies = [
187
+ "rb-sys-build",
188
+ ]
189
+
190
+ [[package]]
191
+ name = "rb-sys-build"
192
+ version = "0.9.46"
193
+ source = "registry+https://github.com/rust-lang/crates.io-index"
194
+ checksum = "fad39a523a00dc5d4f6dcec077568d985807aa5bd03204a0ddf7c1f36544289c"
195
+ dependencies = [
196
+ "bindgen",
197
+ "regex",
198
+ "shell-words",
199
+ ]
200
+
201
+ [[package]]
202
+ name = "rb-sys-env"
203
+ version = "0.1.1"
204
+ source = "registry+https://github.com/rust-lang/crates.io-index"
205
+ checksum = "74c38752410925faeb82c400c06ba2fd9ee6aa8f719dd33994c9e53f5242d25f"
206
+
312
207
  [[package]]
313
208
  name = "regex"
314
- version = "1.5.4"
209
+ version = "1.7.0"
315
210
  source = "registry+https://github.com/rust-lang/crates.io-index"
316
- checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
211
+ checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a"
317
212
  dependencies = [
318
213
  "aho-corasick",
319
214
  "memchr",
@@ -322,9 +217,9 @@ dependencies = [
322
217
 
323
218
  [[package]]
324
219
  name = "regex-syntax"
325
- version = "0.6.25"
220
+ version = "0.6.28"
326
221
  source = "registry+https://github.com/rust-lang/crates.io-index"
327
- checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
222
+ checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
328
223
 
329
224
  [[package]]
330
225
  name = "rustc-hash"
@@ -333,86 +228,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
333
228
  checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
334
229
 
335
230
  [[package]]
336
- name = "shlex"
231
+ name = "shell-words"
337
232
  version = "1.1.0"
338
233
  source = "registry+https://github.com/rust-lang/crates.io-index"
339
- checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
340
-
341
- [[package]]
342
- name = "strsim"
343
- version = "0.8.0"
344
- source = "registry+https://github.com/rust-lang/crates.io-index"
345
- checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
234
+ checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
346
235
 
347
236
  [[package]]
348
- name = "strsim"
349
- version = "0.10.0"
237
+ name = "shlex"
238
+ version = "1.1.0"
350
239
  source = "registry+https://github.com/rust-lang/crates.io-index"
351
- checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
240
+ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
352
241
 
353
242
  [[package]]
354
243
  name = "syn"
355
- version = "1.0.86"
244
+ version = "1.0.105"
356
245
  source = "registry+https://github.com/rust-lang/crates.io-index"
357
- checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b"
246
+ checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908"
358
247
  dependencies = [
359
248
  "proc-macro2",
360
249
  "quote",
361
- "unicode-xid",
250
+ "unicode-ident",
362
251
  ]
363
252
 
364
253
  [[package]]
365
- name = "termcolor"
366
- version = "1.1.2"
254
+ name = "unicode-ident"
255
+ version = "1.0.5"
367
256
  source = "registry+https://github.com/rust-lang/crates.io-index"
368
- checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
369
- dependencies = [
370
- "winapi-util",
371
- ]
372
-
373
- [[package]]
374
- name = "textwrap"
375
- version = "0.11.0"
376
- source = "registry+https://github.com/rust-lang/crates.io-index"
377
- checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
378
- dependencies = [
379
- "unicode-width",
380
- ]
381
-
382
- [[package]]
383
- name = "unicode-width"
384
- version = "0.1.9"
385
- source = "registry+https://github.com/rust-lang/crates.io-index"
386
- checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
387
-
388
- [[package]]
389
- name = "unicode-xid"
390
- version = "0.2.2"
391
- source = "registry+https://github.com/rust-lang/crates.io-index"
392
- checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
393
-
394
- [[package]]
395
- name = "vec_map"
396
- version = "0.8.2"
397
- source = "registry+https://github.com/rust-lang/crates.io-index"
398
- checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
399
-
400
- [[package]]
401
- name = "version_check"
402
- version = "0.9.4"
403
- source = "registry+https://github.com/rust-lang/crates.io-index"
404
- checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
405
-
406
- [[package]]
407
- name = "which"
408
- version = "4.2.4"
409
- source = "registry+https://github.com/rust-lang/crates.io-index"
410
- checksum = "2a5a7e487e921cf220206864a94a89b6c6905bfc19f1057fa26a4cb360e5c1d2"
411
- dependencies = [
412
- "either",
413
- "lazy_static",
414
- "libc",
415
- ]
257
+ checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
416
258
 
417
259
  [[package]]
418
260
  name = "winapi"
@@ -430,15 +272,6 @@ version = "0.4.0"
430
272
  source = "registry+https://github.com/rust-lang/crates.io-index"
431
273
  checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
432
274
 
433
- [[package]]
434
- name = "winapi-util"
435
- version = "0.1.5"
436
- source = "registry+https://github.com/rust-lang/crates.io-index"
437
- checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
438
- dependencies = [
439
- "winapi",
440
- ]
441
-
442
275
  [[package]]
443
276
  name = "winapi-x86_64-pc-windows-gnu"
444
277
  version = "0.4.0"
@@ -9,5 +9,4 @@ crate-type = ["cdylib"]
9
9
 
10
10
  [dependencies]
11
11
  halton = "0.2.1"
12
- lazy_static = "1"
13
- magnus = "0.1.0"
12
+ magnus = "0.4.3"
@@ -0,0 +1,4 @@
1
+ require "mkmf"
2
+ require "rb_sys/mkmf"
3
+
4
+ create_rust_makefile("halton/halton")
@@ -1,6 +1,12 @@
1
1
  use std::cell::RefCell;
2
2
 
3
- use magnus::{define_module, function, method, prelude::*, Error};
3
+ use magnus::{
4
+ block::{block_given, Yield, YieldSplat, YieldValues},
5
+ define_module, exception, function, method,
6
+ scan_args::check_arity,
7
+ prelude::*,
8
+ Error, RArray, Value,
9
+ };
4
10
 
5
11
  #[magnus::wrap(class = "Halton::Sequence", free_immediatly, size)]
6
12
  struct Sequence(RefCell<halton::Sequence>);
@@ -13,7 +19,10 @@ impl Sequence {
13
19
  fn next(&self) -> Result<f64, Error> {
14
20
  match self.0.try_borrow_mut().unwrap().next() {
15
21
  Some(f) => Ok(f),
16
- None => Err(Error::stop_iteration("iteration reached an end")),
22
+ None => Err(Error::new(
23
+ exception::stop_iteration(),
24
+ "iteration reached an end",
25
+ )),
17
26
  }
18
27
  }
19
28
 
@@ -26,14 +35,88 @@ impl Sequence {
26
35
  }
27
36
  }
28
37
 
38
+ fn each_one(rb_self: Value, base: u8) -> Yield<impl Iterator<Item = f64>> {
39
+ if !block_given() {
40
+ return Yield::Enumerator(rb_self.enumeratorize("each_one", (base,)));
41
+ }
42
+ Yield::Iter(halton::Sequence::new(base))
43
+ }
44
+
45
+ fn each_pair(
46
+ rb_self: Value,
47
+ x_base: u8,
48
+ y_base: u8,
49
+ ) -> YieldValues<impl Iterator<Item = (f64, f64)>> {
50
+ if !block_given() {
51
+ return YieldValues::Enumerator(rb_self.enumeratorize("each_pair", (x_base, y_base)));
52
+ }
53
+ let seq_x = halton::Sequence::new(x_base);
54
+ let seq_y = halton::Sequence::new(y_base);
55
+ YieldValues::Iter(seq_x.zip(seq_y))
56
+ }
57
+
58
+ fn each_triple(
59
+ rb_self: Value,
60
+ x_base: u8,
61
+ y_base: u8,
62
+ z_base: u8,
63
+ ) -> YieldValues<impl Iterator<Item = (f64, f64, f64)>> {
64
+ if !block_given() {
65
+ return YieldValues::Enumerator(
66
+ rb_self.enumeratorize("each_triple", (x_base, y_base, z_base)),
67
+ );
68
+ }
69
+ let seq_x = halton::Sequence::new(x_base);
70
+ let seq_y = halton::Sequence::new(y_base);
71
+ let seq_z = halton::Sequence::new(z_base);
72
+ YieldValues::Iter(seq_x.zip(seq_y).zip(seq_z).map(|((x, y), z)| (x, y, z)))
73
+ }
74
+
75
+ fn each_many(
76
+ rb_self: Value,
77
+ args: &[Value],
78
+ ) -> Result<YieldSplat<impl Iterator<Item = RArray>>, Error> {
79
+ check_arity(args.len(), 1..)?;
80
+ let bases = args
81
+ .iter()
82
+ .map(|v| v.try_convert())
83
+ .collect::<Result<Vec<u8>, _>>()?;
84
+
85
+ if !block_given() {
86
+ return Ok(YieldSplat::Enumerator(
87
+ rb_self.enumeratorize("each_many", args),
88
+ ));
89
+ }
90
+ let mut seqs = bases
91
+ .into_iter()
92
+ .map(halton::Sequence::new)
93
+ .collect::<Vec<_>>();
94
+ let mut buffer = Vec::<Value>::with_capacity(seqs.len());
95
+ Ok(YieldSplat::Iter(std::iter::from_fn(move || {
96
+ buffer.clear();
97
+ for seq in &mut seqs {
98
+ if let Some(v) = seq.next() {
99
+ buffer.push(v.into());
100
+ } else {
101
+ return None;
102
+ }
103
+ }
104
+ Some(RArray::from_slice(&buffer))
105
+ })))
106
+ }
107
+
29
108
  #[magnus::init]
30
109
  fn init() -> Result<(), Error> {
31
110
  let module = define_module("Halton")?;
32
- module.define_singleton_method("number", function!(halton::number, 2));
111
+ module.define_singleton_method("number", function!(halton::number, 2))?;
112
+ module.define_singleton_method("each_one", method!(each_one, 1))?;
113
+ module.define_singleton_method("each_pair", method!(each_pair, 2))?;
114
+ module.define_singleton_method("each_triple", method!(each_triple, 3))?;
115
+ module.define_singleton_method("each_many", method!(each_many, -1))?;
33
116
  let class = module.define_class("Sequence", Default::default())?;
34
- class.define_singleton_method("new", function!(Sequence::new, 1));
35
- class.define_method("next", method!(Sequence::next, 0));
36
- class.define_method("skip", method!(Sequence::skip, 1));
37
- class.define_method("remaining", method!(Sequence::remaining, 0));
117
+ class.define_singleton_method("new", function!(Sequence::new, 1))?;
118
+ class.define_method("next", method!(Sequence::next, 0))?;
119
+ class.define_method("skip", method!(Sequence::skip, 1))?;
120
+ class.define_method("remaining", method!(Sequence::remaining, 0))?;
38
121
  Ok(())
39
122
  }
data/lib/halton.rb CHANGED
@@ -1,6 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "halton/halton"
3
+ begin
4
+ /(?<ruby_version>\d+\.\d+)/ =~ RUBY_VERSION
5
+ require_relative "halton/#{ruby_version}/halton"
6
+ rescue LoadError
7
+ require_relative "halton/halton"
8
+ end
4
9
 
5
10
  # The Halton module provides methods for generating Halton sequences, a
6
11
  # deterministic low discrepancy sequence that appears to be random. The uniform
@@ -68,33 +73,17 @@ module Halton
68
73
  #
69
74
  # The numbers yielded will be in the range > 0 and < 1.
70
75
  #
71
- def self.each(base, *bases)
72
- return to_enum(__method__, base, *bases) unless block_given?
73
-
74
- if bases.empty?
75
- seq = Sequence.new(base)
76
- loop {yield seq.next}
77
- return nil
78
- end
79
-
80
- if bases.length == 1
81
- x = Sequence.new(base)
82
- y = Sequence.new(bases.first)
83
- loop {yield x.next, y.next}
84
- return nil
76
+ def self.each(base, *bases, &block)
77
+ case bases.length
78
+ when 0
79
+ each_one(base, &block)
80
+ when 1
81
+ each_pair(base, bases.first, &block)
82
+ when 2
83
+ each_triple(base, bases.first, bases.last, &block)
84
+ else
85
+ each_many(*bases.unshift(base), &block)
85
86
  end
86
-
87
- if bases.length == 2
88
- x = Sequence.new(base)
89
- y = Sequence.new(bases.first)
90
- z = Sequence.new(bases.last)
91
- loop {yield x.next, y.next, z.next}
92
- return nil
93
- end
94
-
95
- seqs = bases.unshift(base).map {|b| Sequence.new(b)}
96
- loop {yield(*seqs.map(&:next))}
97
- nil
98
87
  end
99
88
 
100
89
  # Halton::Sequence implements the fast generation of Halton sequences.
metadata CHANGED
@@ -1,29 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: halton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1.2
4
+ version: 0.2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Sadler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-26 00:00:00.000000000 Z
11
+ date: 2022-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake
14
+ name: rb_sys
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">"
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1'
19
+ version: 0.9.46
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">"
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.46
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake-compiler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
27
55
  description: A module implementing the fast generation of Halton sequences. The method
28
56
  of generation is adapted from "Fast, portable, and reliable algorithm for the calculation
29
57
  of Halton number" by Miroslav Kolář and Seamus F. O'Shea.
@@ -31,14 +59,14 @@ email:
31
59
  - mat@sourcetagsandcodes.com
32
60
  executables: []
33
61
  extensions:
34
- - ext/halton/Rakefile
62
+ - ext/halton/extconf.rb
35
63
  extra_rdoc_files:
36
64
  - README.rdoc
37
65
  files:
38
66
  - README.rdoc
39
67
  - ext/halton/Cargo.lock
40
68
  - ext/halton/Cargo.toml
41
- - ext/halton/Rakefile
69
+ - ext/halton/extconf.rb
42
70
  - ext/halton/src/lib.rs
43
71
  - lib/halton.rb
44
72
  homepage: https://github.com/matsadler/halton-rb
@@ -67,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
95
  version: '0'
68
96
  requirements:
69
97
  - Rust >= 1.51.0
70
- rubygems_version: 3.4.0.dev
98
+ rubygems_version: 3.3.26
71
99
  signing_key:
72
100
  specification_version: 4
73
101
  summary: A module for generating Halton sequences
data/ext/halton/Rakefile DELETED
@@ -1,133 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "shellwords"
4
-
5
- class RakeCargoHelper
6
- attr_reader :gemname
7
-
8
- def initialize(gemname=File.basename(__dir__))
9
- @gemname = gemname
10
- end
11
-
12
- def self.command?(name)
13
- exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
14
- ENV["PATH"].split(File::PATH_SEPARATOR).any? do |path|
15
- exts.any? do |ext|
16
- exe = File.join(path, "#{name}#{ext}")
17
- File.executable?(exe) && !File.directory?(exe)
18
- end
19
- end
20
- end
21
-
22
- def self.rust_toolchain
23
- str = `rustc --version --verbose`
24
- info = str.lines.map {|l| l.chomp.split(/:\s+/, 2)}.drop(1).to_h
25
- info["host"]
26
- end
27
-
28
- def self.cargo_target_dir
29
- return @cargo_target_dir if defined? @cargo_target_dir
30
-
31
- str = `cargo metadata --format-version 1 --offline --no-deps --quiet`
32
- begin
33
- require "json"
34
- dir = JSON.parse(str)["target_directory"]
35
- rescue LoadError # json is usually part of the stdlib, but just in case
36
- /"target_directory"\s*:\s*"(?<dir>[^"]*)"/ =~ str
37
- end
38
- @cargo_target_dir = dir || "target"
39
- end
40
-
41
- def self.dld_flags
42
- map = {"-L" => "-L native=", "-l" => "-l", "-F" => "-l framework="}
43
- map.default_proc = proc {|_, key| "-C link_arg=#{key}"}
44
- Shellwords.split(RbConfig::CONFIG["DLDFLAGS"]).flat_map do |arg|
45
- k, v = arg.split(/(?<=..)/, 2)
46
- case k
47
- when "-L"
48
- [k, "native=#{v}"]
49
- when "-l"
50
- [k, v]
51
- when "-F"
52
- ["-l", "framework=#{v}"]
53
- else
54
- ["-C", "link_arg=#{k}#{v}"]
55
- end
56
- end
57
- end
58
-
59
- def install_dir
60
- File.expand_path(File.join("..", "..", "lib", gemname), __dir__)
61
- end
62
-
63
- def rust_name
64
- prefix = "lib" unless Gem.win_platform?
65
- suffix = if RbConfig::CONFIG["target_os"] =~ /darwin/i
66
- ".dylib"
67
- elsif Gem.win_platform?
68
- ".dll"
69
- else
70
- ".so"
71
- end
72
- "#{prefix}#{gemname}#{suffix}"
73
- end
74
-
75
- def ruby_name
76
- "#{gemname}.#{RbConfig::CONFIG["DLEXT"]}"
77
- end
78
-
79
- end
80
-
81
- task default: [:install, :clean]
82
-
83
- desc "set dev mode for subsequent task, run like `rake dev install`"
84
- task :dev do
85
- @dev = true
86
- end
87
-
88
- desc "build gem native extension and copy to lib"
89
- task install: [:cd, :build] do
90
- helper = RakeCargoHelper.new
91
- profile_dir = @dev ? "debug" : "release"
92
- source = File.join(RakeCargoHelper.cargo_target_dir, profile_dir, helper.rust_name)
93
- dest = File.join(helper.install_dir, helper.ruby_name)
94
- mkdir_p(helper.install_dir)
95
- rm(dest) if File.exist?(dest)
96
- cp(source, dest)
97
- end
98
-
99
- desc "build gem native extension"
100
- task build: [:cargo, :cd] do
101
- sh "cargo", "rustc", *(["--locked", "--release"] unless @dev), "--", *RakeCargoHelper.dld_flags
102
- end
103
-
104
- desc "clean up release build artifacts"
105
- task clean: [:cargo, :cd] do
106
- sh "cargo clean --release"
107
- end
108
-
109
- desc "clean up build artifacts"
110
- task clobber: [:cargo, :cd] do
111
- sh "cargo clean"
112
- end
113
-
114
- desc "check for cargo"
115
- task :cargo do
116
- raise <<-MSG unless RakeCargoHelper.command?("cargo")
117
-
118
- This gem requires a Rust compiler and the `cargo' build tool to build the
119
- gem's native extension. See https://www.rust-lang.org/tools/install for
120
- how to install Rust. `cargo' is usually part of the Rust installation.
121
- MSG
122
-
123
- raise <<-MSG if Gem.win_platform? && RakeCargoHelper.rust_toolchain !~ /gnu/
124
-
125
- Found Rust toolchain `#{RakeCargoHelper.rust_toolchain}' but the gem native
126
- extension requires the gnu toolchain on Windows.
127
- MSG
128
- end
129
-
130
- # ensure task is running in the right dir
131
- task :cd do
132
- cd(__dir__) unless __dir__ == pwd
133
- end