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,45 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
char *p1;
|
6
|
+
BIT_DIGIT *a2;
|
7
|
+
size_t p2;
|
8
|
+
ssize_t s1, s2;
|
9
|
+
size_t *idx1;
|
10
|
+
dtype x;
|
11
|
+
BIT_DIGIT b;
|
12
|
+
INIT_COUNTER(lp, i);
|
13
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
14
|
+
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
15
|
+
if (idx1) {
|
16
|
+
for (; i--;) {
|
17
|
+
GET_DATA_INDEX(p1,idx1,dtype,x);
|
18
|
+
b = (m_<%=method%>(x)) ? 1:0;
|
19
|
+
STORE_BIT(a2,p2,b);
|
20
|
+
p2+=s2;
|
21
|
+
}
|
22
|
+
} else {
|
23
|
+
for (; i--;) {
|
24
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
25
|
+
b = (m_<%=method%>(x)) ? 1:0;
|
26
|
+
STORE_BIT(a2,p2,b);
|
27
|
+
p2+=s2;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
/*
|
33
|
+
Condition of <%=method%>.
|
34
|
+
@overload <%=method%>
|
35
|
+
@return [Numo::Bit] Condition of <%=method%>.
|
36
|
+
*/
|
37
|
+
static VALUE
|
38
|
+
<%=c_func%>(VALUE self)
|
39
|
+
{
|
40
|
+
ndfunc_arg_in_t ain[1] = {{cT,0}};
|
41
|
+
ndfunc_arg_out_t aout[1] = {{numo_cBit,0}};
|
42
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 1, 1, ain, aout };
|
43
|
+
|
44
|
+
return na_ndloop(&ndf, 1, self);
|
45
|
+
}
|
@@ -0,0 +1,42 @@
|
|
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
|
+
dtype x, y;
|
8
|
+
|
9
|
+
INIT_COUNTER(lp, i);
|
10
|
+
INIT_PTR(lp, 0, p1, s1);
|
11
|
+
INIT_PTR(lp, 1, p2, s2);
|
12
|
+
//printf("i=%lu p1=%lx s1=%lu p2=%lx s2=%lu\n",i,(size_t)p1,s1,(size_t)p2,s2);
|
13
|
+
|
14
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
15
|
+
SET_DATA_STRIDE(p2,s2,dtype,x);
|
16
|
+
//printf("i=%lu x=%f\n",i,x);
|
17
|
+
for (i--; i--;) {
|
18
|
+
GET_DATA_STRIDE(p1,s1,dtype,y);
|
19
|
+
x = m_<%=cmacro%>(x,y);
|
20
|
+
SET_DATA_STRIDE(p2,s2,dtype,x);
|
21
|
+
//printf("i=%lu x=%f\n",i,x);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
/*
|
26
|
+
<%=method.capitalize%> of self.
|
27
|
+
@overload <%=method%>(*args)
|
28
|
+
@param [Array of Numeric,Range] args Affected dimensions.
|
29
|
+
@return [Numo::<%=class_name%>] <%=method%> of self.
|
30
|
+
*/
|
31
|
+
static VALUE
|
32
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
33
|
+
{
|
34
|
+
VALUE reduce;
|
35
|
+
ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
|
36
|
+
ndfunc_arg_out_t aout[1] = {{cT,0}};
|
37
|
+
ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP_NIP|NDF_INPLACE|NDF_FLAT_REDUCE|NDF_CUM,
|
38
|
+
2, 1, ain, aout };
|
39
|
+
|
40
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self);
|
41
|
+
return na_ndloop(&ndf, 2, self, reduce);
|
42
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i, s1;
|
5
|
+
char *p1;
|
6
|
+
size_t *idx1;
|
7
|
+
dtype x;
|
8
|
+
VALUE y;
|
9
|
+
|
10
|
+
INIT_COUNTER(lp, i);
|
11
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
12
|
+
if (idx1) {
|
13
|
+
for (; i--;) {
|
14
|
+
GET_DATA_INDEX(p1,idx1,dtype,x);
|
15
|
+
y = m_data_to_num(x);
|
16
|
+
rb_yield(y);
|
17
|
+
}
|
18
|
+
} else {
|
19
|
+
for (; i--;) {
|
20
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
21
|
+
y = m_data_to_num(x);
|
22
|
+
rb_yield(y);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
/*
|
28
|
+
Calls the given block once for each element in self,
|
29
|
+
passing that element as a parameter.
|
30
|
+
@overload <%=method%>
|
31
|
+
@return [Numo::NArray] self
|
32
|
+
For a block {|x| ... }
|
33
|
+
@yield [x] x is element of NArray.
|
34
|
+
*/
|
35
|
+
static VALUE
|
36
|
+
<%=c_func%>(VALUE self)
|
37
|
+
{
|
38
|
+
ndfunc_arg_in_t ain[1] = {{Qnil,0}};
|
39
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP_NIP, 1,0, ain,0};
|
40
|
+
|
41
|
+
na_ndloop(&ndf, 1, self);
|
42
|
+
return self;
|
43
|
+
}
|
@@ -0,0 +1,64 @@
|
|
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] = SIZE2NUM(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, s1;
|
18
|
+
char *p1;
|
19
|
+
size_t *idx1;
|
20
|
+
dtype x;
|
21
|
+
VALUE *a;
|
22
|
+
size_t *c;
|
23
|
+
int nd, md;
|
24
|
+
|
25
|
+
c = (size_t*)(lp->opt_ptr);
|
26
|
+
nd = lp->ndim - 1;
|
27
|
+
md = lp->ndim + 1;
|
28
|
+
a = ALLOCA_N(VALUE,md);
|
29
|
+
|
30
|
+
INIT_COUNTER(lp, i);
|
31
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
32
|
+
c[nd] = 0;
|
33
|
+
if (idx1) {
|
34
|
+
for (; i--;) {
|
35
|
+
GET_DATA_INDEX(p1,idx1,dtype,x);
|
36
|
+
yield_each_with_index(x,c,a,nd,md);
|
37
|
+
c[nd]++;
|
38
|
+
}
|
39
|
+
} else {
|
40
|
+
for (; i--;) {
|
41
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
42
|
+
yield_each_with_index(x,c,a,nd,md);
|
43
|
+
c[nd]++;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
/*
|
49
|
+
Invokes the given block once for each element of self,
|
50
|
+
passing that element and indices along each axis as parameters.
|
51
|
+
@overload <%=method%>
|
52
|
+
@return [Numo::NArray] self
|
53
|
+
For a block {|x,i,j,...| ... }
|
54
|
+
@yield [x,i,j,...] x is an element, i,j,... are multidimensional indices.
|
55
|
+
*/
|
56
|
+
static VALUE
|
57
|
+
<%=c_func%>(VALUE self)
|
58
|
+
{
|
59
|
+
ndfunc_arg_in_t ain[1] = {{Qnil,0}};
|
60
|
+
ndfunc_t ndf = {<%=c_iter%>, FULL_LOOP_NIP, 1,0, ain,0};
|
61
|
+
|
62
|
+
na_ndloop_with_index(&ndf, 1, self);
|
63
|
+
return self;
|
64
|
+
}
|
@@ -0,0 +1,23 @@
|
|
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
|
+
VALUE
|
9
|
+
numo_<%=tp%>_extract(VALUE self)
|
10
|
+
{
|
11
|
+
volatile VALUE v;
|
12
|
+
char *ptr;
|
13
|
+
narray_t *na;
|
14
|
+
GetNArray(self,na);
|
15
|
+
|
16
|
+
if (na->ndim==0) {
|
17
|
+
ptr = na_get_pointer_for_read(self) + na_get_offset(self);
|
18
|
+
v = m_extract(ptr);
|
19
|
+
na_release_lock(self);
|
20
|
+
return v;
|
21
|
+
}
|
22
|
+
return self;
|
23
|
+
}
|
@@ -0,0 +1,91 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t n0, n1;
|
5
|
+
size_t i0, i1;
|
6
|
+
ssize_t s0, s1;
|
7
|
+
char *p0, *p1;
|
8
|
+
char *g;
|
9
|
+
ssize_t kofs;
|
10
|
+
dtype data;
|
11
|
+
|
12
|
+
g = (char*)(lp->opt_ptr);
|
13
|
+
kofs = *(ssize_t*)g;
|
14
|
+
data = *(dtype*)(g+sizeof(ssize_t));
|
15
|
+
|
16
|
+
n0 = lp->args[0].shape[0];
|
17
|
+
n1 = lp->args[0].shape[1];
|
18
|
+
s0 = lp->args[0].iter[0].step;
|
19
|
+
s1 = lp->args[0].iter[1].step;
|
20
|
+
p0 = NDL_PTR(lp,0);
|
21
|
+
|
22
|
+
for (i0=0; i0 < n0; i0++) {
|
23
|
+
p1 = p0;
|
24
|
+
for (i1=0; i1 < n1; i1++) {
|
25
|
+
*(dtype*)p1 = (i0+kofs==i1) ? data : m_zero;
|
26
|
+
p1 += s1;
|
27
|
+
}
|
28
|
+
p0 += s0;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
/*
|
33
|
+
Eye: Set a value to diagonal components, set 0 to non-diagonal components.
|
34
|
+
@overload <%=method%>([element,offset])
|
35
|
+
@param [Numeric] element Diagonal element to be stored. Default is 1.
|
36
|
+
@param [Integer] offset Diagonal offset from the main diagonal. The
|
37
|
+
default is 0. k>0 for diagonals above the main diagonal, and k<0
|
38
|
+
for diagonals below the main diagonal.
|
39
|
+
@return [Numo::<%=class_name%>] <%=method%> of self.
|
40
|
+
*/
|
41
|
+
static VALUE
|
42
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
43
|
+
{
|
44
|
+
ndfunc_arg_in_t ain[1] = {{OVERWRITE,2}};
|
45
|
+
ndfunc_t ndf = {<%=c_iter%>, NO_LOOP, 1,0, ain,0};
|
46
|
+
ssize_t kofs;
|
47
|
+
dtype data;
|
48
|
+
char *g;
|
49
|
+
int nd;
|
50
|
+
narray_t *na;
|
51
|
+
|
52
|
+
// check arguments
|
53
|
+
if (argc > 2) {
|
54
|
+
rb_raise(rb_eArgError,"too many arguments (%d for 0..2)",argc);
|
55
|
+
} else if (argc == 2) {
|
56
|
+
data = m_num_to_data(argv[0]);
|
57
|
+
kofs = NUM2SSIZE(argv[1]);
|
58
|
+
} else if (argc == 1) {
|
59
|
+
data = m_num_to_data(argv[0]);
|
60
|
+
kofs = 0;
|
61
|
+
} else {
|
62
|
+
data = m_one;
|
63
|
+
kofs = 0;
|
64
|
+
}
|
65
|
+
|
66
|
+
GetNArray(self,na);
|
67
|
+
nd = na->ndim;
|
68
|
+
if (nd < 2) {
|
69
|
+
rb_raise(nary_eDimensionError,"less than 2-d array");
|
70
|
+
}
|
71
|
+
|
72
|
+
// Diagonal offset from the main diagonal.
|
73
|
+
if (kofs >= 0) {
|
74
|
+
if ((size_t)(kofs) >= na->shape[nd-1]) {
|
75
|
+
rb_raise(rb_eArgError,"invalid diagonal offset(%ld) for "
|
76
|
+
"last dimension size(%ld)",kofs,na->shape[nd-1]);
|
77
|
+
}
|
78
|
+
} else {
|
79
|
+
if ((size_t)(-kofs) >= na->shape[nd-2]) {
|
80
|
+
rb_raise(rb_eArgError,"invalid diagonal offset(%ld) for "
|
81
|
+
"last-1 dimension size(%ld)",kofs,na->shape[nd-2]);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
g = ALLOCA_N(char,sizeof(ssize_t)+sizeof(dtype));
|
86
|
+
*(ssize_t*)g = kofs;
|
87
|
+
*(dtype*)(g+sizeof(ssize_t)) = data;
|
88
|
+
|
89
|
+
na_ndloop3(&ndf, g, 1, self);
|
90
|
+
return self;
|
91
|
+
}
|
@@ -0,0 +1,38 @@
|
|
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
|
+
VALUE x = lp->option;
|
9
|
+
dtype y;
|
10
|
+
INIT_COUNTER(lp, i);
|
11
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
12
|
+
y = m_num_to_data(x);
|
13
|
+
if (idx1) {
|
14
|
+
for (; i--;) {
|
15
|
+
SET_DATA_INDEX(p1,idx1,dtype,y);
|
16
|
+
}
|
17
|
+
} else {
|
18
|
+
for (; i--;) {
|
19
|
+
SET_DATA_STRIDE(p1,s1,dtype,y);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
/*
|
25
|
+
Fill elements with other.
|
26
|
+
@overload <%=method%> other
|
27
|
+
@param [Numeric] other
|
28
|
+
@return [Numo::<%=class_name%>] self.
|
29
|
+
*/
|
30
|
+
static VALUE
|
31
|
+
<%=c_func%>(VALUE self, VALUE val)
|
32
|
+
{
|
33
|
+
ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{sym_option}};
|
34
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP, 2, 0, ain, 0 };
|
35
|
+
|
36
|
+
na_ndloop(&ndf, 2, self, val);
|
37
|
+
return self;
|
38
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
static VALUE
|
2
|
+
format_<%=tp%>(VALUE fmt, dtype* x)
|
3
|
+
{
|
4
|
+
// fix-me
|
5
|
+
char s[48];
|
6
|
+
int n;
|
7
|
+
|
8
|
+
if (NIL_P(fmt)) {
|
9
|
+
n = m_sprintf(s,*x);
|
10
|
+
return rb_str_new(s,n);
|
11
|
+
}
|
12
|
+
return rb_funcall(fmt, '%', 1, m_data_to_num(*x));
|
13
|
+
}
|
14
|
+
|
15
|
+
static 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;
|
22
|
+
dtype *x;
|
23
|
+
VALUE y;
|
24
|
+
VALUE fmt = lp->option;
|
25
|
+
INIT_COUNTER(lp, i);
|
26
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
27
|
+
INIT_PTR(lp, 1, p2, s2);
|
28
|
+
if (idx1) {
|
29
|
+
for (; i--;) {
|
30
|
+
x = (dtype*)(p1+*idx1); idx1++;
|
31
|
+
y = format_<%=tp%>(fmt, x);
|
32
|
+
SET_DATA_STRIDE(p2, s2, VALUE, y);
|
33
|
+
}
|
34
|
+
} else {
|
35
|
+
for (; i--;) {
|
36
|
+
x = (dtype*)p1; p1+=s1;
|
37
|
+
y = format_<%=tp%>(fmt, x);
|
38
|
+
SET_DATA_STRIDE(p2, s2, VALUE, y);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
/*
|
44
|
+
Format elements into strings.
|
45
|
+
@overload <%=method%> format
|
46
|
+
@param [String] format
|
47
|
+
@return [Numo::RObject] array of formated strings.
|
48
|
+
*/
|
49
|
+
static VALUE
|
50
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
51
|
+
{
|
52
|
+
VALUE fmt=Qnil;
|
53
|
+
|
54
|
+
ndfunc_arg_in_t ain[2] = {{Qnil,0},{sym_option}};
|
55
|
+
ndfunc_arg_out_t aout[1] = {{numo_cRObject,0}};
|
56
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP_NIP, 2, 1, ain, aout };
|
57
|
+
|
58
|
+
rb_scan_args(argc, argv, "01", &fmt);
|
59
|
+
return na_ndloop(&ndf, 2, self, fmt);
|
60
|
+
}
|
@@ -0,0 +1,47 @@
|
|
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
|
+
VALUE y;
|
10
|
+
volatile VALUE a;
|
11
|
+
VALUE fmt = lp->option;
|
12
|
+
INIT_COUNTER(lp, i);
|
13
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
14
|
+
a = rb_ary_new2(i);
|
15
|
+
rb_ary_push(lp->args[1].value, a);
|
16
|
+
if (idx1) {
|
17
|
+
for (; i--;) {
|
18
|
+
x = (dtype*)(p1 + *idx1); idx1++;
|
19
|
+
y = format_<%=tp%>(fmt, x);
|
20
|
+
rb_ary_push(a,y);
|
21
|
+
}
|
22
|
+
} else {
|
23
|
+
for (; i--;) {
|
24
|
+
x = (dtype*)p1; p1+=s1;
|
25
|
+
y = format_<%=tp%>(fmt, x);
|
26
|
+
rb_ary_push(a,y);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
/*
|
32
|
+
Format elements into strings.
|
33
|
+
@overload <%=method%> format
|
34
|
+
@param [String] format
|
35
|
+
@return [Array] array of formated strings.
|
36
|
+
*/
|
37
|
+
static VALUE
|
38
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
39
|
+
{
|
40
|
+
volatile VALUE fmt=Qnil;
|
41
|
+
ndfunc_arg_in_t ain[3] = {{Qnil,0},{sym_loop_opt},{sym_option}};
|
42
|
+
ndfunc_arg_out_t aout[1] = {{rb_cArray,0}}; // dummy?
|
43
|
+
ndfunc_t ndf = { <%=c_iter%>, FULL_LOOP_NIP, 3, 1, ain, aout };
|
44
|
+
|
45
|
+
rb_scan_args(argc, argv, "01", &fmt);
|
46
|
+
return na_ndloop_cast_narray_to_rarray(&ndf, self, fmt);
|
47
|
+
}
|