Commit acbc053
authored
Add zero-dependency native C extension for LSI acceleration (#89)
* feat: add zero-dependency native C extension for LSI acceleration
Replace the rb-gsl dependency with a self-contained C extension that
implements Vector, Matrix, and Jacobi SVD operations. This eliminates
the need for users to install external libraries while providing
significant performance improvements.
The native extension provides 5-50x speedup over pure Ruby, with the
SVD-heavy build_index operation showing up to 384x improvement on
larger document sets. The implementation ports the existing Ruby
Jacobi SVD algorithm to C, ensuring consistent results.
Key changes:
- Add ext/classifier/ with ~850 lines of C code
- Implement Classifier::Linalg::Vector and Matrix classes
- Port Jacobi SVD from Ruby to C
- Auto-detect backend: native extension > pure Ruby fallback
- Remove GSL-related code and dependencies
- Update benchmarks to compare native C vs pure Ruby
Closes #87
* chore: add native extension build artifacts to gitignore
* style: fix RuboCop offenses in tests and config files
Apply RuboCop autocorrections and add necessary inline disables:
- Use %i symbol array syntax in Rakefile
- Add empty lines before assertion methods per Minitest style
- Convert float assert_equal to assert_in_delta for precision
- Disable Style/GlobalVars for $CFLAGS (required for mkmf)
- Disable Style/MapIntoArray in test intentionally testing each
* refactor: address PR review feedback
- Use SVD_CONVERGENCE_THRESHOLD constant instead of magic number
- Clarify comment about undef_method vs override behavior1 parent 2fb18f5 commit acbc053
File tree
19 files changed
+1401
-174
lines changed- benchmark
- ext/classifier
- lib/classifier
- extensions
- lsi
- test
- linalg
- lsi
19 files changed
+1401
-174
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
8 | 17 | | |
9 | 18 | | |
10 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
21 | | - | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
24 | 31 | | |
25 | 32 | | |
26 | 33 | | |
| |||
39 | 46 | | |
40 | 47 | | |
41 | 48 | | |
42 | | - | |
| 49 | + | |
43 | 50 | | |
44 | 51 | | |
45 | 52 | | |
| |||
49 | 56 | | |
50 | 57 | | |
51 | 58 | | |
52 | | - | |
| 59 | + | |
53 | 60 | | |
54 | 61 | | |
55 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
56 | 68 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 69 | + | |
| 70 | + | |
61 | 71 | | |
62 | 72 | | |
63 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
137 | 139 | | |
138 | 140 | | |
139 | 141 | | |
| 142 | + | |
140 | 143 | | |
141 | 144 | | |
142 | 145 | | |
| |||
145 | 148 | | |
146 | 149 | | |
147 | 150 | | |
148 | | - | |
| 151 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 43 | + | |
47 | 44 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
59 | 48 | | |
60 | | - | |
61 | 49 | | |
62 | | - | |
63 | | - | |
| 50 | + | |
64 | 51 | | |
65 | 52 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 53 | + | |
73 | 54 | | |
74 | | - | |
75 | 55 | | |
76 | | - | |
| 56 | + | |
77 | 57 | | |
78 | 58 | | |
79 | | - | |
| 59 | + | |
80 | 60 | | |
81 | 61 | | |
82 | 62 | | |
| |||
181 | 161 | | |
182 | 162 | | |
183 | 163 | | |
184 | | - | |
| 164 | + | |
185 | 165 | | |
186 | | - | |
| 166 | + | |
187 | 167 | | |
188 | 168 | | |
189 | 169 | | |
190 | | - | |
191 | | - | |
192 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
193 | 174 | | |
194 | 175 | | |
195 | | - | |
| 176 | + | |
196 | 177 | | |
197 | 178 | | |
198 | | - | |
| 179 | + | |
199 | 180 | | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
204 | 185 | | |
205 | | - | |
| 186 | + | |
206 | 187 | | |
207 | 188 | | |
208 | 189 | | |
209 | 190 | | |
210 | 191 | | |
211 | 192 | | |
212 | 193 | | |
213 | | - | |
| 194 | + | |
214 | 195 | | |
215 | 196 | | |
216 | 197 | | |
| |||
221 | 202 | | |
222 | 203 | | |
223 | 204 | | |
| 205 | + | |
224 | 206 | | |
225 | 207 | | |
226 | 208 | | |
227 | 209 | | |
228 | 210 | | |
229 | | - | |
| 211 | + | |
230 | 212 | | |
231 | 213 | | |
232 | | - | |
| 214 | + | |
233 | 215 | | |
234 | 216 | | |
235 | 217 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
5 | 17 | | |
6 | | - | |
| 18 | + | |
7 | 19 | | |
8 | 20 | | |
9 | 21 | | |
| |||
0 commit comments