numo-linalg 0.0.1
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 +7 -0
- data/Gemfile +4 -0
- data/README.md +80 -0
- data/Rakefile +18 -0
- data/ext/numo/linalg/blas/blas.c +352 -0
- data/ext/numo/linalg/blas/cblas.h +575 -0
- data/ext/numo/linalg/blas/cblas_t.h +563 -0
- data/ext/numo/linalg/blas/depend.erb +23 -0
- data/ext/numo/linalg/blas/extconf.rb +67 -0
- data/ext/numo/linalg/blas/gen/cogen.rb +72 -0
- data/ext/numo/linalg/blas/gen/decl.rb +203 -0
- data/ext/numo/linalg/blas/gen/desc.rb +8138 -0
- data/ext/numo/linalg/blas/gen/erbpp2.rb +339 -0
- data/ext/numo/linalg/blas/gen/replace_cblas_h.rb +27 -0
- data/ext/numo/linalg/blas/gen/spec.rb +93 -0
- data/ext/numo/linalg/blas/numo_blas.h +41 -0
- data/ext/numo/linalg/blas/tmpl/axpy.c +75 -0
- data/ext/numo/linalg/blas/tmpl/copy.c +57 -0
- data/ext/numo/linalg/blas/tmpl/def_c.c +3 -0
- data/ext/numo/linalg/blas/tmpl/def_d.c +3 -0
- data/ext/numo/linalg/blas/tmpl/def_s.c +3 -0
- data/ext/numo/linalg/blas/tmpl/def_z.c +3 -0
- data/ext/numo/linalg/blas/tmpl/dot.c +68 -0
- data/ext/numo/linalg/blas/tmpl/ger.c +114 -0
- data/ext/numo/linalg/blas/tmpl/init_class.c +20 -0
- data/ext/numo/linalg/blas/tmpl/init_module.c +12 -0
- data/ext/numo/linalg/blas/tmpl/lib.c +40 -0
- data/ext/numo/linalg/blas/tmpl/mm.c +214 -0
- data/ext/numo/linalg/blas/tmpl/module.c +9 -0
- data/ext/numo/linalg/blas/tmpl/mv.c +194 -0
- data/ext/numo/linalg/blas/tmpl/nrm2.c +79 -0
- data/ext/numo/linalg/blas/tmpl/rot.c +65 -0
- data/ext/numo/linalg/blas/tmpl/rotm.c +82 -0
- data/ext/numo/linalg/blas/tmpl/scal.c +69 -0
- data/ext/numo/linalg/blas/tmpl/sdsdot.c +77 -0
- data/ext/numo/linalg/blas/tmpl/set_prefix.c +16 -0
- data/ext/numo/linalg/blas/tmpl/swap.c +57 -0
- data/ext/numo/linalg/blas/tmpl/syr.c +102 -0
- data/ext/numo/linalg/blas/tmpl/syr2.c +110 -0
- data/ext/numo/linalg/blas/tmpl/syr2k.c +129 -0
- data/ext/numo/linalg/blas/tmpl/syrk.c +132 -0
- data/ext/numo/linalg/lapack/depend.erb +23 -0
- data/ext/numo/linalg/lapack/extconf.rb +45 -0
- data/ext/numo/linalg/lapack/gen/cogen.rb +74 -0
- data/ext/numo/linalg/lapack/gen/desc.rb +151278 -0
- data/ext/numo/linalg/lapack/gen/replace_lapacke_h.rb +32 -0
- data/ext/numo/linalg/lapack/gen/spec.rb +104 -0
- data/ext/numo/linalg/lapack/lapack.c +387 -0
- data/ext/numo/linalg/lapack/lapacke.h +16425 -0
- data/ext/numo/linalg/lapack/lapacke_config.h +119 -0
- data/ext/numo/linalg/lapack/lapacke_mangling.h +17 -0
- data/ext/numo/linalg/lapack/lapacke_t.h +10550 -0
- data/ext/numo/linalg/lapack/numo_lapack.h +42 -0
- data/ext/numo/linalg/lapack/tmpl/def_c.c +3 -0
- data/ext/numo/linalg/lapack/tmpl/def_d.c +7 -0
- data/ext/numo/linalg/lapack/tmpl/def_s.c +7 -0
- data/ext/numo/linalg/lapack/tmpl/def_z.c +3 -0
- data/ext/numo/linalg/lapack/tmpl/fact.c +179 -0
- data/ext/numo/linalg/lapack/tmpl/geev.c +123 -0
- data/ext/numo/linalg/lapack/tmpl/gels.c +232 -0
- data/ext/numo/linalg/lapack/tmpl/gesv.c +149 -0
- data/ext/numo/linalg/lapack/tmpl/gesvd.c +189 -0
- data/ext/numo/linalg/lapack/tmpl/ggev.c +138 -0
- data/ext/numo/linalg/lapack/tmpl/gqr.c +121 -0
- data/ext/numo/linalg/lapack/tmpl/init_class.c +20 -0
- data/ext/numo/linalg/lapack/tmpl/init_module.c +12 -0
- data/ext/numo/linalg/lapack/tmpl/lange.c +79 -0
- data/ext/numo/linalg/lapack/tmpl/lib.c +40 -0
- data/ext/numo/linalg/lapack/tmpl/module.c +9 -0
- data/ext/numo/linalg/lapack/tmpl/syev.c +91 -0
- data/ext/numo/linalg/lapack/tmpl/sygv.c +104 -0
- data/ext/numo/linalg/lapack/tmpl/trf.c +276 -0
- data/ext/numo/linalg/numo_linalg.h +115 -0
- data/lib/numo/linalg.rb +3 -0
- data/lib/numo/linalg/function.rb +1008 -0
- data/lib/numo/linalg/linalg.rb +7 -0
- data/lib/numo/linalg/loader.rb +174 -0
- data/lib/numo/linalg/use/atlas.rb +3 -0
- data/lib/numo/linalg/use/lapack.rb +3 -0
- data/lib/numo/linalg/use/mkl.rb +3 -0
- data/lib/numo/linalg/use/openblas.rb +3 -0
- data/lib/numo/linalg/version.rb +5 -0
- data/numo-linalg.gemspec +26 -0
- data/spec/lapack_spec.rb +13 -0
- metadata +172 -0
@@ -0,0 +1,110 @@
|
|
1
|
+
#define args_t <%=name%>_args_t
|
2
|
+
|
3
|
+
typedef struct {
|
4
|
+
enum CBLAS_ORDER order;
|
5
|
+
enum CBLAS_UPLO uplo;
|
6
|
+
dtype alpha;
|
7
|
+
} args_t;
|
8
|
+
|
9
|
+
#define func_p <%=func_name%>_p
|
10
|
+
|
11
|
+
static <%=func_name%>_t func_p = 0;
|
12
|
+
|
13
|
+
static void
|
14
|
+
<%=c_iter%>(na_loop_t *const lp)
|
15
|
+
{
|
16
|
+
dtype *a;
|
17
|
+
char *p1, *p2;
|
18
|
+
ssize_t s1, s2;
|
19
|
+
args_t *g;
|
20
|
+
blasint n, lda;
|
21
|
+
|
22
|
+
INIT_PTR(lp,0,p1,s1);
|
23
|
+
INIT_PTR(lp,1,p2,s2);
|
24
|
+
a = (dtype*)NDL_PTR(lp,2);
|
25
|
+
g = (args_t*)(lp->opt_ptr);
|
26
|
+
|
27
|
+
n = NDL_SHAPE(lp,0)[0];
|
28
|
+
lda = NDL_STEP(lp,2) / sizeof(dtype);
|
29
|
+
|
30
|
+
(*func_p)(g->order, g->uplo, n,
|
31
|
+
DP(g->alpha), (dtype*)p1, s1/sizeof(dtype),
|
32
|
+
(dtype*)p2, s2/sizeof(dtype), a, lda);
|
33
|
+
}
|
34
|
+
|
35
|
+
/*<%
|
36
|
+
params = [
|
37
|
+
vec("x"),
|
38
|
+
vec("y"),
|
39
|
+
mat("a",:inplace),
|
40
|
+
opt("alpha"),
|
41
|
+
opt("uplo"),
|
42
|
+
opt("order")
|
43
|
+
].select{|x| x}.join("\n ")
|
44
|
+
%>
|
45
|
+
@overload <%=name%>( x, y, [a, alpha:1, uplo:'U', order:'R'] )
|
46
|
+
<%=params%>
|
47
|
+
@return [<%=class_name%>] returns a.
|
48
|
+
|
49
|
+
<%=description%>
|
50
|
+
|
51
|
+
*/
|
52
|
+
static VALUE
|
53
|
+
<%=c_func(-1)%>(int argc, VALUE const argv[], VALUE UNUSED(mod))
|
54
|
+
{
|
55
|
+
VALUE ans;
|
56
|
+
VALUE x, y, a, alpha;
|
57
|
+
narray_t *na1, *na2, *na3;
|
58
|
+
blasint nx, ny, na;
|
59
|
+
size_t shape[2];
|
60
|
+
ndfunc_arg_in_t ain[4] = {{cT,1},{cT,1},{OVERWRITE,2},{sym_init,0}};
|
61
|
+
ndfunc_arg_out_t aout[1] = {{cT,2,shape}};
|
62
|
+
ndfunc_t ndf = {<%=c_iter%>, NO_LOOP, 3, 0, ain, aout};
|
63
|
+
|
64
|
+
args_t g;
|
65
|
+
VALUE kw_hash = Qnil;
|
66
|
+
ID kw_table[3] = {id_alpha,id_order,id_uplo};
|
67
|
+
VALUE opts[3] = {Qundef,Qundef,Qundef};
|
68
|
+
|
69
|
+
CHECK_FUNC(func_p,"<%=func_name%>");
|
70
|
+
|
71
|
+
rb_scan_args(argc, argv, "21:", &x, &y, &a, &kw_hash);
|
72
|
+
rb_get_kwargs(kw_hash, kw_table, 0, 3, opts);
|
73
|
+
alpha = option_value(opts[0],Qnil);
|
74
|
+
g.alpha = RTEST(alpha) ? m_num_to_data(alpha) : m_one;
|
75
|
+
g.order = option_order(opts[1]);
|
76
|
+
g.uplo = option_uplo(opts[2]);
|
77
|
+
|
78
|
+
GetNArray(x,na1);
|
79
|
+
GetNArray(y,na2);
|
80
|
+
CHECK_DIM_GE(na1,1);
|
81
|
+
CHECK_DIM_GE(na2,1);
|
82
|
+
nx = COL_SIZE(na1); // n
|
83
|
+
ny = COL_SIZE(na2); // n
|
84
|
+
CHECK_INT_EQ("nx",nx,"ny",ny);
|
85
|
+
|
86
|
+
if (a == Qnil) { // c is not given.
|
87
|
+
ndf.nout = 1;
|
88
|
+
ain[2] = ain[3];
|
89
|
+
a = INT2FIX(0);
|
90
|
+
shape[0] = shape[1] = nx;
|
91
|
+
} else {
|
92
|
+
COPY_OR_CAST_TO(a,cT);
|
93
|
+
GetNArray(a,na3);
|
94
|
+
CHECK_DIM_GE(na3,2);
|
95
|
+
CHECK_SQUARE("a",na3);
|
96
|
+
na = COL_SIZE(na3); // n (lda)
|
97
|
+
CHECK_SIZE_EQ(na,nx);
|
98
|
+
}
|
99
|
+
|
100
|
+
ans = na_ndloop3(&ndf, &g, 3, x, y, a);
|
101
|
+
|
102
|
+
if (ndf.nout == 1) { // a is not given.
|
103
|
+
return ans;
|
104
|
+
} else {
|
105
|
+
return a;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
#undef func_p
|
110
|
+
#undef args_t
|
@@ -0,0 +1,129 @@
|
|
1
|
+
#define args_t <%=name%>_args_t
|
2
|
+
|
3
|
+
typedef struct {
|
4
|
+
enum CBLAS_ORDER order;
|
5
|
+
enum CBLAS_UPLO uplo;
|
6
|
+
enum CBLAS_TRANSPOSE trans;
|
7
|
+
dtype alpha, beta;
|
8
|
+
blasint n, k;
|
9
|
+
} args_t;
|
10
|
+
|
11
|
+
#define func_p <%=func_name%>_p
|
12
|
+
|
13
|
+
static <%=func_name%>_t func_p = 0;
|
14
|
+
|
15
|
+
static void
|
16
|
+
<%=c_iter%>(na_loop_t *const lp)
|
17
|
+
{
|
18
|
+
dtype *a, *b, *c;
|
19
|
+
blasint lda, ldb, ldc;
|
20
|
+
args_t *g;
|
21
|
+
|
22
|
+
a = (dtype*)NDL_PTR(lp,0);
|
23
|
+
b = (dtype*)NDL_PTR(lp,1);
|
24
|
+
c = (dtype*)NDL_PTR(lp,2);
|
25
|
+
g = (args_t*)(lp->opt_ptr);
|
26
|
+
|
27
|
+
lda = NDL_STEP(lp,0) / sizeof(dtype);
|
28
|
+
ldb = NDL_STEP(lp,1) / sizeof(dtype);
|
29
|
+
ldc = NDL_STEP(lp,2) / sizeof(dtype);
|
30
|
+
|
31
|
+
(*func_p)(g->order, g->uplo, g->trans, g->n, g->k,
|
32
|
+
DP(g->alpha), a, lda, b, ldb, DP(g->beta), c, ldc);
|
33
|
+
}
|
34
|
+
|
35
|
+
/*<%
|
36
|
+
params = [
|
37
|
+
mat("a","n-by-k"),
|
38
|
+
mat("b","n-by-k"),
|
39
|
+
mat("c","n-by-n, optional",:inpace),
|
40
|
+
opt("alpha"),
|
41
|
+
opt("beta"),
|
42
|
+
opt("uplo"),
|
43
|
+
opt("trans"),
|
44
|
+
opt("order")
|
45
|
+
].select{|x| x}.join("\n ")
|
46
|
+
%>
|
47
|
+
@overload <%=name%>( a, b, [c, alpha:1, beta:0, uplo:'U', trans:'N', order:'R'] )
|
48
|
+
<%=params%>
|
49
|
+
@return [<%=class_name%>] returns c.
|
50
|
+
|
51
|
+
<%=description%>
|
52
|
+
|
53
|
+
*/
|
54
|
+
static VALUE
|
55
|
+
<%=c_func(-1)%>(int argc, VALUE const argv[], VALUE UNUSED(mod))
|
56
|
+
{
|
57
|
+
VALUE ans;
|
58
|
+
VALUE a, b, c=Qnil, alpha, beta;
|
59
|
+
narray_t *na1, *na2, *na3;
|
60
|
+
blasint na, ka, kb, nb, nc, tmp;
|
61
|
+
size_t shape[2];
|
62
|
+
ndfunc_arg_in_t ain[4] = {{cT,2},{cT,2},{OVERWRITE,2},{sym_init,0}};
|
63
|
+
ndfunc_arg_out_t aout[1] = {{cT,2,shape}};
|
64
|
+
ndfunc_t ndf = {<%=c_iter%>, NO_LOOP, 3, 0, ain, aout};
|
65
|
+
|
66
|
+
args_t g;
|
67
|
+
VALUE kw_hash = Qnil;
|
68
|
+
ID kw_table[5] = {id_alpha,id_beta,id_order,id_uplo,id_trans};
|
69
|
+
VALUE opts[5] = {Qundef,Qundef,Qundef,Qundef,Qundef};
|
70
|
+
|
71
|
+
CHECK_FUNC(func_p,"<%=func_name%>");
|
72
|
+
|
73
|
+
rb_scan_args(argc, argv, "21:", &a, &b, &c, &kw_hash);
|
74
|
+
rb_get_kwargs(kw_hash, kw_table, 0, 5, opts);
|
75
|
+
alpha = option_value(opts[0],Qnil);
|
76
|
+
g.alpha = RTEST(alpha) ? m_num_to_data(alpha) : m_one;
|
77
|
+
beta = option_value(opts[1],Qnil);
|
78
|
+
g.beta = RTEST(beta) ? m_num_to_data(beta) : m_zero;
|
79
|
+
g.order = option_order(opts[2]);
|
80
|
+
g.uplo = option_uplo(opts[3]);
|
81
|
+
g.trans = option_trans(opts[4]);
|
82
|
+
|
83
|
+
GetNArray(a,na1);
|
84
|
+
GetNArray(b,na2);
|
85
|
+
CHECK_DIM_GE(na1,2);
|
86
|
+
CHECK_DIM_GE(na2,2);
|
87
|
+
|
88
|
+
na = ROW_SIZE(na1); // n
|
89
|
+
ka = COL_SIZE(na1); // k (lda)
|
90
|
+
SWAP_IFCOLTR(g.order, g.trans, na, ka, tmp);
|
91
|
+
|
92
|
+
nb = ROW_SIZE(na2); // n
|
93
|
+
kb = COL_SIZE(na2); // k (ldb)
|
94
|
+
SWAP_IFCOLTR(g.order, g.trans, kb, nb, tmp);
|
95
|
+
CHECK_INT_EQ("na",na,"nb",nb);
|
96
|
+
CHECK_INT_EQ("ka",ka,"kb",kb);
|
97
|
+
g.n = nb;
|
98
|
+
g.k = kb;
|
99
|
+
|
100
|
+
SWAP_IFROW(g.order, na, nb, tmp);
|
101
|
+
|
102
|
+
if (c == Qnil) { // c is not given.
|
103
|
+
ndf.nout = 1;
|
104
|
+
ain[2] = ain[3];
|
105
|
+
c = INT2FIX(0);
|
106
|
+
shape[0] = nb;
|
107
|
+
shape[1] = na;
|
108
|
+
} else {
|
109
|
+
COPY_OR_CAST_TO(c,cT);
|
110
|
+
GetNArray(c,na3);
|
111
|
+
CHECK_DIM_GE(na3,2);
|
112
|
+
nc = ROW_SIZE(na3); // n
|
113
|
+
if (nc < nb) {
|
114
|
+
rb_raise(nary_eShapeError,"nc=%d must be >= nb=%d",nc,nb);
|
115
|
+
}
|
116
|
+
//CHECK_LEADING_GE("ldc",g.ldc,"n",na);
|
117
|
+
}
|
118
|
+
|
119
|
+
ans = na_ndloop3(&ndf, &g, 3, a, b, c);
|
120
|
+
|
121
|
+
if (ndf.nout = 1) { // c is not given.
|
122
|
+
return ans;
|
123
|
+
} else {
|
124
|
+
return c;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
#undef func_p
|
129
|
+
#undef args_t
|
@@ -0,0 +1,132 @@
|
|
1
|
+
/*<%
|
2
|
+
is_he = (/^.he/=~name)
|
3
|
+
stype = is_he ? "rtype" : "dtype"
|
4
|
+
%>*/
|
5
|
+
<% if is_he %>
|
6
|
+
#define P(a) (a)
|
7
|
+
<% else %>
|
8
|
+
#define P(a) DP(a)
|
9
|
+
<% end %>
|
10
|
+
|
11
|
+
#define args_t <%=name%>_args_t
|
12
|
+
|
13
|
+
typedef struct {
|
14
|
+
enum CBLAS_ORDER order;
|
15
|
+
enum CBLAS_UPLO uplo;
|
16
|
+
enum CBLAS_TRANSPOSE trans;
|
17
|
+
<%=stype%> alpha, beta;
|
18
|
+
blasint n, k;
|
19
|
+
} args_t;
|
20
|
+
|
21
|
+
#define func_p <%=func_name%>_p
|
22
|
+
|
23
|
+
static <%=func_name%>_t func_p = 0;
|
24
|
+
|
25
|
+
static void
|
26
|
+
<%=c_iter%>(na_loop_t *const lp)
|
27
|
+
{
|
28
|
+
dtype *a, *c;
|
29
|
+
args_t *g;
|
30
|
+
blasint lda, ldc;
|
31
|
+
|
32
|
+
a = (dtype*)NDL_PTR(lp,0);
|
33
|
+
c = (dtype*)NDL_PTR(lp,1);
|
34
|
+
g = (args_t*)(lp->opt_ptr);
|
35
|
+
|
36
|
+
lda = NDL_STEP(lp,0) / sizeof(dtype);
|
37
|
+
ldc = NDL_STEP(lp,1) / sizeof(dtype);
|
38
|
+
|
39
|
+
(*func_p)(g->order, g->uplo, g->trans, g->n, g->k,
|
40
|
+
P(g->alpha), a, lda, P(g->beta), c, ldc);
|
41
|
+
}
|
42
|
+
|
43
|
+
/*<%
|
44
|
+
params = [
|
45
|
+
mat("a","n-by-k",:inpace),
|
46
|
+
mat("c","n-by-n, optional",:inpace),
|
47
|
+
opt("alpha"),
|
48
|
+
opt("beta"),
|
49
|
+
opt("uplo"),
|
50
|
+
opt("trans"),
|
51
|
+
opt("order")
|
52
|
+
].select{|x| x}.join("\n ")
|
53
|
+
%>
|
54
|
+
@overload <%=name%>( a, [c, alpha:1, beta:0, uplo:'U', trans:'N', order:'R'] )
|
55
|
+
<%=params%>
|
56
|
+
@return [<%=class_name%>] returns c.
|
57
|
+
|
58
|
+
<%=description%>
|
59
|
+
|
60
|
+
*/
|
61
|
+
static VALUE
|
62
|
+
<%=c_func(-1)%>(int argc, VALUE const argv[], VALUE UNUSED(mod))
|
63
|
+
{
|
64
|
+
VALUE ans;
|
65
|
+
VALUE a, c, alpha, beta;
|
66
|
+
narray_t *na1, *na3;
|
67
|
+
blasint na, ka, nc, tmp;
|
68
|
+
size_t shape[2];
|
69
|
+
ndfunc_arg_in_t ain[3] = {{cT,2},{OVERWRITE,2},{sym_init,0}};
|
70
|
+
ndfunc_arg_out_t aout[1] = {{cT,2,shape}};
|
71
|
+
ndfunc_t ndf = {<%=c_iter%>, NO_LOOP, 2, 0, ain, aout};
|
72
|
+
|
73
|
+
args_t g;
|
74
|
+
VALUE kw_hash = Qnil;
|
75
|
+
ID kw_table[5] = {id_alpha,id_beta,id_order,id_uplo,id_trans};
|
76
|
+
VALUE opts[5] = {Qundef,Qundef,Qundef,Qundef,Qundef};
|
77
|
+
|
78
|
+
CHECK_FUNC(func_p,"<%=func_name%>");
|
79
|
+
|
80
|
+
rb_scan_args(argc, argv, "11:", &a, &c, &kw_hash);
|
81
|
+
rb_get_kwargs(kw_hash, kw_table, 0, 5, opts);
|
82
|
+
alpha = option_value(opts[0],Qnil);
|
83
|
+
beta = option_value(opts[1],Qnil);
|
84
|
+
<% if is_he %>
|
85
|
+
g.alpha = RTEST(alpha) ? DBL2NUM(alpha) : 1;
|
86
|
+
g.beta = RTEST(beta) ? DBL2NUM(beta) : 0;
|
87
|
+
<% else %>
|
88
|
+
g.alpha = RTEST(alpha) ? m_num_to_data(alpha) : m_one;
|
89
|
+
g.beta = RTEST(beta) ? m_num_to_data(beta) : m_zero;
|
90
|
+
<% end %>
|
91
|
+
g.order = option_order(opts[2]);
|
92
|
+
g.uplo = option_uplo(opts[3]);
|
93
|
+
g.trans = option_trans(opts[4]);
|
94
|
+
|
95
|
+
GetNArray(a,na1);
|
96
|
+
CHECK_DIM_GE(na1,2);
|
97
|
+
|
98
|
+
na = ROW_SIZE(na1); // n
|
99
|
+
ka = COL_SIZE(na1); // k (lda)
|
100
|
+
SWAP_IFCOLTR(g.order,g.trans, na,ka, tmp);
|
101
|
+
g.n = na;
|
102
|
+
g.k = ka;
|
103
|
+
|
104
|
+
if (c == Qnil) { // c is not given.
|
105
|
+
ndf.nout = 1;
|
106
|
+
ain[1] = ain[2];
|
107
|
+
c = INT2FIX(0);
|
108
|
+
shape[0] = na;
|
109
|
+
shape[1] = na;
|
110
|
+
} else {
|
111
|
+
COPY_OR_CAST_TO(c,cT);
|
112
|
+
GetNArray(c,na3);
|
113
|
+
CHECK_DIM_GE(na3,2);
|
114
|
+
nc = ROW_SIZE(na3);
|
115
|
+
if (nc < na) {
|
116
|
+
rb_raise(nary_eShapeError,"nc=%d must be >= na=%d",nc,na);
|
117
|
+
}
|
118
|
+
//CHECK_LEADING_GE("ldc",g.ldc,"n",na);
|
119
|
+
}
|
120
|
+
|
121
|
+
ans = na_ndloop3(&ndf, &g, 2, a, c);
|
122
|
+
|
123
|
+
if (ndf.nout == 1) { // c is not given.
|
124
|
+
return ans;
|
125
|
+
} else {
|
126
|
+
return c;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
|
130
|
+
#undef func_p
|
131
|
+
#undef args_t
|
132
|
+
#undef P
|
@@ -0,0 +1,23 @@
|
|
1
|
+
COGEN=ruby gen/cogen.rb -l
|
2
|
+
GENDEPS=gen/*.rb tmpl/*.c
|
3
|
+
|
4
|
+
<%
|
5
|
+
srcs = %w[s d c z].map{|c| [c, "lapack_#{c}.c"]}
|
6
|
+
srcs.each do |c,s|
|
7
|
+
%>
|
8
|
+
<%=s%>: $(GENDEPS)
|
9
|
+
$(COGEN) -o $@ <%=c%>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
GENSRC=<%= srcs.map{|x| x[1]}.join(" ") %>
|
13
|
+
|
14
|
+
src : lapack.c $(GENSRC)
|
15
|
+
|
16
|
+
doc : $(GENSRC)
|
17
|
+
yard doc -m markdown $(GENSRC)
|
18
|
+
|
19
|
+
clean: cleansrc cleandoc
|
20
|
+
cleansrc:
|
21
|
+
-$(Q)$(RM) $(GENSRC)
|
22
|
+
cleandoc:
|
23
|
+
-$(Q)$(RM_RF) doc .yardoc
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
require 'numo/narray'
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
$LOAD_PATH.each do |x|
|
6
|
+
if File.exist? File.join(x,'numo/numo/narray.h')
|
7
|
+
$INCFLAGS = "-I#{x}/numo " + $INCFLAGS
|
8
|
+
break
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
srcs = %w(
|
13
|
+
lapack
|
14
|
+
lapack_s
|
15
|
+
lapack_d
|
16
|
+
lapack_c
|
17
|
+
lapack_z
|
18
|
+
)
|
19
|
+
$objs = srcs.collect{|i| i+".o"}
|
20
|
+
|
21
|
+
if !have_header('numo/narray.h')
|
22
|
+
puts "
|
23
|
+
Header numo/narray.h was not found. Give pathname as follows:
|
24
|
+
% ruby extconf.rb --with-narray-include=narray_h_dir"
|
25
|
+
exit(1)
|
26
|
+
end
|
27
|
+
|
28
|
+
if have_header("dlfcn.h")
|
29
|
+
exit(1) unless have_library("dl")
|
30
|
+
exit(1) unless have_func("dlopen")
|
31
|
+
elsif have_header("windows.h")
|
32
|
+
exit(1) unless have_func("LoadLibrary")
|
33
|
+
end
|
34
|
+
|
35
|
+
dep_path = File.join(__dir__, "depend")
|
36
|
+
File.open(dep_path, "w") do |dep|
|
37
|
+
dep_erb_path = File.join(__dir__, "depend.erb")
|
38
|
+
File.open(dep_erb_path, "r") do |dep_erb|
|
39
|
+
erb = ERB.new(dep_erb.read)
|
40
|
+
erb.filename = dep_erb_path
|
41
|
+
dep.print(erb.result)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
create_makefile('numo/linalg/lapack')
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
pwd = File.dirname(__FILE__)
|
4
|
+
#libpath = File.absolute_path(File.dirname(__FILE__))+"/../../../../lib"
|
5
|
+
#$LOAD_PATH.unshift libpath
|
6
|
+
|
7
|
+
require_relative "../../blas/gen/decl"
|
8
|
+
|
9
|
+
while true
|
10
|
+
if ARGV[0] == "-l"
|
11
|
+
require "erbpp/line_number"
|
12
|
+
ARGV.shift
|
13
|
+
elsif ARGV[0] == "-o"
|
14
|
+
ARGV.shift
|
15
|
+
$output = ARGV.shift
|
16
|
+
require "fileutils"
|
17
|
+
FileUtils.rm_f($output)
|
18
|
+
else
|
19
|
+
break
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if ARGV.size != 1
|
24
|
+
puts "usage:\n ruby #{$0} [-l] blas_char"
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
|
28
|
+
blas_char = ARGV[0]
|
29
|
+
|
30
|
+
erb_dir = ["../tmpl"]
|
31
|
+
erb_dir.map!{|d| File.join(pwd,d)}
|
32
|
+
|
33
|
+
code = DefLib.new do
|
34
|
+
set erb_dir: erb_dir
|
35
|
+
set erb_suffix: ".c"
|
36
|
+
set ns_var: "mN"
|
37
|
+
|
38
|
+
set file_name: $output || ""
|
39
|
+
#set include_files: ["numo/types/#{type_name}.h"]
|
40
|
+
set lib_name: "numo_linalg_lapack_"+blas_char
|
41
|
+
|
42
|
+
def_module do
|
43
|
+
mname = "Linalg"
|
44
|
+
mbase = mname.downcase
|
45
|
+
set name: mbase
|
46
|
+
set module_name: mname
|
47
|
+
set module_var: "m"+mname
|
48
|
+
set full_module_name: "Numo::"+mname
|
49
|
+
|
50
|
+
def_module do
|
51
|
+
extend Decl
|
52
|
+
name = "Lapack"
|
53
|
+
base = name.downcase
|
54
|
+
set ns_var: "m"+mname
|
55
|
+
set name: base
|
56
|
+
set module_name: name
|
57
|
+
set module_var: "m"+name
|
58
|
+
set full_module_name: "Numo::Linalg::"+name
|
59
|
+
set module_desc: eval(File.read(File.join(pwd,"desc.rb")))
|
60
|
+
|
61
|
+
DefError.new(self,"LapackError","rb_eStandardError");
|
62
|
+
|
63
|
+
ErbPP.new(self,"def_"+blas_char)
|
64
|
+
set blas_char: blas_char
|
65
|
+
eval File.read(File.join(pwd,"spec.rb")), binding, "spec.rb"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end.result
|
69
|
+
|
70
|
+
if $output
|
71
|
+
open($output,"w").write(code)
|
72
|
+
else
|
73
|
+
$stdout.write(code)
|
74
|
+
end
|