fast_statistics 0.1.1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/ext/fast_statistics/array_2d.cpp +24 -12
- data/ext/fast_statistics/array_2d.h +2 -1
- data/ext/fast_statistics/fast_statistics.cpp +28 -46
- data/lib/fast_statistics/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f74e28e9d460ef4ebcab5b0efa21ef0bd7aa1bc17ec398292dbc90fb2f759c10
|
4
|
+
data.tar.gz: 1ab07eeea3e7e139b0305b0d4109f780d2d7f372a0c3d8998ffc297a690f8eef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ce73ccecf92df45a42789a45dab9d00ea0642d5b08904e07ecb43eb75148c33f4d645737cf1999fd2b9b7931e80b5efc9f3882756b62820464481ae8a954bfe
|
7
|
+
data.tar.gz: 8e9385b1776b36d9d45c402ccc3015ecc01c4c52a95fae4321f3f6409ebc050921192d2c049cb8b453c49a46defd899d25a84491dbb811f9e10ae3bc2caa2b60
|
@@ -6,21 +6,32 @@ namespace array_2d
|
|
6
6
|
|
7
7
|
DFloat::~DFloat()
|
8
8
|
{
|
9
|
-
|
10
|
-
|
9
|
+
if (data_initialized) {
|
10
|
+
free(entries);
|
11
|
+
delete[] stats;
|
12
|
+
}
|
11
13
|
}
|
12
14
|
|
13
|
-
DFloat::DFloat(VALUE arrays)
|
15
|
+
DFloat::DFloat(VALUE arrays, bool initialize_data)
|
14
16
|
{
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
data_initialized = initialize_data;
|
18
|
+
|
19
|
+
if (initialize_data) {
|
20
|
+
cols = rb_array_len(arrays);
|
21
|
+
rows = rb_array_len(rb_ary_entry(arrays, 0));
|
22
|
+
entries = (double*)malloc(cols * rows * sizeof(double));
|
23
|
+
stats = new Stats[cols];
|
24
|
+
|
25
|
+
for (int j = 0; j < cols; j++) {
|
26
|
+
for (int i = 0; i < rows; i++) {
|
27
|
+
entries[j * rows + i] = (double)NUM2DBL(rb_ary_entry(rb_ary_entry(arrays, j), i));
|
28
|
+
}
|
23
29
|
}
|
30
|
+
} else {
|
31
|
+
cols = 0;
|
32
|
+
rows = 0;
|
33
|
+
entries = NULL;
|
34
|
+
stats = NULL;
|
24
35
|
}
|
25
36
|
}
|
26
37
|
|
@@ -68,7 +79,7 @@ DFloat::standard_deviation(double* col, double mean)
|
|
68
79
|
Stats*
|
69
80
|
DFloat::descriptive_statistics()
|
70
81
|
{
|
71
|
-
|
82
|
+
if (!data_initialized) return stats;
|
72
83
|
|
73
84
|
for (int col = 0; col < cols; col++) {
|
74
85
|
Stats var_stats;
|
@@ -137,6 +148,7 @@ Stats*
|
|
137
148
|
DFloat::descriptive_statistics_packed()
|
138
149
|
{
|
139
150
|
stats = new Stats[cols];
|
151
|
+
if (!data_initialized) return stats;
|
140
152
|
const int simd_pack_size = 2;
|
141
153
|
|
142
154
|
__m128d lengths = _mm_set_pd1((double)rows);
|
@@ -40,17 +40,16 @@ build_results_hashes(Stats* stats, int num_variables)
|
|
40
40
|
|
41
41
|
// Common
|
42
42
|
void
|
43
|
-
free_wrapped_array(void*
|
43
|
+
free_wrapped_array(void* dfloat)
|
44
44
|
{
|
45
|
-
((DFloat*)
|
45
|
+
((DFloat*)dfloat)->~DFloat();
|
46
|
+
free(dfloat);
|
46
47
|
}
|
47
48
|
|
48
49
|
size_t
|
49
50
|
wrapped_array_size(const void* data)
|
50
51
|
{
|
51
|
-
|
52
|
-
size_t size = sizeof(array->entries) + sizeof(*array);
|
53
|
-
return size;
|
52
|
+
return sizeof(DFloat);
|
54
53
|
}
|
55
54
|
|
56
55
|
static rb_data_type_t dfloat_wrapper = [] {
|
@@ -65,21 +64,36 @@ static rb_data_type_t dfloat_wrapper = [] {
|
|
65
64
|
VALUE
|
66
65
|
cArray2D_alloc(VALUE self)
|
67
66
|
{
|
68
|
-
void* dfloat = (void*)malloc(sizeof(
|
67
|
+
void* dfloat = (void*)malloc(sizeof(DFloat));
|
69
68
|
|
70
69
|
return TypedData_Wrap_Struct(self, &dfloat_wrapper, dfloat);
|
71
70
|
}
|
72
71
|
|
73
|
-
|
74
|
-
|
72
|
+
/*
|
73
|
+
* def initialize(arrays)
|
74
|
+
*/
|
75
|
+
VALUE
|
76
|
+
cArray2D_initialize(VALUE self, VALUE arrays)
|
75
77
|
{
|
76
|
-
|
77
|
-
|
78
|
-
|
78
|
+
// Initialize dfloat structure to store Dfloat in type wrapper
|
79
|
+
void* dfloat;
|
80
|
+
UNWRAP_DFLOAT(self, dfloat);
|
81
|
+
|
82
|
+
// Type-check 2D array
|
83
|
+
if (TYPE(arrays) != T_ARRAY) {
|
84
|
+
new (dfloat) DFloat(arrays, false);
|
79
85
|
Check_Type(arrays, T_ARRAY);
|
86
|
+
return false;
|
87
|
+
}
|
88
|
+
|
89
|
+
if (TYPE(rb_ary_entry(arrays, 0)) != T_ARRAY) {
|
90
|
+
new (dfloat) DFloat(arrays, false);
|
80
91
|
Check_Type(rb_ary_entry(arrays, 0), T_ARRAY);
|
81
92
|
return false;
|
82
93
|
}
|
94
|
+
|
95
|
+
new (dfloat) DFloat(arrays, true);
|
96
|
+
return self;
|
83
97
|
}
|
84
98
|
|
85
99
|
//{{{ Unpacked
|
@@ -89,22 +103,6 @@ simd_disabled(VALUE self)
|
|
89
103
|
return Qfalse;
|
90
104
|
}
|
91
105
|
|
92
|
-
/*
|
93
|
-
* def initialize(arrays)
|
94
|
-
*/
|
95
|
-
VALUE
|
96
|
-
cArray2D_initialize_unpacked(VALUE self, VALUE arrays)
|
97
|
-
{
|
98
|
-
// Typecheck 2d array
|
99
|
-
if (cArray2D_check_array_args(arrays)) {
|
100
|
-
// Initialize dfloat structure to store Dfloat in type wrapper
|
101
|
-
void* dfloat;
|
102
|
-
UNWRAP_DFLOAT(self, dfloat);
|
103
|
-
new (dfloat) DFloat(arrays);
|
104
|
-
}
|
105
|
-
return self;
|
106
|
-
}
|
107
|
-
|
108
106
|
/*
|
109
107
|
* Unpacked descriptive statistics
|
110
108
|
*
|
@@ -122,7 +120,7 @@ cArray2D_descriptive_statistics_unpacked(VALUE self)
|
|
122
120
|
}
|
123
121
|
//}}}
|
124
122
|
|
125
|
-
// Packed
|
123
|
+
//{{{ Packed
|
126
124
|
#ifdef HAVE_XMMINTRIN_H
|
127
125
|
extern "C" VALUE
|
128
126
|
simd_enabled(VALUE self)
|
@@ -130,22 +128,6 @@ simd_enabled(VALUE self)
|
|
130
128
|
return Qtrue;
|
131
129
|
}
|
132
130
|
|
133
|
-
/*
|
134
|
-
* def initialize(arrays)
|
135
|
-
*/
|
136
|
-
VALUE
|
137
|
-
cArray2D_initialize_packed(VALUE self, VALUE arrays)
|
138
|
-
{
|
139
|
-
// Typecheck 2d array
|
140
|
-
if (cArray2D_check_array_args(arrays)) {
|
141
|
-
// Initialize dfloat structure to store Dfloat in type wrapper
|
142
|
-
void* dfloat;
|
143
|
-
UNWRAP_DFLOAT(self, dfloat);
|
144
|
-
new (dfloat) DFloat(arrays);
|
145
|
-
}
|
146
|
-
return self;
|
147
|
-
}
|
148
|
-
|
149
131
|
/*
|
150
132
|
* Packed descriptive statistics
|
151
133
|
*
|
@@ -162,6 +144,7 @@ cArray2D_descriptive_statistics_packed(VALUE self)
|
|
162
144
|
return build_results_hashes(stats, dfloat->cols);
|
163
145
|
}
|
164
146
|
#endif
|
147
|
+
//}}}
|
165
148
|
|
166
149
|
extern "C" void
|
167
150
|
Init_fast_statistics(void)
|
@@ -169,10 +152,10 @@ Init_fast_statistics(void)
|
|
169
152
|
mFastStatistics = rb_define_module("FastStatistics");
|
170
153
|
cArray2D = rb_define_class_under(mFastStatistics, "Array2D", rb_cData);
|
171
154
|
rb_define_alloc_func(cArray2D, cArray2D_alloc);
|
155
|
+
rb_define_method(cArray2D, "initialize", RUBY_METHOD_FUNC(cArray2D_initialize), 1);
|
172
156
|
|
173
157
|
#ifdef HAVE_XMMINTRIN_H
|
174
158
|
rb_define_singleton_method(mFastStatistics, "simd_enabled?", RUBY_METHOD_FUNC(simd_enabled), 0);
|
175
|
-
rb_define_method(cArray2D, "initialize", RUBY_METHOD_FUNC(cArray2D_initialize_packed), 1);
|
176
159
|
rb_define_method(
|
177
160
|
cArray2D,
|
178
161
|
"descriptive_statistics",
|
@@ -180,7 +163,6 @@ Init_fast_statistics(void)
|
|
180
163
|
0);
|
181
164
|
#else
|
182
165
|
rb_define_singleton_method(mFastStatistics, "simd_enabled?", RUBY_METHOD_FUNC(simd_disabled), 0);
|
183
|
-
rb_define_method(cArray2D, "initialize", RUBY_METHOD_FUNC(cArray2D_initialize_unpacked), 1);
|
184
166
|
rb_define_method(
|
185
167
|
cArray2D,
|
186
168
|
"descriptive_statistics",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_statistics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Nyaga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Fast computation of descriptive statistics in ruby using native code
|
14
14
|
and SIMD
|