redshift 1.3.15 → 1.3.16
Sign up to get free protection for your applications and to get access to all the features.
- data/RELEASE-NOTES +4 -0
- data/bench/diff-bench +2 -2
- data/bench/run +1 -1
- data/bench/strictness.rb +2 -2
- data/examples/ball.rb +1 -1
- data/examples/collide.rb +1 -1
- data/examples/delay.rb +1 -1
- data/examples/derivative.rb +1 -1
- data/examples/euler.rb +1 -1
- data/examples/lotka-volterra.rb +1 -1
- data/examples/pid.rb +1 -1
- data/examples/subsystem.rb +1 -1
- data/examples/thermostat.rb +1 -1
- data/lib/redshift/component.rb +2 -2
- data/lib/redshift/redshift.rb +2 -2
- data/lib/{accessible-index.rb → redshift/util/accessible-index.rb} +0 -0
- data/lib/redshift/util/argos.rb +214 -0
- data/lib/redshift/util/histogram.rb +155 -0
- data/lib/redshift/util/object-diff.rb +83 -0
- data/lib/redshift/util/plot.rb +386 -0
- data/lib/redshift/util/random.rb +261 -0
- data/lib/redshift/util/superhash.rb +454 -0
- data/lib/redshift/util/tracer.rb +113 -0
- data/lib/redshift/util/tracer/trace.rb +145 -0
- data/lib/redshift/util/tracer/var.rb +112 -0
- data/rakefile +2 -2
- data/test/test_flow_trans.rb +28 -25
- metadata +45 -7
- data/examples/persist-ball.rb +0 -68
data/RELEASE-NOTES
CHANGED
data/bench/diff-bench
CHANGED
data/bench/run
CHANGED
data/bench/strictness.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'ruby-prof'
|
2
2
|
|
3
3
|
$strict = ARGV.delete("-s")
|
4
4
|
|
@@ -76,7 +76,7 @@ end
|
|
76
76
|
times = Process.times
|
77
77
|
t0 = Time.now
|
78
78
|
pt0 = times.utime #+ times.stime
|
79
|
-
profile
|
79
|
+
RubyProf.profile do
|
80
80
|
w.run 1000
|
81
81
|
end
|
82
82
|
times = Process.times
|
data/examples/ball.rb
CHANGED
data/examples/collide.rb
CHANGED
data/examples/delay.rb
CHANGED
data/examples/derivative.rb
CHANGED
data/examples/euler.rb
CHANGED
data/examples/lotka-volterra.rb
CHANGED
data/examples/pid.rb
CHANGED
data/examples/subsystem.rb
CHANGED
data/examples/thermostat.rb
CHANGED
data/lib/redshift/component.rb
CHANGED
data/lib/redshift/redshift.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2001-
|
1
|
+
# Copyright (C) 2001-2010, Joel VanderWerf
|
2
2
|
# Distributed under the Ruby license. See www.ruby-lang.org.
|
3
3
|
|
4
4
|
# Read all environment variables related to RedShift and store in globals
|
@@ -33,7 +33,7 @@ end
|
|
33
33
|
module RedShift
|
34
34
|
include Math
|
35
35
|
|
36
|
-
VERSION = '1.3.
|
36
|
+
VERSION = '1.3.16'
|
37
37
|
|
38
38
|
Infinity = Math::Infinity
|
39
39
|
|
File without changes
|
@@ -0,0 +1,214 @@
|
|
1
|
+
# A slim command-line parser that does one thing well: turn an array of
|
2
|
+
# strings, such as ARGV, into a hash of recognized options and their
|
3
|
+
# arguments, leaving unrecognized strings in the original array.
|
4
|
+
#
|
5
|
+
# Argos was Odysseus' faithful dog, who was good at recognizing ;)
|
6
|
+
#
|
7
|
+
# Synopsis:
|
8
|
+
#
|
9
|
+
# require 'argos'
|
10
|
+
#
|
11
|
+
# optdef = {
|
12
|
+
# "v" => true,
|
13
|
+
# "n" => proc {|arg| Integer(arg)}
|
14
|
+
# }
|
15
|
+
#
|
16
|
+
# argv = %w{-v -n10 filename}
|
17
|
+
# opts = Argos.parse_options(argv, optdef)
|
18
|
+
# p opts # ==> {"v"=>true, "n"=>10}
|
19
|
+
# p argv # ==> ["filename"]
|
20
|
+
#
|
21
|
+
# Features:
|
22
|
+
#
|
23
|
+
# - Operates on ARGV or any given array of strings.
|
24
|
+
#
|
25
|
+
# - Output is a hash of {option => value, ...}.
|
26
|
+
#
|
27
|
+
# - You can merge this hash on top of a hash of defaults if you want.
|
28
|
+
#
|
29
|
+
# - Supports both long ("--foo") and short ("-f") options.
|
30
|
+
#
|
31
|
+
# - A long option with an argument is --foo=bar or --foo bar.
|
32
|
+
#
|
33
|
+
# - A short option with an argument is -fbar or -f bar.
|
34
|
+
#
|
35
|
+
# - The options -x and --x are synonymous.
|
36
|
+
#
|
37
|
+
# - Short options with no args can be combined as -xyz in place of -x -y -z.
|
38
|
+
#
|
39
|
+
# - If -z takes an argument, then -xyz foo is same as -x -y -z foo.
|
40
|
+
#
|
41
|
+
# - The string "--" terminates option parsing, leaving the rest untouched.
|
42
|
+
#
|
43
|
+
# - The string "-" is not considered an option.
|
44
|
+
#
|
45
|
+
# - ARGV (or other given array) is modified: it has all parsed options
|
46
|
+
# and arguments removed, so you can use ARGF to treat the rest as input files.
|
47
|
+
#
|
48
|
+
# - Unrecognized arguments are left in the argument array. You can catch them
|
49
|
+
# with grep(/^-./), in case you want to pass them on to another program or
|
50
|
+
# warn the user.
|
51
|
+
#
|
52
|
+
# - Argument validation and conversion are in terms of an option definition
|
53
|
+
# hash, which specifies which options are allowed, the number of arguments
|
54
|
+
# for each (0 or 1), and how to generate the value from the argument, if any.
|
55
|
+
#
|
56
|
+
# - Repetition of args ("-v -v", or "-vv") can be handled by closures. See
|
57
|
+
# the example below.
|
58
|
+
#
|
59
|
+
# - Everything is ducky. For example, handlers only need an #arity method
|
60
|
+
# and a #[] method to be recognized as callable. Otherwise they are treated
|
61
|
+
# as static objects.
|
62
|
+
#
|
63
|
+
# Limitations:
|
64
|
+
#
|
65
|
+
# - A particular option takes either 0 args or 1 arg. There are no optional
|
66
|
+
# arguments, in the sense of both "-x" and "-x3" being accepted.
|
67
|
+
#
|
68
|
+
# - Options lose their ordering in the output hash (but they are parsed in
|
69
|
+
# order and you can keep track using state in the handler closures).
|
70
|
+
#
|
71
|
+
# - There is no usage/help output.
|
72
|
+
#
|
73
|
+
# Copyright (C) 2006-2009 Joel VanderWerf, mailto:vjoel@users.sourceforge.net.
|
74
|
+
#
|
75
|
+
# License is the Ruby license. See http://www.ruby-lang.org.
|
76
|
+
#
|
77
|
+
module Argos
|
78
|
+
module_function
|
79
|
+
|
80
|
+
# Raised (a) when an option that takes an argument occurs at the end of the
|
81
|
+
# argv list, with no argument following it, or (b) when a handler barfs.
|
82
|
+
class OptionError < ArgumentError; end
|
83
|
+
|
84
|
+
# Called when an option that takes an argument occurs at the end of the
|
85
|
+
# argv list, with no argument following it.
|
86
|
+
def argument_missing opt
|
87
|
+
raise OptionError, "#{opt}: no argument provided."
|
88
|
+
end
|
89
|
+
|
90
|
+
def handle opt, handler, *args # :nodoc
|
91
|
+
args.empty? ? handler[] : handler[args[0]]
|
92
|
+
rescue => ex
|
93
|
+
raise OptionError, "#{opt}: #{ex}"
|
94
|
+
end
|
95
|
+
|
96
|
+
# Returns the hash of parsed options and argument values. The +argv+ array
|
97
|
+
# is modified: every recognized option and argument is deleted.
|
98
|
+
#
|
99
|
+
# The +optdef+ hash defines the options and their arguments.
|
100
|
+
#
|
101
|
+
# Each key is an option name (without "-" chars).
|
102
|
+
#
|
103
|
+
# The value for a key in +optdef+
|
104
|
+
# is used to generate the value for the same key in the options hash
|
105
|
+
# returned by this method.
|
106
|
+
#
|
107
|
+
# If the value has an #arity method and arity > 0, the value is considered to
|
108
|
+
# be a handler; it is called with the argument string to return the value
|
109
|
+
# associated with the option in the hash returned by the method.
|
110
|
+
#
|
111
|
+
# If the arity <= 0, the value is considered to be a handler for an option
|
112
|
+
# without arguments; it is called with no arguments to return the value of
|
113
|
+
# the option.
|
114
|
+
#
|
115
|
+
# If there is no arity method, the object itself is used as the value of
|
116
|
+
# the option.
|
117
|
+
#
|
118
|
+
# Only one kind of input will cause an exception (not counting exceptions
|
119
|
+
# raised by handler code or by bugs):
|
120
|
+
#
|
121
|
+
# - An option is found at the end of the list, and it requires an argument.
|
122
|
+
# This results in a call to #argument_missing, which by default raises
|
123
|
+
# OptionError.
|
124
|
+
#
|
125
|
+
def parse_options argv, optdef
|
126
|
+
orig = argv.dup; argv.clear
|
127
|
+
opts = {}
|
128
|
+
|
129
|
+
loop do
|
130
|
+
case (argstr=orig.shift)
|
131
|
+
when nil, "--"
|
132
|
+
argv.concat orig
|
133
|
+
break
|
134
|
+
|
135
|
+
when /^(--)([^=]+)=(.*)/, /^(-)([^-])(.+)/
|
136
|
+
short = ($1 == "-"); opt = $2; arg = $3
|
137
|
+
unless optdef.key?(opt)
|
138
|
+
argv << argstr
|
139
|
+
next
|
140
|
+
end
|
141
|
+
handler = optdef[opt]
|
142
|
+
arity = (handler.arity rescue nil)
|
143
|
+
opts[opt] =
|
144
|
+
case arity
|
145
|
+
when nil; orig.unshift("-#{arg}") if short; handler
|
146
|
+
when 0,-1; orig.unshift("-#{arg}") if short; handle(opt, handler)
|
147
|
+
else handle(opt, handler, arg)
|
148
|
+
end
|
149
|
+
|
150
|
+
when /^--(.+)/, /^-(.)$/
|
151
|
+
opt = $1
|
152
|
+
unless optdef.key?(opt)
|
153
|
+
argv << argstr
|
154
|
+
next
|
155
|
+
end
|
156
|
+
handler = optdef[opt]
|
157
|
+
arity = (handler.arity rescue nil)
|
158
|
+
opts[opt] =
|
159
|
+
case arity
|
160
|
+
when nil; handler
|
161
|
+
when 0,-1; handle(opt, handler)
|
162
|
+
else handle(opt, handler, orig.shift || argument_missing(opt))
|
163
|
+
end
|
164
|
+
|
165
|
+
else
|
166
|
+
argv << argstr
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
opts
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
if __FILE__ == $0
|
175
|
+
|
176
|
+
v = 0
|
177
|
+
defaults = {
|
178
|
+
"v" => v,
|
179
|
+
"port" => 4000,
|
180
|
+
"host" => "localhost"
|
181
|
+
}
|
182
|
+
|
183
|
+
optdef = {
|
184
|
+
"x" => true,
|
185
|
+
"y" => "y",
|
186
|
+
"z" => 3,
|
187
|
+
"v" => proc {v+=1}, # no argument, but call the proc to get the value
|
188
|
+
"port" => proc {|arg| Integer(arg)},
|
189
|
+
"n" => proc {|arg| Integer(arg)},
|
190
|
+
"t" => proc {|arg| Float(arg)},
|
191
|
+
"cmd" => proc {|arg| arg.split(",")}
|
192
|
+
}
|
193
|
+
|
194
|
+
ARGV.replace %w{
|
195
|
+
-xyzn5 somefile --port 5000 -t -1.23 -vv -v --unrecognized-option
|
196
|
+
--cmd=ls,-l otherfile -- --port
|
197
|
+
}
|
198
|
+
|
199
|
+
begin
|
200
|
+
cli_opts = Argos.parse_options(ARGV, optdef)
|
201
|
+
rescue Argos::OptionError => ex
|
202
|
+
$stderr.puts ex.message
|
203
|
+
exit
|
204
|
+
end
|
205
|
+
|
206
|
+
opts = defaults.merge cli_opts
|
207
|
+
|
208
|
+
p opts
|
209
|
+
p ARGV
|
210
|
+
unless ARGV.empty?
|
211
|
+
puts "Some arg-looking strings were not handled:", *ARGV.grep(/^-./)
|
212
|
+
end
|
213
|
+
|
214
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
class Histogram
|
2
|
+
# Number of bins.
|
3
|
+
attr_reader :bincount
|
4
|
+
|
5
|
+
# Size of each bin.
|
6
|
+
attr_reader :binsize
|
7
|
+
|
8
|
+
# Count of data points given.
|
9
|
+
attr_reader :count
|
10
|
+
|
11
|
+
# max, as given in opts, or max of data.
|
12
|
+
attr_reader :max
|
13
|
+
|
14
|
+
# min, as given in opts, or min of data.
|
15
|
+
attr_reader :min
|
16
|
+
|
17
|
+
# Unless false, normalize by this factor (or 1).
|
18
|
+
attr_reader :norm
|
19
|
+
|
20
|
+
# If "stats" option is present, calculate statistics in these attrs.
|
21
|
+
attr_reader :mean, :stdev
|
22
|
+
|
23
|
+
# An array of pairs of the form [bin, count]. Suitable for plotting. Bins are
|
24
|
+
# inclusive of lower endpoint. Highest bin is inclusive of both endpoints.
|
25
|
+
attr_reader :bins
|
26
|
+
|
27
|
+
# Options as originally given.
|
28
|
+
attr_reader :opts
|
29
|
+
|
30
|
+
# Construct a Histogram based on +ary+ with the +opts+:
|
31
|
+
#
|
32
|
+
# "bincount" :: number of bins (default is 10)
|
33
|
+
#
|
34
|
+
# "min" :: min value (otherwise, based on data)
|
35
|
+
#
|
36
|
+
# "max" :: max value (otherwise, based on data)
|
37
|
+
#
|
38
|
+
# "normalize" :: divide each bin by the total count, unless false
|
39
|
+
# if numeric, scale the result by the value
|
40
|
+
# (default is false)
|
41
|
+
#
|
42
|
+
# "stats" :: calculate statistics for the data set (min/stdev)
|
43
|
+
# (default is false)
|
44
|
+
#
|
45
|
+
def initialize(ary, opts={})
|
46
|
+
@opts = opts
|
47
|
+
@bins = []
|
48
|
+
|
49
|
+
ary = ary.map {|x| x.to_f}
|
50
|
+
@count = ary.size
|
51
|
+
|
52
|
+
@bincount = opts["bincount"]
|
53
|
+
@binsize = opts["binsize"]
|
54
|
+
@min = opts["min"] || ary.min
|
55
|
+
@max = opts["max"] || ary.max
|
56
|
+
@norm = opts["normalize"] || false
|
57
|
+
@stats = opts["stats"] || false
|
58
|
+
|
59
|
+
if @bincount and @binsize
|
60
|
+
raise ArgumentError, "Cannot specify both bincount and binsize"
|
61
|
+
elsif @bincount
|
62
|
+
@binsize = (@max-@min)/@bincount
|
63
|
+
elsif @binsize
|
64
|
+
@bincount = (@max-@min)/@binsize
|
65
|
+
else
|
66
|
+
@bincount = 10
|
67
|
+
@binsize = (@max-@min)/@bincount
|
68
|
+
end
|
69
|
+
|
70
|
+
raise ArgumentError, "Cannot have binsize==0" if @binsize == 0
|
71
|
+
|
72
|
+
@counts = Array.new(@bincount+1, 0)
|
73
|
+
|
74
|
+
ary.each do |x|
|
75
|
+
@counts[((x-min)/@binsize).round] += 1
|
76
|
+
end
|
77
|
+
|
78
|
+
return if ary.empty?
|
79
|
+
|
80
|
+
if @stats
|
81
|
+
n = ary.size.to_f
|
82
|
+
@mean = ary.inject {|sum, x| sum + x} / n
|
83
|
+
var = ary.inject(0) {|sum,x| sum+(x-@mean)**2} / (n-1)
|
84
|
+
@stdev = Math::sqrt(var)
|
85
|
+
end
|
86
|
+
|
87
|
+
scale = (norm && @count != 0) ? norm/@count.to_f : 1
|
88
|
+
@counts.each_with_index do |bin, i|
|
89
|
+
@bins << [min + i*@binsize, bin*scale]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def inspect
|
94
|
+
attrs = %w{ bincount binsize count min max norm }
|
95
|
+
attrs.concat %w{ mean stdev } if @stats
|
96
|
+
s = attrs.map {|a| "#{a}=#{send(a)}"}.join(", ")
|
97
|
+
"#<#{self.class}: #{s}>"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
if __FILE__ == $0
|
102
|
+
require 'redshift/util/argos'
|
103
|
+
|
104
|
+
defaults = {
|
105
|
+
"v" => 0
|
106
|
+
}
|
107
|
+
|
108
|
+
v=0
|
109
|
+
optdef = {
|
110
|
+
"bincount" => proc {|arg| Integer(arg)},
|
111
|
+
"binsize" => proc {|arg| Integer(arg)},
|
112
|
+
"min" => proc {|arg| Float(arg)},
|
113
|
+
"max" => proc {|arg| Float(arg)},
|
114
|
+
"normalize" => proc {|arg| Integer(arg) rescue 1},
|
115
|
+
|
116
|
+
"v" => proc {v+=1},
|
117
|
+
"plot" => true,
|
118
|
+
"o" => proc {|arg| arg}
|
119
|
+
}
|
120
|
+
|
121
|
+
begin
|
122
|
+
opts = defaults.merge(Argos.parse_options(ARGV, optdef))
|
123
|
+
rescue Argos::OptionError => ex
|
124
|
+
$stderr.puts ex.message
|
125
|
+
exit
|
126
|
+
end
|
127
|
+
|
128
|
+
opts["stats"] = true if opts["v"] > 0
|
129
|
+
|
130
|
+
histo = Histogram.new(ARGF, opts)
|
131
|
+
|
132
|
+
out = histo.bins.map {|d| d.join("\t")}
|
133
|
+
puts out
|
134
|
+
|
135
|
+
if opts["v"] > 0
|
136
|
+
$stderr.puts histo.inspect
|
137
|
+
end
|
138
|
+
|
139
|
+
if opts["plot"]
|
140
|
+
require 'sci/plot'
|
141
|
+
extend Plot::PlotUtils
|
142
|
+
|
143
|
+
gnuplot do |plot|
|
144
|
+
outfile = opts["o"]
|
145
|
+
if outfile
|
146
|
+
ext = File.extname(outfile)[/[^.]+$/]
|
147
|
+
plot.command "set term #{ext}"
|
148
|
+
plot.command "set output #{outfile.inspect}"
|
149
|
+
end
|
150
|
+
plot.add histo.bins, %{w histeps title 'histogram'}
|
151
|
+
end
|
152
|
+
|
153
|
+
sleep 1 if /mswin32|mingw32/ =~ RUBY_PLATFORM
|
154
|
+
end
|
155
|
+
end
|