standard_deviation 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,27 +1,27 @@
1
1
  #include <ruby.h>
2
2
  #include <math.h>
3
3
 
4
- static double sum(double array[], long size) {
5
- int i;
6
- double total = 0;
7
-
8
- for (i = 0; i < size; i++) {
9
- total += array[i];
10
- }
11
-
12
- return total;
13
- }
14
-
15
4
  static double distance_from_mean(VALUE *array, long size) {
16
5
  int i;
17
- double mean, distance;
6
+ double mean, distance, total;
18
7
  double values[size];
19
8
 
20
- for (i = 0; i < size; i++) {
21
- values[i] = NUM2DBL(array[i]);
9
+ for (i = 0, total = 0; i < size; i++) {
10
+ double value;
11
+
12
+ switch (TYPE(array[i])) {
13
+ case T_FIXNUM:
14
+ value = FIX2LONG(array[i]);
15
+ default:
16
+ value = NUM2DBL(array[i]);
17
+ break;
18
+ }
19
+
20
+ values[i] = value;
21
+ total += value;
22
22
  }
23
23
 
24
- mean = sum(values, size) / size;
24
+ mean = total / size;
25
25
 
26
26
  for (i = 0, distance = 0; i < size; i++) {
27
27
  distance += pow(values[i] - mean, 2);
@@ -79,11 +79,15 @@ static VALUE stdevp(VALUE self) {
79
79
  }
80
80
 
81
81
  void Init_standard_deviation() {
82
- rb_define_method(rb_cArray, "stdev", stdev, 0);
83
- rb_define_alias(rb_cArray, "standard_deviation", "stdev");
84
- rb_define_method(rb_cArray, "stdevp", stdevp, 0);
82
+ VALUE mStandardDeviation = rb_define_module("StandardDeviation");
83
+
84
+ rb_define_method(mStandardDeviation, "stdev", stdev, 0);
85
+ rb_define_alias(mStandardDeviation, "standard_deviation", "stdev");
86
+ rb_define_method(mStandardDeviation, "stdevp", stdevp, 0);
87
+
88
+ rb_define_method(mStandardDeviation, "sample_variance", sample_variance, 0);
89
+ rb_define_alias(mStandardDeviation, "variance", "sample_variance");
90
+ rb_define_method(mStandardDeviation, "population_variance", population_variance, 0);
85
91
 
86
- rb_define_method(rb_cArray, "sample_variance", sample_variance, 0);
87
- rb_define_alias(rb_cArray, "variance", "sample_variance");
88
- rb_define_method(rb_cArray, "population_variance", population_variance, 0);
92
+ rb_include_module(rb_cArray, mStandardDeviation);
89
93
  }
@@ -1,5 +1,2 @@
1
1
  require "standard_deviation/version"
2
2
  require "standard_deviation/standard_deviation"
3
-
4
- module StandardDeviation
5
- end
@@ -1,3 +1,3 @@
1
1
  module StandardDeviation
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_deviation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-17 00:00:00.000000000Z
12
+ date: 2012-04-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler
16
- requirement: &2153819300 !ruby/object:Gem::Requirement
16
+ requirement: &2156775860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2153819300
24
+ version_requirements: *2156775860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2153818820 !ruby/object:Gem::Requirement
27
+ requirement: &2156775260 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2153818820
35
+ version_requirements: *2156775260
36
36
  description: ! "An implementation of the standard deviation calculation in C,\n with
37
37
  much better performance (50x-100x) than using pure ruby."
38
38
  email:
@@ -73,7 +73,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  segments:
75
75
  - 0
76
- hash: -1911497483402748616
76
+ hash: 3904352237865759400
77
77
  required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  none: false
79
79
  requirements:
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  version: '0'
83
83
  segments:
84
84
  - 0
85
- hash: -1911497483402748616
85
+ hash: 3904352237865759400
86
86
  requirements: []
87
87
  rubyforge_project:
88
88
  rubygems_version: 1.8.10