libsmatrix 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,77 @@
1
+ /* DO NOT EDIT THIS FILE - it is machine generated */
2
+ #include <jni.h>
3
+ /* Header for class com_paulasmuth_libsmatrix_SparseMatrix */
4
+
5
+ #ifndef _Included_com_paulasmuth_libsmatrix_SparseMatrix
6
+ #define _Included_com_paulasmuth_libsmatrix_SparseMatrix
7
+ #ifdef __cplusplus
8
+ extern "C" {
9
+ #endif
10
+ /*
11
+ * Class: com_paulasmuth_libsmatrix_SparseMatrix
12
+ * Method: get
13
+ * Signature: (II)I
14
+ */
15
+ JNIEXPORT jint JNICALL Java_com_paulasmuth_libsmatrix_SparseMatrix_get
16
+ (JNIEnv *, jobject, jint, jint);
17
+
18
+ /*
19
+ * Class: com_paulasmuth_libsmatrix_SparseMatrix
20
+ * Method: set
21
+ * Signature: (III)V
22
+ */
23
+ JNIEXPORT void JNICALL Java_com_paulasmuth_libsmatrix_SparseMatrix_set
24
+ (JNIEnv *, jobject, jint, jint, jint);
25
+
26
+ /*
27
+ * Class: com_paulasmuth_libsmatrix_SparseMatrix
28
+ * Method: incr
29
+ * Signature: (III)V
30
+ */
31
+ JNIEXPORT void JNICALL Java_com_paulasmuth_libsmatrix_SparseMatrix_incr
32
+ (JNIEnv *, jobject, jint, jint, jint);
33
+
34
+ /*
35
+ * Class: com_paulasmuth_libsmatrix_SparseMatrix
36
+ * Method: decr
37
+ * Signature: (III)V
38
+ */
39
+ JNIEXPORT void JNICALL Java_com_paulasmuth_libsmatrix_SparseMatrix_decr
40
+ (JNIEnv *, jobject, jint, jint, jint);
41
+
42
+ /*
43
+ * Class: com_paulasmuth_libsmatrix_SparseMatrix
44
+ * Method: getRow
45
+ * Signature: (I)Ljava/util/SortedMap;
46
+ */
47
+ JNIEXPORT jobject JNICALL Java_com_paulasmuth_libsmatrix_SparseMatrix_getRow
48
+ (JNIEnv *, jobject, jint);
49
+
50
+ /*
51
+ * Class: com_paulasmuth_libsmatrix_SparseMatrix
52
+ * Method: getRowLength
53
+ * Signature: (I)I
54
+ */
55
+ JNIEXPORT jint JNICALL Java_com_paulasmuth_libsmatrix_SparseMatrix_getRowLength
56
+ (JNIEnv *, jobject, jint);
57
+
58
+ /*
59
+ * Class: com_paulasmuth_libsmatrix_SparseMatrix
60
+ * Method: close
61
+ * Signature: ()V
62
+ */
63
+ JNIEXPORT void JNICALL Java_com_paulasmuth_libsmatrix_SparseMatrix_close
64
+ (JNIEnv *, jobject);
65
+
66
+ /*
67
+ * Class: com_paulasmuth_libsmatrix_SparseMatrix
68
+ * Method: init
69
+ * Signature: (Ljava/lang/String;)V
70
+ */
71
+ JNIEXPORT void JNICALL Java_com_paulasmuth_libsmatrix_SparseMatrix_init
72
+ (JNIEnv *, jobject, jstring);
73
+
74
+ #ifdef __cplusplus
75
+ }
76
+ #endif
77
+ #endif
@@ -0,0 +1,51 @@
1
+ // This file is part of the "libsmatrix" project
2
+ // (c) 2011-2013 Paul Asmuth <paul@paulasmuth.com>
3
+ //
4
+ // Licensed under the MIT License (the "License"); you may not use this
5
+ // file except in compliance with the License. You may obtain a copy of
6
+ // the License at: http://opensource.org/licenses/MIT
7
+
8
+ #ifndef SMATRIX_PRIVATE_H
9
+ #define SMATRIX_PRIVATE_H
10
+
11
+ void smatrix_fcreate(smatrix_t* self);
12
+ void smatrix_fload(smatrix_t* self);
13
+ void smatrix_lookup(smatrix_t* self, smatrix_ref_t* ref, uint32_t x, uint32_t y, int write);
14
+ void smatrix_decref(smatrix_t* self, smatrix_ref_t* ref);
15
+ void* smatrix_malloc(smatrix_t* self, uint64_t bytes);
16
+ void smatrix_mfree(smatrix_t* self, uint64_t bytes);
17
+ uint64_t smatrix_falloc(smatrix_t* self, uint64_t bytes);
18
+ void smatrix_ffree(smatrix_t* self, uint64_t fpos, uint64_t bytes);
19
+ void smatrix_write(smatrix_t* self, uint64_t fpos, char* data, uint64_t bytes);
20
+ void smatrix_rmap_init(smatrix_t* self, smatrix_rmap_t* rmap, uint32_t size);
21
+ smatrix_rmap_slot_t* smatrix_rmap_probe(smatrix_rmap_t* rmap, uint32_t key);
22
+ smatrix_rmap_slot_t* smatrix_rmap_insert(smatrix_t* self, smatrix_rmap_t* rmap, uint32_t key);
23
+ void smatrix_rmap_resize(smatrix_t* self, smatrix_rmap_t* rmap);
24
+ void smatrix_rmap_load(smatrix_t* self, smatrix_rmap_t* rmap);
25
+ void smatrix_rmap_write_batch(smatrix_t* self, smatrix_rmap_t* rmap, int full);
26
+ void smatrix_rmap_write_slot(smatrix_t* self, smatrix_rmap_t* rmap, smatrix_rmap_slot_t* slot);
27
+ void smatrix_rmap_swap(smatrix_t* self, smatrix_rmap_t* rmap);
28
+ void smatrix_rmap_free(smatrix_t* self, smatrix_rmap_t* rmap);
29
+ void smatrix_rmap_sync_defer(smatrix_t* self, smatrix_rmap_t* rmap);
30
+ void smatrix_rmap_sync(smatrix_t* self, smatrix_rmap_t* rmap);
31
+ void smatrix_cmap_init(smatrix_t* self);
32
+ smatrix_rmap_t* smatrix_cmap_lookup(smatrix_t* self, smatrix_cmap_t* cmap, uint32_t key, int create);
33
+ smatrix_cmap_slot_t* smatrix_cmap_probe(smatrix_cmap_t* cmap, uint32_t key);
34
+ smatrix_cmap_slot_t* smatrix_cmap_insert(smatrix_t* self, smatrix_cmap_t* cmap, uint32_t key);
35
+ void smatrix_cmap_resize(smatrix_t* self, smatrix_cmap_t* cmap);
36
+ void smatrix_cmap_free(smatrix_t* self, smatrix_cmap_t* cmap);
37
+ uint64_t smatrix_cmap_falloc(smatrix_t* self, smatrix_cmap_t* cmap);
38
+ void smatrix_cmap_mkblock(smatrix_t* self, smatrix_cmap_t* cmap);
39
+ void smatrix_cmap_write(smatrix_t* self, smatrix_rmap_t* rmap);
40
+ void smatrix_cmap_load(smatrix_t* self, uint64_t head_fpos);
41
+ void smatrix_lock_getmutex(smatrix_lock_t* lock);
42
+ void smatrix_lock_dropmutex(smatrix_lock_t* lock);
43
+ void smatrix_lock_release(smatrix_lock_t* lock);
44
+ void smatrix_lock_incref(smatrix_lock_t* lock);
45
+ void smatrix_lock_decref(smatrix_lock_t* lock);
46
+ void smatrix_error(const char* msg);
47
+ void smatrix_ioqueue_add(smatrix_t* self, smatrix_rmap_t* rmap);
48
+ smatrix_rmap_t* smatrix_ioqueue_pop(smatrix_t* self);
49
+ void* smatrix_io(void* self);
50
+
51
+ #endif
@@ -0,0 +1,178 @@
1
+ /**
2
+ * This file is part of the "libsmatrix" project
3
+ * (c) 2011-2013 Paul Asmuth <paul@paulasmuth.com>
4
+ *
5
+ * Licensed under the MIT License (the "License"); you may not use this
6
+ * file except in compliance with the License. You may obtain a copy of
7
+ * the License at: http://opensource.org/licenses/MIT
8
+ */
9
+ #include <stdlib.h>
10
+ #include <ruby/config.h>
11
+ #include <ruby/ruby.h>
12
+ #include "smatrix.h"
13
+ #include "smatrix_ruby.h"
14
+
15
+ void smatrix_rb_gethandle(VALUE self, smatrix_t** handle) {
16
+ VALUE handle_wrapped = rb_iv_get(self, "@handle");
17
+
18
+ if (rb_type(handle_wrapped) != RUBY_T_DATA) {
19
+ rb_raise(rb_eTypeError, "smatrix @handle is of the wrong type, something went horribly wrong :(");
20
+ return;
21
+ }
22
+
23
+ Data_Get_Struct(handle_wrapped, smatrix_t, *handle);
24
+ }
25
+
26
+ VALUE smatrix_rb_initialize(VALUE self, VALUE filename) {
27
+ smatrix_t* smatrix = NULL;
28
+ VALUE smatrix_handle;
29
+
30
+ switch (rb_type(filename)) {
31
+
32
+ case RUBY_T_STRING:
33
+ smatrix = smatrix_open(RSTRING_PTR(filename));
34
+ break;
35
+
36
+ case RUBY_T_NIL:
37
+ smatrix = smatrix_open(NULL);
38
+ break;
39
+
40
+ default:
41
+ rb_raise(rb_eTypeError, "first argument (filename) must be nil or a string");
42
+ break;
43
+
44
+ }
45
+
46
+ if (smatrix) {
47
+ smatrix_handle = Data_Wrap_Struct(rb_cObject, NULL, smatrix_rb_free, smatrix);
48
+ rb_iv_set(self, "@handle", smatrix_handle);
49
+ }
50
+
51
+ return self;
52
+ }
53
+
54
+ VALUE smatrix_rb_get(VALUE self, VALUE x, VALUE y) {
55
+ smatrix_t* smatrix = NULL;
56
+ smatrix_rb_gethandle(self, &smatrix);
57
+
58
+ if (!smatrix) {
59
+ rb_raise(rb_eTypeError, "smatrix @handle is Nil, something went horribly wrong :(");
60
+ return Qnil;
61
+ }
62
+
63
+ if (rb_type(x) != RUBY_T_FIXNUM) {
64
+ rb_raise(rb_eTypeError, "first argument (x) must be a Fixnum");
65
+ return Qnil;
66
+ }
67
+
68
+ if (rb_type(y) != RUBY_T_FIXNUM) {
69
+ rb_raise(rb_eTypeError, "second argument (y) must be a Fixnum");
70
+ return Qnil;
71
+ }
72
+
73
+ return INT2NUM(smatrix_get(smatrix, NUM2INT(x), NUM2INT(y)));
74
+ }
75
+
76
+ VALUE smatrix_rb_set(VALUE self, VALUE x, VALUE y, VALUE value) {
77
+ smatrix_t* smatrix = NULL;
78
+ smatrix_rb_gethandle(self, &smatrix);
79
+
80
+ if (!smatrix) {
81
+ rb_raise(rb_eTypeError, "smatrix @handle is Nil, something is very bad :'(");
82
+ return Qnil;
83
+ }
84
+
85
+ if (rb_type(x) != RUBY_T_FIXNUM) {
86
+ rb_raise(rb_eTypeError, "first argument (x) must be a Fixnum");
87
+ return Qnil;
88
+ }
89
+
90
+ if (rb_type(y) != RUBY_T_FIXNUM) {
91
+ rb_raise(rb_eTypeError, "second argument (y) must be a Fixnum");
92
+ return Qnil;
93
+ }
94
+
95
+ if (rb_type(value) != RUBY_T_FIXNUM) {
96
+ rb_raise(rb_eTypeError, "third argument must be a Fixnum");
97
+ return Qnil;
98
+ }
99
+
100
+ return INT2NUM(smatrix_set(smatrix, NUM2INT(x), NUM2INT(y), NUM2INT(value)));
101
+ }
102
+
103
+ VALUE smatrix_rb_incr(VALUE self, VALUE x, VALUE y, VALUE value) {
104
+ smatrix_t* smatrix = NULL;
105
+ smatrix_rb_gethandle(self, &smatrix);
106
+
107
+ if (!smatrix) {
108
+ rb_raise(rb_eTypeError, "smatrix @handle is Nil, something is very bad :'(");
109
+ return Qnil;
110
+ }
111
+
112
+ if (rb_type(x) != RUBY_T_FIXNUM) {
113
+ rb_raise(rb_eTypeError, "first argument (x) must be a Fixnum");
114
+ return Qnil;
115
+ }
116
+
117
+ if (rb_type(y) != RUBY_T_FIXNUM) {
118
+ rb_raise(rb_eTypeError, "second argument (y) must be a Fixnum");
119
+ return Qnil;
120
+ }
121
+
122
+ if (rb_type(value) != RUBY_T_FIXNUM) {
123
+ rb_raise(rb_eTypeError, "third argument must be a Fixnum");
124
+ return Qnil;
125
+ }
126
+
127
+ return INT2NUM(smatrix_incr(smatrix, NUM2INT(x), NUM2INT(y), NUM2INT(value)));
128
+ }
129
+
130
+ VALUE smatrix_rb_decr(VALUE self, VALUE x, VALUE y, VALUE value) {
131
+ smatrix_t* smatrix = NULL;
132
+ smatrix_rb_gethandle(self, &smatrix);
133
+
134
+ if (!smatrix) {
135
+ rb_raise(rb_eTypeError, "smatrix @handle is Nil, something is very bad :'(");
136
+ return Qnil;
137
+ }
138
+
139
+ if (rb_type(x) != RUBY_T_FIXNUM) {
140
+ rb_raise(rb_eTypeError, "first argument (x) must be a Fixnum");
141
+ return Qnil;
142
+ }
143
+
144
+ if (rb_type(y) != RUBY_T_FIXNUM) {
145
+ rb_raise(rb_eTypeError, "second argument (y) must be a Fixnum");
146
+ return Qnil;
147
+ }
148
+
149
+ if (rb_type(value) != RUBY_T_FIXNUM) {
150
+ rb_raise(rb_eTypeError, "third argument must be a Fixnum");
151
+ return Qnil;
152
+ }
153
+
154
+ return INT2NUM(smatrix_decr(smatrix, NUM2INT(x), NUM2INT(y), NUM2INT(value)));
155
+ }
156
+
157
+ void smatrix_rb_free(smatrix_t* smatrix) {
158
+ if (!smatrix) {
159
+ rb_raise(rb_eTypeError, "smatrix @handle is Nil, something is very bad :'(");
160
+ return;
161
+ }
162
+
163
+ smatrix_close(smatrix);
164
+ }
165
+
166
+ void Init_smatrix() {
167
+ VALUE klass = rb_define_class("SparseMatrix", rb_cObject);
168
+
169
+ rb_define_method(klass, "initialize", smatrix_rb_initialize, 1);
170
+ rb_define_method(klass, "get", smatrix_rb_get, 2);
171
+ rb_define_method(klass, "set", smatrix_rb_set, 3);
172
+ rb_define_method(klass, "incr", smatrix_rb_incr, 3);
173
+ rb_define_method(klass, "decr", smatrix_rb_decr, 3);
174
+ }
175
+
176
+ void Init_smatrix_ruby() {
177
+ Init_smatrix();
178
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * This file is part of the "libsmatrix" project
3
+ * (c) 2011-2013 Paul Asmuth <paul@paulasmuth.com>
4
+ *
5
+ * Licensed under the MIT License (the "License"); you may not use this
6
+ * file except in compliance with the License. You may obtain a copy of
7
+ * the License at: http://opensource.org/licenses/MIT
8
+ */
9
+ #include <stdlib.h>
10
+ #include "smatrix.h"
11
+
12
+ #ifndef SMATRIX_RUBY_H
13
+ #define SMATRIX_RUBY_H
14
+
15
+ #ifndef RUBY_T_STRING
16
+ #define RUBY_T_STRING T_STRING
17
+ #endif
18
+
19
+ void smatrix_rb_gethandle(VALUE self, smatrix_t** handle);
20
+ VALUE smatrix_rb_get(VALUE self, VALUE x, VALUE y);
21
+ VALUE smatrix_rb_initialize(VALUE self, VALUE filename);
22
+ VALUE smatrix_rb_incr(VALUE self, VALUE x, VALUE y, VALUE value);
23
+ VALUE smatrix_rb_decr(VALUE self, VALUE x, VALUE y, VALUE value);
24
+ VALUE smatrix_rb_set(VALUE self, VALUE x, VALUE y, VALUE value);
25
+ void smatrix_rb_free(smatrix_t* smatrix);
26
+ void Init_smatrix_ruby();
27
+ void Init_smatrix();
28
+
29
+ #endif
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libsmatrix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul Asmuth
8
+ - Amir Friedman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 2.8.0
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 2.8.0
28
+ description: A thread-safe two dimensional sparse matrix data structure with C, Java
29
+ and Ruby bindings. It was created to make loading and accessing medium sized (10GB+)
30
+ matrices in boxed languages like Java/Scala or Ruby easier.
31
+ email:
32
+ - paul@paulasmuth.com
33
+ - amirf@null.co.il
34
+ executables: []
35
+ extensions:
36
+ - src/ruby/extconf.rb
37
+ extra_rdoc_files: []
38
+ files:
39
+ - Makefile
40
+ - README.md
41
+ - examples/.gitignore
42
+ - examples/CFRecommender.java
43
+ - examples/cf_recommender.c
44
+ - examples/smatrix_example.c
45
+ - src/Makefile
46
+ - src/Makefile.in
47
+ - src/java/Makefile
48
+ - src/java/com/paulasmuth/libsmatrix/SparseMatrix.java
49
+ - src/java/pom.xml
50
+ - src/java/test/TestSparseMatrix.java
51
+ - src/ruby/.gitignore
52
+ - src/ruby/Makefile
53
+ - src/ruby/extconf.rb
54
+ - src/ruby/libsmatrix.gemspec
55
+ - src/ruby/libsmatrix.rb
56
+ - src/smatrix.c
57
+ - src/smatrix.h
58
+ - src/smatrix_benchmark.c
59
+ - src/smatrix_jni.c
60
+ - src/smatrix_jni.h
61
+ - src/smatrix_private.h
62
+ - src/smatrix_ruby.c
63
+ - src/smatrix_ruby.h
64
+ homepage: http://github.com/paulasmuth/libsmatrix
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - src/ruby/
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.1.1
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: A thread-safe two dimensional sparse matrix data structure with C, Java and
88
+ Ruby bindings.
89
+ test_files: []
90
+ has_rdoc: