ruby_native_statistics 1.1.1 → 2.0.0.rc.2

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,13 +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.1
4
+ version: 2.0.0.rc.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cory Buecker
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-18 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rake-compiler
@@ -15,70 +15,58 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '1.2'
18
+ version: '1.3'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '1.2'
25
+ version: '1.3'
26
26
  - !ruby/object:Gem::Dependency
27
- name: minitest
27
+ name: rb_sys
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.21'
33
- type: :development
34
- prerelease: false
35
- version_requirements: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '5.21'
40
- - !ruby/object:Gem::Dependency
41
- name: minitest-reporters
42
- requirement: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '1.6'
47
- type: :development
32
+ version: 0.9.91
33
+ type: :runtime
48
34
  prerelease: false
49
35
  version_requirements: !ruby/object:Gem::Requirement
50
36
  requirements:
51
37
  - - "~>"
52
38
  - !ruby/object:Gem::Version
53
- version: '1.6'
39
+ version: 0.9.91
54
40
  - !ruby/object:Gem::Dependency
55
- name: simplecov
41
+ name: rake
56
42
  requirement: !ruby/object:Gem::Requirement
57
43
  requirements:
58
44
  - - "~>"
59
45
  - !ruby/object:Gem::Version
60
- version: '0.21'
46
+ version: '13.0'
61
47
  type: :development
62
48
  prerelease: false
63
49
  version_requirements: !ruby/object:Gem::Requirement
64
50
  requirements:
65
51
  - - "~>"
66
52
  - !ruby/object:Gem::Version
67
- version: '0.21'
53
+ version: '13.0'
68
54
  - !ruby/object:Gem::Dependency
69
- name: simplecov-lcov
55
+ name: minitest
70
56
  requirement: !ruby/object:Gem::Requirement
71
57
  requirements:
72
58
  - - "~>"
73
59
  - !ruby/object:Gem::Version
74
- version: '0.8'
60
+ version: '5.21'
75
61
  type: :development
76
62
  prerelease: false
77
63
  version_requirements: !ruby/object:Gem::Requirement
78
64
  requirements:
79
65
  - - "~>"
80
66
  - !ruby/object:Gem::Version
81
- version: '0.8'
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.
82
70
  email:
83
71
  - cory.buecker@gmail.com
84
72
  executables: []
@@ -86,32 +74,28 @@ extensions:
86
74
  - ext/ruby_native_statistics/extconf.rb
87
75
  extra_rdoc_files: []
88
76
  files:
89
- - ".gitignore"
90
- - Gemfile
91
- - Gemfile.lock
77
+ - Cargo.lock
78
+ - Cargo.toml
92
79
  - README.md
93
80
  - Rakefile
94
81
  - UNLICENSE
95
82
  - changelog.md
96
- - ext/ruby_native_statistics/conversions.c
97
- - ext/ruby_native_statistics/conversions.h
98
- - ext/ruby_native_statistics/dispersion.c
99
- - ext/ruby_native_statistics/dispersion.h
83
+ - ext/ruby_native_statistics/Cargo.toml
100
84
  - ext/ruby_native_statistics/extconf.rb
101
- - ext/ruby_native_statistics/mathematics.c
102
- - ext/ruby_native_statistics/mathematics.h
103
- - ext/ruby_native_statistics/ruby_native_statistics.c
104
- - 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
105
88
  - lib/ruby_native_statistics.rb
106
89
  - lib/ruby_native_statistics/version.rb
107
- - ruby_native_statistics.gemspec
108
90
  homepage: https://github.com/corybuecker/ruby-native-statistics
109
91
  licenses:
110
92
  - Unlicense
111
93
  metadata:
112
94
  allowed_push_host: https://rubygems.org
95
+ changelog_uri: https://github.com/corybuecker/ruby-native-statistics/CHANGELOG.md
113
96
  source_code_uri: https://github.com/corybuecker/ruby-native-statistics
114
- changelog_uri: https://github.com/corybuecker/ruby-native-statistics/changelog.md
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
115
99
  rdoc_options: []
116
100
  require_paths:
117
101
  - lib
@@ -119,14 +103,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
103
  requirements:
120
104
  - - ">="
121
105
  - !ruby/object:Gem::Version
122
- version: 3.2.6
106
+ version: 3.2.8
123
107
  required_rubygems_version: !ruby/object:Gem::Requirement
124
108
  requirements:
125
109
  - - ">="
126
110
  - !ruby/object:Gem::Version
127
111
  version: '0'
128
112
  requirements: []
129
- rubygems_version: 3.6.2
113
+ rubygems_version: 3.6.7
130
114
  specification_version: 4
131
- summary: High performance, native (C) implementations of various statistical functions.
115
+ summary: High performance, native (Rust) implementations of various statistical functions.
132
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.1)
5
- rake-compiler (~> 1.2)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- ansi (1.5.0)
11
- builder (3.3.0)
12
- docile (1.4.1)
13
- minitest (5.25.4)
14
- minitest-reporters (1.7.1)
15
- ansi
16
- builder
17
- minitest (>= 5.0)
18
- ruby-progressbar
19
- rake (13.2.1)
20
- rake-compiler (1.2.9)
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.13.1)
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.6.3
@@ -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;
@@ -1,31 +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.2.6"
14
-
15
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
-
17
- spec.metadata["source_code_uri"] = spec.homepage
18
- spec.metadata["changelog_uri"] = "#{spec.homepage}/changelog.md"
19
-
20
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(.github|.vscode|test|spec|features)/}) }
21
- spec.require_paths = ["lib"]
22
-
23
- spec.extensions = %w[ext/ruby_native_statistics/extconf.rb]
24
-
25
- spec.add_runtime_dependency "rake-compiler", "~> 1.2"
26
-
27
- spec.add_development_dependency "minitest", "~> 5.21"
28
- spec.add_development_dependency "minitest-reporters", "~> 1.6"
29
- spec.add_development_dependency "simplecov", "~> 0.21"
30
- spec.add_development_dependency "simplecov-lcov", "~> 0.8"
31
- end