ruby_native_statistics 1.1.0 → 2.0.0.rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_native_statistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0.rc.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cory Buecker
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-03-03 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rake-compiler
@@ -16,71 +15,58 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '1.2'
18
+ version: '1.3'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '1.2'
25
+ version: '1.3'
27
26
  - !ruby/object:Gem::Dependency
28
- name: minitest
27
+ name: rb_sys
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '5.21'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '5.21'
41
- - !ruby/object:Gem::Dependency
42
- name: minitest-reporters
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.6'
48
- type: :development
32
+ version: 0.9.91
33
+ type: :runtime
49
34
  prerelease: false
50
35
  version_requirements: !ruby/object:Gem::Requirement
51
36
  requirements:
52
37
  - - "~>"
53
38
  - !ruby/object:Gem::Version
54
- version: '1.6'
39
+ version: 0.9.91
55
40
  - !ruby/object:Gem::Dependency
56
- name: simplecov
41
+ name: rake
57
42
  requirement: !ruby/object:Gem::Requirement
58
43
  requirements:
59
44
  - - "~>"
60
45
  - !ruby/object:Gem::Version
61
- version: '0.21'
46
+ version: '13.0'
62
47
  type: :development
63
48
  prerelease: false
64
49
  version_requirements: !ruby/object:Gem::Requirement
65
50
  requirements:
66
51
  - - "~>"
67
52
  - !ruby/object:Gem::Version
68
- version: '0.21'
53
+ version: '13.0'
69
54
  - !ruby/object:Gem::Dependency
70
- name: simplecov-lcov
55
+ name: minitest
71
56
  requirement: !ruby/object:Gem::Requirement
72
57
  requirements:
73
58
  - - "~>"
74
59
  - !ruby/object:Gem::Version
75
- version: '0.8'
60
+ version: '5.21'
76
61
  type: :development
77
62
  prerelease: false
78
63
  version_requirements: !ruby/object:Gem::Requirement
79
64
  requirements:
80
65
  - - "~>"
81
66
  - !ruby/object:Gem::Version
82
- version: '0.8'
83
- description:
67
+ version: '5.21'
68
+ description: A Ruby gem providing high-performance statistical functions implemented
69
+ in Rust for better performance than pure Ruby implementations.
84
70
  email:
85
71
  - cory.buecker@gmail.com
86
72
  executables: []
@@ -88,35 +74,28 @@ extensions:
88
74
  - ext/ruby_native_statistics/extconf.rb
89
75
  extra_rdoc_files: []
90
76
  files:
91
- - ".gitignore"
92
- - Gemfile
93
- - Gemfile.lock
77
+ - Cargo.lock
78
+ - Cargo.toml
94
79
  - README.md
95
80
  - Rakefile
96
81
  - UNLICENSE
97
82
  - changelog.md
98
- - ext/ruby_native_statistics/conversions.c
99
- - ext/ruby_native_statistics/conversions.h
100
- - ext/ruby_native_statistics/dispersion.c
101
- - ext/ruby_native_statistics/dispersion.h
83
+ - ext/ruby_native_statistics/Cargo.toml
102
84
  - ext/ruby_native_statistics/extconf.rb
103
- - ext/ruby_native_statistics/mathematics.c
104
- - ext/ruby_native_statistics/mathematics.h
105
- - ext/ruby_native_statistics/ruby_native_statistics.c
106
- - ext/ruby_native_statistics/ruby_native_statistics.h
85
+ - ext/ruby_native_statistics/src/dispersion.rs
86
+ - ext/ruby_native_statistics/src/lib.rs
87
+ - ext/ruby_native_statistics/src/mathematics.rs
107
88
  - lib/ruby_native_statistics.rb
108
89
  - lib/ruby_native_statistics/version.rb
109
- - renovate.json
110
- - ruby_native_statistics.gemspec
111
90
  homepage: https://github.com/corybuecker/ruby-native-statistics
112
91
  licenses:
113
92
  - Unlicense
114
93
  metadata:
115
94
  allowed_push_host: https://rubygems.org
116
- homepage_uri: https://github.com/corybuecker/ruby-native-statistics
95
+ changelog_uri: https://github.com/corybuecker/ruby-native-statistics/CHANGELOG.md
117
96
  source_code_uri: https://github.com/corybuecker/ruby-native-statistics
118
- changelog_uri: https://github.com/corybuecker/ruby-native-statistics/changelog.md
119
- post_install_message:
97
+ bug_tracker_uri: https://github.com/corybuecker/ruby-native-statistics/issues
98
+ documentation_uri: https://github.com/corybuecker/ruby-native-statistics/blob/main/README.md
120
99
  rdoc_options: []
121
100
  require_paths:
122
101
  - lib
@@ -124,15 +103,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
103
  requirements:
125
104
  - - ">="
126
105
  - !ruby/object:Gem::Version
127
- version: 3.0.3
106
+ version: 3.2.8
128
107
  required_rubygems_version: !ruby/object:Gem::Requirement
129
108
  requirements:
130
109
  - - ">="
131
110
  - !ruby/object:Gem::Version
132
111
  version: '0'
133
112
  requirements: []
134
- rubygems_version: 3.5.6
135
- signing_key:
113
+ rubygems_version: 3.7.1
136
114
  specification_version: 4
137
- summary: High performance, native (C) implementations of various statistical functions.
115
+ summary: High performance, native (Rust) implementations of various statistical functions.
138
116
  test_files: []
data/.gitignore DELETED
@@ -1,58 +0,0 @@
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
- # Used by dotenv library to load environment variables.
14
- # .env
15
-
16
- # Ignore Byebug command history file.
17
- .byebug_history
18
-
19
- ## Specific to RubyMotion:
20
- .dat*
21
- .repl_history
22
- build/
23
- *.bridgesupport
24
- build-iPhoneOS/
25
- build-iPhoneSimulator/
26
-
27
- ## Specific to RubyMotion (use of CocoaPods):
28
- #
29
- # We recommend against adding the Pods directory to your .gitignore. However
30
- # you should judge for yourself, the pros and cons are mentioned at:
31
- # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
- #
33
- # vendor/Pods/
34
-
35
- ## Documentation cache and generated files:
36
- /.yardoc/
37
- /_yardoc/
38
- /doc/
39
- /rdoc/
40
-
41
- ## Environment normalization:
42
- /.bundle/
43
- /vendor/bundle
44
- /lib/bundler/man/
45
-
46
- # for a library or gem, you might want to ignore these files since the code is
47
- # intended to run in multiple environments; otherwise, check them in:
48
- # Gemfile.lock
49
- # .ruby-version
50
- # .ruby-gemset
51
-
52
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
- .rvmrc
54
-
55
- # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
- # .rubocop-https?--*
57
-
58
- *.bundle
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
data/Gemfile.lock DELETED
@@ -1,43 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- ruby_native_statistics (1.1.0)
5
- rake-compiler (~> 1.2)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- ansi (1.5.0)
11
- builder (3.2.4)
12
- docile (1.4.0)
13
- minitest (5.21.2)
14
- minitest-reporters (1.6.1)
15
- ansi
16
- builder
17
- minitest (>= 5.0)
18
- ruby-progressbar
19
- rake (13.1.0)
20
- rake-compiler (1.2.6)
21
- rake
22
- ruby-progressbar (1.13.0)
23
- simplecov (0.22.0)
24
- docile (~> 1.1)
25
- simplecov-html (~> 0.11)
26
- simplecov_json_formatter (~> 0.1)
27
- simplecov-html (0.12.3)
28
- simplecov-lcov (0.8.0)
29
- simplecov_json_formatter (0.1.4)
30
-
31
- PLATFORMS
32
- arm64-darwin-23
33
- ruby
34
-
35
- DEPENDENCIES
36
- minitest (~> 5.21)
37
- minitest-reporters (~> 1.6)
38
- ruby_native_statistics!
39
- simplecov (~> 0.21)
40
- simplecov-lcov (~> 0.8)
41
-
42
- BUNDLED WITH
43
- 2.5.5
@@ -1,56 +0,0 @@
1
- #include "conversions.h"
2
- #include "float.h"
3
-
4
- int compare_doubles(const void *a, const void *b)
5
- {
6
- double *dbl_a = (double *)a;
7
- double *dbl_b = (double *)b;
8
-
9
- double cmp_a = *dbl_a;
10
- double cmp_b = *dbl_b;
11
-
12
- if (fabs(cmp_a - cmp_b) <= (DBL_EPSILON * fabs(cmp_a + cmp_b)))
13
- {
14
- return 0;
15
- }
16
-
17
- if (cmp_a > cmp_b)
18
- {
19
- return 1;
20
- }
21
-
22
- return -1;
23
- }
24
-
25
- double *sorted_ruby_array(VALUE array, long array_length)
26
- {
27
- long i;
28
- double *working_array;
29
-
30
- working_array = malloc(array_length * sizeof(double));
31
-
32
- if (working_array == NULL)
33
- {
34
- rb_raise(rb_eStandardError, "unknown problem sorting array (possibly array is too large)");
35
- }
36
-
37
- for (i = 0; i < array_length; i++)
38
- {
39
- VALUE item = rb_ary_entry(array, i);
40
-
41
- if (!RB_INTEGER_TYPE_P(item) && !RB_FLOAT_TYPE_P(item))
42
- {
43
- free(working_array);
44
- rb_raise(rb_eTypeError, "element is not a number");
45
- }
46
-
47
- working_array[i] = NUM2DBL(item);
48
- }
49
-
50
- // Reminder to myself as I'm learning C. Using an array as a function parameter decays that reference
51
- // to a pointer to the first element in the array.
52
- // https://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html#Function-Parameters
53
- qsort(working_array, array_length, sizeof(double), compare_doubles);
54
-
55
- return working_array;
56
- }
@@ -1,5 +0,0 @@
1
- #include <stdbool.h>
2
- #include <ruby.h>
3
-
4
- int compare_doubles(const void *a, const void *b);
5
- double *sorted_ruby_array(VALUE array, long array_length);
@@ -1,102 +0,0 @@
1
- #include "dispersion.h"
2
-
3
- VALUE rb_sample_standard_deviation(VALUE self)
4
- {
5
- unsigned int array_length;
6
-
7
- Check_Type(self, T_ARRAY);
8
-
9
- array_length = rb_long2int(RARRAY_LEN(self));
10
-
11
- if (array_length <= 1)
12
- {
13
- rb_raise(rb_eRangeError, "array must have more than one element");
14
- }
15
-
16
- return DBL2NUM(sqrt((calculate_total_distance_from_mean(self, array_length) / (array_length - 1))));
17
- }
18
-
19
- VALUE rb_sample_variance(VALUE self)
20
- {
21
- unsigned int array_length;
22
-
23
- Check_Type(self, T_ARRAY);
24
-
25
- array_length = rb_long2int(RARRAY_LEN(self));
26
-
27
- if (array_length <= 1)
28
- {
29
- rb_raise(rb_eRangeError, "array must have more than one element");
30
- }
31
-
32
- return DBL2NUM((calculate_total_distance_from_mean(self, array_length) / (array_length - 1)));
33
- }
34
-
35
- VALUE rb_population_standard_deviation(VALUE self)
36
- {
37
- unsigned int array_length;
38
-
39
- Check_Type(self, T_ARRAY);
40
-
41
- array_length = rb_long2int(RARRAY_LEN(self));
42
-
43
- if (array_length <= 1)
44
- {
45
- rb_raise(rb_eRangeError, "array must have more than one element");
46
- }
47
-
48
- return DBL2NUM(sqrt(calculate_total_distance_from_mean(self, array_length) / array_length));
49
- }
50
-
51
- VALUE rb_population_variance(VALUE self)
52
- {
53
- unsigned int array_length;
54
-
55
- Check_Type(self, T_ARRAY);
56
-
57
- array_length = rb_long2int(RARRAY_LEN(self));
58
-
59
- if (array_length <= 1)
60
- {
61
- rb_raise(rb_eRangeError, "array must have more than one element");
62
- }
63
-
64
- return DBL2NUM(calculate_total_distance_from_mean(self, array_length) / array_length);
65
- }
66
-
67
- VALUE rb_percentile(VALUE self, VALUE r_percentile)
68
- {
69
- double result;
70
- Check_Type(self, T_ARRAY);
71
-
72
- long array_length = rb_array_len(self);
73
- double percentile = NUM2DBL(r_percentile);
74
-
75
- if (array_length == 0)
76
- {
77
- rb_raise(rb_eRangeError, "array must have at least one element");
78
- }
79
-
80
- if (percentile < 0 || percentile > 1)
81
- {
82
- rb_raise(rb_eRangeError, "percentile must be between 0 and 1 inclusive");
83
- }
84
-
85
- double *sorted_array = sorted_ruby_array(self, array_length);
86
-
87
- double h = (array_length - 1) * percentile + 1;
88
-
89
- if (trunc(h) == h)
90
- {
91
- result = sorted_array[(long)h - 1];
92
- }
93
- else
94
- {
95
- long h_floor = (long)trunc(h);
96
- result = (h - h_floor) * (sorted_array[h_floor] - sorted_array[h_floor - 1]) + sorted_array[h_floor - 1];
97
- }
98
-
99
- free(sorted_array);
100
-
101
- return DBL2NUM(result);
102
- }
@@ -1,10 +0,0 @@
1
- #include <ruby.h>
2
- #include <math.h>
3
- #include "conversions.h"
4
- #include "mathematics.h"
5
-
6
- VALUE rb_sample_standard_deviation(VALUE self);
7
- VALUE rb_population_standard_deviation(VALUE self);
8
- VALUE rb_sample_variance(VALUE self);
9
- VALUE rb_population_variance(VALUE self);
10
- VALUE rb_percentile(VALUE self, VALUE percentile);
@@ -1,84 +0,0 @@
1
-
2
- #include "mathematics.h"
3
-
4
- double calculate_mean(VALUE array, unsigned long array_length)
5
- {
6
- unsigned long i;
7
- double total = 0;
8
- double mean = 0;
9
-
10
- for (i = 0; i < array_length; i++)
11
- {
12
- total += rb_num2dbl(rb_ary_entry(array, i));
13
- }
14
-
15
- mean = total / array_length;
16
-
17
- return mean;
18
- }
19
-
20
- double calculate_total_distance_from_mean(VALUE array, unsigned long array_length)
21
- {
22
- unsigned long i;
23
- double mean = 0;
24
- double total_distance_from_mean = 0;
25
-
26
- mean = calculate_mean(array, array_length);
27
-
28
- for (i = 0; i < array_length; i++)
29
- {
30
- total_distance_from_mean += pow((rb_num2dbl(rb_ary_entry(array, i)) - mean), 2);
31
- }
32
-
33
- return total_distance_from_mean;
34
- }
35
-
36
- VALUE rb_mean(VALUE self)
37
- {
38
- unsigned int array_length;
39
-
40
- Check_Type(self, T_ARRAY);
41
-
42
- array_length = rb_long2int(RARRAY_LEN(self));
43
-
44
- if (array_length <= 0)
45
- {
46
- rb_raise(rb_eRangeError, "array must have at least one element");
47
- }
48
-
49
- return DBL2NUM(calculate_mean(self, array_length));
50
- }
51
-
52
- VALUE rb_median(VALUE self)
53
- {
54
- unsigned long array_length;
55
-
56
- VALUE result;
57
-
58
- Check_Type(self, T_ARRAY);
59
-
60
- array_length = RARRAY_LEN(self);
61
-
62
- if (array_length <= 0)
63
- {
64
- rb_raise(rb_eRangeError, "array must have at least one element");
65
- }
66
-
67
- bool array_even_size = (array_length % 2) == 0;
68
- unsigned long middle = (long)floor(array_length / 2.0);
69
-
70
- double *working_array = sorted_ruby_array(self, array_length);
71
-
72
- if (!array_even_size)
73
- {
74
- result = DBL2NUM(working_array[middle]);
75
- }
76
- else
77
- {
78
- result = DBL2NUM((working_array[middle - 1] + working_array[middle]) / 2);
79
- }
80
-
81
- free(working_array);
82
-
83
- return result;
84
- }
@@ -1,9 +0,0 @@
1
- #include <stdbool.h>
2
- #include <ruby.h>
3
- #include "conversions.h"
4
-
5
- VALUE rb_mean(VALUE self);
6
- VALUE rb_median(VALUE self);
7
-
8
- double calculate_mean(VALUE array, unsigned long array_length);
9
- double calculate_total_distance_from_mean(VALUE array, unsigned long array_length);
@@ -1,16 +0,0 @@
1
- #include "ruby_native_statistics.h"
2
-
3
- void Init_ruby_native_statistics()
4
- {
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
- rb_define_method(DispersionModule, "var", rb_sample_variance, 0);
10
- rb_define_method(DispersionModule, "varp", rb_population_variance, 0);
11
- rb_define_method(DispersionModule, "percentile", rb_percentile, 1);
12
-
13
- MathematicsModule = rb_define_module("Mathematics");
14
- rb_define_method(MathematicsModule, "mean", rb_mean, 0);
15
- rb_define_method(MathematicsModule, "median", rb_median, 0);
16
- }
@@ -1,5 +0,0 @@
1
- #include "dispersion.h"
2
- #include "mathematics.h"
3
-
4
- VALUE MathematicsModule = Qnil;
5
- VALUE DispersionModule = Qnil;
data/renovate.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
- "extends": [
4
- "config:base"
5
- ]
6
- }
@@ -1,32 +0,0 @@
1
- require_relative "lib/ruby_native_statistics/version"
2
-
3
- Gem::Specification.new do |spec|
4
- spec.name = "ruby_native_statistics"
5
- spec.version = RubyNativeStatistics::VERSION
6
- spec.authors = ["Cory Buecker"]
7
- spec.email = ["cory.buecker@gmail.com"]
8
-
9
- spec.license = "Unlicense"
10
- spec.summary = "High performance, native (C) implementations of various statistical functions."
11
- spec.homepage = "https://github.com/corybuecker/ruby-native-statistics"
12
-
13
- spec.required_ruby_version = ">= 3.0.3"
14
-
15
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
-
17
- spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = spec.homepage
19
- spec.metadata["changelog_uri"] = "#{spec.homepage}/changelog.md"
20
-
21
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(.github|.vscode|test|spec|features)/}) }
22
- spec.require_paths = ["lib"]
23
-
24
- spec.extensions = %w[ext/ruby_native_statistics/extconf.rb]
25
-
26
- spec.add_runtime_dependency "rake-compiler", "~> 1.2"
27
-
28
- spec.add_development_dependency "minitest", "~> 5.21"
29
- spec.add_development_dependency "minitest-reporters", "~> 1.6"
30
- spec.add_development_dependency "simplecov", "~> 0.21"
31
- spec.add_development_dependency "simplecov-lcov", "~> 0.8"
32
- end