statsample-optimization 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -2,6 +2,6 @@ History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
- ext/statsample/extconf.rb
6
- ext/statsample/optimization.c
5
+ ext/extconf.rb
6
+ ext/statsamplert.c
7
7
  test/test_statsample_optimization.rb
data/Rakefile CHANGED
@@ -4,19 +4,19 @@
4
4
  require 'rubygems'
5
5
  require 'hoe'
6
6
 
7
- EXT = "ext/statsample/optimization.#{Config::CONFIG['DLEXT']}"
7
+ EXT = "ext/statsamplert.#{Config::CONFIG['DLEXT']}"
8
8
 
9
9
  task :test => [EXT]
10
10
 
11
- file "ext/statsample/Makefile" => ["ext/statsample/extconf.rb"] do |t|
12
- Dir.chdir "ext/statsample" do
11
+ file "ext/Makefile" => ["ext/extconf.rb"] do |t|
12
+ Dir.chdir "ext/" do
13
13
  system %(ruby extconf.rb)
14
14
  end
15
15
 
16
16
  end
17
- file EXT => ["ext/statsample/Makefile", "ext/statsample/optimization.c"] do
17
+ file EXT => ["ext/Makefile", "ext/statsamplert.c"] do
18
18
  puts "Compiling"
19
- Dir.chdir "ext/statsample" do
19
+ Dir.chdir "ext" do
20
20
  system %(make)
21
21
  end
22
22
  end
@@ -24,13 +24,13 @@ end
24
24
 
25
25
 
26
26
  Hoe.spec 'statsample-optimization' do |p|
27
- p.version="1.0.0"
27
+ p.version="2.0.0"
28
28
  p.rubyforge_name = 'ruby-statsample'
29
29
  p.developer('Claudio Bustos', 'clbustos_at_gmail.com')
30
- p.spec_extras[:extensions] = ["ext/statsample/extconf.rb"]
31
- p.extra_deps << "statsample"
30
+ p.spec_extras[:extensions] = ["ext/extconf.rb"]
31
+ p.extra_deps << ["statsample","=0.3.4"]
32
32
  p.clean_globs << EXT
33
- p.clean_globs << EXT << "ext/statsample/*.o" << "ext/statsample/*.so" << "ext/statsample/Makefile"
33
+ p.clean_globs << EXT << "ext/*.o" << "ext/*.so" << "ext/Makefile"
34
34
  end
35
35
 
36
36
  # vim: syntax=ruby
@@ -1,3 +1,3 @@
1
1
  require "mkmf"
2
2
  $CFLAGS+=" -Wall "
3
- create_makefile("optimization")
3
+ create_makefile("statsamplert")
@@ -2,29 +2,40 @@
2
2
  /**
3
3
  * :stopdoc:
4
4
  */
5
- void Init_optimization();
6
- VALUE nominal_frequencies(VALUE self);
7
- VALUE rubyss_frequencies(VALUE self, VALUE data);
8
- VALUE rubyss_set_valid_data(VALUE self, VALUE vector);
9
- VALUE dataset_case_as_hash(VALUE self, VALUE index);
10
- VALUE dataset_case_as_array(VALUE self, VALUE index);
11
- void Init_optimization()
5
+ void Init_statsamplert();
6
+ VALUE statsample_frequencies(VALUE self, VALUE data);
7
+ VALUE statsample_set_valid_data_intern(VALUE self, VALUE vector);
8
+ VALUE statsample_case_as_hash(VALUE self, VALUE ds, VALUE index);
9
+ VALUE statsample_case_as_array(VALUE self, VALUE ds, VALUE index);
10
+ void Init_statsamplert()
12
11
  {
13
- VALUE mRubySS = rb_define_module("Statsample");
12
+ VALUE mStatsample;
13
+ VALUE mSTATSAMPLE__;
14
+ ID id_statsample;
15
+ ID id_STATSAMPLE__;
16
+ id_statsample = rb_intern("Statsample");
17
+ id_STATSAMPLE__ = rb_intern("STATSAMPLE__");
14
18
 
15
- VALUE cNominal = rb_define_class_under(mRubySS,"Nominal",rb_cObject);
16
- VALUE cDataset = rb_define_class_under(mRubySS,"Dataset",rb_cObject);
17
-
18
- rb_define_const(mRubySS,"OPTIMIZED",Qtrue);
19
- rb_define_module_function(mRubySS,"_frequencies",rubyss_frequencies,1);
20
- rb_define_module_function(mRubySS,"_set_valid_data",rubyss_set_valid_data,1);
21
- rb_define_method(cNominal,"frequencies",nominal_frequencies,0);
22
- rb_define_method(cDataset,"case_as_hash",dataset_case_as_hash,1);
23
- rb_define_method(cDataset,"case_as_array",dataset_case_as_array,1);
19
+ if(rb_const_defined(rb_cObject, id_statsample)) {
20
+ mStatsample = rb_const_get(rb_cObject, id_statsample);
21
+ } else {
22
+ mStatsample = rb_define_module("Statsample");
23
+ }
24
+ if(rb_const_defined(mStatsample, id_STATSAMPLE__)) {
25
+ mSTATSAMPLE__ = rb_const_get(mStatsample, id_STATSAMPLE__);
26
+ } else {
27
+ mSTATSAMPLE__ = rb_define_module_under(mStatsample, "STATSAMPLE__");
28
+ }
29
+
30
+ rb_define_const(mStatsample, "OPTIMIZED",Qtrue);
31
+ rb_define_module_function(mSTATSAMPLE__,"frequencies",statsample_frequencies,1);
32
+ rb_define_module_function(mSTATSAMPLE__,"set_valid_data_intern", statsample_set_valid_data_intern, 1);
33
+ rb_define_module_function(mSTATSAMPLE__,"case_as_hash",statsample_case_as_hash,2);
34
+ rb_define_module_function(mSTATSAMPLE__,"case_as_array",statsample_case_as_array,2);
24
35
 
25
36
  }
26
37
 
27
- VALUE rubyss_set_valid_data(VALUE self, VALUE vector) {
38
+ VALUE statsample_set_valid_data_intern(VALUE self, VALUE vector) {
28
39
  /** Emulate
29
40
 
30
41
  @data.each do |n|
@@ -60,7 +71,11 @@ VALUE rubyss_set_valid_data(VALUE self, VALUE vector) {
60
71
  rb_iv_set(vector,"@has_missing_data",(RARRAY_LEN(missing_data)>0) ? Qtrue : Qfalse);
61
72
  return Qnil;
62
73
  }
63
- VALUE rubyss_frequencies(VALUE self, VALUE data) {
74
+ /**
75
+ * Retuns frequencies for an array as a hash, with
76
+ * keys as items and values as number of items
77
+ */
78
+ VALUE statsample_frequencies(VALUE self, VALUE data) {
64
79
  VALUE h;
65
80
  VALUE val;
66
81
  long len;
@@ -82,14 +97,10 @@ VALUE rubyss_frequencies(VALUE self, VALUE data) {
82
97
  return h;
83
98
  }
84
99
 
85
- VALUE nominal_frequencies(VALUE self) {
86
- VALUE data=rb_iv_get(self,"@data");
87
- return rubyss_frequencies(self,data);
88
- }
89
- VALUE dataset_case_as_hash(VALUE self, VALUE index) {
100
+ VALUE statsample_case_as_hash(VALUE self, VALUE ds,VALUE index) {
90
101
  VALUE vector,data,key;
91
- VALUE fields=rb_iv_get(self,"@fields");
92
- VALUE vectors=rb_iv_get(self,"@vectors");
102
+ VALUE fields=rb_iv_get(ds,"@fields");
103
+ VALUE vectors=rb_iv_get(ds,"@vectors");
93
104
  VALUE h=rb_hash_new();
94
105
  long len=RARRAY_LEN(fields);
95
106
  long i;
@@ -101,10 +112,10 @@ VALUE dataset_case_as_hash(VALUE self, VALUE index) {
101
112
  }
102
113
  return h;
103
114
  }
104
- VALUE dataset_case_as_array(VALUE self, VALUE index) {
115
+ VALUE statsample_case_as_array(VALUE self, VALUE ds, VALUE index) {
105
116
  VALUE vector,data,key;
106
- VALUE fields=rb_iv_get(self,"@fields");
107
- VALUE vectors=rb_iv_get(self,"@vectors");
117
+ VALUE fields=rb_iv_get(ds,"@fields");
118
+ VALUE vectors=rb_iv_get(ds,"@vectors");
108
119
  VALUE ar=rb_ary_new();
109
120
  long len=RARRAY_LEN(fields);
110
121
  long i;
@@ -1,16 +1,43 @@
1
1
  $:.unshift(File.dirname(__FILE__)+"/ext")
2
2
  require "test/unit"
3
3
  require "statsample"
4
- require "statsample/optimization"
4
+ require "statsamplert"
5
5
 
6
6
  class TestRubyStatsampleOpt < Test::Unit::TestCase
7
7
  def test_base
8
8
  assert(Statsample::OPTIMIZED,true)
9
9
  end
10
10
  def test_frequencies
11
- assert(Statsample.respond_to?(:_frequencies))
11
+ assert(Statsample::STATSAMPLE__.respond_to?(:frequencies))
12
12
  v=[1,1,2].to_vector
13
13
  exp={1=>2,2=>1}
14
- assert_equal(exp,Statsample._frequencies(v.data))
14
+ assert_equal(exp,Statsample::STATSAMPLE__.frequencies(v.data))
15
+ assert_equal(v._frequencies, v.frequencies)
15
16
  end
17
+ def test_set_valid_data
18
+ assert(Statsample::STATSAMPLE__.respond_to?(:set_valid_data_intern))
19
+ v=[2,3,4].to_vector
20
+ v.add(5)
21
+ assert_equal([2,3,4,5], v.valid_data)
22
+ v.add(nil,false)
23
+ assert_equal([2,3,4,5], v.valid_data)
24
+ assert_equal([2,3,4,5,nil], v.data)
25
+ end
26
+ def test_case_as_array
27
+ assert(Statsample::STATSAMPLE__.respond_to?(:case_as_array))
28
+ a=[1,2,3].to_vector(:scale)
29
+ b=[4,5,6].to_vector(:scale)
30
+ ds={"a"=>a,"b"=>b}.to_dataset
31
+ assert_equal([1,4],Statsample::STATSAMPLE__.case_as_array(ds,0))
32
+ assert_equal([2,5],Statsample::STATSAMPLE__.case_as_array(ds,1))
33
+ assert_equal([3,6],Statsample::STATSAMPLE__.case_as_array(ds,2))
34
+ end
35
+ def test_case_as_hash
36
+ assert(Statsample::STATSAMPLE__.respond_to?(:case_as_hash))
37
+ a=[1,2,3].to_vector(:scale)
38
+ b=[4,5,6].to_vector(:scale)
39
+ ds={"a"=>a,"b"=>b}.to_dataset
40
+ assert_equal({"a"=>1,"b"=>4},Statsample::STATSAMPLE__.case_as_hash(ds,0))
41
+ end
42
+
16
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statsample-optimization
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Bustos
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-03 00:00:00 -04:00
12
+ date: 2009-08-21 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -18,9 +18,9 @@ dependencies:
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - ">="
21
+ - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: "0"
23
+ version: 0.3.4
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.3.2
33
+ version: 2.3.3
34
34
  version:
35
35
  description: |-
36
36
  Extension for statsample, that speed some methods.
@@ -45,7 +45,7 @@ email:
45
45
  executables: []
46
46
 
47
47
  extensions:
48
- - ext/statsample/extconf.rb
48
+ - ext/extconf.rb
49
49
  extra_rdoc_files:
50
50
  - History.txt
51
51
  - Manifest.txt
@@ -55,8 +55,8 @@ files:
55
55
  - Manifest.txt
56
56
  - README.txt
57
57
  - Rakefile
58
- - ext/statsample/extconf.rb
59
- - ext/statsample/optimization.c
58
+ - ext/extconf.rb
59
+ - ext/statsamplert.c
60
60
  - test/test_statsample_optimization.rb
61
61
  has_rdoc: true
62
62
  homepage: http://rubyforge.org/projects/ruby-statsample/