halton 0.2.1.4-x64-mingw-ucrt
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +45 -0
- data/lib/halton/3.1/halton.so +0 -0
- data/lib/halton.rb +132 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dc997682f9f9dc57e833b1258d7e8c2f5f0834bdbed5747602c359ce54873781
|
4
|
+
data.tar.gz: 52fe97c9e6d1db1318d68517b915ee3cf4fb20d7442dadd786a1fc170d3b503e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e0f18725329c54a6571dfcf003e6447a3fbf1b67b14c6a6900ca7a96cc0bc546073d0f48bb9f905ccc95d263d846324b733732c22591d669b38ba5ea39f6b769
|
7
|
+
data.tar.gz: d894ba41bbde97f2addefdf5ee959a8df2bdd3893cfa6ba5b2fed3d0229ef0c441bd1668a9be907fbbfadce79e4de85d58c79085bfdd2c2f98df7d6300a66765
|
data/README.rdoc
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
= Halton
|
2
|
+
|
3
|
+
A Ruby library for the fast generation of Halton sequences, a deterministic low
|
4
|
+
discrepancy sequence that appears to be random. The uniform distribution and
|
5
|
+
repeatability makes the sequence ideal for choosing sample points or placing
|
6
|
+
objects in 2D or 3D space.
|
7
|
+
|
8
|
+
grid = 10.times.map {10.times.map {"."}}
|
9
|
+
Halton.each(2, 3).take(26).zip("A".."Z") do |(x, y), c|
|
10
|
+
grid[y * 10][x * 10] = c
|
11
|
+
end
|
12
|
+
grid.each {|row| puts row.join(" ")}
|
13
|
+
|
14
|
+
Outputs:
|
15
|
+
|
16
|
+
. . R . . I . . . .
|
17
|
+
. L . . . . U C . .
|
18
|
+
X . . F . . . . . O
|
19
|
+
. . . J . A . . . .
|
20
|
+
. D . . . . M S . .
|
21
|
+
P . . . V . . . G .
|
22
|
+
. . B . . Y . . . .
|
23
|
+
. T . . . . E . K .
|
24
|
+
H . . . N . . . . W
|
25
|
+
. . . Z . Q . . . .
|
26
|
+
|
27
|
+
The method of generation is adapted from "Fast, portable, and reliable
|
28
|
+
algorithm for the calculation of Halton numbers" by Miroslav Kolář and Seamus F.
|
29
|
+
O'Shea.
|
30
|
+
|
31
|
+
== Install
|
32
|
+
|
33
|
+
Install via Rubygems:
|
34
|
+
|
35
|
+
gem install halton
|
36
|
+
|
37
|
+
or add it to your Gemfile if you're using Bundler:
|
38
|
+
|
39
|
+
gem "halton"
|
40
|
+
|
41
|
+
and then run the bundle command to install.
|
42
|
+
|
43
|
+
This gem requires a Rust compiler and the +cargo+ build tool to build the gem's
|
44
|
+
native extension. See https://www.rust-lang.org/tools/install for how to
|
45
|
+
install Rust. +cargo+ is usually part of the Rust installation.
|
Binary file
|
data/lib/halton.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
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
|
9
|
+
|
10
|
+
# The Halton module provides methods for generating Halton sequences, a
|
11
|
+
# deterministic low discrepancy sequence that appears to be random. The uniform
|
12
|
+
# distribution and repeatability makes the sequence ideal for choosing sample
|
13
|
+
# points or placing objects in 2D or 3D space.
|
14
|
+
#
|
15
|
+
# grid = 10.times.map {10.times.map {"."}}
|
16
|
+
# Halton.each(2, 3).take(26).zip("A".."Z") do |(x, y), c|
|
17
|
+
# grid[y * 10][x * 10] = c
|
18
|
+
# end
|
19
|
+
# grid.each {|row| puts row.join(" ")}
|
20
|
+
#
|
21
|
+
# Outputs:
|
22
|
+
#
|
23
|
+
# . . R . . I . . . .
|
24
|
+
# . L . . . . U C . .
|
25
|
+
# X . . F . . . . . O
|
26
|
+
# . . . J . A . . . .
|
27
|
+
# . D . . . . M S . .
|
28
|
+
# P . . . V . . . G .
|
29
|
+
# . . B . . Y . . . .
|
30
|
+
# . T . . . . E . K .
|
31
|
+
# H . . . N . . . . W
|
32
|
+
# . . . Z . Q . . . .
|
33
|
+
#
|
34
|
+
module Halton
|
35
|
+
|
36
|
+
##
|
37
|
+
# :singleton-method: number
|
38
|
+
# :call-seq: Halton.number(base, index) -> int
|
39
|
+
#
|
40
|
+
# Returns the number at +index+ of the Halton sequence for +base+. The number
|
41
|
+
# returned will be > 0 and < 1, assuming +index+ > 1.
|
42
|
+
#
|
43
|
+
# While #each will be faster for most cases, this function may be
|
44
|
+
# useful for calulating a single number from a Halton sequence, or creating
|
45
|
+
# a 'leaped' sequence.
|
46
|
+
#
|
47
|
+
# 'leaped' Halton sequence:
|
48
|
+
#
|
49
|
+
# step = 409;
|
50
|
+
# i = 1;
|
51
|
+
# while i < 10 * step
|
52
|
+
# puts Halton.number(17, i)
|
53
|
+
# i += step
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# Beware that indexing #each is effectively 0-based, whereas the
|
57
|
+
# `index` argument for [`number`] is 1-based.
|
58
|
+
#
|
59
|
+
# Halton.each(2).take(10)[2] #=> 0.75
|
60
|
+
# Halton.number(2, 3) #=> 0.75
|
61
|
+
|
62
|
+
# :call-seq:
|
63
|
+
# Halton.each(base) {|n| ... }
|
64
|
+
# Halton.each(base_x, base_y) {|x, y| ... }
|
65
|
+
# Halton.each(base_x, base_y, base_z) {|x, y, z| ... }
|
66
|
+
# Halton.each(*bases) {|*n| ... }
|
67
|
+
# Halton.each(*bases) -> Enumerator
|
68
|
+
#
|
69
|
+
# Implements the fast generation of Halton sequences.
|
70
|
+
# The method of generation is adapted from "Fast, portable, and reliable
|
71
|
+
# algorithm for the calculation of Halton numbers" by Miroslav Kolář and
|
72
|
+
# Seamus F. O'Shea.
|
73
|
+
#
|
74
|
+
# The numbers yielded will be in the range > 0 and < 1.
|
75
|
+
#
|
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)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Halton::Sequence implements the fast generation of Halton sequences.
|
90
|
+
# The method of generation is adapted from "Fast, portable, and reliable
|
91
|
+
# algorithm for the calculation of Halton numbers" by Miroslav Kolář and
|
92
|
+
# Seamus F. O'Shea.
|
93
|
+
#
|
94
|
+
# This class is implemented as a stateful iterator, a pattern not common in
|
95
|
+
# Ruby. The Halton::each method provides a more friendly interface to this
|
96
|
+
# class.
|
97
|
+
#
|
98
|
+
class Sequence
|
99
|
+
|
100
|
+
##
|
101
|
+
# :singleton-method: new
|
102
|
+
# :call-seq: Sequence.new(base) -> sequence
|
103
|
+
#
|
104
|
+
# Create a new Halton::Sequence.
|
105
|
+
|
106
|
+
##
|
107
|
+
# :method: next
|
108
|
+
# :call-seq: sequence.next -> int
|
109
|
+
#
|
110
|
+
# Get the next number in the sequence. The numbers will be in the range > 0
|
111
|
+
# and < 1.
|
112
|
+
#
|
113
|
+
# Will raise StopIteration when the sequence has ended.
|
114
|
+
|
115
|
+
##
|
116
|
+
# :method: skip
|
117
|
+
# :call-seq: sequence.skip(n) -> nil
|
118
|
+
#
|
119
|
+
# Can be used to efficiently skip large sections of the sequence. For small
|
120
|
+
# values of +n+ simply advances the sequence +n+ times.
|
121
|
+
|
122
|
+
##
|
123
|
+
# :method: remaining
|
124
|
+
# :call-seq: sequence.remaining -> int or nil
|
125
|
+
#
|
126
|
+
# Returns the count of the remaining numbers in the sequence. May return
|
127
|
+
# +nil+ if the count is larger than the host platform's native unsigned
|
128
|
+
# integer type.
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: halton
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1.4
|
5
|
+
platform: x64-mingw-ucrt
|
6
|
+
authors:
|
7
|
+
- Mat Sadler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rb_sys
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.46
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
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
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
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'
|
55
|
+
description: A module implementing the fast generation of Halton sequences. The method
|
56
|
+
of generation is adapted from "Fast, portable, and reliable algorithm for the calculation
|
57
|
+
of Halton number" by Miroslav Kolář and Seamus F. O'Shea.
|
58
|
+
email:
|
59
|
+
- mat@sourcetagsandcodes.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files:
|
63
|
+
- README.rdoc
|
64
|
+
files:
|
65
|
+
- README.rdoc
|
66
|
+
- lib/halton.rb
|
67
|
+
- lib/halton/3.1/halton.so
|
68
|
+
homepage: https://github.com/matsadler/halton-rb
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options:
|
74
|
+
- "--main"
|
75
|
+
- README.rdoc
|
76
|
+
- "--charset"
|
77
|
+
- utf-8
|
78
|
+
- "--exclude"
|
79
|
+
- ext/
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '3.1'
|
87
|
+
- - "<"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.2.dev
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements:
|
96
|
+
- Rust >= 1.51.0
|
97
|
+
rubygems_version: 3.3.22
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: A module for generating Halton sequences
|
101
|
+
test_files: []
|