cumo 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +16 -36
  3. data/3rd_party/mkmf-cu/lib/mkmf-cu/cli.rb +7 -0
  4. data/CHANGELOG.md +16 -0
  5. data/Dockerfile +34 -0
  6. data/cumo.gemspec +1 -1
  7. data/docker-build.sh +4 -0
  8. data/docker-launch.sh +4 -0
  9. data/docs/src-tree.md +1 -1
  10. data/ext/cumo/cuda/cudnn_impl.cpp +25 -3
  11. data/ext/cumo/cuda/driver.c +8 -0
  12. data/ext/cumo/depend.erb +1 -1
  13. data/ext/cumo/extconf.rb +1 -1
  14. data/ext/cumo/include/cumo/cuda/cumo_thrust.hpp +13 -6
  15. data/ext/cumo/include/cumo/cuda/cumo_thrust_complex.hpp +3 -3
  16. data/ext/cumo/include/cumo/types/complex_macro_kernel.h +15 -4
  17. data/ext/cumo/include/cumo/types/real_accum_kernel.h +15 -4
  18. data/ext/cumo/include/cumo/types/xint_macro_kernel.h +11 -3
  19. data/ext/cumo/include/cumo.h +2 -2
  20. data/ext/cumo/narray/array.c +5 -3
  21. data/ext/cumo/narray/data.c +25 -26
  22. data/ext/cumo/narray/gen/tmpl/accum.c +2 -2
  23. data/ext/cumo/narray/gen/tmpl/accum_binary.c +1 -1
  24. data/ext/cumo/narray/gen/tmpl/aref.c +18 -18
  25. data/ext/cumo/narray/gen/tmpl/aset.c +16 -16
  26. data/ext/cumo/narray/gen/tmpl/batch_norm.c +4 -1
  27. data/ext/cumo/narray/gen/tmpl/batch_norm_backward.c +4 -1
  28. data/ext/cumo/narray/gen/tmpl/bincount.c +7 -7
  29. data/ext/cumo/narray/gen/tmpl/clip.c +11 -15
  30. data/ext/cumo/narray/gen/tmpl/cum.c +1 -1
  31. data/ext/cumo/narray/gen/tmpl/each.c +4 -2
  32. data/ext/cumo/narray/gen/tmpl/each_with_index.c +5 -2
  33. data/ext/cumo/narray/gen/tmpl/fixed_batch_norm.c +4 -1
  34. data/ext/cumo/narray/gen/tmpl/logseq.c +6 -5
  35. data/ext/cumo/narray/gen/tmpl/map_with_index.c +5 -6
  36. data/ext/cumo/narray/gen/tmpl/median.c +2 -2
  37. data/ext/cumo/narray/gen/tmpl/minmax.c +1 -1
  38. data/ext/cumo/narray/gen/tmpl/poly.c +4 -4
  39. data/ext/cumo/narray/gen/tmpl/rand.c +8 -6
  40. data/ext/cumo/narray/gen/tmpl/rand_norm.c +18 -16
  41. data/ext/cumo/narray/gen/tmpl/seq.c +5 -4
  42. data/ext/cumo/narray/gen/tmpl/sort.c +2 -2
  43. data/ext/cumo/narray/gen/tmpl/sort_index.c +2 -2
  44. data/ext/cumo/narray/gen/tmpl_bit/aref.c +26 -32
  45. data/ext/cumo/narray/gen/tmpl_bit/aset.c +18 -30
  46. data/ext/cumo/narray/index.c +1 -1
  47. data/ext/cumo/narray/narray.c +19 -18
  48. data/lib/cumo/narray/extra.rb +160 -156
  49. data/test/cuda/device_test.rb +2 -1
  50. data/test/cudnn_test.rb +2 -2
  51. metadata +5 -2
@@ -195,21 +195,21 @@ check_axis(int axis, int ndim)
195
195
  @example
196
196
  x = Cumo::Int32[[1,2,3]]
197
197
 
198
- p x.swapaxes(0,1)
199
- # Cumo::Int32(view)#shape=[3,1]
198
+ x.swapaxes(0,1)
199
+ # => Cumo::Int32(view)#shape=[3,1]
200
200
  # [[1],
201
201
  # [2],
202
202
  # [3]]
203
203
 
204
- p x = Cumo::Int32[[[0,1],[2,3]],[[4,5],[6,7]]]
205
- # Cumo::Int32#shape=[2,2,2]
204
+ x = Cumo::Int32[[[0,1],[2,3]],[[4,5],[6,7]]]
205
+ # => Cumo::Int32#shape=[2,2,2]
206
206
  # [[[0, 1],
207
207
  # [2, 3]],
208
208
  # [[4, 5],
209
209
  # [6, 7]]]
210
210
 
211
- p x.swapaxes(0,2)
212
- # Cumo::Int32(view)#shape=[2,2,2]
211
+ x.swapaxes(0,2)
212
+ # => Cumo::Int32(view)#shape=[2,2,2]
213
213
  # [[[0, 4],
214
214
  # [2, 6]],
215
215
  # [[1, 5],
@@ -510,7 +510,6 @@ cumo_na_flatten_dim(VALUE self, int sd)
510
510
  case CUMO_NARRAY_FILEMAP_T:
511
511
  stride = cumo_na_element_stride(self);
512
512
  for (i=sd+1; i--; ) {
513
- //printf("data: i=%d shpae[i]=%ld stride=%ld\n",i,shape[i],stride);
514
513
  CUMO_SDX_SET_STRIDE(na2->stridx[i],stride);
515
514
  stride *= shape[i];
516
515
  }
@@ -533,12 +532,10 @@ cumo_na_flatten_dim(VALUE self, int sd)
533
532
  CUMO_SDX_SET_INDEX(na2->stridx[i],idx2);
534
533
  } else {
535
534
  na2->stridx[i] = na1->stridx[i];
536
- //printf("view: i=%d stridx=%d\n",i,CUMO_SDX_GET_STRIDE(sdx));
537
535
  }
538
536
  }
539
537
  // flat dimenion == last dimension
540
538
  if (RTEST(cumo_na_check_ladder(self,sd))) {
541
- //if (0) {
542
539
  na2->stridx[sd] = na1->stridx[nd-1];
543
540
  } else {
544
541
  // set index
@@ -607,28 +604,30 @@ void cumo_na_diagonal_stride_index_kernel_launch(size_t *idx, ssize_t s0, size_t
607
604
  @return [Cumo::NArray] diagonal view of NArray.
608
605
  @example
609
606
  a = Cumo::DFloat.new(4,5).seq
610
- => Cumo::DFloat#shape=[4,5]
611
- [[0, 1, 2, 3, 4],
612
- [5, 6, 7, 8, 9],
613
- [10, 11, 12, 13, 14],
614
- [15, 16, 17, 18, 19]]
607
+ # => Cumo::DFloat#shape=[4,5]
608
+ # [[0, 1, 2, 3, 4],
609
+ # [5, 6, 7, 8, 9],
610
+ # [10, 11, 12, 13, 14],
611
+ # [15, 16, 17, 18, 19]]
615
612
  b = a.diagonal(1)
616
- => Cumo::DFloat(view)#shape=[4]
617
- [1, 7, 13, 19]
613
+ # => Cumo::DFloat(view)#shape=[4]
614
+ # [1, 7, 13, 19]
615
+
618
616
  b.store(0)
619
617
  a
620
- => Cumo::DFloat#shape=[4,5]
621
- [[0, 0, 2, 3, 4],
622
- [5, 6, 0, 8, 9],
623
- [10, 11, 12, 0, 14],
624
- [15, 16, 17, 18, 0]]
618
+ # => Cumo::DFloat#shape=[4,5]
619
+ # [[0, 0, 2, 3, 4],
620
+ # [5, 6, 0, 8, 9],
621
+ # [10, 11, 12, 0, 14],
622
+ # [15, 16, 17, 18, 0]]
623
+
625
624
  b.store([1,2,3,4])
626
625
  a
627
- => Cumo::DFloat#shape=[4,5]
628
- [[0, 1, 2, 3, 4],
629
- [5, 6, 2, 8, 9],
630
- [10, 11, 12, 3, 14],
631
- [15, 16, 17, 18, 4]]
626
+ # => Cumo::DFloat#shape=[4,5]
627
+ # [[0, 1, 2, 3, 4],
628
+ # [5, 6, 2, 8, 9],
629
+ # [10, 11, 12, 3, 14],
630
+ # [15, 16, 17, 18, 4]]
632
631
  */
633
632
  static VALUE
634
633
  cumo_na_diagonal(int argc, VALUE *argv, VALUE self)
@@ -56,8 +56,8 @@ static void
56
56
  <% else %>
57
57
  @overload <%=name%>(axis:nil, keepdims:false)
58
58
  <% end %>
59
- @param [Numeric,Array,Range] axis (keyword) Affected dimensions.
60
- @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array as dimensions with size one.
59
+ @param [Numeric,Array,Range] axis Performs <%=name%> along the axis.
60
+ @param [TrueClass] keepdims If true, the reduced axes are left in the result array as dimensions with size one.
61
61
  @return [Cumo::<%=class_name%>] returns result of <%=name%>.
62
62
  */
63
63
  static VALUE
@@ -91,7 +91,7 @@ static VALUE
91
91
  @overload <%=op_map%>(other, axis:nil, keepdims:false)
92
92
  <% end %>
93
93
  @param [Cumo::NArray,Numeric] other
94
- @param [Numeric,Array,Range] axis (keyword) Affected dimensions.
94
+ @param [Numeric,Array,Range] axis Performs <%=name%> along the axis.
95
95
  @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array as dimensions with size one.
96
96
  <% if is_float %>
97
97
  @param [TrueClass] nan (keyword) If true, apply NaN-aware algorithm (avoid NaN if exists).
@@ -21,35 +21,35 @@ static VALUE
21
21
 
22
22
  @example
23
23
  a = Cumo::DFloat.new(4,5).seq
24
- => Cumo::DFloat#shape=[4,5]
25
- [[0, 1, 2, 3, 4],
26
- [5, 6, 7, 8, 9],
27
- [10, 11, 12, 13, 14],
28
- [15, 16, 17, 18, 19]]
24
+ # => Cumo::DFloat#shape=[4,5]
25
+ # [[0, 1, 2, 3, 4],
26
+ # [5, 6, 7, 8, 9],
27
+ # [10, 11, 12, 13, 14],
28
+ # [15, 16, 17, 18, 19]]
29
29
 
30
30
  a[7]
31
- => Cumo::DFloat#shape=[]
32
- 6.0
31
+ # => Cumo::DFloat#shape=[]
32
+ # 6.0
33
33
 
34
34
  a[1,1]
35
- => Cumo::DFloat#shape=[]
36
- 6.0
35
+ # => Cumo::DFloat#shape=[]
36
+ # 6.0
37
37
 
38
38
  a[1..3,1]
39
- => Cumo::DFloat#shape=[3]
40
- [6, 11, 16]
39
+ # => Cumo::DFloat#shape=[3]
40
+ # [6, 11, 16]
41
41
 
42
42
  a[1,[1,3,4]]
43
- => Cumo::DFloat#shape=[3]
44
- [6, 8, 9]
43
+ # => Cumo::DFloat#shape=[3]
44
+ # [6, 8, 9]
45
45
 
46
46
  a[true,2].fill(99)
47
47
  a
48
- => Cumo::DFloat#shape=[4,5]
49
- [[0, 1, 99, 3, 4],
50
- [5, 6, 99, 8, 9],
51
- [10, 11, 99, 13, 14],
52
- [15, 16, 99, 18, 19]]
48
+ # => Cumo::DFloat#shape=[4,5]
49
+ # [[0, 1, 99, 3, 4],
50
+ # [5, 6, 99, 8, 9],
51
+ # [10, 11, 99, 13, 14],
52
+ # [15, 16, 99, 18, 19]]
53
53
  */
54
54
  static VALUE
55
55
  <%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
@@ -10,31 +10,31 @@
10
10
 
11
11
  @example
12
12
  a = Cumo::DFloat.new(3,4).seq
13
- => Cumo::DFloat#shape=[3,4]
14
- [[0, 1, 2, 3],
15
- [4, 5, 6, 7],
16
- [8, 9, 10, 11]]
13
+ # => Cumo::DFloat#shape=[3,4]
14
+ # [[0, 1, 2, 3],
15
+ # [4, 5, 6, 7],
16
+ # [8, 9, 10, 11]]
17
17
 
18
18
  a[1,2]=99
19
19
  a
20
- => Cumo::DFloat#shape=[3,4]
21
- [[0, 1, 2, 3],
22
- [4, 5, 99, 7],
23
- [8, 9, 10, 11]]
20
+ # => Cumo::DFloat#shape=[3,4]
21
+ # [[0, 1, 2, 3],
22
+ # [4, 5, 99, 7],
23
+ # [8, 9, 10, 11]]
24
24
 
25
25
  a[1,[0,2]] = [101,102]
26
26
  a
27
- => Cumo::DFloat#shape=[3,4]
28
- [[0, 1, 2, 3],
29
- [101, 5, 102, 7],
30
- [8, 9, 10, 11]]
27
+ # => Cumo::DFloat#shape=[3,4]
28
+ # [[0, 1, 2, 3],
29
+ # [101, 5, 102, 7],
30
+ # [8, 9, 10, 11]]
31
31
 
32
32
  a[1,true]=99
33
33
  a
34
- => Cumo::DFloat#shape=[3,4]
35
- [[0, 1, 2, 3],
36
- [99, 99, 99, 99],
37
- [8, 9, 10, 11]]
34
+ # => Cumo::DFloat#shape=[3,4]
35
+ # [[0, 1, 2, 3],
36
+ # [99, 99, 99, 99],
37
+ # [8, 9, 10, 11]]
38
38
 
39
39
  */
40
40
  static VALUE
@@ -157,8 +157,11 @@ static VALUE
157
157
  status = cumo_cuda_cudnn_CreateTensorDescriptor(&x_desc, x_cont, cudnn_dtype);
158
158
  if (status != CUDNN_STATUS_SUCCESS) goto BATCH_NORM_ERROR;
159
159
 
160
+ status = cudnnCreateTensorDescriptor(&bn_desc);
161
+ if (status != CUDNN_STATUS_SUCCESS) goto BATCH_NORM_ERROR;
162
+
160
163
  mode = cumo_cuda_cudnn_GetBatchNormMode(axis_ndim, int_axis);
161
- status = cumo_cuda_cudnn_CreateBNTensorDescriptor(&bn_desc, x_desc, mode);
164
+ status = cudnnDeriveBNTensorDescriptor(bn_desc, x_desc, mode);
162
165
  if (status != CUDNN_STATUS_SUCCESS) goto BATCH_NORM_ERROR;
163
166
  // TODO: bn_desc may return another type, and may need to cast gamma, beta, mean, var
164
167
 
@@ -134,8 +134,11 @@ static VALUE
134
134
  status = cumo_cuda_cudnn_CreateTensorDescriptor(&x_desc, x_cont, cudnn_dtype);
135
135
  if (status != CUDNN_STATUS_SUCCESS) goto BATCH_NORM_BACKWARD_ERROR;
136
136
 
137
+ status = cudnnCreateTensorDescriptor(&bn_desc);
138
+ if (status != CUDNN_STATUS_SUCCESS) goto BATCH_NORM_BACKWARD_ERROR;
139
+
137
140
  mode = cumo_cuda_cudnn_GetBatchNormMode(axis_ndim, int_axis);
138
- status = cumo_cuda_cudnn_CreateBNTensorDescriptor(&bn_desc, x_desc, mode);
141
+ status = cudnnDeriveBNTensorDescriptor(bn_desc, x_desc, mode);
139
142
  if (status != CUDNN_STATUS_SUCCESS) goto BATCH_NORM_BACKWARD_ERROR;
140
143
  // TODO: bn_desc may return another type, and may need to cast gamma, gy, mean, var
141
144
 
@@ -116,22 +116,22 @@ static VALUE
116
116
  otherwise returns UInt32 or UInt64 depending on the size along last axis.
117
117
  @example
118
118
  Cumo::Int32[0..4].bincount
119
- => Cumo::UInt32#shape=[5]
120
- [1, 1, 1, 1, 1]
119
+ # => Cumo::UInt32#shape=[5]
120
+ # [1, 1, 1, 1, 1]
121
121
 
122
122
  Cumo::Int32[0, 1, 1, 3, 2, 1, 7].bincount
123
- => Cumo::UInt32#shape=[8]
124
- [1, 3, 1, 1, 0, 0, 0, 1]
123
+ # => Cumo::UInt32#shape=[8]
124
+ # [1, 3, 1, 1, 0, 0, 0, 1]
125
125
 
126
126
  x = Cumo::Int32[0, 1, 1, 3, 2, 1, 7, 23]
127
127
  x.bincount.size == x.max+1
128
- => true
128
+ # => true
129
129
 
130
130
  w = Cumo::DFloat[0.3, 0.5, 0.2, 0.7, 1.0, -0.6]
131
131
  x = Cumo::Int32[0, 1, 1, 2, 2, 2]
132
132
  x.bincount(w)
133
- => Cumo::DFloat#shape=[3]
134
- [0.3, 0.7, 1.1]
133
+ # => Cumo::DFloat#shape=[3]
134
+ # [0.3, 0.7, 1.1]
135
135
 
136
136
  */
137
137
  static VALUE
@@ -75,28 +75,24 @@ static void
75
75
 
76
76
  @example
77
77
  a = Cumo::Int32.new(10).seq
78
- p a.clip(1,8)
79
- # Cumo::Int32#shape=[10]
80
- # [1, 1, 2, 3, 4, 5, 6, 7, 8, 8]
81
-
82
- p a
83
- # Cumo::Int32#shape=[10]
78
+ # => Cumo::Int32#shape=[10]
84
79
  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
85
80
 
86
- p a.inplace.clip(3,6)
87
- # Cumo::Int32(view)#shape=[10]
88
- # [3, 3, 3, 3, 4, 5, 6, 6, 6, 6]
81
+ a.clip(1,8)
82
+ # => Cumo::Int32#shape=[10]
83
+ # [1, 1, 2, 3, 4, 5, 6, 7, 8, 8]
89
84
 
90
- p a
91
- # Cumo::Int32#shape=[10]
85
+ a.inplace.clip(3,6)
86
+ a
87
+ # => Cumo::Int32#shape=[10]
92
88
  # [3, 3, 3, 3, 4, 5, 6, 6, 6, 6]
93
89
 
94
- p a = Cumo::Int32.new(10).seq
95
- # Cumo::Int32#shape=[10]
90
+ b = Cumo::Int32.new(10).seq
91
+ # => Cumo::Int32#shape=[10]
96
92
  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
97
93
 
98
- p a.clip([3,4,1,1,1,4,4,4,4,4], 8)
99
- # Cumo::Int32#shape=[10]
94
+ b.clip([3,4,1,1,1,4,4,4,4,4], 8)
95
+ # => Cumo::Int32#shape=[10]
100
96
  # [3, 4, 2, 3, 4, 5, 6, 7, 8, 8]
101
97
  */
102
98
  static VALUE
@@ -30,7 +30,7 @@ static void
30
30
  /*
31
31
  <%=name%> of self.
32
32
  @overload <%=name%>(axis:nil, nan:false)
33
- @param [Numeric,Array,Range] axis Affected dimensions.
33
+ @param [Numeric,Array,Range] axis Performs <%=name%> along the axis.
34
34
  @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
35
35
  @return [Cumo::<%=class_name%>] <%=name%> of self.
36
36
  */
@@ -34,8 +34,10 @@ static void
34
34
  passing that element as a parameter.
35
35
  @overload <%=name%>
36
36
  @return [Cumo::NArray] self
37
- For a block {|x| ... }
38
- @yield [x] x is element of NArray.
37
+ For a block `{|x| ... }`,
38
+ @yieldparam [Numeric] x an element of NArray.
39
+ @see #each_with_index
40
+ @see #map
39
41
  */
40
42
  static VALUE
41
43
  <%=c_func(0)%>(VALUE self)
@@ -55,9 +55,12 @@ static void
55
55
  Invokes the given block once for each element of self,
56
56
  passing that element and indices along each axis as parameters.
57
57
  @overload <%=name%>
58
+ For a block `{|x,i,j,...| ... }`,
59
+ @yieldparam [Numeric] x an element
60
+ @yieldparam [Integer] i,j,... multitimensional indices
58
61
  @return [Cumo::NArray] self
59
- For a block {|x,i,j,...| ... }
60
- @yield [x,i,j,...] x is an element, i,j,... are multidimensional indices.
62
+ @see #each
63
+ @see #map_with_index
61
64
  */
62
65
  static VALUE
63
66
  <%=c_func(0)%>(VALUE self)
@@ -106,8 +106,11 @@ static VALUE
106
106
  status = cumo_cuda_cudnn_CreateTensorDescriptor(&x_desc, x_cont, cudnn_dtype);
107
107
  if (status != CUDNN_STATUS_SUCCESS) goto FIXED_BATCH_NORM_ERROR;
108
108
 
109
+ status = cudnnCreateTensorDescriptor(&bn_desc);
110
+ if (status != CUDNN_STATUS_SUCCESS) goto FIXED_BATCH_NORM_ERROR;
111
+
109
112
  mode = cumo_cuda_cudnn_GetBatchNormMode(axis_ndim, int_axis);
110
- status = cumo_cuda_cudnn_CreateBNTensorDescriptor(&bn_desc, x_desc, mode);
113
+ status = cudnnDeriveBNTensorDescriptor(bn_desc, x_desc, mode);
111
114
  if (status != CUDNN_STATUS_SUCCESS) goto FIXED_BATCH_NORM_ERROR;
112
115
  // TODO: bn_desc may return another type, and may need to cast gamma, beta, mean, var
113
116
 
@@ -62,7 +62,7 @@ static void
62
62
 
63
63
  /*
64
64
  Set logarithmic sequence of numbers to self. The sequence is obtained from
65
- base**(beg+i*step)
65
+ `base**(beg+i*step)`
66
66
  where i is 1-dimensional index.
67
67
  Applicable classes: DFloat, SFloat, DComplex, SCopmplex.
68
68
 
@@ -74,11 +74,12 @@ static void
74
74
 
75
75
  @example
76
76
  Cumo::DFloat.new(5).logseq(4,-1,2)
77
- => Cumo::DFloat#shape=[5]
78
- [16, 8, 4, 2, 1]
77
+ # => Cumo::DFloat#shape=[5]
78
+ # [16, 8, 4, 2, 1]
79
+
79
80
  Cumo::DComplex.new(5).logseq(0,1i*Math::PI/3,Math::E)
80
- => Cumo::DComplex#shape=[5]
81
- [1+7.26156e-310i, 0.5+0.866025i, -0.5+0.866025i, -1+1.22465e-16i, ...]
81
+ # => Cumo::DComplex#shape=[5]
82
+ # [1+7.26156e-310i, 0.5+0.866025i, -0.5+0.866025i, -1+1.22465e-16i, ...]
82
83
  */
83
84
  static VALUE
84
85
  <%=c_func(-1)%>(int argc, VALUE *args, VALUE self)
@@ -78,14 +78,13 @@ static void
78
78
  passing that element and indices along each axis as parameters.
79
79
  Creates a new NArray containing the values returned by the block.
80
80
  Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.
81
-
82
81
  @overload <%=name%>
83
-
84
- For a block {|x,i,j,...| ... }
85
- @yield [x,i,j,...] x is an element, i,j,... are multidimensional indices.
86
-
82
+ For a block `{|x,i,j,...| ... }`,
83
+ @yieldparam [Numeric] x an element
84
+ @yieldparam [Integer] i,j,... multitimensional indices
87
85
  @return [Cumo::NArray] mapped array
88
-
86
+ @see #map
87
+ @see #each_with_index
89
88
  */
90
89
  static VALUE
91
90
  <%=c_func(0)%>(VALUE self)
@@ -40,8 +40,8 @@ static void
40
40
  <% else %>
41
41
  @overload <%=name%>(axis:nil, keepdims:false)
42
42
  <% end %>
43
- @param [Numeric,Array,Range] axis (keyword) Affected dimensions.
44
- @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array as dimensions with size one.
43
+ @param [Numeric,Array,Range] axis Finds <%=name%> along the axis.
44
+ @param [TrueClass] keepdims If true, the reduced axes are left in the result array as dimensions with size one.
45
45
  @return [Cumo::<%=class_name%>] returns <%=name%> of self.
46
46
  */
47
47
 
@@ -26,7 +26,7 @@ static void
26
26
  <% else %>
27
27
  @overload <%=name%>(axis:nil, keepdims:false)
28
28
  <% end %>
29
- @param [Numeric,Array,Range] axis (keyword) Affected dimensions.
29
+ @param [Numeric,Array,Range] axis Finds min-max along the axis.
30
30
  @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array as dimensions with size one.
31
31
  @return [Cumo::<%=class_name%>,Cumo::<%=class_name%>] min and max of self.
32
32
  */
@@ -18,10 +18,10 @@ static void
18
18
  }
19
19
 
20
20
  /*
21
- Polynomial.: a0 + a1*x + a2*x**2 + a3*x**3 + ... + an*x**n
22
- @overload <%=name%> a0, a1, ...
23
- @param [Cumo::NArray,Numeric] a0
24
- @param [Cumo::NArray,Numeric] a1 , ...
21
+ Calculate polynomial.
22
+ `x.poly(a0,a1,a2,...,an) = a0 + a1*x + a2*x**2 + ... + an*x**n`
23
+ @overload <%=name%> a0, a1, ..., an
24
+ @param [Cumo::NArray,Numeric] a0,a1,...,an
25
25
  @return [Cumo::<%=class_name%>]
26
26
  */
27
27
  static VALUE
@@ -115,14 +115,16 @@ static void
115
115
  @return [Cumo::<%=class_name%>] self.
116
116
  @example
117
117
  Cumo::DFloat.new(6).rand
118
- => Cumo::DFloat#shape=[6]
119
- [0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032]
118
+ # => Cumo::DFloat#shape=[6]
119
+ # [0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032]
120
+
120
121
  Cumo::DComplex.new(6).rand(5+5i)
121
- => Cumo::DComplex#shape=[6]
122
- [2.69974+3.68908i, 0.825443+0.254414i, 0.540323+0.34354i, 4.52061+2.39322i, ...]
122
+ # => Cumo::DComplex#shape=[6]
123
+ # [2.69974+3.68908i, 0.825443+0.254414i, 0.540323+0.34354i, 4.52061+2.39322i, ...]
124
+
123
125
  Cumo::Int32.new(6).rand(2,5)
124
- => Cumo::Int32#shape=[6]
125
- [4, 3, 3, 2, 4, 2]
126
+ # => Cumo::Int32#shape=[6]
127
+ # [4, 3, 3, 2, 4, 2]
126
128
  */
127
129
  static VALUE
128
130
  <%=c_func(-1)%>(int argc, VALUE *args, VALUE self)
@@ -77,24 +77,26 @@ static void
77
77
  @return [Cumo::<%=class_name%>] self.
78
78
  @example
79
79
  Cumo::DFloat.new(5,5).rand_norm
80
- => Cumo::DFloat#shape=[5,5]
81
- [[-0.581255, -0.168354, 0.586895, -0.595142, -0.802802],
82
- [-0.326106, 0.282922, 1.68427, 0.918499, -0.0485384],
83
- [-0.464453, -0.992194, 0.413794, -0.60717, -0.699695],
84
- [-1.64168, 0.48676, -0.875871, -1.43275, 0.812172],
85
- [-0.209975, -0.103612, -0.878617, -1.42495, 1.0968]]
80
+ # => Cumo::DFloat#shape=[5,5]
81
+ # [[-0.581255, -0.168354, 0.586895, -0.595142, -0.802802],
82
+ # [-0.326106, 0.282922, 1.68427, 0.918499, -0.0485384],
83
+ # [-0.464453, -0.992194, 0.413794, -0.60717, -0.699695],
84
+ # [-1.64168, 0.48676, -0.875871, -1.43275, 0.812172],
85
+ # [-0.209975, -0.103612, -0.878617, -1.42495, 1.0968]]
86
+
86
87
  Cumo::DFloat.new(5,5).rand_norm(10,0.1)
87
- => Cumo::DFloat#shape=[5,5]
88
- [[9.9019, 9.90339, 10.0826, 9.98384, 9.72861],
89
- [9.81507, 10.0272, 9.91445, 10.0568, 9.88923],
90
- [10.0234, 9.97874, 9.96011, 9.9006, 9.99964],
91
- [10.0186, 9.94598, 9.92236, 9.99811, 9.97003],
92
- [9.79266, 9.95044, 9.95212, 9.93692, 10.2027]]
88
+ # => Cumo::DFloat#shape=[5,5]
89
+ # [[9.9019, 9.90339, 10.0826, 9.98384, 9.72861],
90
+ # [9.81507, 10.0272, 9.91445, 10.0568, 9.88923],
91
+ # [10.0234, 9.97874, 9.96011, 9.9006, 9.99964],
92
+ # [10.0186, 9.94598, 9.92236, 9.99811, 9.97003],
93
+ # [9.79266, 9.95044, 9.95212, 9.93692, 10.2027]]
94
+
93
95
  Cumo::DComplex.new(3,3).rand_norm(5+5i)
94
- => Cumo::DComplex#shape=[3,3]
95
- [[5.84303+4.40052i, 4.00984+6.08982i, 5.10979+5.13215i],
96
- [4.26477+3.99655i, 4.90052+5.00763i, 4.46607+2.3444i],
97
- [4.5528+7.11003i, 5.62117+6.69094i, 5.05443+5.35133i]]
96
+ # => Cumo::DComplex#shape=[3,3]
97
+ # [[5.84303+4.40052i, 4.00984+6.08982i, 5.10979+5.13215i],
98
+ # [4.26477+3.99655i, 4.90052+5.00763i, 4.46607+2.3444i],
99
+ # [4.5528+7.11003i, 5.62117+6.69094i, 5.05443+5.35133i]]
98
100
  */
99
101
  static VALUE
100
102
  <%=c_func(-1)%>(int argc, VALUE *args, VALUE self)
@@ -80,11 +80,12 @@ static void
80
80
  @return [Cumo::<%=class_name%>] self.
81
81
  @example
82
82
  Cumo::DFloat.new(6).seq(1,-0.2)
83
- => Cumo::DFloat#shape=[6]
84
- [1, 0.8, 0.6, 0.4, 0.2, 0]
83
+ # => Cumo::DFloat#shape=[6]
84
+ # [1, 0.8, 0.6, 0.4, 0.2, 0]
85
+
85
86
  Cumo::DComplex.new(6).seq(1,-0.2+0.2i)
86
- => Cumo::DComplex#shape=[6]
87
- [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]
87
+ # => Cumo::DComplex#shape=[6]
88
+ # [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]
88
89
  */
89
90
  static VALUE
90
91
  <%=c_func(-1)%>(int argc, VALUE *args, VALUE self)
@@ -22,10 +22,10 @@ static void
22
22
  <% else %>
23
23
  @overload <%=name%>(axis:nil)
24
24
  <% end %>
25
- @param [Numeric,Array,Range] axis Affected dimensions.
25
+ @param [Numeric,Array,Range] axis Performs <%=name%> along the axis.
26
26
  @return [Cumo::<%=class_name%>] returns result of <%=name%>.
27
27
  @example
28
- Cumo::DFloat[3,4,1,2].sort => Cumo::DFloat[1,2,3,4]
28
+ Cumo::DFloat[3,4,1,2].sort # => Cumo::DFloat[1,2,3,4]
29
29
  */
30
30
  static VALUE
31
31
  <%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
@@ -52,10 +52,10 @@ static void
52
52
  <% else %>
53
53
  @overload <%=name%>(axis:nil)
54
54
  <% end %>
55
- @param [Numeric,Array,Range] axis Affected dimensions.
55
+ @param [Numeric,Array,Range] axis Performs <%=name%> along the axis.
56
56
  @return [Integer,Cumo::Int] returns result index of <%=name%>.
57
57
  @example
58
- Cumo::NArray[3,4,1,2].sort_index => Cumo::Int32[2,3,0,1]
58
+ Cumo::NArray[3,4,1,2].sort_index # => Cumo::Int32[2,3,0,1]
59
59
  */
60
60
  static VALUE
61
61
  <%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
@@ -2,42 +2,36 @@ static VALUE
2
2
  <%=c_func(-1)%>_cpu(int argc, VALUE *argv, VALUE self);
3
3
 
4
4
  /*
5
- Array element referenece or slice view.
5
+ Array indexing.
6
6
  @overload [](dim0,...,dimL)
7
- @param [Numeric,Range,etc] dim0,...,dimL Multi-dimensional Index.
8
- @return [Numeric,NArray::<%=class_name%>] Element object or NArray view.
7
+ @param [Numeric,Range,Array,Cumo::Bit,Cumo::Int32,Cumo::Int64] dim0,...,dimL Multi-dimensional Index.
8
+ @return [Cumo::Bit,Numeric] Element value or NArray view.
9
9
 
10
- --- Returns the element at +dim0+, +dim1+, ... are Numeric indices
11
- for each dimension, or returns a NArray View as a sliced subarray if
12
- +dim0+, +dim1+, ... includes other than Numeric index, e.g., Range
13
- or Array or true.
10
+ --- Returns an element at `dim0`, `dim1`, ... are Numeric indices for each dimension, or returns a NArray View as a sliced array if `dim0`, `dim1`, ... includes other than Numeric index, e.g., Range or Array or true.
11
+
12
+ @see #[]=
14
13
 
15
14
  @example
16
- a = Cumo::DFloat.new(4,5).seq
17
- => Cumo::DFloat#shape=[4,5]
18
- [[0, 1, 2, 3, 4],
19
- [5, 6, 7, 8, 9],
20
- [10, 11, 12, 13, 14],
21
- [15, 16, 17, 18, 19]]
22
-
23
- a[1,1]
24
- => 6.0
25
-
26
- a[1..3,1]
27
- => Cumo::DFloat#shape=[3]
28
- [6, 11, 16]
29
-
30
- a[1,[1,3,4]]
31
- => Cumo::DFloat#shape=[3]
32
- [6, 8, 9]
33
-
34
- a[true,2].fill(99)
35
- a
36
- => Cumo::DFloat#shape=[4,5]
37
- [[0, 1, 99, 3, 4],
38
- [5, 6, 99, 8, 9],
39
- [10, 11, 99, 13, 14],
40
- [15, 16, 99, 18, 19]]
15
+ a = Cumo::Int32.new(3,4).seq
16
+ # => Cumo::Int32#shape=[3,4]
17
+ # [[0, 1, 2, 3],
18
+ # [4, 5, 6, 7],
19
+ # [8, 9, 10, 11]]
20
+
21
+ b = (a%2).eq(0)
22
+ # => Cumo::Bit#shape=[3,4]
23
+ # [[1, 0, 1, 0],
24
+ # [1, 0, 1, 0],
25
+ # [1, 0, 1, 0]]
26
+
27
+ b[true,(0..-1)%2]
28
+ # => Cumo::Bit(view)#shape=[3,2]
29
+ # [[1, 1],
30
+ # [1, 1],
31
+ # [1, 1]]
32
+
33
+ b[1,1]
34
+ # => 0
41
35
  */
42
36
  static VALUE
43
37
  <%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)