ruby-mext 0.6.0 → 0.7.0

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: 4b73cba301d8a424b583b1cdf7f7865d70303650f65e1ec369859bfa7fa32eb7
4
- data.tar.gz: 0aaaf5442309c8bd92e6a5a83c611655fcc3bc87924104ad9bc805f18525d42e
3
+ metadata.gz: 5f86e7d87ee04f60b780f4a82f982239fffe311475bb0553c9072ef4aaf1340e
4
+ data.tar.gz: 476180537e18d2f41fad5cb6ea86c78db5a7d0beabb245385455b3a67d0a946a
5
5
  SHA512:
6
- metadata.gz: d828a3d2fa1589b342c6f2ad981299e4074ee0ba4bfe283c5a65af2ce157a771b39dceb23ba00bc4ec722645c9a90afd4c5fb871e13f8080977f88d2c6874830
7
- data.tar.gz: 65e5b198dfa246b0a2d3995513aef60e5ee0441e46f78d384dcf6656962e0792f108fec234670f2278a0d8a590ef3a69236a04fa97162f3a1638f7bc95a57aef
6
+ metadata.gz: 894b67cfa2db0c20a59ddf9fff63bcc88671eebe1eab681f712656b8bc0c588e65e5a40417d72750d297ac5c34bfe7068e61f15ce95781fc23c3f17d19962ee2
7
+ data.tar.gz: 8b072063935a3b6be99092e9fc935c0236ee081fdc22b750b5c19710cd571dbd05e585d60ff020de5b0b68878549947964313d03a556b02e1c82a63d087fcdb0
@@ -0,0 +1,98 @@
1
+ module Math
2
+
3
+ class Stepwise < Function
4
+
5
+ class Point
6
+ attr_reader :x, :y
7
+
8
+ def initialize(x, y)
9
+ @x = x
10
+ @y = y
11
+ end
12
+ end
13
+
14
+ #
15
+ # +:values+
16
+ #
17
+ # is an array of pairs (+x+, +y+)
18
+ #
19
+ attr_reader :values
20
+
21
+ #
22
+ # +Math::Stepwise.new(values = [])+
23
+ #
24
+ # stepwise function
25
+ #
26
+ # Arguments are:
27
+ #
28
+ # +values+: an array of (+x+, +y+) pairs
29
+ #
30
+ #:nodoc:
31
+ def initialize(vs = [])
32
+ setup(vs)
33
+ end
34
+
35
+ #:doc:
36
+ #
37
+ # +y(x)+:
38
+ #
39
+ # Returns a value for any given x
40
+ #
41
+ #:nodoc:
42
+ def y(x)
43
+ lookup(x)
44
+ end
45
+
46
+ def label
47
+ 'stepwise function'
48
+ end
49
+
50
+ class << self
51
+
52
+ #
53
+ # +from_yaml(yaml_hash)+:
54
+ #
55
+ # creates a Math::Stepwise class from a yaml file which must have the
56
+ # relevant fields:
57
+ #
58
+ # +values+: an array of duples [x, y]
59
+ #
60
+ def from_yaml(yh)
61
+ new(yh['values'])
62
+ end
63
+
64
+ end
65
+
66
+ private
67
+
68
+ def lookup(x)
69
+ last = nil
70
+ self.values.each do
71
+ |p|
72
+ break if p.x > x
73
+ last = p.y
74
+ end
75
+ last
76
+ end
77
+
78
+ #
79
+ # +setup+
80
+ #
81
+ # setup basically sorts the input array in time creating points
82
+ #
83
+ #:nodoc:
84
+ def setup(vs)
85
+ @values = []
86
+ sorted = vs.sort { |a, b| a[0] <=> b[0] }
87
+ sorted.each { |duple| self.values << Point.new(duple[0], duple[1]) }
88
+ #
89
+ # keep in mind that vs might be empty
90
+ #
91
+ @x_start = self.values.first ? self.values.first.x : self.values.first
92
+ @x_end = self.values.last ? self.values.last.x : self.values.last
93
+ end
94
+
95
+ end
96
+
97
+ end
98
+
data/lib/mext/math.rb CHANGED
@@ -8,4 +8,5 @@ end
8
8
  function
9
9
  line
10
10
  expon
11
+ stepwise
11
12
  ).each { |f| require File.join(Mext::MATH_PATH, f) }
@@ -1,6 +1,6 @@
1
1
 
2
2
  desc 'plot all plots'
3
- task :plot => ['plot:expon', 'plot:line']
3
+ task :plot => ['plot:expon', 'plot:line', 'plot:stepwise']
4
4
 
5
5
  namespace :plot do
6
6
 
@@ -0,0 +1,19 @@
1
+ require 'fileutils'
2
+ require File.expand_path(File.join(['..'] * 4, 'spec', 'fixtures', 'stepwise_dataset'), __FILE__)
3
+ require File.expand_path(File.join('..', 'gruff_plot'), __FILE__)
4
+
5
+ require 'byebug'
6
+
7
+ namespace :plot do
8
+
9
+ desc 'plot the Stepwise dataset'
10
+ task :stepwise => :create_output_dir do
11
+ ranges = [ Range.new(0, 1) ]
12
+ p = Mext::Gruff::Plotter.new('stepwise_dataset', 800, Mext::Spec::Fixtures::Math::STEPWISE_DATASETS, ranges)
13
+ p.plot do
14
+ |args|
15
+ Math::Stepwise.new(args)
16
+ end
17
+ end
18
+
19
+ end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mext
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicola Bernardini
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-26 00:00:00.000000000 Z
11
+ date: 2019-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,7 @@ files:
122
122
  - lib/mext/math/expon.rb
123
123
  - lib/mext/math/function.rb
124
124
  - lib/mext/math/line.rb
125
+ - lib/mext/math/stepwise.rb
125
126
  - lib/mext/numeric.rb
126
127
  - lib/mext/numeric/ampdb.rb
127
128
  - lib/mext/numeric/cpspch.rb
@@ -143,6 +144,7 @@ files:
143
144
  - lib/tasks/gruff/gruff.rake
144
145
  - lib/tasks/gruff/gruff_plot.rb
145
146
  - lib/tasks/gruff/line.rake
147
+ - lib/tasks/gruff/stepwise.rake
146
148
  - lib/version.rb
147
149
  - ruby-mext.gemspec
148
150
  homepage: https://github.com/nicb/ruby-mext