numo-narray 0.9.0.1-x86-mingw32 → 0.9.0.3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -7
- data/Rakefile +21 -6
- data/ext/numo/narray/array.c +3 -3
- data/ext/numo/narray/data.c +102 -81
- data/ext/numo/narray/depend.erb +9 -7
- data/ext/numo/narray/extconf.rb +5 -24
- data/ext/numo/narray/gen/cogen.rb +19 -4
- data/ext/numo/narray/gen/def/bit.rb +31 -0
- data/ext/numo/narray/gen/def/robject.rb +1 -1
- data/ext/numo/narray/gen/dtype.erb.c +11 -257
- data/ext/numo/narray/gen/spec.rb +294 -0
- data/ext/numo/narray/gen/tmpl/aset.c +1 -1
- data/ext/numo/narray/gen/tmpl/each_with_index.c +1 -1
- data/ext/numo/narray/gen/tmpl/eye.c +5 -5
- data/ext/numo/narray/gen/tmpl/logseq.c +82 -0
- data/ext/numo/narray/gen/tmpl/map_with_index.c +1 -1
- data/ext/numo/narray/gen/tmpl/rand.c +126 -5
- data/ext/numo/narray/gen/tmpl/seq.c +43 -12
- data/ext/numo/narray/gen/tmpl/store_bit.c +55 -0
- data/ext/numo/narray/gen/tmpl_bit/allocate.c +28 -0
- data/ext/numo/narray/gen/tmpl_bit/aref.c +53 -0
- data/ext/numo/narray/gen/tmpl_bit/aset.c +63 -0
- data/ext/numo/narray/gen/{tmpl/bit_binary.c → tmpl_bit/binary.c} +1 -1
- data/ext/numo/narray/gen/{tmpl → tmpl_bit}/bit_count.c +5 -3
- data/ext/numo/narray/gen/tmpl_bit/bit_reduce.c +128 -0
- data/ext/numo/narray/gen/tmpl_bit/cast.c +37 -0
- data/ext/numo/narray/gen/tmpl_bit/cast_array.c +80 -0
- data/ext/numo/narray/gen/tmpl_bit/cast_numeric.c +22 -0
- data/ext/numo/narray/gen/tmpl_bit/coerce_cast.c +8 -0
- data/ext/numo/narray/gen/tmpl_bit/each.c +44 -0
- data/ext/numo/narray/gen/tmpl_bit/each_with_index.c +66 -0
- data/ext/numo/narray/gen/tmpl_bit/extract.c +25 -0
- data/ext/numo/narray/gen/tmpl_bit/fill.c +65 -0
- data/ext/numo/narray/gen/tmpl_bit/format.c +61 -0
- data/ext/numo/narray/gen/tmpl_bit/format_to_a.c +48 -0
- data/ext/numo/narray/gen/tmpl_bit/inspect.c +18 -0
- data/ext/numo/narray/gen/tmpl_bit/map_with_index.c +94 -0
- data/ext/numo/narray/gen/tmpl_bit/mask.c +117 -0
- data/ext/numo/narray/gen/tmpl_bit/none_p.c +14 -0
- data/ext/numo/narray/gen/tmpl_bit/store.c +32 -0
- data/ext/numo/narray/gen/tmpl_bit/store_array.c +5 -0
- data/ext/numo/narray/gen/tmpl_bit/store_bit.c +66 -0
- data/ext/numo/narray/gen/tmpl_bit/store_from.c +56 -0
- data/ext/numo/narray/gen/tmpl_bit/store_numeric.c +22 -0
- data/ext/numo/narray/gen/tmpl_bit/to_a.c +43 -0
- data/ext/numo/narray/gen/{tmpl/bit_unary.c → tmpl_bit/unary.c} +1 -1
- data/ext/numo/narray/gen/tmpl_bit/where.c +102 -0
- data/ext/numo/narray/gen/tmpl_bit/where2.c +37 -0
- data/ext/numo/narray/index.c +9 -7
- data/ext/numo/narray/math.c +6 -1
- data/ext/numo/narray/narray.c +307 -103
- data/ext/numo/narray/ndloop.c +21 -36
- data/ext/numo/narray/numo/intern.h +3 -3
- data/ext/numo/narray/numo/narray.h +5 -41
- data/ext/numo/narray/numo/template.h +2 -2
- data/ext/numo/narray/numo/types/bit.h +27 -13
- data/ext/numo/narray/numo/types/complex.h +2 -2
- data/ext/numo/narray/numo/types/complex_macro.h +19 -7
- data/ext/numo/narray/numo/types/dcomplex.h +9 -0
- data/ext/numo/narray/numo/types/dfloat.h +6 -0
- data/ext/numo/narray/numo/types/float_macro.h +9 -2
- data/ext/numo/narray/numo/types/int16.h +0 -1
- data/ext/numo/narray/numo/types/int32.h +0 -1
- data/ext/numo/narray/numo/types/int64.h +0 -1
- data/ext/numo/narray/numo/types/int8.h +0 -1
- data/ext/numo/narray/numo/types/int_macro.h +2 -1
- data/ext/numo/narray/numo/types/robj_macro.h +9 -2
- data/ext/numo/narray/numo/types/robject.h +6 -0
- data/ext/numo/narray/numo/types/scomplex.h +9 -0
- data/ext/numo/narray/numo/types/sfloat.h +6 -0
- data/ext/numo/narray/numo/types/uint16.h +0 -1
- data/ext/numo/narray/numo/types/uint32.h +0 -1
- data/ext/numo/narray/numo/types/uint64.h +0 -1
- data/ext/numo/narray/numo/types/uint8.h +0 -1
- data/ext/numo/narray/numo/types/uint_macro.h +2 -1
- data/ext/numo/narray/numo/types/xint_macro.h +6 -1
- data/ext/numo/narray/rand.c +2 -2
- data/ext/numo/narray/step.c +7 -7
- data/ext/numo/narray/struct.c +11 -12
- data/lib/2.0/numo/narray.so +0 -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/2.4/numo/narray.so +0 -0
- data/lib/erbpp.rb +6 -2
- data/lib/erbpp/line_number.rb +1 -1
- data/lib/erbpp/narray_def.rb +23 -19
- data/numo-narray.gemspec +2 -2
- metadata +45 -10
- data/ext/numo/narray/gen/bit.erb.c +0 -811
@@ -0,0 +1,44 @@
|
|
1
|
+
void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
BIT_DIGIT *a1, x=0;
|
6
|
+
size_t p1;
|
7
|
+
ssize_t s1;
|
8
|
+
size_t *idx1;
|
9
|
+
VALUE y;
|
10
|
+
|
11
|
+
INIT_COUNTER(lp, i);
|
12
|
+
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
13
|
+
if (idx1) {
|
14
|
+
for (; i--;) {
|
15
|
+
LOAD_BIT(a1, p1+*idx1, x); idx1++;
|
16
|
+
y = m_data_to_num(x);
|
17
|
+
rb_yield(y);
|
18
|
+
}
|
19
|
+
} else {
|
20
|
+
for (; i--;) {
|
21
|
+
LOAD_BIT(a1, p1, x); p1+=s1;
|
22
|
+
y = m_data_to_num(x);
|
23
|
+
rb_yield(y);
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
/*
|
29
|
+
Calls the given block once for each element in self,
|
30
|
+
passing that element as a parameter.
|
31
|
+
@overload <%=method%>
|
32
|
+
@return [Numo::NArray] self
|
33
|
+
For a block {|x| ... }
|
34
|
+
@yield [x] x is element of NArray.
|
35
|
+
*/
|
36
|
+
static VALUE
|
37
|
+
<%=c_func%>(VALUE self)
|
38
|
+
{
|
39
|
+
ndfunc_arg_in_t ain[1] = {{Qnil,0}};
|
40
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP_NIP, 1,0, ain,0};
|
41
|
+
|
42
|
+
na_ndloop(&ndf, 1, self);
|
43
|
+
return self;
|
44
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
static inline void
|
2
|
+
yield_each_with_index(dtype x, size_t *c, VALUE *a, int nd, int md)
|
3
|
+
{
|
4
|
+
int j;
|
5
|
+
|
6
|
+
a[0] = m_data_to_num(x);
|
7
|
+
for (j=0; j<=nd; j++) {
|
8
|
+
a[j+1] = SIZET2NUM(c[j]);
|
9
|
+
}
|
10
|
+
rb_yield(rb_ary_new4(md,a));
|
11
|
+
}
|
12
|
+
|
13
|
+
|
14
|
+
void
|
15
|
+
<%=c_iter%>(na_loop_t *const lp)
|
16
|
+
{
|
17
|
+
size_t i;
|
18
|
+
BIT_DIGIT *a1, x=0;
|
19
|
+
size_t p1;
|
20
|
+
ssize_t s1;
|
21
|
+
size_t *idx1;
|
22
|
+
|
23
|
+
VALUE *a;
|
24
|
+
size_t *c;
|
25
|
+
int nd, md;
|
26
|
+
|
27
|
+
c = (size_t*)(lp->opt_ptr);
|
28
|
+
nd = lp->ndim - 1;
|
29
|
+
md = lp->ndim + 1;
|
30
|
+
a = ALLOCA_N(VALUE,md);
|
31
|
+
|
32
|
+
INIT_COUNTER(lp, i);
|
33
|
+
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
34
|
+
c[nd] = 0;
|
35
|
+
if (idx1) {
|
36
|
+
for (; i--;) {
|
37
|
+
LOAD_BIT(a1, p1+*idx1, x); idx1++;
|
38
|
+
yield_each_with_index(x,c,a,nd,md);
|
39
|
+
c[nd]++;
|
40
|
+
}
|
41
|
+
} else {
|
42
|
+
for (; i--;) {
|
43
|
+
LOAD_BIT(a1, p1, x); p1+=s1;
|
44
|
+
yield_each_with_index(x,c,a,nd,md);
|
45
|
+
c[nd]++;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
/*
|
51
|
+
Invokes the given block once for each element of self,
|
52
|
+
passing that element and indices along each axis as parameters.
|
53
|
+
@overload <%=method%>
|
54
|
+
@return [Numo::NArray] self
|
55
|
+
For a block {|x,i,j,...| ... }
|
56
|
+
@yield [x,i,j,...] x is an element, i,j,... are multidimensional indices.
|
57
|
+
*/
|
58
|
+
static VALUE
|
59
|
+
<%=c_func%>(VALUE self)
|
60
|
+
{
|
61
|
+
ndfunc_arg_in_t ain[1] = {{Qnil,0}};
|
62
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP_NIP, 1,0, ain,0};
|
63
|
+
|
64
|
+
na_ndloop_with_index(&ndf, 1, self);
|
65
|
+
return self;
|
66
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
/*
|
2
|
+
Extract an element only if self is a dimensionless NArray.
|
3
|
+
@overload extract
|
4
|
+
@return [Numeric,Numo::NArray]
|
5
|
+
--- Extract element value as Ruby Object if self is a dimensionless NArray,
|
6
|
+
otherwise returns self.
|
7
|
+
*/
|
8
|
+
|
9
|
+
static VALUE
|
10
|
+
numo_bit_extract(VALUE self)
|
11
|
+
{
|
12
|
+
BIT_DIGIT *ptr, val;
|
13
|
+
size_t pos;
|
14
|
+
narray_t *na;
|
15
|
+
GetNArray(self,na);
|
16
|
+
|
17
|
+
if (na->ndim==0) {
|
18
|
+
pos = na_get_offset(self);
|
19
|
+
ptr = (BIT_DIGIT*)na_get_pointer_for_read(self);
|
20
|
+
val = ((*((ptr)+(pos)/NB)) >> ((pos)%NB)) & 1u;
|
21
|
+
na_release_lock(self);
|
22
|
+
return INT2FIX(val);
|
23
|
+
}
|
24
|
+
return self;
|
25
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t n;
|
5
|
+
size_t p3;
|
6
|
+
ssize_t s3;
|
7
|
+
size_t *idx3;
|
8
|
+
int len;
|
9
|
+
BIT_DIGIT *a3;
|
10
|
+
BIT_DIGIT y;
|
11
|
+
VALUE x = lp->option;
|
12
|
+
|
13
|
+
if (x==INT2FIX(0) || x==Qfalse) {
|
14
|
+
y = 0;
|
15
|
+
} else
|
16
|
+
if (x==INT2FIX(1) || x==Qtrue) {
|
17
|
+
y = ~(BIT_DIGIT)0;
|
18
|
+
} else {
|
19
|
+
rb_raise(rb_eArgError, "invalid value for Bit");
|
20
|
+
}
|
21
|
+
|
22
|
+
INIT_COUNTER(lp, n);
|
23
|
+
INIT_PTR_BIT_IDX(lp, 0, a3, p3, s3, idx3);
|
24
|
+
if (idx3) {
|
25
|
+
y = y&1;
|
26
|
+
for (; n--;) {
|
27
|
+
STORE_BIT(a3, p3+*idx3, y); idx3++;
|
28
|
+
}
|
29
|
+
} else if (s3!=1) {
|
30
|
+
y = y&1;
|
31
|
+
for (; n--;) {
|
32
|
+
STORE_BIT(a3, p3, y); p3+=s3;
|
33
|
+
}
|
34
|
+
} else {
|
35
|
+
if (p3>0 || n<NB) {
|
36
|
+
len = NB - p3;
|
37
|
+
if ((int)n<len) len=n;
|
38
|
+
*a3 = (y & (SLB(len)<<p3)) | (*a3 & ~(SLB(len)<<p3));
|
39
|
+
a3++;
|
40
|
+
n -= len;
|
41
|
+
}
|
42
|
+
for (; n>=NB; n-=NB) {
|
43
|
+
*(a3++) = y;
|
44
|
+
}
|
45
|
+
if (n>0) {
|
46
|
+
*a3 = (y & SLB(n)) | (*a3 & BALL<<n);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
/*
|
52
|
+
Fill elements with other.
|
53
|
+
@overload <%=method%> other
|
54
|
+
@param [Numeric] other
|
55
|
+
@return [Numo::<%=class_name%>] self.
|
56
|
+
*/
|
57
|
+
static VALUE
|
58
|
+
<%=c_func%>(VALUE self, VALUE val)
|
59
|
+
{
|
60
|
+
ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{sym_option}};
|
61
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP, 2,0, ain,0};
|
62
|
+
|
63
|
+
na_ndloop(&ndf, 2, self, val);
|
64
|
+
return self;
|
65
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
static VALUE
|
2
|
+
format_<%=tp%>(VALUE fmt, dtype x)
|
3
|
+
{
|
4
|
+
if (NIL_P(fmt)) {
|
5
|
+
char s[4];
|
6
|
+
int n;
|
7
|
+
n = m_sprintf(s,x);
|
8
|
+
return rb_str_new(s,n);
|
9
|
+
}
|
10
|
+
return rb_funcall(fmt, '%', 1, m_data_to_num(x));
|
11
|
+
}
|
12
|
+
|
13
|
+
static void
|
14
|
+
<%=c_iter%>(na_loop_t *const lp)
|
15
|
+
{
|
16
|
+
size_t i;
|
17
|
+
BIT_DIGIT *a1, x=0;
|
18
|
+
size_t p1;
|
19
|
+
char *p2;
|
20
|
+
ssize_t s1, s2;
|
21
|
+
size_t *idx1;
|
22
|
+
VALUE y;
|
23
|
+
VALUE fmt = lp->option;
|
24
|
+
|
25
|
+
INIT_COUNTER(lp, i);
|
26
|
+
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
27
|
+
INIT_PTR(lp, 1, p2, s2);
|
28
|
+
|
29
|
+
if (idx1) {
|
30
|
+
for (; i--;) {
|
31
|
+
LOAD_BIT(a1, p1+*idx1, x); idx1++;
|
32
|
+
y = format_<%=tp%>(fmt, x);
|
33
|
+
SET_DATA_STRIDE(p2, s2, VALUE, y);
|
34
|
+
}
|
35
|
+
} else {
|
36
|
+
for (; i--;) {
|
37
|
+
LOAD_BIT(a1, p1, x); p1+=s1;
|
38
|
+
y = format_<%=tp%>(fmt, x);
|
39
|
+
SET_DATA_STRIDE(p2, s2, VALUE, y);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
/*
|
45
|
+
Format elements into strings.
|
46
|
+
@overload <%=method%> format
|
47
|
+
@param [String] format
|
48
|
+
@return [Numo::RObject] array of formated strings.
|
49
|
+
*/
|
50
|
+
static VALUE
|
51
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
52
|
+
{
|
53
|
+
VALUE fmt=Qnil;
|
54
|
+
|
55
|
+
ndfunc_arg_in_t ain[2] = {{Qnil,0},{sym_option}};
|
56
|
+
ndfunc_arg_out_t aout[1] = {{numo_cRObject,0}};
|
57
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP_NIP, 2,1, ain,aout};
|
58
|
+
|
59
|
+
rb_scan_args(argc, argv, "01", &fmt);
|
60
|
+
return na_ndloop(&ndf, 2, self, fmt);
|
61
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
BIT_DIGIT *a1, x=0;
|
6
|
+
size_t p1;
|
7
|
+
ssize_t s1;
|
8
|
+
size_t *idx1;
|
9
|
+
VALUE y;
|
10
|
+
VALUE fmt = lp->option;
|
11
|
+
volatile VALUE a;
|
12
|
+
|
13
|
+
INIT_COUNTER(lp, i);
|
14
|
+
INIT_PTR_BIT_IDX(lp, 0, a1, p1, s1, idx1);
|
15
|
+
a = rb_ary_new2(i);
|
16
|
+
rb_ary_push(lp->args[1].value, a);
|
17
|
+
if (idx1) {
|
18
|
+
for (; i--;) {
|
19
|
+
LOAD_BIT(a1, p1+*idx1, x); idx1++;
|
20
|
+
y = format_bit(fmt, x);
|
21
|
+
rb_ary_push(a,y);
|
22
|
+
}
|
23
|
+
} else {
|
24
|
+
for (; i--;) {
|
25
|
+
LOAD_BIT(a1, p1, x); p1+=s1;
|
26
|
+
y = format_bit(fmt, x);
|
27
|
+
rb_ary_push(a,y);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
/*
|
33
|
+
Format elements into strings.
|
34
|
+
@overload <%=method%> format
|
35
|
+
@param [String] format
|
36
|
+
@return [Array] array of formated strings.
|
37
|
+
*/
|
38
|
+
static VALUE
|
39
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
40
|
+
{
|
41
|
+
volatile VALUE fmt=Qnil;
|
42
|
+
ndfunc_arg_in_t ain[3] = {{Qnil,0},{sym_loop_opt},{sym_option}};
|
43
|
+
ndfunc_arg_out_t aout[1] = {{rb_cArray,0}}; // dummy?
|
44
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP_NIP, 3,1, ain,aout};
|
45
|
+
|
46
|
+
rb_scan_args(argc, argv, "01", &fmt);
|
47
|
+
return na_ndloop_cast_narray_to_rarray(&ndf, self, fmt);
|
48
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
static VALUE
|
2
|
+
<%=c_iter%>(char *ptr, size_t pos, VALUE fmt)
|
3
|
+
{
|
4
|
+
dtype x;
|
5
|
+
LOAD_BIT(ptr,pos,x);
|
6
|
+
return format_<%=tp%>(fmt, x);
|
7
|
+
}
|
8
|
+
|
9
|
+
/*
|
10
|
+
Returns a string containing a human-readable representation of NArray.
|
11
|
+
@overload inspect
|
12
|
+
@return [String]
|
13
|
+
*/
|
14
|
+
VALUE
|
15
|
+
<%=c_func%>(VALUE ary)
|
16
|
+
{
|
17
|
+
return na_ndloop_inspect(ary, <%=c_iter%>, Qnil);
|
18
|
+
}
|
@@ -0,0 +1,94 @@
|
|
1
|
+
static inline dtype
|
2
|
+
yield_map_with_index(dtype x, size_t *c, VALUE *a, int nd, int md)
|
3
|
+
{
|
4
|
+
int j;
|
5
|
+
VALUE y;
|
6
|
+
|
7
|
+
a[0] = m_data_to_num(x);
|
8
|
+
for (j=0; j<=nd; j++) {
|
9
|
+
a[j+1] = SIZET2NUM(c[j]);
|
10
|
+
}
|
11
|
+
y = rb_yield(rb_ary_new4(md,a));
|
12
|
+
return m_num_to_data(y);
|
13
|
+
}
|
14
|
+
|
15
|
+
void
|
16
|
+
<%=c_iter%>(na_loop_t *const lp)
|
17
|
+
{
|
18
|
+
size_t i;
|
19
|
+
char *p1, *p2;
|
20
|
+
ssize_t s1, s2;
|
21
|
+
size_t *idx1, *idx2;
|
22
|
+
dtype x;
|
23
|
+
VALUE *a;
|
24
|
+
size_t *c;
|
25
|
+
int nd, md;
|
26
|
+
|
27
|
+
c = (size_t*)(lp->opt_ptr);
|
28
|
+
nd = lp->ndim - 1;
|
29
|
+
md = lp->ndim + 1;
|
30
|
+
a = ALLOCA_N(VALUE,md);
|
31
|
+
|
32
|
+
INIT_COUNTER(lp, i);
|
33
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
34
|
+
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
35
|
+
|
36
|
+
c[nd] = 0;
|
37
|
+
if (idx1) {
|
38
|
+
if (idx2) {
|
39
|
+
for (; i--;) {
|
40
|
+
GET_DATA_INDEX(p1,idx1,dtype,x);
|
41
|
+
x = yield_map_with_index(x,c,a,nd,md);
|
42
|
+
SET_DATA_INDEX(p2,idx2,dtype,x);
|
43
|
+
c[nd]++;
|
44
|
+
}
|
45
|
+
} else {
|
46
|
+
for (; i--;) {
|
47
|
+
GET_DATA_INDEX(p1,idx1,dtype,x);
|
48
|
+
x = yield_map_with_index(x,c,a,nd,md);
|
49
|
+
SET_DATA_STRIDE(p2,s2,dtype,x);
|
50
|
+
c[nd]++;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
} else {
|
54
|
+
if (idx2) {
|
55
|
+
for (; i--;) {
|
56
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
57
|
+
x = yield_map_with_index(x,c,a,nd,md);
|
58
|
+
SET_DATA_INDEX(p2,idx2,dtype,x);
|
59
|
+
c[nd]++;
|
60
|
+
}
|
61
|
+
} else {
|
62
|
+
for (; i--;) {
|
63
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
64
|
+
x = yield_map_with_index(x,c,a,nd,md);
|
65
|
+
SET_DATA_STRIDE(p2,s2,dtype,x);
|
66
|
+
c[nd]++;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
/*
|
73
|
+
Invokes the given block once for each element of self,
|
74
|
+
passing that element and indices along each axis as parameters.
|
75
|
+
Creates a new NArray containing the values returned by the block.
|
76
|
+
Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.
|
77
|
+
|
78
|
+
@overload <%=method%>
|
79
|
+
|
80
|
+
For a block {|x,i,j,...| ... }
|
81
|
+
@yield [x,i,j,...] x is an element, i,j,... are multidimensional indices.
|
82
|
+
|
83
|
+
@return [Numo::NArray] mapped array
|
84
|
+
|
85
|
+
*/
|
86
|
+
static VALUE
|
87
|
+
<%=c_func%>(VALUE self)
|
88
|
+
{
|
89
|
+
ndfunc_arg_in_t ain[1] = {{Qnil,0}};
|
90
|
+
ndfunc_arg_out_t aout[1] = {{cT,0}};
|
91
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP, 1,1, ain,aout};
|
92
|
+
|
93
|
+
return na_ndloop_with_index(&ndf, 1, self);
|
94
|
+
}
|
@@ -0,0 +1,117 @@
|
|
1
|
+
static void
|
2
|
+
iter_bit_pointer(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
BIT_DIGIT *a;
|
6
|
+
size_t p1, p2;
|
7
|
+
ssize_t s1, s2;
|
8
|
+
size_t *idx1, *idx2, *pidx;
|
9
|
+
BIT_DIGIT x=0;
|
10
|
+
size_t count;
|
11
|
+
where_opt_t *g;
|
12
|
+
|
13
|
+
g = (where_opt_t*)(lp->opt_ptr);
|
14
|
+
count = g->count;
|
15
|
+
pidx = (size_t*)(g->idx1);
|
16
|
+
INIT_COUNTER(lp, i);
|
17
|
+
INIT_PTR_BIT_IDX(lp, 0, a, p1, s1, idx1);
|
18
|
+
//INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
19
|
+
p2 = lp->args[1].iter[0].pos;
|
20
|
+
s2 = lp->args[1].iter[0].step;
|
21
|
+
idx2 = lp->args[1].iter[0].idx;
|
22
|
+
|
23
|
+
if (idx1) {
|
24
|
+
if (idx2) {
|
25
|
+
for (; i--;) {
|
26
|
+
LOAD_BIT(a, p1+*idx1, x);
|
27
|
+
idx1++;
|
28
|
+
if (x) {
|
29
|
+
*(pidx++) = p2+*idx2;
|
30
|
+
count++;
|
31
|
+
}
|
32
|
+
idx2++;
|
33
|
+
}
|
34
|
+
} else {
|
35
|
+
for (; i--;) {
|
36
|
+
LOAD_BIT(a, p1+*idx1, x);
|
37
|
+
idx1++;
|
38
|
+
if (x) {
|
39
|
+
*(pidx++) = p2;
|
40
|
+
count++;
|
41
|
+
}
|
42
|
+
p2 += s2;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
} else {
|
46
|
+
if (idx2) {
|
47
|
+
for (; i--;) {
|
48
|
+
LOAD_BIT(a, p1, x);
|
49
|
+
p1 += s1;
|
50
|
+
if (x) {
|
51
|
+
*(pidx++) = p2+*idx2;
|
52
|
+
count++;
|
53
|
+
}
|
54
|
+
idx2++;
|
55
|
+
}
|
56
|
+
} else {
|
57
|
+
for (; i--;) {
|
58
|
+
LOAD_BIT(a, p1, x);
|
59
|
+
p1 += s1;
|
60
|
+
if (x) {
|
61
|
+
*(pidx++) = p2;
|
62
|
+
count++;
|
63
|
+
}
|
64
|
+
p2 += s2;
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
g->count = count;
|
69
|
+
g->idx1 = (char*)pidx;
|
70
|
+
}
|
71
|
+
|
72
|
+
#if SIZEOF_VOIDP == 8
|
73
|
+
#define cIndex numo_cInt64
|
74
|
+
#elif SIZEOF_VOIDP == 4
|
75
|
+
#define cIndex numo_cInt32
|
76
|
+
#endif
|
77
|
+
|
78
|
+
/*
|
79
|
+
Return subarray of argument masked with self bit array.
|
80
|
+
@overload <%=op_map%>(array)
|
81
|
+
@param [Numo::NArray] array narray to be masked.
|
82
|
+
@return [Numo::NArray] view of masked array.
|
83
|
+
*/
|
84
|
+
static VALUE
|
85
|
+
numo_bit_mask(VALUE mask, VALUE val)
|
86
|
+
{
|
87
|
+
volatile VALUE idx_1, view;
|
88
|
+
narray_data_t *nidx;
|
89
|
+
narray_view_t *nv;
|
90
|
+
stridx_t stridx0;
|
91
|
+
size_t n_1;
|
92
|
+
where_opt_t g;
|
93
|
+
ndfunc_arg_in_t ain[2] = {{cT,0},{Qnil,0}};
|
94
|
+
ndfunc_t ndf = {iter_bit_pointer, FULL_LOOP, 2, 0, ain, 0};
|
95
|
+
|
96
|
+
n_1 = NUM2SIZET(numo_bit_count_true(0, NULL, mask));
|
97
|
+
idx_1 = rb_narray_new(cIndex, 1, &n_1);
|
98
|
+
g.count = 0;
|
99
|
+
g.elmsz = SIZEOF_VOIDP;
|
100
|
+
g.idx1 = na_get_pointer_for_write(idx_1);
|
101
|
+
g.idx0 = NULL;
|
102
|
+
na_ndloop3(&ndf, &g, 2, mask, val);
|
103
|
+
|
104
|
+
view = na_s_allocate_view(CLASS_OF(val));
|
105
|
+
GetNArrayView(view, nv);
|
106
|
+
na_setup_shape((narray_t*)nv, 1, &n_1);
|
107
|
+
|
108
|
+
GetNArrayData(idx_1,nidx);
|
109
|
+
SDX_SET_INDEX(stridx0,(size_t*)nidx->ptr);
|
110
|
+
nidx->ptr = NULL;
|
111
|
+
|
112
|
+
nv->stridx = ALLOC_N(stridx_t,1);
|
113
|
+
nv->stridx[0] = stridx0;
|
114
|
+
nv->offset = 0;
|
115
|
+
nv->data = val;
|
116
|
+
return view;
|
117
|
+
}
|