numo-linalg 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,214 @@
|
|
1
|
+
/*<%
|
2
|
+
is_ge = (/^.ge/ =~ name)
|
3
|
+
is_tr = (/^.tr/ =~ name)
|
4
|
+
is_tr = (/^.tr/ =~ name)
|
5
|
+
%>*/
|
6
|
+
<% %>
|
7
|
+
#define GE <%= is_ge ? "1":"0" %>
|
8
|
+
#define TR <%= is_tr ? "1":"0" %>
|
9
|
+
#define args_t <%=name%>_args_t
|
10
|
+
|
11
|
+
typedef struct {
|
12
|
+
enum CBLAS_ORDER order;
|
13
|
+
enum CBLAS_TRANSPOSE transa, transb;
|
14
|
+
enum CBLAS_SIDE side;
|
15
|
+
enum CBLAS_UPLO uplo;
|
16
|
+
enum CBLAS_DIAG diag;
|
17
|
+
dtype alpha, beta;
|
18
|
+
blasint m, 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, *b;
|
29
|
+
int lda, ldb;
|
30
|
+
#if !TR
|
31
|
+
dtype *c;
|
32
|
+
int ldc;
|
33
|
+
#endif
|
34
|
+
args_t *g;
|
35
|
+
|
36
|
+
a = (dtype*)NDL_PTR(lp,0);
|
37
|
+
b = (dtype*)NDL_PTR(lp,1);
|
38
|
+
#if !TR
|
39
|
+
c = (dtype*)NDL_PTR(lp,2);
|
40
|
+
#endif
|
41
|
+
g = (args_t*)(lp->opt_ptr);
|
42
|
+
|
43
|
+
lda = NDL_STEP(lp,0) / sizeof(dtype);
|
44
|
+
ldb = NDL_STEP(lp,1) / sizeof(dtype);
|
45
|
+
#if !TR
|
46
|
+
ldc = NDL_STEP(lp,2) / sizeof(dtype);
|
47
|
+
#endif
|
48
|
+
|
49
|
+
//printf("m=%d n=%d k=%d\n",g->m,g->n,g->k);
|
50
|
+
|
51
|
+
#if GE
|
52
|
+
(*func_p)( g->order, g->transa, g->transb, g->m, g->n, g->k,
|
53
|
+
DP(g->alpha), a, lda, b, ldb, DP(g->beta), c, ldc);
|
54
|
+
#elif TR
|
55
|
+
(*func_p)( g->order, g->side, g->uplo, g->transa, g->diag, g->m, g->n,
|
56
|
+
DP(g->alpha), a, lda, b, ldb);
|
57
|
+
#else // SY,HE
|
58
|
+
(*func_p)( g->order, g->side, g->uplo, g->m, g->n,
|
59
|
+
DP(g->alpha), a, lda, b, ldb, DP(g->beta), c, ldc);
|
60
|
+
#endif
|
61
|
+
}
|
62
|
+
|
63
|
+
/*
|
64
|
+
<%
|
65
|
+
args_v =
|
66
|
+
if is_ge
|
67
|
+
"a, b, [c, alpha:1, beta:0, transa:'N', transb:'N'"
|
68
|
+
elsif is_tr
|
69
|
+
"a, b, [alpha:1, side:'L', uplo:'U', transa:'N', diag:'U'"
|
70
|
+
else
|
71
|
+
"a, b, [c, alpha:1, beta:0, side:'L', uplo:'U'"
|
72
|
+
end + ", order:'R'"
|
73
|
+
|
74
|
+
params = [
|
75
|
+
mat("a"),
|
76
|
+
mat("b"),
|
77
|
+
!is_tr && mat("c","optional",:inplace),
|
78
|
+
opt("alpha"),
|
79
|
+
opt("beta"),
|
80
|
+
!is_ge && opt("side"),
|
81
|
+
!is_ge && opt("uplo"),
|
82
|
+
(is_ge || is_tr) && opt("transa"),
|
83
|
+
is_ge && opt("transb"),
|
84
|
+
opt("order")
|
85
|
+
].select{|x| x}.join("\n ")
|
86
|
+
%>
|
87
|
+
@overload <%=name%>(<%=args_v%>)
|
88
|
+
<%=params%>
|
89
|
+
@return [<%=class_name%>] returns c = alpha\*op( A )\*op( B ) + beta\*C.
|
90
|
+
<%=description%>
|
91
|
+
|
92
|
+
*/
|
93
|
+
static VALUE
|
94
|
+
<%=c_func(-1)%>(int argc, VALUE const argv[], VALUE UNUSED(mod))
|
95
|
+
{
|
96
|
+
VALUE a, b, c=Qnil, alpha, beta;
|
97
|
+
narray_t *na1, *na2;
|
98
|
+
blasint ma, ka, kb, nb, tmp;
|
99
|
+
size_t shape[2];
|
100
|
+
ndfunc_arg_in_t ain[3] = {{cT,2},{cT,2},{OVERWRITE,2}};
|
101
|
+
ndfunc_arg_out_t aout[1] = {{cT,2,shape}};
|
102
|
+
ndfunc_t ndf = {<%=c_iter%>, NO_LOOP, 3, 0, ain, aout};
|
103
|
+
|
104
|
+
args_t g;
|
105
|
+
VALUE kw_hash = Qnil;
|
106
|
+
#if GE
|
107
|
+
ID kw_table[5] = {id_alpha,id_beta,id_order,id_transa,id_transb};
|
108
|
+
#elif TR
|
109
|
+
ID kw_table[7] = {id_alpha,id_beta,id_order,id_side,id_uplo,id_transa,id_diag};
|
110
|
+
#else
|
111
|
+
ID kw_table[5] = {id_alpha,id_beta,id_order,id_side,id_uplo};
|
112
|
+
#endif
|
113
|
+
VALUE opts[7] = {Qundef,Qundef,Qundef,Qundef,Qundef,Qundef,Qundef};
|
114
|
+
|
115
|
+
CHECK_FUNC(func_p,"<%=func_name%>");
|
116
|
+
|
117
|
+
rb_scan_args(argc, argv, "21:", &a, &b, &c, &kw_hash);
|
118
|
+
rb_get_kwargs(kw_hash, kw_table, 0, 5+TR*2, opts);
|
119
|
+
alpha = option_value(opts[0],Qnil);
|
120
|
+
g.alpha = RTEST(alpha) ? m_num_to_data(alpha) : m_one;
|
121
|
+
beta = option_value(opts[1],Qnil);
|
122
|
+
g.beta = RTEST(beta) ? m_num_to_data(beta) : m_zero;
|
123
|
+
g.order = option_order(opts[2]);
|
124
|
+
#if GE
|
125
|
+
g.transa = option_trans(opts[3]);
|
126
|
+
g.transb = option_trans(opts[4]);
|
127
|
+
#else
|
128
|
+
g.side = option_side(opts[3]);
|
129
|
+
g.uplo = option_uplo(opts[4]);
|
130
|
+
#endif
|
131
|
+
#if TR
|
132
|
+
g.transa = option_trans(opts[5]);
|
133
|
+
g.diag = option_diag(opts[6]);
|
134
|
+
#endif
|
135
|
+
|
136
|
+
GetNArray(a,na1);
|
137
|
+
GetNArray(b,na2);
|
138
|
+
CHECK_DIM_GE(na1,2);
|
139
|
+
CHECK_DIM_GE(na2,2);
|
140
|
+
ma = ROW_SIZE(na1); // m
|
141
|
+
ka = COL_SIZE(na1); // k (lda)
|
142
|
+
kb = ROW_SIZE(na2); // k
|
143
|
+
nb = COL_SIZE(na2); // n (ldb)
|
144
|
+
|
145
|
+
#if GE
|
146
|
+
SWAP_IFCOLTR(g.order,g.transa, ma,ka, tmp);
|
147
|
+
SWAP_IFCOLTR(g.order,g.transb, kb,nb, tmp);
|
148
|
+
CHECK_INT_EQ("ka",ka,"kb",kb);
|
149
|
+
g.m = ma;
|
150
|
+
g.n = nb;
|
151
|
+
g.k = ka;
|
152
|
+
#else
|
153
|
+
CHECK_SQUARE("a",na1); // ma == ka
|
154
|
+
SWAP_IFCOL(g.order, kb,nb, tmp);
|
155
|
+
// row major L R
|
156
|
+
//ma = ROW_SIZE(na1); // m or n
|
157
|
+
//ka = COL_SIZE(na1); // m or n (lda)
|
158
|
+
g.m = kb; // m
|
159
|
+
g.n = nb; // n (ldb)
|
160
|
+
if (g.side == CblasLeft) {
|
161
|
+
CHECK_SIZE_EQ(ka, g.m);
|
162
|
+
} else {
|
163
|
+
CHECK_SIZE_EQ(ka, g.n);
|
164
|
+
}
|
165
|
+
#endif
|
166
|
+
|
167
|
+
SWAP_IFROW(g.order, ma,nb, tmp);
|
168
|
+
|
169
|
+
#if TR
|
170
|
+
if (c != Qnil) {
|
171
|
+
rb_raise(rb_eArgError,"wrong number of arguments (3 for 2)");
|
172
|
+
}
|
173
|
+
COPY_OR_CAST_TO(b,cT);
|
174
|
+
ndf.nin = 2;
|
175
|
+
|
176
|
+
na_ndloop3(&ndf, &g, 2, a, b);
|
177
|
+
return b;
|
178
|
+
#else
|
179
|
+
|
180
|
+
if (c == Qnil) { // c is not given.
|
181
|
+
ndfunc_arg_in_t ain_init = {sym_init,0};
|
182
|
+
ain[2] = ain_init;
|
183
|
+
ndf.nout = 1;
|
184
|
+
c = INT2FIX(0);
|
185
|
+
shape[0] = nb;
|
186
|
+
shape[1] = ma;
|
187
|
+
} else {
|
188
|
+
narray_t *na3;
|
189
|
+
int nc;
|
190
|
+
COPY_OR_CAST_TO(c,cT);
|
191
|
+
GetNArray(c,na3);
|
192
|
+
CHECK_DIM_GE(na3,2);
|
193
|
+
nc = ROW_SIZE(na3);
|
194
|
+
if (nc < nb) {
|
195
|
+
rb_raise(nary_eShapeError,"nc=%d must be >= nb=%d",nc,nb);
|
196
|
+
}
|
197
|
+
//CHECK_LEADING_GE("ldc",g.ldc,"m",ma);
|
198
|
+
}
|
199
|
+
{
|
200
|
+
VALUE ans = na_ndloop3(&ndf, &g, 3, a, b, c);
|
201
|
+
|
202
|
+
if (ndf.nout == 1) { // c is not given.
|
203
|
+
return ans;
|
204
|
+
} else {
|
205
|
+
return c;
|
206
|
+
}
|
207
|
+
}
|
208
|
+
#endif
|
209
|
+
}
|
210
|
+
|
211
|
+
#undef func_p
|
212
|
+
#undef args_t
|
213
|
+
#undef GE
|
214
|
+
#undef TR
|
@@ -0,0 +1,194 @@
|
|
1
|
+
/*<%
|
2
|
+
is_ge = (/^.ge/ =~ name)
|
3
|
+
is_tr = (/^.tr/ =~ name)
|
4
|
+
%>*/
|
5
|
+
<% %>
|
6
|
+
#define GE <%= is_ge ? "1":"0" %>
|
7
|
+
#define TR <%= is_tr ? "1":"0" %>
|
8
|
+
#define args_t <%=name%>_args_t
|
9
|
+
|
10
|
+
typedef struct {
|
11
|
+
enum CBLAS_ORDER order;
|
12
|
+
enum CBLAS_TRANSPOSE trans;
|
13
|
+
enum CBLAS_UPLO uplo;
|
14
|
+
enum CBLAS_DIAG diag;
|
15
|
+
dtype alpha, beta;
|
16
|
+
blasint m, n;
|
17
|
+
} args_t;
|
18
|
+
|
19
|
+
#define func_p <%=func_name%>_p
|
20
|
+
|
21
|
+
static <%=func_name%>_t func_p = 0;
|
22
|
+
|
23
|
+
static void
|
24
|
+
<%=c_iter%>(na_loop_t *const lp)
|
25
|
+
{
|
26
|
+
dtype *a;
|
27
|
+
char *p1;
|
28
|
+
ssize_t s1;
|
29
|
+
#if !TR
|
30
|
+
char *p2;
|
31
|
+
ssize_t s2;
|
32
|
+
#endif
|
33
|
+
#if !GE
|
34
|
+
int n;
|
35
|
+
#endif
|
36
|
+
int lda;
|
37
|
+
args_t *g;
|
38
|
+
|
39
|
+
a = (dtype*)NDL_PTR(lp,0);
|
40
|
+
INIT_PTR(lp,1,p1,s1);
|
41
|
+
#if !TR
|
42
|
+
INIT_PTR(lp,2,p2,s2);
|
43
|
+
#endif
|
44
|
+
g = (args_t*)(lp->opt_ptr);
|
45
|
+
|
46
|
+
#if !GE
|
47
|
+
n = NDL_SHAPE(lp,0)[1];
|
48
|
+
#endif
|
49
|
+
lda = NDL_STEP(lp,0) / sizeof(dtype);
|
50
|
+
|
51
|
+
#if GE
|
52
|
+
(*func_p)( g->order, g->trans, g->m, g->n,
|
53
|
+
DP(g->alpha), a, lda, (dtype*)p1, s1/sizeof(dtype),
|
54
|
+
DP(g->beta), (dtype*)p2, s2/sizeof(dtype) );
|
55
|
+
#elif TR
|
56
|
+
(*func_p)( g->order, g->uplo, g->trans, g->diag, n, a, lda,
|
57
|
+
(dtype*)p1, s1/sizeof(dtype) );
|
58
|
+
#else // SY,HE
|
59
|
+
(*func_p)( g->order, g->uplo, n,
|
60
|
+
DP(g->alpha), a, lda, (dtype*)p1, s1/sizeof(dtype),
|
61
|
+
DP(g->beta), (dtype*)p2, s2/sizeof(dtype) );
|
62
|
+
#endif
|
63
|
+
}
|
64
|
+
|
65
|
+
/*<%
|
66
|
+
args_v =
|
67
|
+
if is_ge
|
68
|
+
"a, x, [y, alpha:1, beta:0, trans:'N'"
|
69
|
+
elsif is_tr
|
70
|
+
"a, x, [uplo:'U', trans:'N', diag:'U'"
|
71
|
+
else
|
72
|
+
"a, x, [y, alpha:1, beta:0, uplo:'U'"
|
73
|
+
end + ", order:'R'"
|
74
|
+
params = [
|
75
|
+
mat("a"),
|
76
|
+
vec("x"),
|
77
|
+
!is_tr && vec("y","optional",:inplace),
|
78
|
+
opt("alpha"),
|
79
|
+
opt("beta"),
|
80
|
+
!is_ge && opt("side"),
|
81
|
+
!is_ge && opt("uplo"),
|
82
|
+
is_ge || is_tr && opt("trans"),
|
83
|
+
opt("order")
|
84
|
+
].select{|x| x}.join("\n ")
|
85
|
+
%>
|
86
|
+
@overload <%=name%>(<%=args_v%>)
|
87
|
+
<%=params%>
|
88
|
+
@return [<%=class_name%>] returns y = alpha*op(A)\*x + beta\*y.
|
89
|
+
|
90
|
+
<%=description%>
|
91
|
+
|
92
|
+
*/
|
93
|
+
static VALUE
|
94
|
+
<%=c_func(-1)%>(int argc, VALUE const argv[], VALUE UNUSED(mod))
|
95
|
+
{
|
96
|
+
VALUE a, x, y=Qnil, alpha, beta;
|
97
|
+
narray_t *na1, *na2;
|
98
|
+
blasint ma, na, nx;
|
99
|
+
#if GE
|
100
|
+
blasint tmp;
|
101
|
+
#endif
|
102
|
+
size_t shape[1];
|
103
|
+
ndfunc_arg_in_t ain[4] = {{cT,2},{cT,1},{OVERWRITE,1},{sym_init,0}};
|
104
|
+
ndfunc_arg_out_t aout[1] = {{cT,1,shape}};
|
105
|
+
ndfunc_t ndf = {<%=c_iter%>, NO_LOOP, 3, 0, ain, aout};
|
106
|
+
|
107
|
+
args_t g;
|
108
|
+
VALUE kw_hash = Qnil;
|
109
|
+
#if GE
|
110
|
+
ID kw_table[4] = {id_alpha,id_beta,id_order,id_trans};
|
111
|
+
#elif TR
|
112
|
+
ID kw_table[6] = {id_alpha,id_beta,id_order,id_uplo,id_trans,id_diag};
|
113
|
+
#else
|
114
|
+
ID kw_table[4] = {id_alpha,id_beta,id_order,id_uplo};
|
115
|
+
#endif
|
116
|
+
VALUE opts[6] = {Qundef,Qundef,Qundef,Qundef,Qundef,Qundef};
|
117
|
+
|
118
|
+
CHECK_FUNC(func_p,"<%=func_name%>");
|
119
|
+
|
120
|
+
rb_scan_args(argc, argv, "21:", &a, &x, &y, &kw_hash);
|
121
|
+
rb_get_kwargs(kw_hash, kw_table, 0, 4+2*TR, opts);
|
122
|
+
alpha = option_value(opts[0],Qnil);
|
123
|
+
g.alpha = RTEST(alpha) ? m_num_to_data(alpha) : m_one;
|
124
|
+
beta = option_value(opts[1],Qnil);
|
125
|
+
g.beta = RTEST(beta) ? m_num_to_data(beta) : m_zero;
|
126
|
+
g.order = option_order(opts[2]);
|
127
|
+
#if GE
|
128
|
+
g.trans = option_trans(opts[3]);
|
129
|
+
#else
|
130
|
+
g.uplo = option_uplo(opts[3]);
|
131
|
+
#endif
|
132
|
+
#if TR
|
133
|
+
g.trans = option_trans(opts[4]);
|
134
|
+
g.diag = option_diag(opts[5]);
|
135
|
+
#endif
|
136
|
+
|
137
|
+
GetNArray(a,na1);
|
138
|
+
CHECK_DIM_GE(na1,2);
|
139
|
+
ma = ROW_SIZE(na1);
|
140
|
+
na = COL_SIZE(na1);
|
141
|
+
|
142
|
+
GetNArray(x,na2);
|
143
|
+
CHECK_DIM_GE(na2,1);
|
144
|
+
nx = COL_SIZE(na2);
|
145
|
+
#if GE
|
146
|
+
SWAP_IFCOLTR(g.order,g.trans, ma,na, tmp);
|
147
|
+
g.m = ma;
|
148
|
+
g.n = na;
|
149
|
+
#else
|
150
|
+
CHECK_SQUARE("a",na1);
|
151
|
+
#endif
|
152
|
+
CHECK_INT_EQ("na",na,"nx",nx);
|
153
|
+
shape[0] = ma;
|
154
|
+
|
155
|
+
#if TR
|
156
|
+
if (y != Qnil) {
|
157
|
+
rb_raise(rb_eArgError,"wrong number of arguments (3 for 2)");
|
158
|
+
}
|
159
|
+
COPY_OR_CAST_TO(x,cT);
|
160
|
+
ndf.nin = 2;
|
161
|
+
na_ndloop3(&ndf, &g, 2, a, x);
|
162
|
+
return x;
|
163
|
+
|
164
|
+
#else // GE,SY,HE
|
165
|
+
|
166
|
+
if (y == Qnil) { // c is not given.
|
167
|
+
ndf.nout = 1;
|
168
|
+
ain[2] = ain[3];
|
169
|
+
y = INT2FIX(0);
|
170
|
+
shape[0] = ma;
|
171
|
+
} else {
|
172
|
+
narray_t *na3;
|
173
|
+
COPY_OR_CAST_TO(y,cT);
|
174
|
+
GetNArray(y,na3);
|
175
|
+
CHECK_DIM_GE(na3,1);
|
176
|
+
CHECK_SIZE_GE(na3,nx);
|
177
|
+
}
|
178
|
+
{
|
179
|
+
VALUE ans;
|
180
|
+
ans = na_ndloop3(&ndf, &g, 3, a, x, y);
|
181
|
+
|
182
|
+
if (ndf.nout == 1) { // c is not given.
|
183
|
+
return ans;
|
184
|
+
} else {
|
185
|
+
return y;
|
186
|
+
}
|
187
|
+
}
|
188
|
+
#endif
|
189
|
+
}
|
190
|
+
|
191
|
+
#undef func_p
|
192
|
+
#undef args_t
|
193
|
+
#undef GE
|
194
|
+
#undef TR
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#define func_p <%=func_name%>_p
|
2
|
+
|
3
|
+
static <%=func_name%>_t func_p = 0;
|
4
|
+
|
5
|
+
#undef result_dtype
|
6
|
+
#define result_dtype <%=result_dtype%>
|
7
|
+
|
8
|
+
static void
|
9
|
+
<%=c_iter%>(na_loop_t *const lp)
|
10
|
+
{
|
11
|
+
char *p1, *p2;
|
12
|
+
size_t n;
|
13
|
+
ssize_t s1;
|
14
|
+
|
15
|
+
INIT_PTR(lp,0,p1,s1);
|
16
|
+
p2 = NDL_PTR(lp,1);
|
17
|
+
n = NDL_SHAPE(lp,0)[0];
|
18
|
+
|
19
|
+
*(result_dtype*)p2 = (*func_p)(n, (dtype*)p1, s1/sizeof(dtype));
|
20
|
+
}
|
21
|
+
|
22
|
+
/*
|
23
|
+
<%
|
24
|
+
case name
|
25
|
+
when /^dz/
|
26
|
+
arg_class = "Numo::DComplex"
|
27
|
+
retT = "cRT"
|
28
|
+
when /^sc/
|
29
|
+
arg_class = "Numo::SComplex"
|
30
|
+
retT = "cRT"
|
31
|
+
else
|
32
|
+
arg_class = class_name
|
33
|
+
retT = "cT"
|
34
|
+
end
|
35
|
+
params = [
|
36
|
+
vec("x",type:arg_class),
|
37
|
+
opt("keepdims"),
|
38
|
+
].select{|x| x}.join("\n ")
|
39
|
+
%>
|
40
|
+
@overload <%=name%>( x )
|
41
|
+
<%=params%>
|
42
|
+
@return [<%=class_name%>] euclidean norm of x
|
43
|
+
|
44
|
+
<%=description%>
|
45
|
+
|
46
|
+
*/
|
47
|
+
static VALUE
|
48
|
+
<%=c_func(-1)%>(int argc, VALUE const argv[], VALUE UNUSED(mod))
|
49
|
+
{
|
50
|
+
VALUE x, keepdims, ans;
|
51
|
+
narray_t *na1;
|
52
|
+
ndfunc_arg_in_t ain[1] = {{cT,1}};
|
53
|
+
ndfunc_arg_out_t aout[1] = {{<%=retT%>,0}};
|
54
|
+
ndfunc_t ndf = {<%=c_iter%>, NDF_EXTRACT, 1,1, ain,aout};
|
55
|
+
|
56
|
+
VALUE opts[1] = {Qundef};
|
57
|
+
ID kw_table[1] = {id_keepdims};
|
58
|
+
VALUE kw_hash = Qnil;
|
59
|
+
|
60
|
+
CHECK_FUNC(func_p,"<%=func_name%>");
|
61
|
+
|
62
|
+
rb_scan_args(argc, argv, "1:", &x, &kw_hash);
|
63
|
+
rb_get_kwargs(kw_hash, kw_table, 0, 1, opts);
|
64
|
+
keepdims = option_value(opts[0],Qfalse);
|
65
|
+
|
66
|
+
if (RTEST(keepdims)) {
|
67
|
+
ndf.flag |= NDF_KEEP_DIM;
|
68
|
+
}
|
69
|
+
|
70
|
+
GetNArray(x,na1);
|
71
|
+
CHECK_DIM_GE(na1,1);
|
72
|
+
CHECK_NON_EMPTY(na1);
|
73
|
+
|
74
|
+
ans = na_ndloop(&ndf, 1, x);
|
75
|
+
|
76
|
+
return ans;
|
77
|
+
}
|
78
|
+
|
79
|
+
#undef func_p
|