numo-narray 0.9.0.1-x64-mingw32
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 +47 -0
- data/Rakefile +41 -0
- data/ext/numo/narray/SFMT-params.h +97 -0
- data/ext/numo/narray/SFMT-params19937.h +46 -0
- data/ext/numo/narray/SFMT.c +620 -0
- data/ext/numo/narray/SFMT.h +157 -0
- data/ext/numo/narray/array.c +525 -0
- data/ext/numo/narray/data.c +901 -0
- data/ext/numo/narray/depend.erb +33 -0
- data/ext/numo/narray/extconf.rb +117 -0
- data/ext/numo/narray/gen/bit.erb.c +811 -0
- data/ext/numo/narray/gen/cogen.rb +18 -0
- data/ext/numo/narray/gen/def/dcomplex.rb +32 -0
- data/ext/numo/narray/gen/def/dfloat.rb +30 -0
- data/ext/numo/narray/gen/def/int16.rb +29 -0
- data/ext/numo/narray/gen/def/int32.rb +29 -0
- data/ext/numo/narray/gen/def/int64.rb +29 -0
- data/ext/numo/narray/gen/def/int8.rb +29 -0
- data/ext/numo/narray/gen/def/robject.rb +30 -0
- data/ext/numo/narray/gen/def/scomplex.rb +32 -0
- data/ext/numo/narray/gen/def/sfloat.rb +30 -0
- data/ext/numo/narray/gen/def/uint16.rb +29 -0
- data/ext/numo/narray/gen/def/uint32.rb +29 -0
- data/ext/numo/narray/gen/def/uint64.rb +29 -0
- data/ext/numo/narray/gen/def/uint8.rb +29 -0
- data/ext/numo/narray/gen/dtype.erb.c +328 -0
- data/ext/numo/narray/gen/tmpl/accum.c +36 -0
- data/ext/numo/narray/gen/tmpl/accum_binary.c +75 -0
- data/ext/numo/narray/gen/tmpl/accum_index.c +58 -0
- data/ext/numo/narray/gen/tmpl/allocate.c +35 -0
- data/ext/numo/narray/gen/tmpl/aref.c +51 -0
- data/ext/numo/narray/gen/tmpl/aset.c +61 -0
- data/ext/numo/narray/gen/tmpl/binary.c +53 -0
- data/ext/numo/narray/gen/tmpl/binary2.c +55 -0
- data/ext/numo/narray/gen/tmpl/binary_s.c +34 -0
- data/ext/numo/narray/gen/tmpl/bit_binary.c +94 -0
- data/ext/numo/narray/gen/tmpl/bit_count.c +82 -0
- data/ext/numo/narray/gen/tmpl/bit_unary.c +77 -0
- data/ext/numo/narray/gen/tmpl/cast.c +37 -0
- data/ext/numo/narray/gen/tmpl/cast_array.c +79 -0
- data/ext/numo/narray/gen/tmpl/cast_numeric.c +22 -0
- data/ext/numo/narray/gen/tmpl/coerce_cast.c +8 -0
- data/ext/numo/narray/gen/tmpl/cond_binary.c +51 -0
- data/ext/numo/narray/gen/tmpl/cond_unary.c +45 -0
- data/ext/numo/narray/gen/tmpl/cum.c +42 -0
- data/ext/numo/narray/gen/tmpl/each.c +43 -0
- data/ext/numo/narray/gen/tmpl/each_with_index.c +64 -0
- data/ext/numo/narray/gen/tmpl/extract.c +23 -0
- data/ext/numo/narray/gen/tmpl/eye.c +91 -0
- data/ext/numo/narray/gen/tmpl/fill.c +38 -0
- data/ext/numo/narray/gen/tmpl/format.c +60 -0
- data/ext/numo/narray/gen/tmpl/format_to_a.c +47 -0
- data/ext/numo/narray/gen/tmpl/head.c +25 -0
- data/ext/numo/narray/gen/tmpl/inspect.c +16 -0
- data/ext/numo/narray/gen/tmpl/map_with_index.c +94 -0
- data/ext/numo/narray/gen/tmpl/median.c +44 -0
- data/ext/numo/narray/gen/tmpl/minmax.c +47 -0
- data/ext/numo/narray/gen/tmpl/poly.c +49 -0
- data/ext/numo/narray/gen/tmpl/pow.c +74 -0
- data/ext/numo/narray/gen/tmpl/powint.c +17 -0
- data/ext/numo/narray/gen/tmpl/qsort.c +149 -0
- data/ext/numo/narray/gen/tmpl/rand.c +33 -0
- data/ext/numo/narray/gen/tmpl/rand_norm.c +46 -0
- data/ext/numo/narray/gen/tmpl/robj_allocate.c +32 -0
- data/ext/numo/narray/gen/tmpl/seq.c +61 -0
- data/ext/numo/narray/gen/tmpl/set2.c +56 -0
- data/ext/numo/narray/gen/tmpl/sort.c +36 -0
- data/ext/numo/narray/gen/tmpl/sort_index.c +86 -0
- data/ext/numo/narray/gen/tmpl/store.c +31 -0
- data/ext/numo/narray/gen/tmpl/store_array.c +5 -0
- data/ext/numo/narray/gen/tmpl/store_from.c +53 -0
- data/ext/numo/narray/gen/tmpl/store_numeric.c +22 -0
- data/ext/numo/narray/gen/tmpl/to_a.c +41 -0
- data/ext/numo/narray/gen/tmpl/unary.c +58 -0
- data/ext/numo/narray/gen/tmpl/unary2.c +58 -0
- data/ext/numo/narray/gen/tmpl/unary_s.c +57 -0
- data/ext/numo/narray/index.c +822 -0
- data/ext/numo/narray/kwarg.c +79 -0
- data/ext/numo/narray/math.c +140 -0
- data/ext/numo/narray/narray.c +1539 -0
- data/ext/numo/narray/ndloop.c +1928 -0
- data/ext/numo/narray/numo/compat.h +23 -0
- data/ext/numo/narray/numo/intern.h +112 -0
- data/ext/numo/narray/numo/narray.h +411 -0
- data/ext/numo/narray/numo/ndloop.h +99 -0
- data/ext/numo/narray/numo/template.h +140 -0
- data/ext/numo/narray/numo/types/bit.h +19 -0
- data/ext/numo/narray/numo/types/complex.h +410 -0
- data/ext/numo/narray/numo/types/complex_macro.h +205 -0
- data/ext/numo/narray/numo/types/dcomplex.h +11 -0
- data/ext/numo/narray/numo/types/dfloat.h +12 -0
- data/ext/numo/narray/numo/types/float_def.h +34 -0
- data/ext/numo/narray/numo/types/float_macro.h +277 -0
- data/ext/numo/narray/numo/types/int16.h +12 -0
- data/ext/numo/narray/numo/types/int32.h +12 -0
- data/ext/numo/narray/numo/types/int64.h +12 -0
- data/ext/numo/narray/numo/types/int8.h +12 -0
- data/ext/numo/narray/numo/types/int_macro.h +34 -0
- data/ext/numo/narray/numo/types/robj_macro.h +218 -0
- data/ext/numo/narray/numo/types/robject.h +21 -0
- data/ext/numo/narray/numo/types/scomplex.h +11 -0
- data/ext/numo/narray/numo/types/sfloat.h +13 -0
- data/ext/numo/narray/numo/types/uint16.h +12 -0
- data/ext/numo/narray/numo/types/uint32.h +12 -0
- data/ext/numo/narray/numo/types/uint64.h +12 -0
- data/ext/numo/narray/numo/types/uint8.h +12 -0
- data/ext/numo/narray/numo/types/uint_macro.h +31 -0
- data/ext/numo/narray/numo/types/xint_macro.h +133 -0
- data/ext/numo/narray/rand.c +87 -0
- data/ext/numo/narray/step.c +506 -0
- data/ext/numo/narray/struct.c +872 -0
- data/lib/2.1/numo/narray.so +0 -0
- data/lib/2.2/numo/narray.so +0 -0
- data/lib/2.3/numo/narray.so +0 -0
- data/lib/erbpp.rb +286 -0
- data/lib/erbpp/line_number.rb +126 -0
- data/lib/erbpp/narray_def.rb +338 -0
- data/lib/numo/narray.rb +6 -0
- data/numo-narray.gemspec +35 -0
- data/spec/bit_spec.rb +93 -0
- data/spec/narray_spec.rb +249 -0
- metadata +238 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
char *p1;
|
6
|
+
ssize_t s1;
|
7
|
+
size_t *idx1;
|
8
|
+
dtype x;
|
9
|
+
|
10
|
+
INIT_COUNTER(lp, i);
|
11
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
12
|
+
if (idx1) {
|
13
|
+
for (; i--;) {
|
14
|
+
x = m_rand;
|
15
|
+
SET_DATA_INDEX(p1,idx1,dtype,x);
|
16
|
+
}
|
17
|
+
} else {
|
18
|
+
for (; i--;) {
|
19
|
+
x = m_rand;
|
20
|
+
SET_DATA_STRIDE(p1,s1,dtype,x);
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
static VALUE
|
26
|
+
<%=c_func%>(VALUE self)
|
27
|
+
{
|
28
|
+
ndfunc_arg_in_t ain[1] = {{OVERWRITE,0}};
|
29
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 1, 0, ain, 0 };
|
30
|
+
|
31
|
+
na_ndloop(&ndf, 1, self);
|
32
|
+
return self;
|
33
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
char *p1;
|
6
|
+
ssize_t s1;
|
7
|
+
size_t *idx1;
|
8
|
+
dtype y;
|
9
|
+
dtype a[2];
|
10
|
+
|
11
|
+
INIT_COUNTER(lp, i);
|
12
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
13
|
+
if (idx1) {
|
14
|
+
for (; i>1; i-=2) {
|
15
|
+
m_rand_norm(a);
|
16
|
+
*(dtype*)(p1+*idx1) = a[0];
|
17
|
+
*(dtype*)(p1+*(idx1+1)) = a[1];
|
18
|
+
idx1 += 2;
|
19
|
+
}
|
20
|
+
if (i>0) {
|
21
|
+
m_rand_norm(a);
|
22
|
+
*(dtype*)(p1+*idx1) = a[0];
|
23
|
+
}
|
24
|
+
} else {
|
25
|
+
for (; i>1; i-=2) {
|
26
|
+
m_rand_norm(a);
|
27
|
+
*(dtype*)(p1) = a[0];
|
28
|
+
*(dtype*)(p1+s1) = a[1];
|
29
|
+
p1 += s1*2;
|
30
|
+
}
|
31
|
+
if (i>0) {
|
32
|
+
m_rand_norm(a);
|
33
|
+
*(dtype*)(p1) = a[0];
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
static VALUE
|
39
|
+
<%=c_func%>(VALUE self)
|
40
|
+
{
|
41
|
+
ndfunc_arg_in_t ain[1] = {{OVERWRITE,0}};
|
42
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 1, 0, ain, 0 };
|
43
|
+
|
44
|
+
na_ndloop(&ndf, 1, self);
|
45
|
+
return self
|
46
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
static void
|
2
|
+
na_gc_mark_robj(narray_data_t* na)
|
3
|
+
{
|
4
|
+
size_t n, i;
|
5
|
+
VALUE *a;
|
6
|
+
|
7
|
+
if (na->ptr) {
|
8
|
+
a = (VALUE*)(na->ptr);
|
9
|
+
n = na->base.size;
|
10
|
+
for (i=0; i<n; i++) {
|
11
|
+
rb_gc_mark(a[i]);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
void na_free(narray_data_t* na);
|
17
|
+
|
18
|
+
VALUE
|
19
|
+
<%=c_func%>(VALUE klass)
|
20
|
+
{
|
21
|
+
narray_data_t *na = ALLOC(narray_data_t);
|
22
|
+
|
23
|
+
na->base.ndim = 0;
|
24
|
+
na->base.type = NARRAY_DATA_T;
|
25
|
+
na->base.flag[0] = 0;
|
26
|
+
na->base.flag[1] = 0;
|
27
|
+
na->base.size = 0;
|
28
|
+
na->base.shape = NULL;
|
29
|
+
na->base.reduce = INT2FIX(0);
|
30
|
+
na->ptr = NULL;
|
31
|
+
return Data_Wrap_Struct(klass, na_gc_mark_robj, na_free, na);
|
32
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
char *p1;
|
6
|
+
ssize_t s1;
|
7
|
+
size_t *idx1;
|
8
|
+
double x, beg, step, c;
|
9
|
+
dtype y;
|
10
|
+
seq_opt_t *g;
|
11
|
+
|
12
|
+
INIT_COUNTER(lp, i);
|
13
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
14
|
+
g = (seq_opt_t*)(lp->opt_ptr);
|
15
|
+
beg = g->beg;
|
16
|
+
step = g->step;
|
17
|
+
c = g->count;
|
18
|
+
if (idx1) {
|
19
|
+
for (; i--;) {
|
20
|
+
x = beg + step * c++;
|
21
|
+
y = m_from_double(x);
|
22
|
+
*(dtype*)(p1+*idx1) = y;
|
23
|
+
idx1++;
|
24
|
+
}
|
25
|
+
} else {
|
26
|
+
for (; i--;) {
|
27
|
+
x = beg + step * c++;
|
28
|
+
y = m_from_double(x);
|
29
|
+
*(dtype*)(p1) = y;
|
30
|
+
p1 += s1;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
g->count = c;
|
34
|
+
}
|
35
|
+
|
36
|
+
/*
|
37
|
+
Set Sequence of numbers to self NArray.
|
38
|
+
@overload seq([beg,[step]])
|
39
|
+
@param [Numeric] beg begining of sequence. (default=0)
|
40
|
+
@param [Numeric] step step of sequence. (default=1)
|
41
|
+
@return [Numo::<%=class_name%>] self.
|
42
|
+
*/
|
43
|
+
static VALUE
|
44
|
+
<%=c_func%>(int argc, VALUE *args, VALUE self)
|
45
|
+
{
|
46
|
+
seq_opt_t *g;
|
47
|
+
VALUE vbeg=Qnil, vstep=Qnil;
|
48
|
+
ndfunc_arg_in_t ain[1] = {{OVERWRITE,0}};
|
49
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 1, 0, ain, 0 };
|
50
|
+
|
51
|
+
g = ALLOCA_N(seq_opt_t,1);
|
52
|
+
g->beg = 0;
|
53
|
+
g->step = 1;
|
54
|
+
g->count = 0;
|
55
|
+
rb_scan_args(argc, args, "02", &vbeg, &vstep);
|
56
|
+
if (vbeg!=Qnil) {g->beg = NUM2DBL(vbeg);}
|
57
|
+
if (vstep!=Qnil) {g->step = NUM2DBL(vstep);}
|
58
|
+
|
59
|
+
na_ndloop3(&ndf, g, 1, self);
|
60
|
+
return self;
|
61
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
char *p1, *p2;
|
6
|
+
ssize_t s1, s2;
|
7
|
+
size_t *idx1, *idx2;
|
8
|
+
dtype x;
|
9
|
+
<%=dtype%> y;
|
10
|
+
INIT_COUNTER(lp, i);
|
11
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
12
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
13
|
+
if (idx1) {
|
14
|
+
if (idx2) {
|
15
|
+
for (; i--;) {
|
16
|
+
GET_DATA_INDEX(p1,idx1,dtype,x);
|
17
|
+
GET_DATA_INDEX(p2,idx2,<%=dtype%>,y);
|
18
|
+
x = m_<%=method%>(x,y);
|
19
|
+
SET_DATA_INDEX(p1,idx1,dtype,x);
|
20
|
+
}
|
21
|
+
} else {
|
22
|
+
for (; i--;) {
|
23
|
+
GET_DATA_INDEX(p1,idx1,dtype,x);
|
24
|
+
GET_DATA_STRIDE(p2,s2,<%=dtype%>,y);
|
25
|
+
x = m_<%=method%>(x,y);
|
26
|
+
SET_DATA_INDEX(p1,idx1,dtype,x);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
} else {
|
30
|
+
if (idx2) {
|
31
|
+
for (; i--;) {
|
32
|
+
GET_DATA(p1,dtype,x);
|
33
|
+
GET_DATA_INDEX(p2,idx2,<%=dtype%>,y);
|
34
|
+
x = m_<%=method%>(x,y);
|
35
|
+
SET_DATA_STRIDE(p1,s1,dtype,x);
|
36
|
+
}
|
37
|
+
} else {
|
38
|
+
for (; i--;) {
|
39
|
+
GET_DATA(p1,dtype,x);
|
40
|
+
GET_DATA_STRIDE(p2,s2,<%=dtype%>,y);
|
41
|
+
x = m_<%=method%>(x,y);
|
42
|
+
SET_DATA_STRIDE(p1,s1,dtype,x);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
static VALUE
|
49
|
+
<%=c_func%>(VALUE self, VALUE a1)
|
50
|
+
{
|
51
|
+
ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{<%=tpclass%>,0}};
|
52
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 2, 0, ain, 0 };
|
53
|
+
|
54
|
+
na_ndloop(&ndf, 2, self, a1);
|
55
|
+
return a1;
|
56
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t n;
|
5
|
+
char *ptr;
|
6
|
+
ssize_t step;
|
7
|
+
|
8
|
+
INIT_COUNTER(lp, n);
|
9
|
+
INIT_PTR(lp, 0, ptr, step);
|
10
|
+
<%=tp%>_qsort(ptr, n, step);
|
11
|
+
}
|
12
|
+
|
13
|
+
/*
|
14
|
+
* call-seq:
|
15
|
+
* narray.sort() => narray
|
16
|
+
* narray.sort(dim0,dim1,...) => narray
|
17
|
+
*
|
18
|
+
* Return an index array of sort result.
|
19
|
+
*
|
20
|
+
* Numo::DFloat[3,4,1,2].sort => Numo::DFloat[1,2,3,4]
|
21
|
+
*/
|
22
|
+
static VALUE
|
23
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
24
|
+
{
|
25
|
+
VALUE reduce;
|
26
|
+
ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{sym_reduce,0}};
|
27
|
+
ndfunc_t ndf = {<%=c_iter%>, STRIDE_LOOP_NIP|NDF_INPLACE|NDF_FLAT_REDUCE, 2,0, ain,0};
|
28
|
+
|
29
|
+
if (!TEST_INPLACE(self)) {
|
30
|
+
self = na_copy(self);
|
31
|
+
}
|
32
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self); // v[0] = self
|
33
|
+
|
34
|
+
na_ndloop(&ndf, 2, self, reduce);
|
35
|
+
return self;
|
36
|
+
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
|
2
|
+
<% [64,32].each do |i| %>
|
3
|
+
#define idx_t int<%=i%>_t
|
4
|
+
static void
|
5
|
+
<%=tp%>_index<%=i%>_qsort(na_loop_t *const lp)
|
6
|
+
{
|
7
|
+
size_t i, n, idx;
|
8
|
+
char *d_ptr, *i_ptr, *o_ptr;
|
9
|
+
ssize_t d_step, i_step, o_step;
|
10
|
+
char **ptr;
|
11
|
+
|
12
|
+
INIT_COUNTER(lp, n);
|
13
|
+
INIT_PTR(lp, 0, d_ptr, d_step);
|
14
|
+
INIT_PTR(lp, 1, i_ptr, i_step);
|
15
|
+
INIT_PTR(lp, 2, o_ptr, o_step);
|
16
|
+
|
17
|
+
ptr = (char**)(lp->opt_ptr);
|
18
|
+
|
19
|
+
//printf("(ptr=%lx, d_ptr=%lx,d_step=%ld, i_ptr=%lx,i_step=%ld, o_ptr=%lx,o_step=%ld)\n",(size_t)ptr,(size_t)d_ptr,(ssize_t)d_step,(size_t)i_ptr,(ssize_t)i_step,(size_t)o_ptr,(ssize_t)o_step);
|
20
|
+
|
21
|
+
for (i=0; i<n; i++) {
|
22
|
+
ptr[i] = d_ptr + d_step * i;
|
23
|
+
//printf("(%ld,%.3f)",i,*(double*)ptr[i]);
|
24
|
+
}
|
25
|
+
|
26
|
+
<%=tp%>_index_qsort(ptr, n, sizeof(dtype*));
|
27
|
+
|
28
|
+
//d_ptr = lp->args[0].ptr;
|
29
|
+
//printf("(d_ptr=%lx)\n",(size_t)d_ptr);
|
30
|
+
|
31
|
+
for (i=0; i<n; i++) {
|
32
|
+
idx = (ptr[i] - d_ptr) / d_step;
|
33
|
+
*(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
|
34
|
+
//printf("(idx[%ld]=%ld,%d)",i,idx,*(idx_t*)o_ptr);
|
35
|
+
o_ptr += o_step;
|
36
|
+
}
|
37
|
+
//printf("\n");
|
38
|
+
}
|
39
|
+
#undef idx_t
|
40
|
+
<% end %>
|
41
|
+
|
42
|
+
/*
|
43
|
+
* call-seq:
|
44
|
+
* narray.sort_index() => narray
|
45
|
+
* narray.sort_index(dim0,dim1,..) => narray
|
46
|
+
*
|
47
|
+
* Return an index array of sort result.
|
48
|
+
*
|
49
|
+
* Numo::NArray[3,4,1,2].sort_index => Numo::Int32[2,3,0,1]
|
50
|
+
*/
|
51
|
+
static VALUE
|
52
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
53
|
+
{
|
54
|
+
size_t size;
|
55
|
+
narray_t *na;
|
56
|
+
VALUE idx, tmp, reduce, res;
|
57
|
+
char *buf;
|
58
|
+
ndfunc_arg_in_t ain[3] = {{cT,0},{0,0},{sym_reduce,0}};
|
59
|
+
ndfunc_arg_out_t aout[1] = {{0,0,0}};
|
60
|
+
ndfunc_t ndf = {0, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE|NDF_CUM, 3,1, ain,aout};
|
61
|
+
|
62
|
+
GetNArray(self,na);
|
63
|
+
if (na->ndim==0) {
|
64
|
+
return INT2FIX(0);
|
65
|
+
}
|
66
|
+
if (na->size > (~(u_int32_t)0)) {
|
67
|
+
ain[1].type =
|
68
|
+
aout[0].type = numo_cInt64;
|
69
|
+
idx = rb_narray_new(numo_cInt64, na->ndim, na->shape);
|
70
|
+
ndf.func = <%=tp%>_index64_qsort;
|
71
|
+
} else {
|
72
|
+
ain[1].type =
|
73
|
+
aout[0].type = numo_cInt32;
|
74
|
+
idx = rb_narray_new(numo_cInt32, na->ndim, na->shape);
|
75
|
+
ndf.func = <%=tp%>_index32_qsort;
|
76
|
+
}
|
77
|
+
rb_funcall(idx, rb_intern("seq"), 0);
|
78
|
+
|
79
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self); // v[0] = self
|
80
|
+
|
81
|
+
size = na->size*sizeof(void*);
|
82
|
+
buf = rb_alloc_tmp_buffer(&tmp, size);
|
83
|
+
res = na_ndloop3(&ndf, buf, 3, self, idx, reduce);
|
84
|
+
rb_free_tmp_buffer(&tmp);
|
85
|
+
return res;
|
86
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
/*
|
2
|
+
Store elements to Numo::<%=class_name%> from other.
|
3
|
+
@overload store(other)
|
4
|
+
@param [Object] other
|
5
|
+
@return [Numo::<%=class_name%>] self
|
6
|
+
*/
|
7
|
+
static VALUE
|
8
|
+
<%=c_func%>(VALUE self, VALUE obj)
|
9
|
+
{
|
10
|
+
VALUE r;
|
11
|
+
|
12
|
+
<% Store.definitions.each do |x| %>
|
13
|
+
if (<%=x.condition%>) {
|
14
|
+
<%=x.c_func%>(self,obj);
|
15
|
+
return self;
|
16
|
+
}
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
if (IsNArray(obj)) {
|
20
|
+
r = rb_funcall(obj, rb_intern("coerce_cast"), 1, cT);
|
21
|
+
if (CLASS_OF(r)==cT) {
|
22
|
+
<%=c_func%>(self,r);
|
23
|
+
return self;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
rb_raise(nary_eCastError, "unknown conversion from %s to %s",
|
28
|
+
rb_class2name(CLASS_OF(obj)),
|
29
|
+
rb_class2name(CLASS_OF(self)));
|
30
|
+
return self;
|
31
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i, s1, s2;
|
5
|
+
char *p1, *p2;
|
6
|
+
size_t *idx1, *idx2;
|
7
|
+
<%=dtype%> x;
|
8
|
+
dtype y;
|
9
|
+
|
10
|
+
INIT_COUNTER(lp, i);
|
11
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
12
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
13
|
+
if (idx2) {
|
14
|
+
if (idx1) {
|
15
|
+
for (; i--;) {
|
16
|
+
GET_DATA_INDEX(p2,idx2,<%=dtype%>,x);
|
17
|
+
y = <%=macro%>(x);
|
18
|
+
SET_DATA_INDEX(p1,idx1,dtype,y);
|
19
|
+
}
|
20
|
+
} else {
|
21
|
+
for (; i--;) {
|
22
|
+
GET_DATA_INDEX(p2,idx2,<%=dtype%>,x);
|
23
|
+
y = <%=macro%>(x);
|
24
|
+
SET_DATA_STRIDE(p1,s1,dtype,y);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
} else {
|
28
|
+
if (idx1) {
|
29
|
+
for (; i--;) {
|
30
|
+
GET_DATA_STRIDE(p2,s2,<%=dtype%>,x);
|
31
|
+
y = <%=macro%>(x);
|
32
|
+
SET_DATA_INDEX(p1,idx1,dtype,y);
|
33
|
+
}
|
34
|
+
} else {
|
35
|
+
for (; i--;) {
|
36
|
+
GET_DATA_STRIDE(p2,s2,<%=dtype%>,x);
|
37
|
+
y = <%=macro%>(x);
|
38
|
+
SET_DATA_STRIDE(p1,s1,dtype,y);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
|
45
|
+
static VALUE
|
46
|
+
<%=c_func%>(VALUE self, VALUE obj)
|
47
|
+
{
|
48
|
+
ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{Qnil,0}};
|
49
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 2, 0, ain, 0 };
|
50
|
+
|
51
|
+
na_ndloop(&ndf, 2, self, obj);
|
52
|
+
return self;
|
53
|
+
}
|