cumo 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/3rd_party/LICENSE.txt +60 -0
- data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +13 -1
- data/LICENSE.txt +1 -62
- data/README.md +33 -29
- data/bench/cumo_bench.rb +47 -25
- data/bench/numo_bench.rb +27 -25
- data/docs/src-tree.md +16 -0
- data/ext/cumo/cuda/cublas.c +69 -219
- data/ext/cumo/cuda/memory_pool_impl.hpp +1 -0
- data/ext/cumo/cuda/runtime.c +2 -14
- data/ext/cumo/cumo.c +16 -16
- data/ext/cumo/include/cumo.h +2 -2
- data/ext/cumo/include/cumo/cuda/cublas.h +6 -129
- data/ext/cumo/include/cumo/cuda/runtime.h +16 -0
- data/ext/cumo/include/cumo/indexer.h +46 -63
- data/ext/cumo/include/cumo/intern.h +58 -112
- data/ext/cumo/include/cumo/narray.h +214 -185
- data/ext/cumo/include/cumo/narray_kernel.h +66 -37
- data/ext/cumo/include/cumo/ndloop.h +42 -42
- data/ext/cumo/include/cumo/reduce_kernel.h +55 -71
- data/ext/cumo/include/cumo/template.h +56 -51
- data/ext/cumo/include/cumo/template_kernel.h +31 -31
- data/ext/cumo/include/cumo/types/bit.h +3 -3
- data/ext/cumo/include/cumo/types/bit_kernel.h +2 -2
- data/ext/cumo/include/cumo/types/complex.h +126 -126
- data/ext/cumo/include/cumo/types/complex_kernel.h +126 -126
- data/ext/cumo/include/cumo/types/complex_macro.h +28 -28
- data/ext/cumo/include/cumo/types/complex_macro_kernel.h +20 -20
- data/ext/cumo/include/cumo/types/dcomplex.h +5 -5
- data/ext/cumo/include/cumo/types/dcomplex_kernel.h +1 -1
- data/ext/cumo/include/cumo/types/int_macro.h +1 -1
- data/ext/cumo/include/cumo/types/int_macro_kernel.h +1 -1
- data/ext/cumo/include/cumo/types/robj_macro.h +30 -30
- data/ext/cumo/include/cumo/types/scomplex.h +5 -5
- data/ext/cumo/include/cumo/types/scomplex_kernel.h +1 -1
- data/ext/cumo/narray/array.c +143 -143
- data/ext/cumo/narray/data.c +184 -184
- data/ext/cumo/narray/gen/cogen.rb +5 -2
- data/ext/cumo/narray/gen/cogen_kernel.rb +5 -2
- data/ext/cumo/narray/gen/def/dcomplex.rb +1 -1
- data/ext/cumo/narray/gen/def/scomplex.rb +1 -1
- data/ext/cumo/narray/gen/erbln.rb +132 -0
- data/ext/cumo/narray/gen/erbpp2.rb +18 -13
- data/ext/cumo/narray/gen/narray_def.rb +3 -3
- data/ext/cumo/narray/gen/spec.rb +2 -2
- data/ext/cumo/narray/gen/tmpl/accum.c +15 -15
- data/ext/cumo/narray/gen/tmpl/accum_binary.c +22 -22
- data/ext/cumo/narray/gen/tmpl/accum_binary_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/accum_index.c +30 -30
- data/ext/cumo/narray/gen/tmpl/accum_index_kernel.cu +2 -2
- data/ext/cumo/narray/gen/tmpl/accum_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/alloc_func.c +14 -14
- data/ext/cumo/narray/gen/tmpl/allocate.c +11 -11
- data/ext/cumo/narray/gen/tmpl/aref.c +2 -2
- data/ext/cumo/narray/gen/tmpl/aref_cpu.c +4 -4
- data/ext/cumo/narray/gen/tmpl/aset.c +2 -2
- data/ext/cumo/narray/gen/tmpl/binary.c +28 -28
- data/ext/cumo/narray/gen/tmpl/binary2.c +18 -18
- data/ext/cumo/narray/gen/tmpl/binary2_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/binary_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/binary_s.c +13 -13
- data/ext/cumo/narray/gen/tmpl/binary_s_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/bincount.c +23 -23
- data/ext/cumo/narray/gen/tmpl/cast.c +7 -7
- data/ext/cumo/narray/gen/tmpl/cast_array.c +3 -3
- data/ext/cumo/narray/gen/tmpl/clip.c +38 -38
- data/ext/cumo/narray/gen/tmpl/complex_accum_kernel.cu +2 -2
- data/ext/cumo/narray/gen/tmpl/cond_binary.c +19 -19
- data/ext/cumo/narray/gen/tmpl/cond_binary_kernel.cu +7 -7
- data/ext/cumo/narray/gen/tmpl/cond_unary.c +15 -15
- data/ext/cumo/narray/gen/tmpl/cum.c +15 -15
- data/ext/cumo/narray/gen/tmpl/each.c +9 -9
- data/ext/cumo/narray/gen/tmpl/each_with_index.c +9 -9
- data/ext/cumo/narray/gen/tmpl/ewcomp.c +15 -15
- data/ext/cumo/narray/gen/tmpl/ewcomp_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/extract_cpu.c +5 -5
- data/ext/cumo/narray/gen/tmpl/extract_data.c +12 -12
- data/ext/cumo/narray/gen/tmpl/eye.c +9 -9
- data/ext/cumo/narray/gen/tmpl/eye_kernel.cu +3 -3
- data/ext/cumo/narray/gen/tmpl/fill.c +9 -9
- data/ext/cumo/narray/gen/tmpl/fill_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/float_accum_kernel.cu +1 -1
- data/ext/cumo/narray/gen/tmpl/format.c +11 -11
- data/ext/cumo/narray/gen/tmpl/format_to_a.c +8 -8
- data/ext/cumo/narray/gen/tmpl/frexp.c +13 -13
- data/ext/cumo/narray/gen/tmpl/gemm.c +252 -108
- data/ext/cumo/narray/gen/tmpl/inspect.c +1 -1
- data/ext/cumo/narray/gen/tmpl/lib.c +2 -2
- data/ext/cumo/narray/gen/tmpl/logseq.c +7 -7
- data/ext/cumo/narray/gen/tmpl/logseq_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/map_with_index.c +17 -17
- data/ext/cumo/narray/gen/tmpl/median.c +10 -10
- data/ext/cumo/narray/gen/tmpl/minmax.c +10 -10
- data/ext/cumo/narray/gen/tmpl/new_dim0.c +3 -3
- data/ext/cumo/narray/gen/tmpl/poly.c +6 -6
- data/ext/cumo/narray/gen/tmpl/pow.c +28 -28
- data/ext/cumo/narray/gen/tmpl/pow_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/rand.c +10 -10
- data/ext/cumo/narray/gen/tmpl/rand_norm.c +7 -7
- data/ext/cumo/narray/gen/tmpl/real_accum_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/seq.c +7 -7
- data/ext/cumo/narray/gen/tmpl/seq_kernel.cu +6 -6
- data/ext/cumo/narray/gen/tmpl/set2.c +20 -20
- data/ext/cumo/narray/gen/tmpl/sort.c +11 -11
- data/ext/cumo/narray/gen/tmpl/sort_index.c +18 -18
- data/ext/cumo/narray/gen/tmpl/store.c +6 -6
- data/ext/cumo/narray/gen/tmpl/store_array.c +19 -19
- data/ext/cumo/narray/gen/tmpl/store_array_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl/store_bit.c +23 -23
- data/ext/cumo/narray/gen/tmpl/store_bit_kernel.cu +28 -28
- data/ext/cumo/narray/gen/tmpl/store_from.c +16 -16
- data/ext/cumo/narray/gen/tmpl/store_from_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl/to_a.c +10 -10
- data/ext/cumo/narray/gen/tmpl/unary.c +25 -25
- data/ext/cumo/narray/gen/tmpl/unary2.c +17 -17
- data/ext/cumo/narray/gen/tmpl/unary_kernel.cu +15 -15
- data/ext/cumo/narray/gen/tmpl/unary_ret2.c +13 -13
- data/ext/cumo/narray/gen/tmpl/unary_s.c +17 -17
- data/ext/cumo/narray/gen/tmpl/unary_s_kernel.cu +12 -12
- data/ext/cumo/narray/gen/tmpl_bit/allocate.c +9 -9
- data/ext/cumo/narray/gen/tmpl_bit/aref.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/aref_cpu.c +5 -5
- data/ext/cumo/narray/gen/tmpl_bit/aset.c +2 -2
- data/ext/cumo/narray/gen/tmpl_bit/binary.c +29 -29
- data/ext/cumo/narray/gen/tmpl_bit/bit_count.c +14 -14
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_cpu.c +21 -21
- data/ext/cumo/narray/gen/tmpl_bit/bit_count_kernel.cu +28 -28
- data/ext/cumo/narray/gen/tmpl_bit/bit_reduce.c +29 -29
- data/ext/cumo/narray/gen/tmpl_bit/each.c +10 -10
- data/ext/cumo/narray/gen/tmpl_bit/each_with_index.c +10 -10
- data/ext/cumo/narray/gen/tmpl_bit/extract.c +8 -8
- data/ext/cumo/narray/gen/tmpl_bit/extract_cpu.c +8 -8
- data/ext/cumo/narray/gen/tmpl_bit/fill.c +17 -17
- data/ext/cumo/narray/gen/tmpl_bit/format.c +14 -14
- data/ext/cumo/narray/gen/tmpl_bit/format_to_a.c +11 -11
- data/ext/cumo/narray/gen/tmpl_bit/inspect.c +3 -3
- data/ext/cumo/narray/gen/tmpl_bit/mask.c +33 -33
- data/ext/cumo/narray/gen/tmpl_bit/store_array.c +19 -19
- data/ext/cumo/narray/gen/tmpl_bit/store_bit.c +22 -22
- data/ext/cumo/narray/gen/tmpl_bit/store_from.c +18 -18
- data/ext/cumo/narray/gen/tmpl_bit/to_a.c +12 -12
- data/ext/cumo/narray/gen/tmpl_bit/unary.c +24 -24
- data/ext/cumo/narray/gen/tmpl_bit/where.c +16 -16
- data/ext/cumo/narray/gen/tmpl_bit/where2.c +20 -20
- data/ext/cumo/narray/index.c +213 -213
- data/ext/cumo/narray/math.c +27 -27
- data/ext/cumo/narray/narray.c +484 -484
- data/ext/cumo/narray/ndloop.c +259 -258
- data/ext/cumo/narray/rand.c +3 -3
- data/ext/cumo/narray/step.c +70 -70
- data/ext/cumo/narray/struct.c +139 -139
- metadata +6 -7
- data/ext/cumo/include/cumo/intern_fwd.h +0 -38
- data/lib/erbpp.rb +0 -294
- data/lib/erbpp/line_number.rb +0 -137
- data/lib/erbpp/narray_def.rb +0 -381
@@ -3,23 +3,23 @@ void <%="cumo_#{c_iter}_stride_kernel_launch"%>(char *p1, char *p2, char *p3, ch
|
|
3
3
|
<% end %>
|
4
4
|
|
5
5
|
static void
|
6
|
-
<%=c_iter%>(
|
6
|
+
<%=c_iter%>(cumo_na_loop_t *const lp)
|
7
7
|
{
|
8
8
|
size_t i, n;
|
9
9
|
char *p1, *p2, *p3, *p4;
|
10
10
|
ssize_t s1, s2, s3, s4;
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
CUMO_INIT_COUNTER(lp, n);
|
12
|
+
CUMO_INIT_PTR(lp, 0, p1, s1);
|
13
|
+
CUMO_INIT_PTR(lp, 1, p2, s2);
|
14
|
+
CUMO_INIT_PTR(lp, 2, p3, s3);
|
15
|
+
CUMO_INIT_PTR(lp, 3, p4, s4);
|
16
16
|
for (i=n; i--;) {
|
17
17
|
<% if type_name == 'robject' %>
|
18
18
|
{
|
19
19
|
dtype x, y, a, b;
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
21
|
+
CUMO_GET_DATA_STRIDE(p1,s1,dtype,x);
|
22
|
+
CUMO_GET_DATA_STRIDE(p2,s2,dtype,y);
|
23
23
|
<% if is_int and %w[divmod].include? name %>
|
24
24
|
if (y==0) {
|
25
25
|
lp->err_type = rb_eZeroDivError;
|
@@ -27,8 +27,8 @@ static void
|
|
27
27
|
}
|
28
28
|
<% end %>
|
29
29
|
m_<%=name%>(x,y,a,b);
|
30
|
-
|
31
|
-
|
30
|
+
CUMO_SET_DATA_STRIDE(p3,s3,dtype,a);
|
31
|
+
CUMO_SET_DATA_STRIDE(p4,s4,dtype,b);
|
32
32
|
}
|
33
33
|
<% else %>
|
34
34
|
<%="cumo_#{c_iter}_stride_kernel_launch"%>(p1,p2,p3,p4,s1,s2,s3,s4,n);
|
@@ -39,11 +39,11 @@ static void
|
|
39
39
|
static VALUE
|
40
40
|
<%=c_func%>_self(VALUE self, VALUE other)
|
41
41
|
{
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
cumo_ndfunc_arg_in_t ain[2] = {{cT,0},{cT,0}};
|
43
|
+
cumo_ndfunc_arg_out_t aout[2] = {{cT,0},{cT,0}};
|
44
|
+
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP, 2, 2, ain, aout };
|
45
45
|
|
46
|
-
return
|
46
|
+
return cumo_na_ndloop(&ndf, 2, self, other);
|
47
47
|
}
|
48
48
|
|
49
49
|
/*
|
@@ -59,12 +59,12 @@ static VALUE
|
|
59
59
|
return <%=c_func%>_self(self, other);
|
60
60
|
<% else %>
|
61
61
|
VALUE klass, v;
|
62
|
-
klass =
|
62
|
+
klass = cumo_na_upcast(rb_obj_class(self),rb_obj_class(other));
|
63
63
|
if (klass==cT) {
|
64
64
|
return <%=c_func%>_self(self, other);
|
65
65
|
} else {
|
66
|
-
v = rb_funcall(klass,
|
67
|
-
return rb_funcall(v, <%=
|
66
|
+
v = rb_funcall(klass, cumo_id_cast, 1, self);
|
67
|
+
return rb_funcall(v, <%=cumo_id_op%>, 1, other);
|
68
68
|
}
|
69
69
|
<% end %>
|
70
70
|
}
|
@@ -8,8 +8,8 @@ __global__ void <%="cumo_#{c_iter}_stride_kernel"%>(char *p1, char *p2, char *p3
|
|
8
8
|
|
9
9
|
void <%="cumo_#{c_iter}_stride_kernel_launch"%>(char *p1, char *p2, char *p3, char *p4, ssize_t s1, ssize_t s2, ssize_t s3, ssize_t s4, uint64_t n)
|
10
10
|
{
|
11
|
-
size_t
|
12
|
-
size_t
|
13
|
-
<%="cumo_#{c_iter}_stride_kernel"%><<<
|
11
|
+
size_t grid_dim = cumo_get_grid_dim(n);
|
12
|
+
size_t block_dim = cumo_get_block_dim(n);
|
13
|
+
<%="cumo_#{c_iter}_stride_kernel"%><<<grid_dim, block_dim>>>(p1,p2,p3,p4,s1,s2,s3,s4,n);
|
14
14
|
}
|
15
15
|
<% end %>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<% unless type_name == 'robject' %>
|
2
2
|
|
3
3
|
<% ((0..opt_indexer_ndim).to_a << '').each do |idim| %>
|
4
|
-
__global__ void <%="cumo_#{c_iter}_kernel_dim#{idim}"%>(
|
4
|
+
__global__ void <%="cumo_#{c_iter}_kernel_dim#{idim}"%>(cumo_na_iarray_t a1, cumo_na_iarray_t a2, cumo_na_iarray_t a3, cumo_na_indexer_t indexer)
|
5
5
|
{
|
6
6
|
for (uint64_t i = blockIdx.x * blockDim.x + threadIdx.x; i < indexer.total_size; i += blockDim.x * gridDim.x) {
|
7
7
|
cumo_na_indexer_set_dim<%=idim%>(&indexer, i);
|
@@ -13,18 +13,18 @@ __global__ void <%="cumo_#{c_iter}_kernel_dim#{idim}"%>(na_iarray_t a1, na_iarra
|
|
13
13
|
}
|
14
14
|
<% end %>
|
15
15
|
|
16
|
-
void <%="cumo_#{c_iter}_kernel_launch"%>(
|
16
|
+
void <%="cumo_#{c_iter}_kernel_launch"%>(cumo_na_iarray_t* a1, cumo_na_iarray_t* a2, cumo_na_iarray_t* a3, cumo_na_indexer_t* indexer)
|
17
17
|
{
|
18
|
-
size_t
|
19
|
-
size_t
|
18
|
+
size_t grid_dim = cumo_get_grid_dim(indexer->total_size);
|
19
|
+
size_t block_dim = cumo_get_block_dim(indexer->total_size);
|
20
20
|
switch (indexer->ndim) {
|
21
21
|
<% (0..opt_indexer_ndim).each do |idim| %>
|
22
22
|
case <%=idim%>:
|
23
|
-
<%="cumo_#{c_iter}_kernel_dim#{idim}"%><<<
|
23
|
+
<%="cumo_#{c_iter}_kernel_dim#{idim}"%><<<grid_dim, block_dim>>>(*a1,*a2,*a3,*indexer);
|
24
24
|
break;
|
25
25
|
<% end %>
|
26
26
|
default:
|
27
|
-
<%="cumo_#{c_iter}_kernel_dim"%><<<
|
27
|
+
<%="cumo_#{c_iter}_kernel_dim"%><<<grid_dim, block_dim>>>(*a1,*a2,*a3,*indexer);
|
28
28
|
break;
|
29
29
|
}
|
30
30
|
}
|
@@ -3,24 +3,24 @@ void <%="cumo_#{c_iter}_stride_kernel_launch"%>(char *p1, char *p2, char *p3, ss
|
|
3
3
|
<% end %>
|
4
4
|
|
5
5
|
static void
|
6
|
-
<%=c_iter%>(
|
6
|
+
<%=c_iter%>(cumo_na_loop_t *const lp)
|
7
7
|
{
|
8
8
|
size_t i;
|
9
9
|
char *p1, *p2, *p3;
|
10
10
|
ssize_t s1, s2, s3;
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
CUMO_INIT_COUNTER(lp, i);
|
12
|
+
CUMO_INIT_PTR(lp, 0, p1, s1);
|
13
|
+
CUMO_INIT_PTR(lp, 1, p2, s2);
|
14
|
+
CUMO_INIT_PTR(lp, 2, p3, s3);
|
15
15
|
<% if type_name == 'robject' %>
|
16
16
|
{
|
17
17
|
dtype x, y;
|
18
|
-
|
18
|
+
CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
19
19
|
for (; i--;) {
|
20
|
-
|
21
|
-
|
20
|
+
CUMO_GET_DATA_STRIDE(p1,s1,dtype,x);
|
21
|
+
CUMO_GET_DATA_STRIDE(p2,s2,dtype,y);
|
22
22
|
x = m_<%=name%>(x,y);
|
23
|
-
|
23
|
+
CUMO_SET_DATA_STRIDE(p3,s3,dtype,x);
|
24
24
|
}
|
25
25
|
}
|
26
26
|
<% else %>
|
@@ -38,8 +38,8 @@ static void
|
|
38
38
|
static VALUE
|
39
39
|
<%=c_func(2)%>(VALUE mod, VALUE a1, VALUE a2)
|
40
40
|
{
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
return
|
41
|
+
cumo_ndfunc_arg_in_t ain[2] = {{cT,0},{cT,0}};
|
42
|
+
cumo_ndfunc_arg_out_t aout[1] = {{cT,0}};
|
43
|
+
cumo_ndfunc_t ndf = { <%=c_iter%>, CUMO_STRIDE_LOOP, 2, 1, ain, aout };
|
44
|
+
return cumo_na_ndloop(&ndf, 2, a1, a2);
|
45
45
|
}
|
@@ -8,8 +8,8 @@ __global__ void <%="cumo_#{c_iter}_stride_kernel"%>(char *p1, char *p2, char *p3
|
|
8
8
|
|
9
9
|
void <%="cumo_#{c_iter}_stride_kernel_launch"%>(char *p1, char *p2, char *p3, ssize_t s1, ssize_t s2, ssize_t s3, uint64_t n)
|
10
10
|
{
|
11
|
-
size_t
|
12
|
-
size_t
|
13
|
-
<%="cumo_#{c_iter}_stride_kernel"%><<<
|
11
|
+
size_t grid_dim = cumo_get_grid_dim(n);
|
12
|
+
size_t block_dim = cumo_get_block_dim(n);
|
13
|
+
<%="cumo_#{c_iter}_stride_kernel"%><<<grid_dim, block_dim>>>(p1,p2,p3,s1,s2,s3,n);
|
14
14
|
}
|
15
15
|
<% end %>
|
@@ -5,15 +5,15 @@
|
|
5
5
|
cnt_type = "u_int#{bits}_t"
|
6
6
|
%>
|
7
7
|
static void
|
8
|
-
<%=c_iter%>_<%=bits%>(
|
8
|
+
<%=c_iter%>_<%=bits%>(cumo_na_loop_t *const lp)
|
9
9
|
{
|
10
10
|
size_t i, x, n;
|
11
11
|
char *p1, *p2;
|
12
12
|
ssize_t s1, s2;
|
13
13
|
size_t *idx1;
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
CUMO_INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
16
|
+
CUMO_INIT_PTR(lp, 1, p2, s2);
|
17
17
|
i = lp->args[0].shape[0];
|
18
18
|
n = lp->args[1].shape[0];
|
19
19
|
|
@@ -22,15 +22,15 @@ static void
|
|
22
22
|
*(<%=cnt_type%>*)(p2 + s2*x) = 0;
|
23
23
|
}
|
24
24
|
|
25
|
-
|
25
|
+
CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>_<%=bits%>", "<%=type_name%>");
|
26
26
|
if (idx1) {
|
27
27
|
for (; i--;) {
|
28
|
-
|
28
|
+
CUMO_GET_DATA_INDEX(p1,idx1,dtype,x);
|
29
29
|
(*(<%=cnt_type%>*)(p2 + s2*x))++;
|
30
30
|
}
|
31
31
|
} else {
|
32
32
|
for (; i--;) {
|
33
|
-
|
33
|
+
CUMO_GET_DATA_STRIDE(p1,s1,dtype,x);
|
34
34
|
(*(<%=cnt_type%>*)(p2 + s2*x))++;
|
35
35
|
}
|
36
36
|
}
|
@@ -40,12 +40,12 @@ static VALUE
|
|
40
40
|
<%=c_func%>_<%=bits%>(VALUE self, size_t length)
|
41
41
|
{
|
42
42
|
size_t shape_out[1] = {length};
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
cumo_ndfunc_arg_in_t ain[1] = {{cT,1}};
|
44
|
+
cumo_ndfunc_arg_out_t aout[1] = {{<%=cnt_cT%>,1,shape_out}};
|
45
|
+
cumo_ndfunc_t ndf = {<%=c_iter%>_<%=bits%>, CUMO_NO_LOOP|CUMO_NDF_STRIDE_LOOP|CUMO_NDF_INDEX_LOOP,
|
46
46
|
1, 1, ain, aout};
|
47
47
|
|
48
|
-
return
|
48
|
+
return cumo_na_ndloop(&ndf, 1, self);
|
49
49
|
}
|
50
50
|
<% end %>
|
51
51
|
// ------- end of Integer count without weights -------
|
@@ -58,22 +58,22 @@ static VALUE
|
|
58
58
|
fn = fn.downcase
|
59
59
|
%>
|
60
60
|
static void
|
61
|
-
<%=c_iter%>_<%=fn%>(
|
61
|
+
<%=c_iter%>_<%=fn%>(cumo_na_loop_t *const lp)
|
62
62
|
{
|
63
63
|
<%=cnt_type%> w;
|
64
64
|
size_t i, x, n, m;
|
65
65
|
char *p1, *p2, *p3;
|
66
66
|
ssize_t s1, s2, s3;
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
CUMO_INIT_PTR(lp, 0, p1, s1);
|
69
|
+
CUMO_INIT_PTR(lp, 1, p2, s2);
|
70
|
+
CUMO_INIT_PTR(lp, 2, p3, s3);
|
71
71
|
i = lp->args[0].shape[0];
|
72
72
|
m = lp->args[1].shape[0];
|
73
73
|
n = lp->args[2].shape[0];
|
74
74
|
|
75
75
|
if (i != m) {
|
76
|
-
rb_raise(
|
76
|
+
rb_raise(cumo_na_eShapeError,
|
77
77
|
"size mismatch along last axis between self and weight");
|
78
78
|
}
|
79
79
|
|
@@ -82,8 +82,8 @@ static void
|
|
82
82
|
*(<%=cnt_type%>*)(p3 + s3*x) = 0;
|
83
83
|
}
|
84
84
|
for (; i--;) {
|
85
|
-
|
86
|
-
|
85
|
+
CUMO_GET_DATA_STRIDE(p1,s1,dtype,x);
|
86
|
+
CUMO_GET_DATA_STRIDE(p2,s2,<%=cnt_type%>,w);
|
87
87
|
(*(<%=cnt_type%>*)(p3 + s3*x)) += w;
|
88
88
|
}
|
89
89
|
}
|
@@ -92,12 +92,12 @@ static VALUE
|
|
92
92
|
<%=c_func%>_<%=fn%>(VALUE self, VALUE weight, size_t length)
|
93
93
|
{
|
94
94
|
size_t shape_out[1] = {length};
|
95
|
-
|
96
|
-
|
97
|
-
|
95
|
+
cumo_ndfunc_arg_in_t ain[2] = {{cT,1},{<%=cnt_cT%>,1}};
|
96
|
+
cumo_ndfunc_arg_out_t aout[1] = {{<%=cnt_cT%>,1,shape_out}};
|
97
|
+
cumo_ndfunc_t ndf = {<%=c_iter%>_<%=fn%>, CUMO_NO_LOOP|CUMO_NDF_STRIDE_LOOP,
|
98
98
|
2, 1, ain, aout};
|
99
99
|
|
100
|
-
return
|
100
|
+
return cumo_na_ndloop(&ndf, 2, self, weight);
|
101
101
|
}
|
102
102
|
<% end %>
|
103
103
|
// ------- end of Float count with weights -------
|
@@ -140,7 +140,7 @@ static VALUE
|
|
140
140
|
VALUE weight=Qnil, kw=Qnil;
|
141
141
|
VALUE opts[1] = {Qundef};
|
142
142
|
VALUE v, wclass;
|
143
|
-
ID table[1] = {
|
143
|
+
ID table[1] = {cumo_id_minlength};
|
144
144
|
size_t length, minlength;
|
145
145
|
|
146
146
|
rb_scan_args(argc, argv, "01:", &weight, &kw);
|
@@ -171,7 +171,7 @@ static VALUE
|
|
171
171
|
return <%=c_func%>_32(self, length);
|
172
172
|
}
|
173
173
|
} else {
|
174
|
-
wclass =
|
174
|
+
wclass = rb_obj_class(weight);
|
175
175
|
if (wclass == cumo_cSFloat) {
|
176
176
|
return <%=c_func%>_sf(self, weight, length);
|
177
177
|
} else {
|
@@ -14,10 +14,10 @@ static VALUE
|
|
14
14
|
<%=c_func(1)%>(VALUE type, VALUE obj)
|
15
15
|
{
|
16
16
|
VALUE v;
|
17
|
-
|
17
|
+
cumo_narray_t *na;
|
18
18
|
dtype x;
|
19
19
|
|
20
|
-
if (
|
20
|
+
if (rb_obj_class(obj)==cT) {
|
21
21
|
return obj;
|
22
22
|
}
|
23
23
|
if (RTEST(rb_obj_is_kind_of(obj,rb_cNumeric))) {
|
@@ -27,10 +27,10 @@ static VALUE
|
|
27
27
|
if (RTEST(rb_obj_is_kind_of(obj,rb_cArray))) {
|
28
28
|
return <%=find_tmpl("cast_array").c_func%>(obj);
|
29
29
|
}
|
30
|
-
if (
|
31
|
-
|
32
|
-
v =
|
33
|
-
if (
|
30
|
+
if (CumoIsNArray(obj)) {
|
31
|
+
CumoGetNArray(obj,na);
|
32
|
+
v = cumo_na_new(cT, CUMO_NA_NDIM(na), CUMO_NA_SHAPE(na));
|
33
|
+
if (CUMO_NA_SIZE(na) > 0) {
|
34
34
|
<%=find_tmpl("store").c_func%>(v,obj);
|
35
35
|
}
|
36
36
|
return v;
|
@@ -38,7 +38,7 @@ static VALUE
|
|
38
38
|
<% if is_object %>
|
39
39
|
return robject_new_dim0(obj);
|
40
40
|
<% else %>
|
41
|
-
rb_raise(
|
41
|
+
rb_raise(cumo_na_eCastError,"cannot cast to %s",rb_class2name(type));
|
42
42
|
return Qnil;
|
43
43
|
<% end %>
|
44
44
|
}
|
@@ -2,10 +2,10 @@ static VALUE
|
|
2
2
|
<%=c_func(:nodef)%>(VALUE rary)
|
3
3
|
{
|
4
4
|
VALUE nary;
|
5
|
-
|
5
|
+
cumo_narray_t *na;
|
6
6
|
|
7
|
-
nary =
|
8
|
-
|
7
|
+
nary = cumo_na_s_new_like(cT, rary);
|
8
|
+
CumoGetNArray(nary,na);
|
9
9
|
if (na->size > 0) {
|
10
10
|
<%=find_tmpl("store").find("array").c_func%>(nary,rary);
|
11
11
|
}
|
@@ -1,64 +1,64 @@
|
|
1
1
|
static void
|
2
|
-
<%=c_iter%>(
|
2
|
+
<%=c_iter%>(cumo_na_loop_t *const lp)
|
3
3
|
{
|
4
4
|
size_t i;
|
5
5
|
char *p1, *p2, *p3, *p4;
|
6
6
|
ssize_t s1, s2, s3, s4;
|
7
7
|
dtype x, min, max;
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
CUMO_INIT_COUNTER(lp, i);
|
9
|
+
CUMO_INIT_PTR(lp, 0, p1, s1);
|
10
|
+
CUMO_INIT_PTR(lp, 1, p2, s2);
|
11
|
+
CUMO_INIT_PTR(lp, 2, p3, s3);
|
12
|
+
CUMO_INIT_PTR(lp, 3, p4, s4);
|
13
|
+
CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>", "<%=type_name%>");
|
14
14
|
for (; i--;) {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
if (m_gt(min,max)) {rb_raise(
|
15
|
+
CUMO_GET_DATA_STRIDE(p1,s1,dtype,x);
|
16
|
+
CUMO_GET_DATA_STRIDE(p2,s2,dtype,min);
|
17
|
+
CUMO_GET_DATA_STRIDE(p3,s3,dtype,max);
|
18
|
+
if (m_gt(min,max)) {rb_raise(cumo_na_eOperationError,"min is greater than max");}
|
19
19
|
if (m_lt(x,min)) {x=min;}
|
20
20
|
if (m_gt(x,max)) {x=max;}
|
21
|
-
|
21
|
+
CUMO_SET_DATA_STRIDE(p4,s4,dtype,x);
|
22
22
|
}
|
23
23
|
}
|
24
24
|
|
25
25
|
static void
|
26
|
-
<%=c_iter%>_min(
|
26
|
+
<%=c_iter%>_min(cumo_na_loop_t *const lp)
|
27
27
|
{
|
28
28
|
size_t i;
|
29
29
|
char *p1, *p2, *p3;
|
30
30
|
ssize_t s1, s2, s3;
|
31
31
|
dtype x, min;
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
CUMO_INIT_COUNTER(lp, i);
|
33
|
+
CUMO_INIT_PTR(lp, 0, p1, s1);
|
34
|
+
CUMO_INIT_PTR(lp, 1, p2, s2);
|
35
|
+
CUMO_INIT_PTR(lp, 2, p3, s3);
|
36
|
+
CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>_min", "<%=type_name%>");
|
37
37
|
for (; i--;) {
|
38
|
-
|
39
|
-
|
38
|
+
CUMO_GET_DATA_STRIDE(p1,s1,dtype,x);
|
39
|
+
CUMO_GET_DATA_STRIDE(p2,s2,dtype,min);
|
40
40
|
if (m_lt(x,min)) {x=min;}
|
41
|
-
|
41
|
+
CUMO_SET_DATA_STRIDE(p3,s3,dtype,x);
|
42
42
|
}
|
43
43
|
}
|
44
44
|
|
45
45
|
static void
|
46
|
-
<%=c_iter%>_max(
|
46
|
+
<%=c_iter%>_max(cumo_na_loop_t *const lp)
|
47
47
|
{
|
48
48
|
size_t i;
|
49
49
|
char *p1, *p2, *p3;
|
50
50
|
ssize_t s1, s2, s3;
|
51
51
|
dtype x, max;
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
CUMO_INIT_COUNTER(lp, i);
|
53
|
+
CUMO_INIT_PTR(lp, 0, p1, s1);
|
54
|
+
CUMO_INIT_PTR(lp, 1, p2, s2);
|
55
|
+
CUMO_INIT_PTR(lp, 2, p3, s3);
|
56
|
+
CUMO_SHOW_SYNCHRONIZE_FIXME_WARNING_ONCE("<%=name%>_max", "<%=type_name%>");
|
57
57
|
for (; i--;) {
|
58
|
-
|
59
|
-
|
58
|
+
CUMO_GET_DATA_STRIDE(p1,s1,dtype,x);
|
59
|
+
CUMO_GET_DATA_STRIDE(p2,s2,dtype,max);
|
60
60
|
if (m_gt(x,max)) {x=max;}
|
61
|
-
|
61
|
+
CUMO_SET_DATA_STRIDE(p3,s3,dtype,x);
|
62
62
|
}
|
63
63
|
}
|
64
64
|
|
@@ -99,21 +99,21 @@ static void
|
|
99
99
|
static VALUE
|
100
100
|
<%=c_func(2)%>(VALUE self, VALUE min, VALUE max)
|
101
101
|
{
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
102
|
+
cumo_ndfunc_arg_in_t ain[3] = {{Qnil,0},{cT,0},{cT,0}};
|
103
|
+
cumo_ndfunc_arg_out_t aout[1] = {{cT,0}};
|
104
|
+
cumo_ndfunc_t ndf_min = { <%=c_iter%>_min, CUMO_STRIDE_LOOP, 2, 1, ain, aout };
|
105
|
+
cumo_ndfunc_t ndf_max = { <%=c_iter%>_max, CUMO_STRIDE_LOOP, 2, 1, ain, aout };
|
106
|
+
cumo_ndfunc_t ndf_both = { <%=c_iter%>, CUMO_STRIDE_LOOP, 3, 1, ain, aout };
|
107
107
|
|
108
108
|
if (RTEST(min)) {
|
109
109
|
if (RTEST(max)) {
|
110
|
-
return
|
110
|
+
return cumo_na_ndloop(&ndf_both, 3, self, min, max);
|
111
111
|
} else {
|
112
|
-
return
|
112
|
+
return cumo_na_ndloop(&ndf_min, 2, self, min);
|
113
113
|
}
|
114
114
|
} else {
|
115
115
|
if (RTEST(max)) {
|
116
|
-
return
|
116
|
+
return cumo_na_ndloop(&ndf_max, 2, self, max);
|
117
117
|
}
|
118
118
|
}
|
119
119
|
rb_raise(rb_eArgError,"min and max are not given");
|