distance_measures 0.0.2 → 0.0.3
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.
- data/.gitignore +1 -0
- data/VERSION +1 -1
- data/distance_measures.gemspec +3 -4
- data/ext/19_fix/19_fix.c +8 -0
- data/ext/core/core.c +10 -9
- data/ext/euclidean_distance/euclidean_distance.c +4 -3
- metadata +4 -5
- data/lib/distance_measures/core.bundle +0 -0
- data/lib/distance_measures/euclidean_distance.bundle +0 -0
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/distance_measures.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{distance_measures}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["reddavis"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-15}
|
13
13
|
s.description = %q{A bundle of distance measures with C extensions for the slow bits}
|
14
14
|
s.email = %q{reddavis@gmail.com}
|
15
15
|
s.extensions = ["ext/core/extconf.rb", "ext/euclidean_distance/extconf.rb"]
|
@@ -25,14 +25,13 @@ Gem::Specification.new do |s|
|
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"distance_measures.gemspec",
|
28
|
+
"ext/19_fix/19_fix.c",
|
28
29
|
"ext/core/core.c",
|
29
30
|
"ext/core/extconf.rb",
|
30
31
|
"ext/euclidean_distance/euclidean_distance.c",
|
31
32
|
"ext/euclidean_distance/extconf.rb",
|
32
33
|
"lib/distance_measures.rb",
|
33
|
-
"lib/distance_measures/core.bundle",
|
34
34
|
"lib/distance_measures/cosine_similarity.rb",
|
35
|
-
"lib/distance_measures/euclidean_distance.bundle",
|
36
35
|
"lib/distance_measures/jaccard.rb",
|
37
36
|
"lib/distance_measures/tanimoto_coefficient.rb",
|
38
37
|
"spec/distance_measures_spec.rb",
|
data/ext/19_fix/19_fix.c
ADDED
data/ext/core/core.c
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
#include <math.h>
|
3
|
+
#include "../19_fix/19_fix.c"
|
3
4
|
|
4
5
|
// Prototypes
|
5
6
|
long c_array_size(VALUE array);
|
@@ -27,8 +28,8 @@ static VALUE rb_dot_product(VALUE self, VALUE other_array) {
|
|
27
28
|
for(index = 0; index <= array_size; index++) {
|
28
29
|
double x, y;
|
29
30
|
|
30
|
-
x = NUM2DBL(
|
31
|
-
y = NUM2DBL(
|
31
|
+
x = NUM2DBL(RARRAY_PTR(self)[index]);
|
32
|
+
y = NUM2DBL(RARRAY_PTR(other_array)[index]);
|
32
33
|
|
33
34
|
sum += x * y;
|
34
35
|
}
|
@@ -51,7 +52,7 @@ static VALUE rb_sum_of_squares(VALUE self) {
|
|
51
52
|
for(index = 0; index <= array_size; index++) {
|
52
53
|
double x;
|
53
54
|
|
54
|
-
x = NUM2DBL(
|
55
|
+
x = NUM2DBL(RARRAY_PTR(self)[index]);
|
55
56
|
|
56
57
|
sum += pow(x, 2);
|
57
58
|
}
|
@@ -79,7 +80,7 @@ static VALUE rb_euclidean_normalize(VALUE self) {
|
|
79
80
|
for(index = 0; index <= array_size; index++) {
|
80
81
|
double x;
|
81
82
|
|
82
|
-
x = NUM2DBL(
|
83
|
+
x = NUM2DBL(RARRAY_PTR(self)[index]);
|
83
84
|
|
84
85
|
sum += pow(x, 2);
|
85
86
|
}
|
@@ -110,8 +111,8 @@ static VALUE rb_binary_union_with(VALUE self, VALUE other_array) {
|
|
110
111
|
VALUE results = rb_ary_new();
|
111
112
|
|
112
113
|
for(index = 0; index <= array_size; index++) {
|
113
|
-
int self_attribute = NUM2INT(
|
114
|
-
int other_array_attribute = NUM2INT(
|
114
|
+
int self_attribute = NUM2INT(RARRAY_PTR(self)[index]);
|
115
|
+
int other_array_attribute = NUM2INT(RARRAY_PTR(other_array)[index]);
|
115
116
|
|
116
117
|
if(self_attribute == 1 || other_array_attribute == 1) {
|
117
118
|
rb_ary_push(results, rb_int_new(1));
|
@@ -146,8 +147,8 @@ static VALUE rb_binary_intersection_with(VALUE self, VALUE other_array) {
|
|
146
147
|
VALUE results = rb_ary_new();
|
147
148
|
|
148
149
|
for(index = 0; index <= array_size; index++) {
|
149
|
-
int self_attribute = NUM2INT(
|
150
|
-
int other_array_attribute = NUM2INT(
|
150
|
+
int self_attribute = NUM2INT(RARRAY_PTR(self)[index]);
|
151
|
+
int other_array_attribute = NUM2INT(RARRAY_PTR(other_array)[index]);
|
151
152
|
|
152
153
|
if(self_attribute == 1 && other_array_attribute == 1) {
|
153
154
|
rb_ary_push(results, rb_int_new(1));
|
@@ -161,7 +162,7 @@ static VALUE rb_binary_intersection_with(VALUE self, VALUE other_array) {
|
|
161
162
|
|
162
163
|
// return the size of a Ruby array - 1
|
163
164
|
long c_array_size(VALUE array) {
|
164
|
-
return (
|
165
|
+
return (RARRAY_LEN(array) - 1);
|
165
166
|
}
|
166
167
|
|
167
168
|
void Init_core() {
|
@@ -1,5 +1,6 @@
|
|
1
1
|
#include <ruby.h>
|
2
2
|
#include <math.h>
|
3
|
+
#include "../19_fix/19_fix.c"
|
3
4
|
|
4
5
|
/*
|
5
6
|
|
@@ -16,14 +17,14 @@ static VALUE rb_euclidean_distance(VALUE self, VALUE other_array) {
|
|
16
17
|
double value = 0.0;
|
17
18
|
|
18
19
|
//TODO: check they're the same size
|
19
|
-
long vector_length = (
|
20
|
+
long vector_length = (RARRAY_LEN(self) - 1);
|
20
21
|
int index;
|
21
22
|
|
22
23
|
for(index = 0; index <= vector_length; index++) {
|
23
24
|
double x, y;
|
24
25
|
|
25
|
-
x = NUM2DBL(
|
26
|
-
y = NUM2DBL(
|
26
|
+
x = NUM2DBL(RARRAY_PTR(self)[index]);
|
27
|
+
y = NUM2DBL(RARRAY_PTR(other_array)[index]);
|
27
28
|
|
28
29
|
value += pow(x - y, 2);
|
29
30
|
}
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- reddavis
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-08-15 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -49,14 +49,13 @@ files:
|
|
49
49
|
- Rakefile
|
50
50
|
- VERSION
|
51
51
|
- distance_measures.gemspec
|
52
|
+
- ext/19_fix/19_fix.c
|
52
53
|
- ext/core/core.c
|
53
54
|
- ext/core/extconf.rb
|
54
55
|
- ext/euclidean_distance/euclidean_distance.c
|
55
56
|
- ext/euclidean_distance/extconf.rb
|
56
57
|
- lib/distance_measures.rb
|
57
|
-
- lib/distance_measures/core.bundle
|
58
58
|
- lib/distance_measures/cosine_similarity.rb
|
59
|
-
- lib/distance_measures/euclidean_distance.bundle
|
60
59
|
- lib/distance_measures/jaccard.rb
|
61
60
|
- lib/distance_measures/tanimoto_coefficient.rb
|
62
61
|
- spec/distance_measures_spec.rb
|
Binary file
|
Binary file
|