ruby_native_statistics 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +37 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +25 -0
- data/LICENSE +24 -0
- data/README.md +35 -0
- data/Rakefile +13 -0
- data/ext/dispersion/dispersion.c +52 -0
- data/ext/dispersion/dispersion.h +4 -0
- data/ext/dispersion/extconf.rb +2 -0
- data/lib/ruby_native_statistics.rb +6 -0
- data/lib/ruby_native_statistics/version.rb +3 -0
- data/ruby_native_statistics.gemspec +26 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a01f2968f24b3e0c105a78755534c3e3ae2ff956
|
4
|
+
data.tar.gz: 0c4d49a30ef69306dbe2e7509d4d8b33fd9a0e21
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0a3c5b5fc5a81ec0d70d869bef3c9b25d8bf57c6270bc93e8af11748f5f003eddc73cb2b1cd84097427578afb4c13fca1772c077005682e4e5b23b9c0f8bd08a
|
7
|
+
data.tar.gz: b6353a7646c37a0a7db2294fbd146f595de88cad078da381e3c17a6fbbc4371ff1145f96ce3bc88335fb9968cc55356d438e6091607da79b93facc338599e41b
|
data/.gitignore
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
|
18
|
+
## Documentation cache and generated files:
|
19
|
+
/.yardoc/
|
20
|
+
/_yardoc/
|
21
|
+
/doc/
|
22
|
+
/rdoc/
|
23
|
+
|
24
|
+
## Environment normalization:
|
25
|
+
/.bundle/
|
26
|
+
/vendor/bundle
|
27
|
+
/lib/bundler/man/
|
28
|
+
|
29
|
+
# for a library or gem, you might want to ignore these files since the code is
|
30
|
+
# intended to run in multiple environments; otherwise, check them in:
|
31
|
+
# Gemfile.lock
|
32
|
+
# .ruby-version
|
33
|
+
# .ruby-gemset
|
34
|
+
|
35
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
36
|
+
.rvmrc
|
37
|
+
*.bundle
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,25 @@
|
|
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
|
data/LICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <http://unlicense.org>
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Ruby Native Statistics
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/corybuecker/ruby-native-statistics.svg)](https://travis-ci.org/corybuecker/ruby-native-statistics)
|
4
|
+
|
5
|
+
This is a native extension to Ruby that adds native (C) statistical functions to the Array class. At present the following functions are provided:
|
6
|
+
|
7
|
+
* [Sample Standard Deviation](https://en.wikipedia.org/wiki/Standard_deviation#Corrected_sample_standard_deviation) (stdev, stdevs)
|
8
|
+
* [Population Standard Deviation](https://en.wikipedia.org/wiki/Standard_deviation#Uncorrected_sample_standard_deviation) (stdevp)
|
9
|
+
|
10
|
+
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
|
+
|
12
|
+
It is much more performant than calculating the standard deviation with pure Ruby. For a comparison, run the benchmarks with rake.
|
13
|
+
|
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
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
require 'ruby_native_statistics'
|
20
|
+
r = [1,3,21,32,42]
|
21
|
+
|
22
|
+
# calculate sample standard deviation, you can also use "stdevs"
|
23
|
+
p r.stdev
|
24
|
+
|
25
|
+
# calculate population standard deviation
|
26
|
+
p r.stdevp
|
27
|
+
|
28
|
+
## Links
|
29
|
+
|
30
|
+
This is the third version of this gem, and it is a total rewrite of a SWIG-based design. Lots of thanks to the following resources:
|
31
|
+
|
32
|
+
* https://blog.jcoglan.com/2012/07/29/your-first-ruby-native-extension-c/
|
33
|
+
* https://github.com/andremedeiros/ruby-c-cheat-sheet
|
34
|
+
* http://silverhammermba.github.io/emberb/c/
|
35
|
+
* http://docs.ruby-lang.org/en/2.3.0/extension_rdoc.html
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
require 'rake/extensiontask'
|
4
|
+
|
5
|
+
Rake::TestTask.new(:test) do |t|
|
6
|
+
t.libs << "test"
|
7
|
+
t.libs << "lib"
|
8
|
+
t.test_files = FileList['test/**/*_test.rb', "test/**/*_benchmark.rb"]
|
9
|
+
end
|
10
|
+
|
11
|
+
Rake::ExtensionTask.new("dispersion")
|
12
|
+
|
13
|
+
task :default => [:compile, :test]
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include "dispersion.h"
|
3
|
+
|
4
|
+
void Init_dispersion() {
|
5
|
+
DispersionModule = rb_define_module("Dispersion");
|
6
|
+
rb_define_method(DispersionModule, "stdev", rb_sample_standard_deviation, 0);
|
7
|
+
rb_define_method(DispersionModule, "stdevs", rb_sample_standard_deviation, 0);
|
8
|
+
rb_define_method(DispersionModule, "stdevp", rb_population_standard_deviation, 0);
|
9
|
+
}
|
10
|
+
|
11
|
+
double calculate_total_distance_from_mean(VALUE array, unsigned long array_length){
|
12
|
+
unsigned long i;
|
13
|
+
double total = 0;
|
14
|
+
double mean = 0;
|
15
|
+
double total_distance_from_mean = 0;
|
16
|
+
|
17
|
+
for(i = 0; i < array_length; i++){
|
18
|
+
total += rb_num2dbl(rb_ary_entry(array, i));
|
19
|
+
}
|
20
|
+
|
21
|
+
mean = total / array_length;
|
22
|
+
|
23
|
+
for(i = 0; i < array_length; i++){
|
24
|
+
total_distance_from_mean += pow((rb_num2dbl(rb_ary_entry(array, i)) - mean), 2);
|
25
|
+
}
|
26
|
+
|
27
|
+
return total_distance_from_mean;
|
28
|
+
}
|
29
|
+
|
30
|
+
VALUE rb_sample_standard_deviation(VALUE self) {
|
31
|
+
Check_Type(self, T_ARRAY);
|
32
|
+
|
33
|
+
unsigned int array_length = rb_long2int(RARRAY_LEN(self));
|
34
|
+
|
35
|
+
if (array_length <= 1) {
|
36
|
+
rb_raise(rb_eRangeError, "array must have more than one element");
|
37
|
+
}
|
38
|
+
|
39
|
+
return DBL2NUM(sqrt((calculate_total_distance_from_mean(self, array_length)/(array_length - 1))));
|
40
|
+
}
|
41
|
+
|
42
|
+
VALUE rb_population_standard_deviation(VALUE self) {
|
43
|
+
Check_Type(self, T_ARRAY);
|
44
|
+
|
45
|
+
unsigned int array_length = rb_long2int(RARRAY_LEN(self));
|
46
|
+
|
47
|
+
if (array_length <= 1) {
|
48
|
+
rb_raise(rb_eRangeError, "array must have more than one element");
|
49
|
+
}
|
50
|
+
|
51
|
+
return DBL2NUM(sqrt(calculate_total_distance_from_mean(self, array_length) / array_length));
|
52
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruby_native_statistics/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruby_native_statistics"
|
8
|
+
spec.version = RubyNativeStatistics::VERSION
|
9
|
+
spec.authors = ["Cory Buecker"]
|
10
|
+
spec.email = ["email@corybuecker.com"]
|
11
|
+
spec.license = "Unlicense"
|
12
|
+
spec.summary = "This is a native extension to Ruby that adds various statistical functions to the Array class."
|
13
|
+
spec.homepage = "https://github.com/corybuecker/ruby-native-statistics"
|
14
|
+
|
15
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.extensions << "ext/dispersion/extconf.rb"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 11.0"
|
24
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
25
|
+
spec.add_development_dependency "rake-compiler", "~> 0.9"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_native_statistics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cory Buecker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '11.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '11.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake-compiler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- email@corybuecker.com
|
72
|
+
executables: []
|
73
|
+
extensions:
|
74
|
+
- ext/dispersion/extconf.rb
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- ext/dispersion/dispersion.c
|
84
|
+
- ext/dispersion/dispersion.h
|
85
|
+
- ext/dispersion/extconf.rb
|
86
|
+
- lib/ruby_native_statistics.rb
|
87
|
+
- lib/ruby_native_statistics/version.rb
|
88
|
+
- ruby_native_statistics.gemspec
|
89
|
+
homepage: https://github.com/corybuecker/ruby-native-statistics
|
90
|
+
licenses:
|
91
|
+
- Unlicense
|
92
|
+
metadata:
|
93
|
+
allowed_push_host: https://rubygems.org
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.5.1
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: This is a native extension to Ruby that adds various statistical functions
|
114
|
+
to the Array class.
|
115
|
+
test_files: []
|