flex-cartesian 1.1 → 1.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +4 -2
- data/lib/flex-cartesian.rb +15 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ffe9aa47d7a73dc2f4ab52cc4943d3bdec7ce709a0712b7e92cc4077f785f82
|
4
|
+
data.tar.gz: d788a54aee87646c8ab77e58762068dcb4c7d644fdae027365e2ee3446399f8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be6655fc4acce24a97f2287ee81df181c2a7426fd70b52d0ba02bae3facb80e9720dc5116a9f1dd0afdc0adf412f48b558ee2e5ef154a178a5da5b45dc5e47de
|
7
|
+
data.tar.gz: 26210fc67b053bd01946d3ce052c13fe54c035235357ddc7778af98b8487c8485af927d092944dabf92a95c91f040da51bb546617772d6aed2246fe52b079120
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -297,7 +297,7 @@ s.func(:add, :time) { |v| v.raw_ping[/min\/avg\/max\/(?:mdev|stddev) = [^\/]+\/(
|
|
297
297
|
s.func(:add, :min) { |v| v.raw_ping[/min\/avg\/max\/(?:mdev|stddev) = ([^\/]+)/, 1]&.to_f } # fetch min time from result
|
298
298
|
s.func(:add, :loss) { |v| v.raw_ping[/(\d+(?:\.\d+)?)% packet loss/, 1]&.to_f } # fetch ping loss from result
|
299
299
|
|
300
|
-
s.func(:run) # Sweep analysis! Benchmark all possible combinations of parameters
|
300
|
+
s.func(:run, progress: true, title: "Pinging") # Sweep analysis! Benchmark all possible combinations of parameters
|
301
301
|
|
302
302
|
s.output(format: :csv, file: './result.csv') # save benchmark result as CSV
|
303
303
|
|
@@ -374,7 +374,7 @@ s.cartesian { |v| puts "#{v.dim1} - #{v.dim2}" }
|
|
374
374
|
|
375
375
|
### Handling Functions
|
376
376
|
```ruby
|
377
|
-
func(command = :print, name = nil, hide: false, &block)
|
377
|
+
func(command = :print, name = nil, hide: false, progress: false, title: "calculating functions", &block)
|
378
378
|
```
|
379
379
|
- `command`: symbol, one of the following
|
380
380
|
- `:add` to add function as a virtual dimension to Cartesian space
|
@@ -383,6 +383,8 @@ func(command = :print, name = nil, hide: false, &block)
|
|
383
383
|
- `:run` to calculate all the functions defined for Cartesian space
|
384
384
|
- `name`: symbol, name of the virtual dimension, e.g. `:my_function`
|
385
385
|
- `hide`: flag that hides or shows the function in .output; it is useful to hide intermediate calculations
|
386
|
+
- `progress`: show progress bar during `:run`, useful for large Cartesian space
|
387
|
+
- `title`: title of the progress bar
|
386
388
|
- `block`: a function that receives each vector and returns a computed value
|
387
389
|
|
388
390
|
Functions show up in `.output` like additional (virtual) dimensions.
|
data/lib/flex-cartesian.rb
CHANGED
@@ -59,7 +59,7 @@ class FlexCartesian
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
def func(command = :print, name = nil, hide: false, &block)
|
62
|
+
def func(command = :print, name = nil, hide: false, progress: false, title: "calculating functions", &block)
|
63
63
|
case command
|
64
64
|
when :add
|
65
65
|
raise ArgumentError, "Function name and block required for :add" unless name && block_given?
|
@@ -86,12 +86,26 @@ def func(command = :print, name = nil, hide: false, &block)
|
|
86
86
|
|
87
87
|
when :run
|
88
88
|
@function_results = {}
|
89
|
+
|
90
|
+
if progress
|
91
|
+
bar = ProgressBar.create(title: title, total: size, format: '%t [%B] %p%% %e')
|
92
|
+
|
93
|
+
cartesian do |v|
|
94
|
+
@function_results[v] ||= {}
|
95
|
+
@derived.each do |fname, block|
|
96
|
+
@function_results[v][fname] = block.call(v)
|
97
|
+
end
|
98
|
+
bar.increment if progress
|
99
|
+
end
|
100
|
+
|
101
|
+
else
|
89
102
|
cartesian do |v|
|
90
103
|
@function_results[v] ||= {}
|
91
104
|
@derived.each do |fname, block|
|
92
105
|
@function_results[v][fname] = block.call(v)
|
93
106
|
end
|
94
107
|
end
|
108
|
+
end
|
95
109
|
|
96
110
|
else
|
97
111
|
raise ArgumentError, "Unknown command for function: #{command.inspect}"
|