halton 0.2.1.2 → 0.2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/halton/Cargo.lock +2 -3
- data/ext/halton/Cargo.toml +1 -2
- data/ext/halton/Rakefile +40 -14
- data/ext/halton/src/lib.rs +89 -7
- data/lib/halton.rb +10 -26
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 367da6d10b20e537ed6a0bb6153bc95ab3c09313b9edd71736315708d60eafbe
|
4
|
+
data.tar.gz: ca90d4c261f13077f2294e23d14de023074649a4e0e39faa56ca550e6eeb0210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f936ff151b3964e44220d8a1036e0ed710eaf7821e633e361ef36b21307569c4be6bee16ee79cecc6c8492f6f69755745e91d953fd75e79308a0468a8fe63e0c
|
7
|
+
data.tar.gz: fa78a84ab664803a29762e9c968c5dd048f9655525f47134622a687fa7e9dfb9d86f169ab2ccb2fb7a2c8a279c2683c09d489344d5767e9cc689c1325bdd4445
|
data/ext/halton/Cargo.lock
CHANGED
@@ -172,7 +172,6 @@ name = "halton"
|
|
172
172
|
version = "0.1.0"
|
173
173
|
dependencies = [
|
174
174
|
"halton 0.2.1",
|
175
|
-
"lazy_static",
|
176
175
|
"magnus",
|
177
176
|
]
|
178
177
|
|
@@ -242,9 +241,9 @@ dependencies = [
|
|
242
241
|
|
243
242
|
[[package]]
|
244
243
|
name = "magnus"
|
245
|
-
version = "0.1
|
244
|
+
version = "0.3.1"
|
246
245
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
247
|
-
checksum = "
|
246
|
+
checksum = "e772e3622600833393ebd9c89a5f963a9c9699528cb60764e7f178e0cc96344a"
|
248
247
|
dependencies = [
|
249
248
|
"bindgen",
|
250
249
|
"magnus-macros",
|
data/ext/halton/Cargo.toml
CHANGED
data/ext/halton/Rakefile
CHANGED
@@ -38,21 +38,47 @@ class RakeCargoHelper
|
|
38
38
|
@cargo_target_dir = dir || "target"
|
39
39
|
end
|
40
40
|
|
41
|
+
def self.flags
|
42
|
+
cc_flags = Shellwords.split(RbConfig.expand(RbConfig::MAKEFILE_CONFIG["CC"].dup))
|
43
|
+
|
44
|
+
["-C", "linker=#{cc_flags.shift}",
|
45
|
+
*cc_flags.flat_map {|a| ["-C", "link-arg=#{a}"] },
|
46
|
+
"-L", "native=#{RbConfig::CONFIG["libdir"]}",
|
47
|
+
*dld_flags,
|
48
|
+
*platform_flags]
|
49
|
+
end
|
50
|
+
|
41
51
|
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
52
|
Shellwords.split(RbConfig::CONFIG["DLDFLAGS"]).flat_map do |arg|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
arg = arg.gsub(/\$\((\w+)\)/) do
|
54
|
+
$1 == "DEFFILE" ? nil : RbConfig::CONFIG[name]
|
55
|
+
end.strip
|
56
|
+
next [] if arg.empty?
|
57
|
+
|
58
|
+
transform_flag(arg)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.platform_flags
|
63
|
+
return unless RbConfig::CONFIG["target_os"] =~ /mingw/i
|
64
|
+
|
65
|
+
[*Shellwords.split(RbConfig::CONFIG["LIBRUBYARG"]).flat_map {|arg| transform_flag(arg)},
|
66
|
+
"-C", "link-arg=-Wl,--dynamicbase",
|
67
|
+
"-C", "link-arg=-Wl,--disable-auto-image-base",
|
68
|
+
"-C", "link-arg=-static-libgcc"]
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.transform_flag(arg)
|
72
|
+
k, v = arg.split(/(?<=..)/, 2)
|
73
|
+
case k
|
74
|
+
when "-L"
|
75
|
+
[k, "native=#{v}"]
|
76
|
+
when "-l"
|
77
|
+
[k, v]
|
78
|
+
when "-F"
|
79
|
+
["-l", "framework=#{v}"]
|
80
|
+
else
|
81
|
+
["-C", "link_arg=#{k}#{v}"]
|
56
82
|
end
|
57
83
|
end
|
58
84
|
|
@@ -98,7 +124,7 @@ end
|
|
98
124
|
|
99
125
|
desc "build gem native extension"
|
100
126
|
task build: [:cargo, :cd] do
|
101
|
-
sh "cargo", "rustc", *(["--locked", "--release"] unless @dev), "--", *RakeCargoHelper.
|
127
|
+
sh "cargo", "rustc", *(["--locked", "--release"] unless @dev), "--", *RakeCargoHelper.flags
|
102
128
|
end
|
103
129
|
|
104
130
|
desc "clean up release build artifacts"
|
data/ext/halton/src/lib.rs
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
use std::cell::RefCell;
|
2
2
|
|
3
|
-
use magnus::{
|
3
|
+
use magnus::{
|
4
|
+
block::{block_given, Yield, YieldSplat, YieldValues},
|
5
|
+
define_module, exception, function, method,
|
6
|
+
prelude::*,
|
7
|
+
Error, RArray, Value,
|
8
|
+
};
|
4
9
|
|
5
10
|
#[magnus::wrap(class = "Halton::Sequence", free_immediatly, size)]
|
6
11
|
struct Sequence(RefCell<halton::Sequence>);
|
@@ -13,7 +18,10 @@ impl Sequence {
|
|
13
18
|
fn next(&self) -> Result<f64, Error> {
|
14
19
|
match self.0.try_borrow_mut().unwrap().next() {
|
15
20
|
Some(f) => Ok(f),
|
16
|
-
None => Err(Error::
|
21
|
+
None => Err(Error::new(
|
22
|
+
exception::stop_iteration(),
|
23
|
+
"iteration reached an end",
|
24
|
+
)),
|
17
25
|
}
|
18
26
|
}
|
19
27
|
|
@@ -26,14 +34,88 @@ impl Sequence {
|
|
26
34
|
}
|
27
35
|
}
|
28
36
|
|
37
|
+
fn each_one(rb_self: Value, base: u8) -> Yield<impl Iterator<Item = f64>> {
|
38
|
+
if !block_given() {
|
39
|
+
return Yield::Enumerator(rb_self.enumeratorize("each_one", (base,)));
|
40
|
+
}
|
41
|
+
Yield::Iter(halton::Sequence::new(base))
|
42
|
+
}
|
43
|
+
|
44
|
+
fn each_pair(
|
45
|
+
rb_self: Value,
|
46
|
+
x_base: u8,
|
47
|
+
y_base: u8,
|
48
|
+
) -> YieldValues<impl Iterator<Item = (f64, f64)>> {
|
49
|
+
if !block_given() {
|
50
|
+
return YieldValues::Enumerator(rb_self.enumeratorize("each_pair", (x_base, y_base)));
|
51
|
+
}
|
52
|
+
let seq_x = halton::Sequence::new(x_base);
|
53
|
+
let seq_y = halton::Sequence::new(y_base);
|
54
|
+
YieldValues::Iter(seq_x.zip(seq_y))
|
55
|
+
}
|
56
|
+
|
57
|
+
fn each_triple(
|
58
|
+
rb_self: Value,
|
59
|
+
x_base: u8,
|
60
|
+
y_base: u8,
|
61
|
+
z_base: u8,
|
62
|
+
) -> YieldValues<impl Iterator<Item = (f64, f64, f64)>> {
|
63
|
+
if !block_given() {
|
64
|
+
return YieldValues::Enumerator(
|
65
|
+
rb_self.enumeratorize("each_triple", (x_base, y_base, z_base)),
|
66
|
+
);
|
67
|
+
}
|
68
|
+
let seq_x = halton::Sequence::new(x_base);
|
69
|
+
let seq_y = halton::Sequence::new(y_base);
|
70
|
+
let seq_z = halton::Sequence::new(z_base);
|
71
|
+
YieldValues::Iter(seq_x.zip(seq_y).zip(seq_z).map(|((x, y), z)| (x, y, z)))
|
72
|
+
}
|
73
|
+
|
74
|
+
fn each_many(
|
75
|
+
rb_self: Value,
|
76
|
+
bases: &[Value],
|
77
|
+
) -> Result<YieldSplat<impl Iterator<Item = RArray>>, Error> {
|
78
|
+
if bases.is_empty() {
|
79
|
+
return Err(Error::new(
|
80
|
+
exception::arg_error(),
|
81
|
+
"wrong number of arguments (given 0, expected 1+)",
|
82
|
+
));
|
83
|
+
}
|
84
|
+
if !block_given() {
|
85
|
+
return Ok(YieldSplat::Enumerator(
|
86
|
+
rb_self.enumeratorize("each_many", bases),
|
87
|
+
));
|
88
|
+
}
|
89
|
+
let mut seqs = bases
|
90
|
+
.iter()
|
91
|
+
.map(|v| v.try_convert().map(halton::Sequence::new))
|
92
|
+
.collect::<Result<Vec<_>, _>>()?;
|
93
|
+
let mut buffer = Vec::<Value>::with_capacity(seqs.len());
|
94
|
+
Ok(YieldSplat::Iter(std::iter::from_fn(move || {
|
95
|
+
buffer.clear();
|
96
|
+
for seq in &mut seqs {
|
97
|
+
if let Some(v) = seq.next() {
|
98
|
+
buffer.push(v.into());
|
99
|
+
} else {
|
100
|
+
return None;
|
101
|
+
}
|
102
|
+
}
|
103
|
+
Some(RArray::from_slice(&buffer))
|
104
|
+
})))
|
105
|
+
}
|
106
|
+
|
29
107
|
#[magnus::init]
|
30
108
|
fn init() -> Result<(), Error> {
|
31
109
|
let module = define_module("Halton")?;
|
32
|
-
module.define_singleton_method("number", function!(halton::number, 2))
|
110
|
+
module.define_singleton_method("number", function!(halton::number, 2))?;
|
111
|
+
module.define_singleton_method("each_one", method!(each_one, 1))?;
|
112
|
+
module.define_singleton_method("each_pair", method!(each_pair, 2))?;
|
113
|
+
module.define_singleton_method("each_triple", method!(each_triple, 3))?;
|
114
|
+
module.define_singleton_method("each_many", method!(each_many, -1))?;
|
33
115
|
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))
|
116
|
+
class.define_singleton_method("new", function!(Sequence::new, 1))?;
|
117
|
+
class.define_method("next", method!(Sequence::next, 0))?;
|
118
|
+
class.define_method("skip", method!(Sequence::skip, 1))?;
|
119
|
+
class.define_method("remaining", method!(Sequence::remaining, 0))?;
|
38
120
|
Ok(())
|
39
121
|
}
|
data/lib/halton.rb
CHANGED
@@ -68,33 +68,17 @@ module Halton
|
|
68
68
|
#
|
69
69
|
# The numbers yielded will be in the range > 0 and < 1.
|
70
70
|
#
|
71
|
-
def self.each(base, *bases)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
x = Sequence.new(base)
|
82
|
-
y = Sequence.new(bases.first)
|
83
|
-
loop {yield x.next, y.next}
|
84
|
-
return nil
|
71
|
+
def self.each(base, *bases, &block)
|
72
|
+
case bases.length
|
73
|
+
when 0
|
74
|
+
each_one(base, &block)
|
75
|
+
when 1
|
76
|
+
each_pair(base, bases.first, &block)
|
77
|
+
when 2
|
78
|
+
each_triple(base, bases.first, bases.last, &block)
|
79
|
+
else
|
80
|
+
each_many(*bases.unshift(base), &block)
|
85
81
|
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
82
|
end
|
99
83
|
|
100
84
|
# Halton::Sequence implements the fast generation of Halton sequences.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: halton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.1.
|
4
|
+
version: 0.2.1.3
|
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-
|
11
|
+
date: 2022-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|