redshift 1.3.24 → 1.3.26

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6efe4898ea37d2d69e2bf76b09c1a8f21a49f5e1
4
+ data.tar.gz: f49ba364d83aeab669be50e244c09a49499e600c
5
+ SHA512:
6
+ metadata.gz: 6116140716bae7b6b7555d714aac7d3f3d7f62c04583f1da0128c17303449fc254342ad7857757ae65503bae44f96df031054c176dd7a4a7307b5c164a90653c
7
+ data.tar.gz: 442f564bc09f72a30b8914e8e32b5bb124fee97b0abffb50f932001c1c0ed011e3d1ceb6304817861f1c7de8e7bca84187aac23ea64048d8b6310c556e57aac3
@@ -1,25 +1,25 @@
1
- = RedShift
1
+ # RedShift #
2
2
 
3
3
  A framework for simulation of networks of hybrid automata, similar to SHIFT and Lambda-SHIFT. Includes ruby-based DSL for defining simulation components, and ruby/C code generation and runtime.
4
4
 
5
- There's no documentation yet, but it will be at http://redshift.sourceforge.net and http://redshift.rubyforge.org. For now, start with the examples.
5
+ There's no documentation yet. For now, start with the examples.
6
6
 
7
- == Requirements
7
+ ## Requirements ##
8
8
 
9
9
  RedShift needs ruby 1.8.x and a compatible C compiler. If you can build native gems, you're all set.
10
10
 
11
11
  Some of the examples also use Ruby/Tk and the tkar gem.
12
12
 
13
- == Env vars
13
+ ## Env vars ##
14
14
 
15
15
  If you have a multicore system and are using the gnu toolchain, set
16
16
 
17
- REDSHIFT_MAKE_ARGS='-j -l2'
17
+ REDSHIFT_MAKE_ARGS='-j -l2'
18
18
 
19
19
  or some variation. You'll find that rebuilds of your simulation code go faster.
20
20
 
21
21
  ----
22
22
 
23
- Copyright (C) 2001-2010, Joel VanderWerf, vjoel@users.sourceforge.net
23
+ Copyright (C) 2001-2013, Joel VanderWerf, mailto:vjoel@users.sourceforge.net
24
24
  Distributed under the Ruby license. See www.ruby-lang.org.
25
25
 
@@ -1,3 +1,17 @@
1
+ redshift 1.3.26
2
+
3
+ - updated to ruby 2.0
4
+
5
+ - fixed gemspec
6
+
7
+ redshift 1.3.25
8
+
9
+ - added DVectorFloat
10
+
11
+ - added 'rake ex' task to build extensions for current ruby version
12
+
13
+ - minor bug fixes and updates
14
+
1
15
  redshift 1.3.24
2
16
 
3
17
  - fixed include path problem when running from installed gem
@@ -9,7 +9,7 @@ def bench_one(name)
9
9
  puts "#{name}:"
10
10
  #{name.split(/[-_]/).map {|w|w.capitalize}.join}.do_bench {|l| puts l}
11
11
  }
12
- ruby = Config::CONFIG["RUBY_INSTALL_NAME"]
12
+ ruby = RbConfig::CONFIG["RUBY_INSTALL_NAME"]
13
13
  system ruby, "-r" , "./bench", "-r", lib, "-e", cmd
14
14
  end
15
15
 
@@ -0,0 +1,183 @@
1
+ #include "dvector-float.h"
2
+ #include <math.h>
3
+
4
+ static VALUE dvf_alloc(VALUE klass)
5
+ {
6
+ VALUE self;
7
+ RS_DVectorFloat *dvf;
8
+
9
+ self = Data_Make_Struct(klass, RS_DVectorFloat, 0, -1, dvf);
10
+
11
+ dvf->len = 0;
12
+ dvf->capa = 0;
13
+ dvf->ptr = 0;
14
+
15
+ return self;
16
+ }
17
+
18
+ void rs_dvf_grow(RS_DVectorFloat *dvf)
19
+ {
20
+ if (!dvf->ptr) {
21
+ dvf->capa = 16;
22
+ dvf->ptr = ALLOC_N(float, dvf->capa);
23
+ }
24
+ else if (dvf->len == dvf->capa) {
25
+ dvf->capa *= 2;
26
+ REALLOC_N(dvf->ptr, float, dvf->capa);
27
+ }
28
+ }
29
+
30
+ void rs_dvf_shrink(RS_DVectorFloat *dvf)
31
+ {
32
+ if (dvf->ptr && dvf->len < dvf->capa) {
33
+ REALLOC_N(dvf->ptr, float, dvf->len);
34
+ dvf->capa = dvf->len;
35
+ }
36
+ }
37
+
38
+ static VALUE dvf_method_push(int argc, VALUE *argv, VALUE self)
39
+ {
40
+ int i;
41
+ RS_DVectorFloat *dvf;
42
+
43
+ Data_Get_Struct(self, RS_DVectorFloat, dvf);
44
+
45
+ for (i = 0; i < argc; i++) {
46
+ rs_dvf_push(dvf, NUM2DBL(argv[i]));
47
+ }
48
+
49
+ return self;
50
+ }
51
+
52
+ static VALUE dvf_method_pop(VALUE self)
53
+ {
54
+ RS_DVectorFloat *dvf;
55
+
56
+ Data_Get_Struct(self, RS_DVectorFloat, dvf);
57
+
58
+ return dvf->len == 0 ? Qnil : rb_float_new(rs_dvf_pop(dvf));
59
+ }
60
+
61
+ static VALUE dvf_method_each(VALUE self)
62
+ {
63
+ long i;
64
+ RS_DVectorFloat *dvf;
65
+
66
+ Data_Get_Struct(self, RS_DVectorFloat, dvf);
67
+
68
+ RETURN_ENUMERATOR(self, 0, 0);
69
+ for (i=0; i < dvf->len; i++) {
70
+ rb_yield(rb_float_new(dvf->ptr[i]));
71
+ }
72
+
73
+ return self;
74
+ }
75
+
76
+ static VALUE dvf_method_to_a(VALUE self)
77
+ {
78
+ int i;
79
+ RS_DVectorFloat *dvf;
80
+ VALUE ary;
81
+
82
+ Data_Get_Struct(self, RS_DVectorFloat, dvf);
83
+
84
+ ary = rb_ary_new();
85
+ if (!dvf->ptr) return ary;
86
+
87
+ for (i=0; i < dvf->len; i++) {
88
+ rb_ary_push(ary, rb_float_new(dvf->ptr[i]));
89
+ }
90
+
91
+ return ary;
92
+ }
93
+
94
+ static VALUE dvf_method_length(VALUE self)
95
+ {
96
+ RS_DVectorFloat *dvf;
97
+ Data_Get_Struct(self, RS_DVectorFloat, dvf);
98
+ return INT2NUM(dvf->len);
99
+ }
100
+
101
+ static VALUE dvf_method_equal(VALUE self, VALUE other)
102
+ {
103
+ int i;
104
+ RS_DVectorFloat *dvf1, *dvf2;
105
+
106
+ if (self == other) return Qtrue;
107
+ if (CLASS_OF(self) != CLASS_OF(other)) return Qfalse;
108
+
109
+ Data_Get_Struct(self, RS_DVectorFloat, dvf1);
110
+ Data_Get_Struct(other, RS_DVectorFloat, dvf2);
111
+ if (dvf1->len != dvf2->len) return Qfalse;
112
+
113
+ for (i=0; i < dvf1->len; i++) {
114
+ if (dvf1->ptr[i] != dvf2->ptr[i]) return Qfalse;
115
+ }
116
+ return Qtrue;
117
+ }
118
+
119
+ static VALUE dvf_method_hash(VALUE self)
120
+ {
121
+ long i, h;
122
+ RS_DVectorFloat *dvf;
123
+
124
+ Data_Get_Struct(self, RS_DVectorFloat, dvf);
125
+
126
+ h = dvf->len;
127
+ for (i=0; i < dvf->len; i++) {
128
+ int hash, j;
129
+ char *c;
130
+ float f;
131
+
132
+ h = (h << 1) | (h<0 ? 1 : 0);
133
+ f = dvf->ptr[i];
134
+
135
+ if (f == 0) f = fabs(f);
136
+ c = (char*)&f;
137
+ for (hash=0, j=0; j<sizeof(float); j++) {
138
+ hash = (hash * 971) ^ (unsigned char)c[j];
139
+ }
140
+ if (hash < 0) hash = -hash;
141
+
142
+ h ^= hash;
143
+ }
144
+ return LONG2FIX(h);
145
+ }
146
+
147
+ static VALUE dvf_method_load_data(VALUE self, VALUE from_array)
148
+ {
149
+ long i;
150
+ RS_DVectorFloat *dvf;
151
+ Data_Get_Struct(self, RS_DVectorFloat, dvf);
152
+
153
+ for (i=0; i < RARRAY_LEN(from_array); i++) {
154
+ rs_dvf_push(dvf, NUM2DBL(RARRAY_PTR(from_array)[i]));
155
+ }
156
+
157
+ return self;
158
+ }
159
+
160
+ VALUE rs_cDVectorFloat;
161
+
162
+ void
163
+ Init_dvector_float(void)
164
+ {
165
+ rs_cDVectorFloat = rb_path2class("RedShift::DVectorFloat");
166
+
167
+ rb_define_alloc_func(rs_cDVectorFloat, dvf_alloc);
168
+ rb_define_method(rs_cDVectorFloat, "push", dvf_method_push, -1);
169
+ rb_define_method(rs_cDVectorFloat, "pop", dvf_method_pop, 0);
170
+ rb_define_alias(rs_cDVectorFloat, "<<", "push");
171
+
172
+ rb_define_method(rs_cDVectorFloat, "each", dvf_method_each, 0);
173
+ rb_define_method(rs_cDVectorFloat, "to_a", dvf_method_to_a, 0);
174
+ rb_define_method(rs_cDVectorFloat, "length", dvf_method_length, 0);
175
+ rb_define_alias(rs_cDVectorFloat, "size", "length");
176
+
177
+ rb_define_method(rs_cDVectorFloat, "==", dvf_method_equal, 1);
178
+ rb_define_method(rs_cDVectorFloat, "eql?", dvf_method_equal, 1);
179
+ rb_define_method(rs_cDVectorFloat, "hash", dvf_method_hash, 0);
180
+
181
+ rb_define_method(rs_cDVectorFloat, "_load_data", dvf_method_load_data, 1);
182
+ rb_define_method(rs_cDVectorFloat, "_dump_data", dvf_method_to_a, 0);
183
+ }
@@ -0,0 +1,36 @@
1
+ #ifndef dvector_float_h
2
+ #define dvector_float_h
3
+
4
+ #include <ruby.h>
5
+
6
+ typedef struct {
7
+ long len;
8
+ long capa;
9
+ float *ptr;
10
+ } RS_DVectorFloat;
11
+
12
+ extern void rs_dvf_grow(RS_DVectorFloat *dvf);
13
+ extern void rs_dvf_shrink(RS_DVectorFloat *dvf);
14
+
15
+ inline static RS_DVectorFloat *rs_dvf(VALUE obj)
16
+ {
17
+ return (RS_DVectorFloat *)DATA_PTR(obj);
18
+ }
19
+
20
+ inline static void rs_dvf_push(RS_DVectorFloat *dvf, float val)
21
+ {
22
+ if (dvf->len == dvf->capa) {
23
+ rs_dvf_grow(dvf);
24
+ }
25
+ dvf->ptr[dvf->len++] = val;
26
+ }
27
+
28
+ inline static float rs_dvf_pop(RS_DVectorFloat *dvf)
29
+ {
30
+ if (dvf->len == 0) {
31
+ return 0;
32
+ }
33
+ return dvf->ptr[--dvf->len];
34
+ }
35
+
36
+ #endif
@@ -0,0 +1,33 @@
1
+ module RedShift; end
2
+
3
+ # A linear collection of single-precision floats.
4
+ #
5
+ # Intended primarily for access from C code, using the inline
6
+ # rs_dvf_push() and rs_dvf_pop() functions.
7
+ #
8
+ # Implements some of the same methods as Array, but not all.
9
+ #
10
+ # Like an Array, a DVector grows implicitly as elements are
11
+ # pushed. But unlike an Array, a DVector shrinks only explicitly.
12
+ # This is to minimize realloc() calls when a DVector rapidly
13
+ # grows and shrinks.
14
+
15
+ class RedShift::DVectorFloat
16
+ include Enumerable
17
+ require 'redshift/dvector-float/dvector_float.so'
18
+
19
+ def self.[](*elts)
20
+ new elts
21
+ end
22
+
23
+ def initialize(elts=nil)
24
+ push(*elts) if elts
25
+ end
26
+
27
+ def inspect; to_a.inspect; end
28
+ def to_s; to_a.to_s; end
29
+
30
+ def dup
31
+ self.class.new to_a
32
+ end
33
+ end
@@ -0,0 +1,2 @@
1
+ require 'mkmf'
2
+ create_makefile 'dvector_float'
@@ -70,7 +70,7 @@ end
70
70
  module RedShift
71
71
  include Math
72
72
 
73
- VERSION = '1.3.24'
73
+ VERSION = '1.3.25'
74
74
 
75
75
  Infinity = Math::Infinity
76
76
 
@@ -1294,7 +1294,8 @@ class World
1294
1294
 
1295
1295
  hook = /\bhook_\w+/
1296
1296
  world_classes = World.subclasses + [World]
1297
- hooks = Hash.new {|h,cl| h[cl] = cl.instance_methods(true).grep(hook).sort}
1297
+ hooks = Hash.new {|h,cl| h[cl] =
1298
+ cl.instance_methods(true).grep(hook).sort.map{|s|s.to_sym} }
1298
1299
  hooks[World.superclass] = nil
1299
1300
  known_hooks = nil
1300
1301
 
@@ -37,7 +37,7 @@ tests.sort!
37
37
  #end
38
38
 
39
39
  require 'rbconfig'
40
- ruby = Config::CONFIG["RUBY_INSTALL_NAME"]
40
+ ruby = RbConfig::CONFIG["RUBY_INSTALL_NAME"]
41
41
 
42
42
  pending = tests.dup
43
43
  failed = []
@@ -0,0 +1,113 @@
1
+ require 'redshift/dvector-float/dvector-float'
2
+ require 'test/unit'
3
+
4
+ DVectorFloat = RedShift::DVectorFloat
5
+
6
+ class TestDVectorFloat < Test::Unit::TestCase
7
+ def make_dvs n
8
+ assert_nothing_thrown do
9
+ n.times do
10
+ DVectorFloat.new
11
+ end
12
+ end
13
+ end
14
+
15
+ def test_gc
16
+ GC.start
17
+ n = ObjectSpace.each_object(DVectorFloat){}
18
+
19
+ assert_nothing_thrown do
20
+ make_dvs 100
21
+ end
22
+
23
+ GC.start
24
+ n2 = ObjectSpace.each_object(DVectorFloat){}
25
+
26
+ assert((0..n+1) === n2, "Not in #{0}..#{n+1}: #{n2}")
27
+ end
28
+
29
+ def test_gc_stress
30
+ GC.stress = true
31
+ assert_nothing_thrown do
32
+ make_dvs 10
33
+ end
34
+ ensure
35
+ GC.stress = false
36
+ end
37
+
38
+ def test_push_pop
39
+ dv = DVectorFloat.new
40
+ assert_nothing_thrown do
41
+ dv.push(1)
42
+ dv.push(2.567)
43
+ dv.push(3)
44
+ end
45
+ assert_equal(3, dv.pop)
46
+ assert_in_delta(2.567, dv.pop, 0.01)
47
+ assert_equal(1, dv.pop)
48
+ assert_equal(nil, dv.pop)
49
+ end
50
+
51
+ def test_each
52
+ dv = DVectorFloat[1, 2.567, 3]
53
+ a = []
54
+ dv.each do |x|
55
+ a << x
56
+ end
57
+ [1,2.567,3].zip a do |x,y|
58
+ assert_in_delta(x, y, 0.01)
59
+ end
60
+ end
61
+
62
+ def test_to_a
63
+ dv = DVectorFloat[1, 2.567, 3]
64
+ [1,2.567,3].zip dv.to_a do |x,y|
65
+ assert_in_delta(x, y, 0.01)
66
+ end
67
+ end
68
+
69
+ def test_length
70
+ dv = DVectorFloat[1, 2.567, 3]
71
+ assert_equal(3, dv.length)
72
+ dv = DVectorFloat.new
73
+ assert_equal(0, dv.length)
74
+ end
75
+
76
+ def test_equal
77
+ dv1 = DVectorFloat[1, 2.567, 3]
78
+ dv2 = DVectorFloat[1, 2.567, 3, 4]
79
+ assert_equal(false, dv1 == dv2)
80
+ assert_equal(false, dv1 == [1,2.567,3])
81
+ assert_equal(false, dv1 == 123)
82
+ assert_equal(true, dv1 == dv1)
83
+ assert_equal(true, DVectorFloat.new == DVectorFloat.new)
84
+ assert_equal(true, DVectorFloat[1] == DVectorFloat[1.0])
85
+ end
86
+
87
+ def test_eql
88
+ dv1 = DVectorFloat[1, 2.567, 3]
89
+ dv2 = DVectorFloat[1, 2.567, 3, 4]
90
+ assert_equal(false, dv1.eql?(dv2))
91
+ assert_equal(false, dv1.eql?([1,2.567,3]))
92
+ assert_equal(false, dv1.eql?(123))
93
+ assert_equal(true, dv1.eql?(dv1))
94
+ assert_equal(true, DVectorFloat.new.eql?(DVectorFloat.new))
95
+ end
96
+
97
+ def test_hash
98
+ h = {}
99
+ h[DVectorFloat[1,2.567,3]] = true
100
+ assert_equal(true, h[DVectorFloat[1,2.567,3]])
101
+ assert_equal(nil, h[DVectorFloat[1,2.567,3,4]])
102
+ end
103
+
104
+ def test_dup
105
+ DVectorFloat[1,2.567,3] == DVectorFloat[1,2.567,3].dup
106
+ end
107
+
108
+ def test_marshal
109
+ dv = DVectorFloat[1, 2.567, 3]
110
+ dv2 = Marshal.load(Marshal.dump(dv))
111
+ assert_equal(dv.to_a, dv2.to_a)
112
+ end
113
+ end