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,36 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t n;
|
5
|
+
char *p1, *p2;
|
6
|
+
ssize_t s1;
|
7
|
+
|
8
|
+
INIT_COUNTER(lp, n);
|
9
|
+
INIT_PTR(lp, 0, p1, s1);
|
10
|
+
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
11
|
+
|
12
|
+
*(<%=dtype%>*)p2 = f_<%=method%>(n,p1,s1);
|
13
|
+
}
|
14
|
+
|
15
|
+
/*
|
16
|
+
<%=method.capitalize%> of self.
|
17
|
+
@overload <%=method%>(*args)
|
18
|
+
@param [Array of Numeric,Range] args Affected dimensions.
|
19
|
+
@return [Numo::<%=class_name%>] <%=method%> of self.
|
20
|
+
*/
|
21
|
+
static VALUE
|
22
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
23
|
+
{
|
24
|
+
VALUE v, reduce;
|
25
|
+
ndfunc_arg_in_t ain[2] = {{cT,0},{sym_reduce,0}};
|
26
|
+
ndfunc_arg_out_t aout[1] = {{<%=tpclass%>,0}};
|
27
|
+
ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
28
|
+
|
29
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self);
|
30
|
+
v = na_ndloop(&ndf, 2, self, reduce);
|
31
|
+
<% if tpclass == "cT" %>
|
32
|
+
return numo_<%=tp%>_extract(v);
|
33
|
+
<% else %>
|
34
|
+
return rb_funcall(v,rb_intern("extract"),0);
|
35
|
+
<% end %>
|
36
|
+
}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
char *p1, *p2, *p3;
|
6
|
+
ssize_t s1, s2, s3;
|
7
|
+
dtype x, y, z;
|
8
|
+
|
9
|
+
INIT_COUNTER(lp, i);
|
10
|
+
INIT_PTR(lp, 0, p1, s1);
|
11
|
+
INIT_PTR(lp, 1, p2, s2);
|
12
|
+
INIT_PTR(lp, 2, p3, s3);
|
13
|
+
if (s3==0) {
|
14
|
+
// Reduce loop
|
15
|
+
GET_DATA(p3,dtype,z);
|
16
|
+
for (; i--;) {
|
17
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
18
|
+
GET_DATA_STRIDE(p2,s2,dtype,y);
|
19
|
+
m_<%=method%>(x,y,z);
|
20
|
+
}
|
21
|
+
SET_DATA(p3,dtype,z);
|
22
|
+
} else {
|
23
|
+
for (; i--;) {
|
24
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
25
|
+
GET_DATA_STRIDE(p2,s2,dtype,y);
|
26
|
+
GET_DATA(p3,dtype,z);
|
27
|
+
m_<%=method%>(x,y,z);
|
28
|
+
SET_DATA_STRIDE(p3,s3,dtype,z);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
static VALUE
|
35
|
+
<%=c_func%>_self(int argc, VALUE *argv, VALUE self)
|
36
|
+
{
|
37
|
+
VALUE v, reduce;
|
38
|
+
VALUE naryv[2];
|
39
|
+
ndfunc_arg_in_t ain[4] = {{cT,0},{cT,0},{sym_reduce,0},{sym_init,0}};
|
40
|
+
ndfunc_arg_out_t aout[1] = {{cT,0}};
|
41
|
+
ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP_NIP, 4, 1, ain, aout };
|
42
|
+
|
43
|
+
if (argc < 1) {
|
44
|
+
rb_raise(rb_eArgError,"wrong number of arguments (%d for >=1)",argc);
|
45
|
+
}
|
46
|
+
// should fix below: [self.ndim,other.ndim].max or?
|
47
|
+
naryv[0] = self;
|
48
|
+
naryv[1] = argv[0];
|
49
|
+
reduce = na_reduce_dimension(argc-1, argv+1, 2, naryv);
|
50
|
+
v = na_ndloop(&ndf, 4, self, argv[0], reduce, m_<%=method%>_init);
|
51
|
+
return numo_<%=tp%>_extract(v);
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
/*
|
56
|
+
Binary <%=method%>.
|
57
|
+
@overload <%=op_map%> other
|
58
|
+
@param [Numo::NArray,Numeric] other
|
59
|
+
@return [Numo::NArray] <%=method%> of self and other.
|
60
|
+
*/
|
61
|
+
static VALUE
|
62
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
63
|
+
{
|
64
|
+
VALUE klass, v;
|
65
|
+
if (argc < 1) {
|
66
|
+
rb_raise(rb_eArgError,"wrong number of arguments (%d for >=1)",argc);
|
67
|
+
}
|
68
|
+
klass = na_upcast(CLASS_OF(self),CLASS_OF(argv[0]));
|
69
|
+
if (klass==cT) {
|
70
|
+
return <%=c_func%>_self(argc, argv, self);
|
71
|
+
} else {
|
72
|
+
v = rb_funcall(klass, id_cast, 1, self);
|
73
|
+
return rb_funcall2(v, rb_intern("<%=method%>"), argc, argv);
|
74
|
+
}
|
75
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
<% [64,32].each do |i| %>
|
2
|
+
#define idx_t int<%=i%>_t
|
3
|
+
static void
|
4
|
+
<%=c_iter%>_index<%=i%>(na_loop_t *const lp)
|
5
|
+
{
|
6
|
+
size_t n, idx;
|
7
|
+
char *d_ptr, *i_ptr, *o_ptr;
|
8
|
+
ssize_t d_step, i_step;
|
9
|
+
|
10
|
+
INIT_COUNTER(lp, n);
|
11
|
+
INIT_PTR(lp, 0, d_ptr, d_step);
|
12
|
+
|
13
|
+
idx = f_<%=method%>(n,d_ptr,d_step);
|
14
|
+
|
15
|
+
INIT_PTR(lp, 1, i_ptr, i_step);
|
16
|
+
o_ptr = NDL_PTR(lp,2);
|
17
|
+
*(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
|
18
|
+
}
|
19
|
+
#undef idx_t
|
20
|
+
<% end %>
|
21
|
+
|
22
|
+
/*
|
23
|
+
* call-seq:
|
24
|
+
* narray.<%=method%>() => Integer
|
25
|
+
* narray.<%=method%>(dim0,dim1,..) => Integer or Numo::Int32/64
|
26
|
+
*
|
27
|
+
* Return an index of result.
|
28
|
+
*
|
29
|
+
* Numo::NArray[3,4,1,2].min_index => 3
|
30
|
+
*/
|
31
|
+
static VALUE
|
32
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
33
|
+
{
|
34
|
+
narray_t *na;
|
35
|
+
VALUE idx, reduce;
|
36
|
+
ndfunc_arg_in_t ain[3] = {{Qnil,0},{Qnil,0},{sym_reduce,0}};
|
37
|
+
ndfunc_arg_out_t aout[1] = {{0,0,0}};
|
38
|
+
ndfunc_t ndf = {0, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE|NDF_EXTRACT, 3,1, ain,aout};
|
39
|
+
|
40
|
+
GetNArray(self,na);
|
41
|
+
if (na->ndim==0) {
|
42
|
+
return INT2FIX(0);
|
43
|
+
}
|
44
|
+
if (na->size > (~(u_int32_t)0)) {
|
45
|
+
aout[0].type = numo_cInt64;
|
46
|
+
idx = rb_narray_new(numo_cInt64, na->ndim, na->shape);
|
47
|
+
ndf.func = <%=c_iter%>_index64;
|
48
|
+
} else {
|
49
|
+
aout[0].type = numo_cInt32;
|
50
|
+
idx = rb_narray_new(numo_cInt32, na->ndim, na->shape);
|
51
|
+
ndf.func = <%=c_iter%>_index32;
|
52
|
+
}
|
53
|
+
rb_funcall(idx, rb_intern("seq"), 0);
|
54
|
+
|
55
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self);
|
56
|
+
|
57
|
+
return na_ndloop(&ndf, 3, self, idx, reduce);
|
58
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
static VALUE
|
2
|
+
<%=c_func%>(VALUE self)
|
3
|
+
{
|
4
|
+
narray_t *na;
|
5
|
+
char *ptr;
|
6
|
+
|
7
|
+
GetNArray(self,na);
|
8
|
+
|
9
|
+
switch(NA_TYPE(na)) {
|
10
|
+
case NARRAY_DATA_T:
|
11
|
+
ptr = NA_DATA_PTR(na);
|
12
|
+
if (na->size > 0 && ptr == NULL) {
|
13
|
+
ptr = xmalloc(sizeof(dtype) * na->size);
|
14
|
+
<% if is_object %>
|
15
|
+
{ size_t i;
|
16
|
+
VALUE *a = (VALUE*)ptr;
|
17
|
+
for (i=na->size; i--;) {
|
18
|
+
*a++ = Qnil;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
<% end %>
|
22
|
+
NA_DATA_PTR(na) = ptr;
|
23
|
+
}
|
24
|
+
break;
|
25
|
+
case NARRAY_VIEW_T:
|
26
|
+
rb_funcall(NA_VIEW_DATA(na), rb_intern("allocate"), 0);
|
27
|
+
break;
|
28
|
+
case NARRAY_FILEMAP_T:
|
29
|
+
//ptr = ((narray_filemap_t*)na)->ptr;
|
30
|
+
// to be implemented
|
31
|
+
default:
|
32
|
+
rb_bug("invalid narray type : %d",NA_TYPE(na));
|
33
|
+
}
|
34
|
+
return self;
|
35
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/*
|
2
|
+
Array element referenece or slice view.
|
3
|
+
@overload [](dim0,...,dimL)
|
4
|
+
@param [Numeric,Range,etc] dim0,...,dimL Multi-dimensional Index.
|
5
|
+
@return [Numeric,NArray::<%=class_name%>] Element object or NArray view.
|
6
|
+
|
7
|
+
--- Returns the element at +dim0+, +dim1+, ... are Numeric indices
|
8
|
+
for each dimension, or returns a NArray View as a sliced subarray if
|
9
|
+
+dim0+, +dim1+, ... includes other than Numeric index, e.g., Range
|
10
|
+
or Array or true.
|
11
|
+
|
12
|
+
a = Numo::DFloat.new(4,5).seq
|
13
|
+
=> Numo::DFloat#shape=[4,5]
|
14
|
+
[[0, 1, 2, 3, 4],
|
15
|
+
[5, 6, 7, 8, 9],
|
16
|
+
[10, 11, 12, 13, 14],
|
17
|
+
[15, 16, 17, 18, 19]]
|
18
|
+
|
19
|
+
a[1,1]
|
20
|
+
=> 6.0
|
21
|
+
|
22
|
+
a[1..3,1]
|
23
|
+
=> Numo::DFloat#shape=[3]
|
24
|
+
[6, 11, 16]
|
25
|
+
|
26
|
+
a[1,[1,3,4]]
|
27
|
+
=> Numo::DFloat#shape=[3]
|
28
|
+
[6, 8, 9]
|
29
|
+
|
30
|
+
a[true,2].fill(99)
|
31
|
+
a
|
32
|
+
=> Numo::DFloat#shape=[4,5]
|
33
|
+
[[0, 1, 99, 3, 4],
|
34
|
+
[5, 6, 99, 8, 9],
|
35
|
+
[10, 11, 99, 13, 14],
|
36
|
+
[15, 16, 99, 18, 19]]
|
37
|
+
*/
|
38
|
+
static VALUE
|
39
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
40
|
+
{
|
41
|
+
ssize_t pos;
|
42
|
+
char *ptr;
|
43
|
+
|
44
|
+
pos = na_get_scalar_position(self, argc, argv, sizeof(dtype));
|
45
|
+
if (pos == -1) {
|
46
|
+
return na_aref_main(argc, argv, self, 0);
|
47
|
+
} else {
|
48
|
+
ptr = na_get_pointer_for_read(self) + pos;
|
49
|
+
return m_extract(ptr);
|
50
|
+
}
|
51
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
/*
|
2
|
+
Array element(s) set.
|
3
|
+
@overload []=(dim0,..,dimL,val)
|
4
|
+
@param [Numeric,Range,etc] dim0,..,dimL Multi-dimensional Index.
|
5
|
+
@param [Numeric,Numo::NArray,etc] val Value(s) to be set to self.
|
6
|
+
@return [Numeric] returns val (last argument).
|
7
|
+
|
8
|
+
--- Replace element(s) at +dim0+, +dim1+, ... (index/range/array/true
|
9
|
+
for each dimention). Broadcasting mechanism is applied.
|
10
|
+
|
11
|
+
a = Numo::DFloat.new(3,4).seq
|
12
|
+
=> Numo::DFloat#shape=[3,4]
|
13
|
+
[[0, 1, 2, 3],
|
14
|
+
[4, 5, 6, 7],
|
15
|
+
[8, 9, 10, 11]]
|
16
|
+
|
17
|
+
a[1,2]=99
|
18
|
+
a
|
19
|
+
=> Numo::DFloat#shape=[3,4]
|
20
|
+
[[0, 1, 2, 3],
|
21
|
+
[4, 5, 99, 7],
|
22
|
+
[8, 9, 10, 11]]
|
23
|
+
|
24
|
+
a[1,[0,2]] = [101,102]
|
25
|
+
a
|
26
|
+
=> Numo::DFloat#shape=[3,4]
|
27
|
+
[[0, 1, 2, 3],
|
28
|
+
[101, 5, 102, 7],
|
29
|
+
[8, 9, 10, 11]]
|
30
|
+
|
31
|
+
a[1,true]=99
|
32
|
+
a
|
33
|
+
=> Numo::DFloat#shape=[3,4]
|
34
|
+
[[0, 1, 2, 3],
|
35
|
+
[99, 99, 99, 99],
|
36
|
+
[8, 9, 10, 11]]
|
37
|
+
|
38
|
+
*/
|
39
|
+
static VALUE
|
40
|
+
<%=c_func%>(int argc, VALUE *argv, VALUE self)
|
41
|
+
{
|
42
|
+
ssize_t pos;
|
43
|
+
char *ptr;
|
44
|
+
VALUE a;
|
45
|
+
|
46
|
+
argc--;
|
47
|
+
if (argc==0) {
|
48
|
+
<%=c_func.sub(/_aset/,"_store")%>(self, argv[argc]);
|
49
|
+
} else {
|
50
|
+
pos = na_get_scalar_position(self, argc, argv, sizeof(dtype));
|
51
|
+
if (pos == -1) {
|
52
|
+
a = na_aref_main(argc, argv, self, 0);
|
53
|
+
<%=c_func.sub(/_aset/,"_store")%>(a, argv[argc]);
|
54
|
+
} else {
|
55
|
+
ptr = na_get_pointer_for_read(self) + pos;
|
56
|
+
*(dtype*)ptr = m_num_to_data(argv[argc]);
|
57
|
+
}
|
58
|
+
|
59
|
+
}
|
60
|
+
return argv[argc];
|
61
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i, n;
|
5
|
+
char *p1, *p2, *p3;
|
6
|
+
ssize_t s1, s2, s3;
|
7
|
+
dtype x, y;
|
8
|
+
INIT_COUNTER(lp, n);
|
9
|
+
INIT_PTR(lp, 0, p1, s1);
|
10
|
+
INIT_PTR(lp, 1, p2, s2);
|
11
|
+
INIT_PTR(lp, 2, p3, s3);
|
12
|
+
for (i=n; i--;) {
|
13
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
14
|
+
GET_DATA_STRIDE(p2,s2,dtype,y);
|
15
|
+
<% if is_int and %w[div mod divmod].include? method %>
|
16
|
+
if (y==0) {
|
17
|
+
lp->err_type = rb_eZeroDivError;
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
<% end %>
|
21
|
+
x = m_<%=method%>(x,y);
|
22
|
+
SET_DATA_STRIDE(p3,s3,dtype,x);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
static VALUE
|
27
|
+
<%=c_func%>_self(VALUE self, VALUE other)
|
28
|
+
{
|
29
|
+
ndfunc_arg_in_t ain[2] = {{cT,0},{cT,0}};
|
30
|
+
ndfunc_arg_out_t aout[1] = {{cT,0}};
|
31
|
+
ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP, 2, 1, ain, aout };
|
32
|
+
|
33
|
+
return na_ndloop(&ndf, 2, self, other);
|
34
|
+
}
|
35
|
+
|
36
|
+
/*
|
37
|
+
Binary <%=method%>.
|
38
|
+
@overload <%=op_map%> other
|
39
|
+
@param [Numo::NArray,Numeric] other
|
40
|
+
@return [Numo::NArray] self <%=op_map%> other
|
41
|
+
*/
|
42
|
+
static VALUE
|
43
|
+
<%=c_func%>(VALUE self, VALUE other)
|
44
|
+
{
|
45
|
+
VALUE klass, v;
|
46
|
+
klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
|
47
|
+
if (klass==cT) {
|
48
|
+
return <%=c_func%>_self(self, other);
|
49
|
+
} else {
|
50
|
+
v = rb_funcall(klass, id_cast, 1, self);
|
51
|
+
return rb_funcall(v, <%=id_op%>, 1, other);
|
52
|
+
}
|
53
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i, n;
|
5
|
+
char *p1, *p2, *p3, *p4;
|
6
|
+
ssize_t s1, s2, s3, s4;
|
7
|
+
dtype x, y, a, b;
|
8
|
+
INIT_COUNTER(lp, n);
|
9
|
+
INIT_PTR(lp, 0, p1, s1);
|
10
|
+
INIT_PTR(lp, 1, p2, s2);
|
11
|
+
INIT_PTR(lp, 2, p3, s3);
|
12
|
+
INIT_PTR(lp, 3, p4, s4);
|
13
|
+
for (i=n; i--;) {
|
14
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
15
|
+
GET_DATA_STRIDE(p2,s2,dtype,y);
|
16
|
+
<% if is_int and %w[divmod].include? method %>
|
17
|
+
if (y==0) {
|
18
|
+
lp->err_type = rb_eZeroDivError;
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
<% end %>
|
22
|
+
m_<%=method%>(x,y,a,b);
|
23
|
+
SET_DATA_STRIDE(p3,s3,dtype,a);
|
24
|
+
SET_DATA_STRIDE(p4,s4,dtype,b);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
static VALUE
|
29
|
+
<%=c_func%>_self(VALUE self, VALUE other)
|
30
|
+
{
|
31
|
+
ndfunc_arg_in_t ain[2] = {{cT,0},{cT,0}};
|
32
|
+
ndfunc_arg_out_t aout[2] = {{cT,0},{cT,0}};
|
33
|
+
ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP, 2, 2, ain, aout };
|
34
|
+
|
35
|
+
return na_ndloop(&ndf, 2, self, other);
|
36
|
+
}
|
37
|
+
|
38
|
+
/*
|
39
|
+
Binary <%=method%>.
|
40
|
+
@overload <%=op_map%> other
|
41
|
+
@param [Numo::NArray,Numeric] other
|
42
|
+
@return [Numo::NArray] <%=method%> of self and other.
|
43
|
+
*/
|
44
|
+
static VALUE
|
45
|
+
<%=c_func%>(VALUE self, VALUE other)
|
46
|
+
{
|
47
|
+
VALUE klass, v;
|
48
|
+
klass = na_upcast(CLASS_OF(self),CLASS_OF(other));
|
49
|
+
if (klass==cT) {
|
50
|
+
return <%=c_func%>_self(self, other);
|
51
|
+
} else {
|
52
|
+
v = rb_funcall(klass, id_cast, 1, self);
|
53
|
+
return rb_funcall(v, <%=id_op%>, 1, other);
|
54
|
+
}
|
55
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
static void
|
2
|
+
<%=c_iter%>(na_loop_t *const lp)
|
3
|
+
{
|
4
|
+
size_t i;
|
5
|
+
char *p1, *p2, *p3;
|
6
|
+
ssize_t s1, s2, s3;
|
7
|
+
dtype x, y;
|
8
|
+
INIT_COUNTER(lp, i);
|
9
|
+
INIT_PTR(lp, 0, p1, s1);
|
10
|
+
INIT_PTR(lp, 1, p2, s2);
|
11
|
+
INIT_PTR(lp, 2, p3, s3);
|
12
|
+
for (; i--;) {
|
13
|
+
GET_DATA_STRIDE(p1,s1,dtype,x);
|
14
|
+
GET_DATA_STRIDE(p2,s2,dtype,y);
|
15
|
+
x = m_<%=method%>(x,y);
|
16
|
+
SET_DATA_STRIDE(p3,s3,dtype,x);
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
/*
|
21
|
+
Calculate <%=method%>(a1,a2).
|
22
|
+
@overload <%=method%>(a1,a2)
|
23
|
+
@param [Numo::NArray,Numeric] a1 first value
|
24
|
+
@param [Numo::NArray,Numeric] a2 second value
|
25
|
+
@return [Numo::<%=class_name%>] <%=method%>(a1,a2).
|
26
|
+
*/
|
27
|
+
static VALUE
|
28
|
+
<%=c_func%>(VALUE mod, VALUE a1, VALUE a2)
|
29
|
+
{
|
30
|
+
ndfunc_arg_in_t ain[2] = {{cT,0},{cT,0}};
|
31
|
+
ndfunc_arg_out_t aout[1] = {{cT,0}};
|
32
|
+
ndfunc_t ndf = { <%=c_iter%>, STRIDE_LOOP, 2, 1, ain, aout };
|
33
|
+
return na_ndloop(&ndf, 2, a1, a2);
|
34
|
+
}
|