flex-cartesian 1.1 → 1.2.1
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 +12 -0
- data/README.md +4 -2
- data/lib/flex-cartesian.rb +28 -1
- 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: f3005b96077c2ec5e9a273bf58c6740fb3715524ca69328523370f1d67db01e9
|
4
|
+
data.tar.gz: 95c612d95526fa4fa2aafa3fe38ab9861e0bb2b442bdec5a34b74bd45ee3180b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0560a624b178dda3526775093e692a3cb09d032a5b00463ec556bd6a24a4bc51281c0294249f6ae2c0a1070bee8eae8ef4f7f686aed4092ea1f8e33295a4da57
|
7
|
+
data.tar.gz: fabdc19cb4647e2863aceffbf3888c3f274c7df3f1514ff31dd9e94f142506cf67b3715b7d6bac9df8aa504d416ba39282a319d59bb370f9a63e424c389e3e57
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.2.1 - 2025-07-28
|
4
|
+
### Fixed
|
5
|
+
- When adding function, check if its namesake exists
|
6
|
+
|
7
|
+
## 1.2 - 2025-07-23
|
8
|
+
## Added
|
9
|
+
- Optional progress bar to the function command :run
|
10
|
+
|
11
|
+
## 1.1 - 2025-07=22
|
12
|
+
### Fixed
|
13
|
+
- Dependencies
|
14
|
+
|
3
15
|
## 1.0 - 2025-07-14
|
4
16
|
### Added
|
5
17
|
- Optional flad for hiding function from output
|
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,13 +86,27 @@ 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
|
+
|
89
93
|
cartesian do |v|
|
90
94
|
@function_results[v] ||= {}
|
91
95
|
@derived.each do |fname, block|
|
92
96
|
@function_results[v][fname] = block.call(v)
|
93
97
|
end
|
98
|
+
bar.increment if progress
|
94
99
|
end
|
95
100
|
|
101
|
+
else
|
102
|
+
cartesian do |v|
|
103
|
+
@function_results[v] ||= {}
|
104
|
+
@derived.each do |fname, block|
|
105
|
+
@function_results[v][fname] = block.call(v)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
96
110
|
else
|
97
111
|
raise ArgumentError, "Unknown command for function: #{command.inspect}"
|
98
112
|
end
|
@@ -100,6 +114,11 @@ end
|
|
100
114
|
|
101
115
|
def add_function(name, &block)
|
102
116
|
raise ArgumentError, "Block required" unless block_given?
|
117
|
+
if reserved_function_names.include?(name.to_sym)
|
118
|
+
raise ArgumentError, "Function name '#{name}' has been already added"
|
119
|
+
elsif reserved_struct_names.include?(name.to_sym)
|
120
|
+
raise ArgumentError, "Name '#{name}' has been reserved for internal method, you can't use it for a function"
|
121
|
+
end
|
103
122
|
@derived[name.to_sym] = block
|
104
123
|
end
|
105
124
|
|
@@ -268,6 +287,14 @@ end
|
|
268
287
|
|
269
288
|
private
|
270
289
|
|
290
|
+
def reserved_struct_names
|
291
|
+
(base_struct_methods = Struct.new(:dummy).methods(false) + Struct.new(:dummy).instance_methods(false)).uniq
|
292
|
+
end
|
293
|
+
|
294
|
+
def reserved_function_names
|
295
|
+
(self.methods + self.class.instance_methods(false)).uniq
|
296
|
+
end
|
297
|
+
|
271
298
|
def fmt_cell(value, colorize, width = nil)
|
272
299
|
str = case value
|
273
300
|
when String then value
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flex-cartesian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Rassokhin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-07-
|
11
|
+
date: 2025-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|