liblinear-ruby-swig 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +2 -0
- data/COPYING +24 -0
- data/History.txt +5 -0
- data/Manifest.txt +20 -0
- data/README.rdoc +79 -0
- data/Rakefile +48 -0
- data/ext/blas.h +25 -0
- data/ext/blasp.h +430 -0
- data/ext/daxpy.c +49 -0
- data/ext/ddot.c +50 -0
- data/ext/dnrm2.c +62 -0
- data/ext/dscal.c +44 -0
- data/ext/extconf.rb +17 -0
- data/ext/liblinear_wrap.cxx +4562 -0
- data/ext/linear.cpp +2096 -0
- data/ext/linear.h +70 -0
- data/ext/tron.cpp +235 -0
- data/ext/tron.h +34 -0
- data/lib/linear.rb +357 -0
- data/lib/linear_cv.rb +36 -0
- metadata +98 -0
data/ext/ddot.c
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#include "blas.h"
|
2
|
+
|
3
|
+
double ddot_(int *n, double *sx, int *incx, double *sy, int *incy)
|
4
|
+
{
|
5
|
+
long int i, m, nn, iincx, iincy;
|
6
|
+
double stemp;
|
7
|
+
long int ix, iy;
|
8
|
+
|
9
|
+
/* forms the dot product of two vectors.
|
10
|
+
uses unrolled loops for increments equal to one.
|
11
|
+
jack dongarra, linpack, 3/11/78.
|
12
|
+
modified 12/3/93, array(1) declarations changed to array(*) */
|
13
|
+
|
14
|
+
/* Dereference inputs */
|
15
|
+
nn = *n;
|
16
|
+
iincx = *incx;
|
17
|
+
iincy = *incy;
|
18
|
+
|
19
|
+
stemp = 0.0;
|
20
|
+
if (nn > 0)
|
21
|
+
{
|
22
|
+
if (iincx == 1 && iincy == 1) /* code for both increments equal to 1 */
|
23
|
+
{
|
24
|
+
m = nn-4;
|
25
|
+
for (i = 0; i < m; i += 5)
|
26
|
+
stemp += sx[i] * sy[i] + sx[i+1] * sy[i+1] + sx[i+2] * sy[i+2] +
|
27
|
+
sx[i+3] * sy[i+3] + sx[i+4] * sy[i+4];
|
28
|
+
|
29
|
+
for ( ; i < nn; i++) /* clean-up loop */
|
30
|
+
stemp += sx[i] * sy[i];
|
31
|
+
}
|
32
|
+
else /* code for unequal increments or equal increments not equal to 1 */
|
33
|
+
{
|
34
|
+
ix = 0;
|
35
|
+
iy = 0;
|
36
|
+
if (iincx < 0)
|
37
|
+
ix = (1 - nn) * iincx;
|
38
|
+
if (iincy < 0)
|
39
|
+
iy = (1 - nn) * iincy;
|
40
|
+
for (i = 0; i < nn; i++)
|
41
|
+
{
|
42
|
+
stemp += sx[ix] * sy[iy];
|
43
|
+
ix += iincx;
|
44
|
+
iy += iincy;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
return stemp;
|
50
|
+
} /* ddot_ */
|
data/ext/dnrm2.c
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#include <math.h> /* Needed for fabs() and sqrt() */
|
2
|
+
#include "blas.h"
|
3
|
+
|
4
|
+
double dnrm2_(int *n, double *x, int *incx)
|
5
|
+
{
|
6
|
+
long int ix, nn, iincx;
|
7
|
+
double norm, scale, absxi, ssq, temp;
|
8
|
+
|
9
|
+
/* DNRM2 returns the euclidean norm of a vector via the function
|
10
|
+
name, so that
|
11
|
+
|
12
|
+
DNRM2 := sqrt( x'*x )
|
13
|
+
|
14
|
+
-- This version written on 25-October-1982.
|
15
|
+
Modified on 14-October-1993 to inline the call to SLASSQ.
|
16
|
+
Sven Hammarling, Nag Ltd. */
|
17
|
+
|
18
|
+
/* Dereference inputs */
|
19
|
+
nn = *n;
|
20
|
+
iincx = *incx;
|
21
|
+
|
22
|
+
if( nn > 0 && iincx > 0 )
|
23
|
+
{
|
24
|
+
if (nn == 1)
|
25
|
+
{
|
26
|
+
norm = fabs(x[0]);
|
27
|
+
}
|
28
|
+
else
|
29
|
+
{
|
30
|
+
scale = 0.0;
|
31
|
+
ssq = 1.0;
|
32
|
+
|
33
|
+
/* The following loop is equivalent to this call to the LAPACK
|
34
|
+
auxiliary routine: CALL SLASSQ( N, X, INCX, SCALE, SSQ ) */
|
35
|
+
|
36
|
+
for (ix=(nn-1)*iincx; ix>=0; ix-=iincx)
|
37
|
+
{
|
38
|
+
if (x[ix] != 0.0)
|
39
|
+
{
|
40
|
+
absxi = fabs(x[ix]);
|
41
|
+
if (scale < absxi)
|
42
|
+
{
|
43
|
+
temp = scale / absxi;
|
44
|
+
ssq = ssq * (temp * temp) + 1.0;
|
45
|
+
scale = absxi;
|
46
|
+
}
|
47
|
+
else
|
48
|
+
{
|
49
|
+
temp = absxi / scale;
|
50
|
+
ssq += temp * temp;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
norm = scale * sqrt(ssq);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
else
|
58
|
+
norm = 0.0;
|
59
|
+
|
60
|
+
return norm;
|
61
|
+
|
62
|
+
} /* dnrm2_ */
|
data/ext/dscal.c
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#include "blas.h"
|
2
|
+
|
3
|
+
int dscal_(int *n, double *sa, double *sx, int *incx)
|
4
|
+
{
|
5
|
+
long int i, m, nincx, nn, iincx;
|
6
|
+
double ssa;
|
7
|
+
|
8
|
+
/* scales a vector by a constant.
|
9
|
+
uses unrolled loops for increment equal to 1.
|
10
|
+
jack dongarra, linpack, 3/11/78.
|
11
|
+
modified 3/93 to return if incx .le. 0.
|
12
|
+
modified 12/3/93, array(1) declarations changed to array(*) */
|
13
|
+
|
14
|
+
/* Dereference inputs */
|
15
|
+
nn = *n;
|
16
|
+
iincx = *incx;
|
17
|
+
ssa = *sa;
|
18
|
+
|
19
|
+
if (nn > 0 && iincx > 0)
|
20
|
+
{
|
21
|
+
if (iincx == 1) /* code for increment equal to 1 */
|
22
|
+
{
|
23
|
+
m = nn-4;
|
24
|
+
for (i = 0; i < m; i += 5)
|
25
|
+
{
|
26
|
+
sx[i] = ssa * sx[i];
|
27
|
+
sx[i+1] = ssa * sx[i+1];
|
28
|
+
sx[i+2] = ssa * sx[i+2];
|
29
|
+
sx[i+3] = ssa * sx[i+3];
|
30
|
+
sx[i+4] = ssa * sx[i+4];
|
31
|
+
}
|
32
|
+
for ( ; i < nn; ++i) /* clean-up loop */
|
33
|
+
sx[i] = ssa * sx[i];
|
34
|
+
}
|
35
|
+
else /* code for increment not equal to 1 */
|
36
|
+
{
|
37
|
+
nincx = nn * iincx;
|
38
|
+
for (i = 0; i < nincx; i += iincx)
|
39
|
+
sx[i] = ssa * sx[i];
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
return 0;
|
44
|
+
} /* dscal_ */
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
CONFIG["LDSHARED"] = "g++ -shared"
|
3
|
+
$CFLAGS = "#{ENV['CFLAGS']} -Wall -O3 "
|
4
|
+
if CONFIG["MAJOR"].to_i >= 1 && CONFIG["MINOR"].to_i >= 8
|
5
|
+
$CFLAGS << " -DHAVE_DEFINE_ALLOC_FUNCTION"
|
6
|
+
end
|
7
|
+
create_makefile('liblinear-ruby-swig/liblinear')
|
8
|
+
=begin
|
9
|
+
extra_mk = <<-eos
|
10
|
+
|
11
|
+
eos
|
12
|
+
|
13
|
+
File.open("Makefile", "a") do |mf|
|
14
|
+
mf.puts extra_mk
|
15
|
+
end
|
16
|
+
=end
|
17
|
+
|