ruby_native_statistics 0.7.0 → 0.7.1

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
  SHA1:
3
- metadata.gz: a01f2968f24b3e0c105a78755534c3e3ae2ff956
4
- data.tar.gz: 0c4d49a30ef69306dbe2e7509d4d8b33fd9a0e21
3
+ metadata.gz: 7d28a071262364616d7c795523cdb92d3599a4a8
4
+ data.tar.gz: ff6bbc9fd223643270f11306e500cb30c70722d8
5
5
  SHA512:
6
- metadata.gz: 0a3c5b5fc5a81ec0d70d869bef3c9b25d8bf57c6270bc93e8af11748f5f003eddc73cb2b1cd84097427578afb4c13fca1772c077005682e4e5b23b9c0f8bd08a
7
- data.tar.gz: b6353a7646c37a0a7db2294fbd146f595de88cad078da381e3c17a6fbbc4371ff1145f96ce3bc88335fb9968cc55356d438e6091607da79b93facc338599e41b
6
+ metadata.gz: 681db7264f890633e2b60534f3c555cbc2672597734c070d313bd04d266b086fa79b1871cbcc170754820b15b785ba4dfeafe8ccf809dfe9e158fd28bc245656
7
+ data.tar.gz: d6a4a73bb61fce93344efb29f14adae989404b3e6287e8df4f3b15aee42d2eba30da19be791ce1cc3678d490f4163b141b88aaf8c0a68cfe98d7ddd9aab16f32
data/.gitignore CHANGED
@@ -28,9 +28,9 @@ build/
28
28
 
29
29
  # for a library or gem, you might want to ignore these files since the code is
30
30
  # intended to run in multiple environments; otherwise, check them in:
31
- # Gemfile.lock
32
- # .ruby-version
33
- # .ruby-gemset
31
+ Gemfile.lock
32
+ .ruby-version
33
+ .ruby-gemset
34
34
 
35
35
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
36
  .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ - 2.2.5
5
+ - 2.1.9
6
+ before_install:
7
+ - gem install bundler
data/README.md CHANGED
@@ -6,13 +6,16 @@ This is a native extension to Ruby that adds native (C) statistical functions to
6
6
 
7
7
  * [Sample Standard Deviation](https://en.wikipedia.org/wiki/Standard_deviation#Corrected_sample_standard_deviation) (stdev, stdevs)
8
8
  * [Population Standard Deviation](https://en.wikipedia.org/wiki/Standard_deviation#Uncorrected_sample_standard_deviation) (stdevp)
9
+ * [Sample Variance](https://en.wikipedia.org/wiki/Variance#Population_variance_and_sample_variance) (var)
10
+ * [Population Variance](https://en.wikipedia.org/wiki/Variance#Population_variance_and_sample_variance) (varp)
11
+
9
12
 
10
13
  Check the TravisCI build to see the currently supported versions of Ruby. This list will match whatever versions are specified at https://www.ruby-lang.org/en/downloads/.
11
14
 
12
15
  It is much more performant than calculating the standard deviation with pure Ruby. For a comparison, run the benchmarks with rake.
13
16
 
14
- bench_native_extension 0.000573 0.000507 0.000616 0.000606 0.000528
15
- bench_pure_ruby 0.004794 0.004045 0.002673 0.002667 0.003728
17
+ bench_native_dispersion 0.000686 0.000628 0.000595 0.000475 0.000590
18
+ bench_ruby_dispersion 0.002630 0.004559 0.002589 0.002909 0.002812
16
19
 
17
20
  ## Usage
18
21
 
@@ -6,6 +6,8 @@ void Init_dispersion() {
6
6
  rb_define_method(DispersionModule, "stdev", rb_sample_standard_deviation, 0);
7
7
  rb_define_method(DispersionModule, "stdevs", rb_sample_standard_deviation, 0);
8
8
  rb_define_method(DispersionModule, "stdevp", rb_population_standard_deviation, 0);
9
+ rb_define_method(DispersionModule, "var", rb_sample_variance, 0);
10
+ rb_define_method(DispersionModule, "varp", rb_population_variance, 0);
9
11
  }
10
12
 
11
13
  double calculate_total_distance_from_mean(VALUE array, unsigned long array_length){
@@ -39,6 +41,18 @@ VALUE rb_sample_standard_deviation(VALUE self) {
39
41
  return DBL2NUM(sqrt((calculate_total_distance_from_mean(self, array_length)/(array_length - 1))));
40
42
  }
41
43
 
44
+ VALUE rb_sample_variance(VALUE self) {
45
+ Check_Type(self, T_ARRAY);
46
+
47
+ unsigned int array_length = rb_long2int(RARRAY_LEN(self));
48
+
49
+ if (array_length <= 1) {
50
+ rb_raise(rb_eRangeError, "array must have more than one element");
51
+ }
52
+
53
+ return DBL2NUM((calculate_total_distance_from_mean(self, array_length)/(array_length - 1)));
54
+ }
55
+
42
56
  VALUE rb_population_standard_deviation(VALUE self) {
43
57
  Check_Type(self, T_ARRAY);
44
58
 
@@ -50,3 +64,15 @@ VALUE rb_population_standard_deviation(VALUE self) {
50
64
 
51
65
  return DBL2NUM(sqrt(calculate_total_distance_from_mean(self, array_length) / array_length));
52
66
  }
67
+
68
+ VALUE rb_population_variance(VALUE self) {
69
+ Check_Type(self, T_ARRAY);
70
+
71
+ unsigned int array_length = rb_long2int(RARRAY_LEN(self));
72
+
73
+ if (array_length <= 1) {
74
+ rb_raise(rb_eRangeError, "array must have more than one element");
75
+ }
76
+
77
+ return DBL2NUM(calculate_total_distance_from_mean(self, array_length) / array_length);
78
+ }
@@ -1,4 +1,6 @@
1
1
  VALUE DispersionModule = Qnil;
2
2
  VALUE rb_sample_standard_deviation(VALUE self);
3
3
  VALUE rb_population_standard_deviation(VALUE self);
4
+ VALUE rb_sample_variance(VALUE self);
5
+ VALUE rb_population_variance(VALUE self);
4
6
  double calculate_total_distance_from_mean(VALUE array, unsigned long array_length);
@@ -1,3 +1,3 @@
1
1
  module RubyNativeStatistics
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_native_statistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cory Buecker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-15 00:00:00.000000000 Z
11
+ date: 2016-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,8 +75,8 @@ extensions:
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
+ - ".travis.yml"
78
79
  - Gemfile
79
- - Gemfile.lock
80
80
  - LICENSE
81
81
  - README.md
82
82
  - Rakefile
data/Gemfile.lock DELETED
@@ -1,25 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- ruby_native_statistics (0.7.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- minitest (5.8.4)
10
- rake (11.1.2)
11
- rake-compiler (0.9.9)
12
- rake
13
-
14
- PLATFORMS
15
- ruby
16
-
17
- DEPENDENCIES
18
- bundler (~> 1.11)
19
- minitest (~> 5.0)
20
- rake (~> 11.0)
21
- rake-compiler (~> 0.9)
22
- ruby_native_statistics!
23
-
24
- BUNDLED WITH
25
- 1.11.2