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 +4 -4
- data/.gitignore +3 -3
- data/.travis.yml +7 -0
- data/README.md +5 -2
- data/ext/dispersion/dispersion.c +26 -0
- data/ext/dispersion/dispersion.h +2 -0
- data/lib/ruby_native_statistics/version.rb +1 -1
- metadata +3 -3
- data/Gemfile.lock +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d28a071262364616d7c795523cdb92d3599a4a8
|
4
|
+
data.tar.gz: ff6bbc9fd223643270f11306e500cb30c70722d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
32
|
-
|
33
|
-
|
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
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
|
-
|
15
|
-
|
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
|
|
data/ext/dispersion/dispersion.c
CHANGED
@@ -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
|
+
}
|
data/ext/dispersion/dispersion.h
CHANGED
@@ -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);
|
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.
|
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-
|
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
|