numo-narray 0.9.1.4 → 0.9.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -6
  3. data/Rakefile +4 -63
  4. data/ext/numo/narray/array.c +35 -32
  5. data/ext/numo/narray/data.c +40 -43
  6. data/ext/numo/narray/depend.erb +6 -10
  7. data/ext/numo/narray/extconf.rb +24 -21
  8. data/ext/numo/narray/gen/cogen.rb +2 -2
  9. data/ext/numo/narray/gen/narray_def.rb +5 -1
  10. data/ext/numo/narray/gen/spec.rb +17 -7
  11. data/ext/numo/narray/gen/tmpl/accum.c +2 -2
  12. data/ext/numo/narray/gen/tmpl/accum_arg.c +88 -0
  13. data/ext/numo/narray/gen/tmpl/accum_binary.c +1 -1
  14. data/ext/numo/narray/gen/tmpl/accum_index.c +25 -14
  15. data/ext/numo/narray/gen/tmpl/alloc_func.c +4 -1
  16. data/ext/numo/narray/gen/tmpl/allocate.c +1 -0
  17. data/ext/numo/narray/gen/tmpl/aref.c +5 -35
  18. data/ext/numo/narray/gen/tmpl/aset.c +7 -37
  19. data/ext/numo/narray/gen/tmpl/bincount.c +7 -7
  20. data/ext/numo/narray/gen/tmpl/cast.c +7 -0
  21. data/ext/numo/narray/gen/tmpl/clip.c +11 -15
  22. data/ext/numo/narray/gen/tmpl/cum.c +1 -1
  23. data/ext/numo/narray/gen/tmpl/each.c +4 -2
  24. data/ext/numo/narray/gen/tmpl/each_with_index.c +5 -2
  25. data/ext/numo/narray/gen/tmpl/lib.c +2 -2
  26. data/ext/numo/narray/gen/tmpl/logseq.c +6 -5
  27. data/ext/numo/narray/gen/tmpl/map_with_index.c +5 -6
  28. data/ext/numo/narray/gen/tmpl/median.c +2 -2
  29. data/ext/numo/narray/gen/tmpl/minmax.c +1 -1
  30. data/ext/numo/narray/gen/tmpl/poly.c +4 -4
  31. data/ext/numo/narray/gen/tmpl/qsort.c +1 -1
  32. data/ext/numo/narray/gen/tmpl/rand.c +8 -6
  33. data/ext/numo/narray/gen/tmpl/rand_norm.c +18 -16
  34. data/ext/numo/narray/gen/tmpl/seq.c +5 -4
  35. data/ext/numo/narray/gen/tmpl/sort.c +3 -3
  36. data/ext/numo/narray/gen/tmpl/sort_index.c +2 -2
  37. data/ext/numo/narray/gen/tmpl/store_array.c +14 -2
  38. data/ext/numo/narray/gen/tmpl/unary_s.c +55 -31
  39. data/ext/numo/narray/gen/tmpl_bit/allocate.c +1 -0
  40. data/ext/numo/narray/gen/tmpl_bit/aref.c +22 -30
  41. data/ext/numo/narray/gen/tmpl_bit/aset.c +20 -34
  42. data/ext/numo/narray/gen/tmpl_bit/binary.c +48 -14
  43. data/ext/numo/narray/gen/tmpl_bit/bit_count.c +5 -0
  44. data/ext/numo/narray/gen/tmpl_bit/bit_reduce.c +5 -0
  45. data/ext/numo/narray/gen/tmpl_bit/store_array.c +14 -2
  46. data/ext/numo/narray/gen/tmpl_bit/store_bit.c +27 -9
  47. data/ext/numo/narray/gen/tmpl_bit/unary.c +25 -7
  48. data/ext/numo/narray/index.c +363 -59
  49. data/ext/numo/narray/math.c +2 -2
  50. data/ext/numo/narray/narray.c +151 -36
  51. data/ext/numo/narray/ndloop.c +4 -4
  52. data/ext/numo/narray/numo/intern.h +3 -2
  53. data/ext/numo/narray/numo/narray.h +37 -14
  54. data/ext/numo/narray/numo/ndloop.h +2 -2
  55. data/ext/numo/narray/numo/template.h +11 -15
  56. data/ext/numo/narray/numo/types/complex.h +2 -2
  57. data/ext/numo/narray/numo/types/int16.h +5 -2
  58. data/ext/numo/narray/numo/types/int32.h +0 -1
  59. data/ext/numo/narray/numo/types/int64.h +0 -1
  60. data/ext/numo/narray/numo/types/int8.h +1 -2
  61. data/ext/numo/narray/numo/types/uint16.h +5 -2
  62. data/ext/numo/narray/numo/types/uint32.h +0 -1
  63. data/ext/numo/narray/numo/types/uint64.h +0 -1
  64. data/ext/numo/narray/numo/types/uint8.h +1 -2
  65. data/ext/numo/narray/numo/types/xint_macro.h +2 -0
  66. data/ext/numo/narray/step.c +58 -252
  67. data/ext/numo/narray/struct.c +3 -3
  68. data/lib/numo/narray.rb +1 -7
  69. data/lib/numo/narray/extra.rb +214 -213
  70. data/numo-narray.gemspec +7 -8
  71. metadata +17 -36
@@ -1,41 +1,11 @@
1
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
- @example
12
- a = Numo::DFloat.new(3,4).seq
13
- => Numo::DFloat#shape=[3,4]
14
- [[0, 1, 2, 3],
15
- [4, 5, 6, 7],
16
- [8, 9, 10, 11]]
17
-
18
- a[1,2]=99
19
- a
20
- => Numo::DFloat#shape=[3,4]
21
- [[0, 1, 2, 3],
22
- [4, 5, 99, 7],
23
- [8, 9, 10, 11]]
24
-
25
- a[1,[0,2]] = [101,102]
26
- a
27
- => Numo::DFloat#shape=[3,4]
28
- [[0, 1, 2, 3],
29
- [101, 5, 102, 7],
30
- [8, 9, 10, 11]]
31
-
32
- a[1,true]=99
33
- a
34
- => Numo::DFloat#shape=[3,4]
35
- [[0, 1, 2, 3],
36
- [99, 99, 99, 99],
37
- [8, 9, 10, 11]]
38
-
2
+ Multi-dimensional element assignment.
3
+ @overload []=(dim0,...,dimL,val)
4
+ @param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,Symbol] dim0,...,dimL multi-dimensional indices.
5
+ @param [Numeric,Numo::NArray,Array] val Value(s) to be set to self.
6
+ @return [Numeric,Numo::NArray,Array] returns `val` (last argument).
7
+ @see Numo::NArray#[]=
8
+ @see #[]
39
9
  */
40
10
  static VALUE
41
11
  <%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
@@ -115,22 +115,22 @@ static VALUE
115
115
  otherwise returns UInt32 or UInt64 depending on the size along last axis.
116
116
  @example
117
117
  Numo::Int32[0..4].bincount
118
- => Numo::UInt32#shape=[5]
119
- [1, 1, 1, 1, 1]
118
+ # => Numo::UInt32#shape=[5]
119
+ # [1, 1, 1, 1, 1]
120
120
 
121
121
  Numo::Int32[0, 1, 1, 3, 2, 1, 7].bincount
122
- => Numo::UInt32#shape=[8]
123
- [1, 3, 1, 1, 0, 0, 0, 1]
122
+ # => Numo::UInt32#shape=[8]
123
+ # [1, 3, 1, 1, 0, 0, 0, 1]
124
124
 
125
125
  x = Numo::Int32[0, 1, 1, 3, 2, 1, 7, 23]
126
126
  x.bincount.size == x.max+1
127
- => true
127
+ # => true
128
128
 
129
129
  w = Numo::DFloat[0.3, 0.5, 0.2, 0.7, 1.0, -0.6]
130
130
  x = Numo::Int32[0, 1, 1, 2, 2, 2]
131
131
  x.bincount(w)
132
- => Numo::DFloat#shape=[3]
133
- [0.3, 0.7, 1.1]
132
+ # => Numo::DFloat#shape=[3]
133
+ # [0.3, 0.7, 1.1]
134
134
 
135
135
  */
136
136
  static VALUE
@@ -35,6 +35,13 @@ static VALUE
35
35
  }
36
36
  return v;
37
37
  }
38
+ if (rb_respond_to(obj,id_to_a)) {
39
+ obj = rb_funcall(obj,id_to_a,0);
40
+ if (TYPE(obj)!=T_ARRAY) {
41
+ rb_raise(rb_eTypeError, "`to_a' did not return Array");
42
+ }
43
+ return <%=find_tmpl("cast_array").c_func%>(obj);
44
+ }
38
45
  <% if is_object %>
39
46
  return robject_new_dim0(obj);
40
47
  <% else %>
@@ -69,28 +69,24 @@ static void
69
69
 
70
70
  @example
71
71
  a = Numo::Int32.new(10).seq
72
- p a.clip(1,8)
73
- # Numo::Int32#shape=[10]
74
- # [1, 1, 2, 3, 4, 5, 6, 7, 8, 8]
75
-
76
- p a
77
- # Numo::Int32#shape=[10]
72
+ # => Numo::Int32#shape=[10]
78
73
  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
79
74
 
80
- p a.inplace.clip(3,6)
81
- # Numo::Int32(view)#shape=[10]
82
- # [3, 3, 3, 3, 4, 5, 6, 6, 6, 6]
75
+ a.clip(1,8)
76
+ # => Numo::Int32#shape=[10]
77
+ # [1, 1, 2, 3, 4, 5, 6, 7, 8, 8]
83
78
 
84
- p a
85
- # Numo::Int32#shape=[10]
79
+ a.inplace.clip(3,6)
80
+ a
81
+ # => Numo::Int32#shape=[10]
86
82
  # [3, 3, 3, 3, 4, 5, 6, 6, 6, 6]
87
83
 
88
- p a = Numo::Int32.new(10).seq
89
- # Numo::Int32#shape=[10]
84
+ b = Numo::Int32.new(10).seq
85
+ # => Numo::Int32#shape=[10]
90
86
  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
91
87
 
92
- p a.clip([3,4,1,1,1,4,4,4,4,4], 8)
93
- # Numo::Int32#shape=[10]
88
+ b.clip([3,4,1,1,1,4,4,4,4,4], 8)
89
+ # => Numo::Int32#shape=[10]
94
90
  # [3, 4, 2, 3, 4, 5, 6, 7, 8, 8]
95
91
  */
96
92
  static VALUE
@@ -27,7 +27,7 @@ static void
27
27
  /*
28
28
  <%=name%> of self.
29
29
  @overload <%=name%>(axis:nil, nan:false)
30
- @param [Numeric,Array,Range] axis Affected dimensions.
30
+ @param [Numeric,Array,Range] axis Performs <%=name%> along the axis.
31
31
  @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
32
32
  @return [Numo::<%=class_name%>] <%=name%> of self.
33
33
  */
@@ -29,8 +29,10 @@ static void
29
29
  passing that element as a parameter.
30
30
  @overload <%=name%>
31
31
  @return [Numo::NArray] self
32
- For a block {|x| ... }
33
- @yield [x] x is element of NArray.
32
+ For a block `{|x| ... }`,
33
+ @yieldparam [Numeric] x an element of NArray.
34
+ @see #each_with_index
35
+ @see #map
34
36
  */
35
37
  static VALUE
36
38
  <%=c_func(0)%>(VALUE self)
@@ -50,9 +50,12 @@ static void
50
50
  Invokes the given block once for each element of self,
51
51
  passing that element and indices along each axis as parameters.
52
52
  @overload <%=name%>
53
+ For a block `{|x,i,j,...| ... }`,
54
+ @yieldparam [Numeric] x an element
55
+ @yieldparam [Integer] i,j,... multitimensional indices
53
56
  @return [Numo::NArray] self
54
- For a block {|x,i,j,...| ... }
55
- @yield [x,i,j,...] x is an element, i,j,... are multidimensional indices.
57
+ @see #each
58
+ @see #map_with_index
56
59
  */
57
60
  static VALUE
58
61
  <%=c_func(0)%>(VALUE self)
@@ -1,9 +1,9 @@
1
1
  /*
2
2
  <%= file_name %>
3
- Ruby/Numo::GSL - GSL wrapper for Ruby/Numo::NArray
3
+ Ruby/Numo::NArray - Numerical Array class for Ruby
4
4
 
5
5
  created on: 2017-03-11
6
- Copyright (C) 2017 Masahiro Tanaka
6
+ Copyright (C) 2017-2020 Masahiro Tanaka
7
7
  */
8
8
 
9
9
  #include <ruby.h>
@@ -42,7 +42,7 @@ static void
42
42
 
43
43
  /*
44
44
  Set logarithmic sequence of numbers to self. The sequence is obtained from
45
- base**(beg+i*step)
45
+ `base**(beg+i*step)`
46
46
  where i is 1-dimensional index.
47
47
  Applicable classes: DFloat, SFloat, DComplex, SCopmplex.
48
48
 
@@ -54,11 +54,12 @@ static void
54
54
 
55
55
  @example
56
56
  Numo::DFloat.new(5).logseq(4,-1,2)
57
- => Numo::DFloat#shape=[5]
58
- [16, 8, 4, 2, 1]
57
+ # => Numo::DFloat#shape=[5]
58
+ # [16, 8, 4, 2, 1]
59
+
59
60
  Numo::DComplex.new(5).logseq(0,1i*Math::PI/3,Math::E)
60
- => Numo::DComplex#shape=[5]
61
- [1+7.26156e-310i, 0.5+0.866025i, -0.5+0.866025i, -1+1.22465e-16i, ...]
61
+ # => Numo::DComplex#shape=[5]
62
+ # [1+7.26156e-310i, 0.5+0.866025i, -0.5+0.866025i, -1+1.22465e-16i, ...]
62
63
  */
63
64
  static VALUE
64
65
  <%=c_func(-1)%>(int argc, VALUE *args, VALUE self)
@@ -75,14 +75,13 @@ static void
75
75
  passing that element and indices along each axis as parameters.
76
76
  Creates a new NArray containing the values returned by the block.
77
77
  Inplace option is allowed, i.e., `nary.inplace.map` overwrites `nary`.
78
-
79
78
  @overload <%=name%>
80
-
81
- For a block {|x,i,j,...| ... }
82
- @yield [x,i,j,...] x is an element, i,j,... are multidimensional indices.
83
-
79
+ For a block `{|x,i,j,...| ... }`,
80
+ @yieldparam [Numeric] x an element
81
+ @yieldparam [Integer] i,j,... multitimensional indices
84
82
  @return [Numo::NArray] mapped array
85
-
83
+ @see #map
84
+ @see #each_with_index
86
85
  */
87
86
  static VALUE
88
87
  <%=c_func(0)%>(VALUE self)
@@ -39,8 +39,8 @@ static void
39
39
  <% else %>
40
40
  @overload <%=name%>(axis:nil, keepdims:false)
41
41
  <% end %>
42
- @param [Numeric,Array,Range] axis (keyword) Affected dimensions.
43
- @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array as dimensions with size one.
42
+ @param [Numeric,Array,Range] axis Finds <%=name%> along the axis.
43
+ @param [TrueClass] keepdims If true, the reduced axes are left in the result array as dimensions with size one.
44
44
  @return [Numo::<%=class_name%>] returns <%=name%> of self.
45
45
  */
46
46
 
@@ -25,7 +25,7 @@ static void
25
25
  <% else %>
26
26
  @overload <%=name%>(axis:nil, keepdims:false)
27
27
  <% end %>
28
- @param [Numeric,Array,Range] axis (keyword) Affected dimensions.
28
+ @param [Numeric,Array,Range] axis Finds min-max along the axis.
29
29
  @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array as dimensions with size one.
30
30
  @return [Numo::<%=class_name%>,Numo::<%=class_name%>] min and max of self.
31
31
  */
@@ -17,10 +17,10 @@ static void
17
17
  }
18
18
 
19
19
  /*
20
- Polynomial.: a0 + a1*x + a2*x**2 + a3*x**3 + ... + an*x**n
21
- @overload <%=name%> a0, a1, ...
22
- @param [Numo::NArray,Numeric] a0
23
- @param [Numo::NArray,Numeric] a1 , ...
20
+ Calculate polynomial.
21
+ `x.poly(a0,a1,a2,...,an) = a0 + a1*x + a2*x**2 + ... + an*x**n`
22
+ @overload <%=name%> a0, a1, ..., an
23
+ @param [Numo::NArray,Numeric] a0,a1,...,an
24
24
  @return [Numo::<%=class_name%>]
25
25
  */
26
26
  static VALUE
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  qsort.c
3
- Numerical Array Extension for Ruby
3
+ Ruby/Numo::NArray - Numerical Array class for Ruby
4
4
  modified by Masahiro TANAKA
5
5
  */
6
6
 
@@ -113,14 +113,16 @@ static void
113
113
  @return [Numo::<%=class_name%>] self.
114
114
  @example
115
115
  Numo::DFloat.new(6).rand
116
- => Numo::DFloat#shape=[6]
117
- [0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032]
116
+ # => Numo::DFloat#shape=[6]
117
+ # [0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032]
118
+
118
119
  Numo::DComplex.new(6).rand(5+5i)
119
- => Numo::DComplex#shape=[6]
120
- [2.69974+3.68908i, 0.825443+0.254414i, 0.540323+0.34354i, 4.52061+2.39322i, ...]
120
+ # => Numo::DComplex#shape=[6]
121
+ # [2.69974+3.68908i, 0.825443+0.254414i, 0.540323+0.34354i, 4.52061+2.39322i, ...]
122
+
121
123
  Numo::Int32.new(6).rand(2,5)
122
- => Numo::Int32#shape=[6]
123
- [4, 3, 3, 2, 4, 2]
124
+ # => Numo::Int32#shape=[6]
125
+ # [4, 3, 3, 2, 4, 2]
124
126
  */
125
127
  static VALUE
126
128
  <%=c_func(-1)%>(int argc, VALUE *args, VALUE self)
@@ -75,24 +75,26 @@ static void
75
75
  @return [Numo::<%=class_name%>] self.
76
76
  @example
77
77
  Numo::DFloat.new(5,5).rand_norm
78
- => Numo::DFloat#shape=[5,5]
79
- [[-0.581255, -0.168354, 0.586895, -0.595142, -0.802802],
80
- [-0.326106, 0.282922, 1.68427, 0.918499, -0.0485384],
81
- [-0.464453, -0.992194, 0.413794, -0.60717, -0.699695],
82
- [-1.64168, 0.48676, -0.875871, -1.43275, 0.812172],
83
- [-0.209975, -0.103612, -0.878617, -1.42495, 1.0968]]
78
+ # => Numo::DFloat#shape=[5,5]
79
+ # [[-0.581255, -0.168354, 0.586895, -0.595142, -0.802802],
80
+ # [-0.326106, 0.282922, 1.68427, 0.918499, -0.0485384],
81
+ # [-0.464453, -0.992194, 0.413794, -0.60717, -0.699695],
82
+ # [-1.64168, 0.48676, -0.875871, -1.43275, 0.812172],
83
+ # [-0.209975, -0.103612, -0.878617, -1.42495, 1.0968]]
84
+
84
85
  Numo::DFloat.new(5,5).rand_norm(10,0.1)
85
- => Numo::DFloat#shape=[5,5]
86
- [[9.9019, 9.90339, 10.0826, 9.98384, 9.72861],
87
- [9.81507, 10.0272, 9.91445, 10.0568, 9.88923],
88
- [10.0234, 9.97874, 9.96011, 9.9006, 9.99964],
89
- [10.0186, 9.94598, 9.92236, 9.99811, 9.97003],
90
- [9.79266, 9.95044, 9.95212, 9.93692, 10.2027]]
86
+ # => Numo::DFloat#shape=[5,5]
87
+ # [[9.9019, 9.90339, 10.0826, 9.98384, 9.72861],
88
+ # [9.81507, 10.0272, 9.91445, 10.0568, 9.88923],
89
+ # [10.0234, 9.97874, 9.96011, 9.9006, 9.99964],
90
+ # [10.0186, 9.94598, 9.92236, 9.99811, 9.97003],
91
+ # [9.79266, 9.95044, 9.95212, 9.93692, 10.2027]]
92
+
91
93
  Numo::DComplex.new(3,3).rand_norm(5+5i)
92
- => Numo::DComplex#shape=[3,3]
93
- [[5.84303+4.40052i, 4.00984+6.08982i, 5.10979+5.13215i],
94
- [4.26477+3.99655i, 4.90052+5.00763i, 4.46607+2.3444i],
95
- [4.5528+7.11003i, 5.62117+6.69094i, 5.05443+5.35133i]]
94
+ # => Numo::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
98
  */
97
99
  static VALUE
98
100
  <%=c_func(-1)%>(int argc, VALUE *args, VALUE self)
@@ -60,11 +60,12 @@ static void
60
60
  @return [Numo::<%=class_name%>] self.
61
61
  @example
62
62
  Numo::DFloat.new(6).seq(1,-0.2)
63
- => Numo::DFloat#shape=[6]
64
- [1, 0.8, 0.6, 0.4, 0.2, 0]
63
+ # => Numo::DFloat#shape=[6]
64
+ # [1, 0.8, 0.6, 0.4, 0.2, 0]
65
+
65
66
  Numo::DComplex.new(6).seq(1,-0.2+0.2i)
66
- => Numo::DComplex#shape=[6]
67
- [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]
67
+ # => Numo::DComplex#shape=[6]
68
+ # [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]
68
69
  */
69
70
  static VALUE
70
71
  <%=c_func(-1)%>(int argc, VALUE *args, VALUE self)
@@ -20,17 +20,17 @@ static void
20
20
  <% else %>
21
21
  @overload <%=name%>(axis:nil)
22
22
  <% end %>
23
- @param [Numeric,Array,Range] axis Affected dimensions.
23
+ @param [Numeric,Array,Range] axis Performs <%=name%> along the axis.
24
24
  @return [Numo::<%=class_name%>] returns result of <%=name%>.
25
25
  @example
26
- Numo::DFloat[3,4,1,2].sort => Numo::DFloat[1,2,3,4]
26
+ Numo::DFloat[3,4,1,2].sort #=> Numo::DFloat[1,2,3,4]
27
27
  */
28
28
  static VALUE
29
29
  <%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
30
30
  {
31
31
  VALUE reduce;
32
32
  ndfunc_arg_in_t ain[2] = {{OVERWRITE,0},{sym_reduce,0}};
33
- ndfunc_t ndf = {0, STRIDE_LOOP|NDF_FLAT_REDUCE, 2,0, ain,0};
33
+ ndfunc_t ndf = {0, NDF_HAS_LOOP|NDF_FLAT_REDUCE, 2,0, ain,0};
34
34
 
35
35
  if (!TEST_INPLACE(self)) {
36
36
  self = na_copy(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,Numo::Int] returns result index of <%=name%>.
57
57
  @example
58
- Numo::NArray[3,4,1,2].sort_index => Numo::Int32[2,3,0,1]
58
+ Numo::NArray[3,4,1,2].sort_index #=> Numo::Int32[2,3,0,1]
59
59
  */
60
60
  static VALUE
61
61
  <%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
@@ -47,7 +47,13 @@ static void
47
47
  if (idx1) {
48
48
  for (i=i1=0; i1<n1 && i<n; i++,i1++) {
49
49
  x = ptr[i1];
50
- if (rb_obj_is_kind_of(x, rb_cRange) || rb_obj_is_kind_of(x, na_cStep)) {
50
+ if (rb_obj_is_kind_of(x, rb_cRange)
51
+ #ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
52
+ || rb_obj_is_kind_of(x, rb_cArithSeq)
53
+ #else
54
+ || rb_obj_is_kind_of(x, rb_cEnumerator)
55
+ #endif
56
+ ) {
51
57
  nary_step_sequence(x,&len,&beg,&step);
52
58
  for (c=0; c<len && i<n; c++,i++) {
53
59
  y = beg + step * c;
@@ -63,7 +69,13 @@ static void
63
69
  } else {
64
70
  for (i=i1=0; i1<n1 && i<n; i++,i1++) {
65
71
  x = ptr[i1];
66
- if (rb_obj_is_kind_of(x, rb_cRange) || rb_obj_is_kind_of(x, na_cStep)) {
72
+ if (rb_obj_is_kind_of(x, rb_cRange)
73
+ #ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
74
+ || rb_obj_is_kind_of(x, rb_cArithSeq)
75
+ #else
76
+ || rb_obj_is_kind_of(x, rb_cEnumerator)
77
+ #endif
78
+ ) {
67
79
  nary_step_sequence(x,&len,&beg,&step);
68
80
  for (c=0; c<len && i<n; c++,i++) {
69
81
  y = beg + step * c;
@@ -44,44 +44,68 @@ static void
44
44
  SET_DATA_INDEX(p2,idx2,dtype,x);
45
45
  }
46
46
  } else {
47
- <% if is_simd and !is_complex and %w[sqrt].include? name %>
48
- // Check number of elements. & Check same alignment.
49
- if ((n >= num_pack) && is_same_aligned2(&((dtype*)p1)[i], &((dtype*)p2)[i], SIMD_ALIGNMENT_SIZE)){
50
- // Calculate up to the position just before the start of SIMD computation.
51
- cnt = get_count_of_elements_not_aligned_to_simd_size(&((dtype*)p1)[i], SIMD_ALIGNMENT_SIZE, sizeof(dtype));
52
- for (i=0; i < cnt; i++) {
53
- ((dtype*)p2)[i] = m_<%=name%>(((dtype*)p1)[i]);
54
- }
47
+ //<% if need_align %>
48
+ if (is_aligned(p1,sizeof(dtype)) &&
49
+ is_aligned(p2,sizeof(dtype)) ) {
50
+ if (s1 == sizeof(dtype) &&
51
+ s2 == sizeof(dtype) ) {
52
+ //<% if is_simd and !is_complex and %w[sqrt].include? name %>
53
+ // Check number of elements. & Check same alignment.
54
+ if ((n >= num_pack) && is_same_aligned2(&((dtype*)p1)[i], &((dtype*)p2)[i], SIMD_ALIGNMENT_SIZE)){
55
+ // Calculate up to the position just before the start of SIMD computation.
56
+ cnt = get_count_of_elements_not_aligned_to_simd_size(&((dtype*)p1)[i], SIMD_ALIGNMENT_SIZE, sizeof(dtype));
57
+ for (i=0; i < cnt; i++) {
58
+ ((dtype*)p2)[i] = m_<%=name%>(((dtype*)p1)[i]);
59
+ }
55
60
 
56
- // Get the count of SIMD computation loops.
57
- cnt_simd_loop = (n - i) % num_pack;
61
+ // Get the count of SIMD computation loops.
62
+ cnt_simd_loop = (n - i) % num_pack;
63
+
64
+ // SIMD computation.
65
+ if (p1 == p2) { // inplace case
66
+ for(; i < n - cnt_simd_loop; i += num_pack){
67
+ a = _mm_load_<%=simd_type%>(&((dtype*)p1)[i]);
68
+ a = _mm_<%=name%>_<%=simd_type%>(a);
69
+ _mm_store_<%=simd_type%>(&((dtype*)p1)[i], a);
70
+ }
71
+ } else {
72
+ for(; i < n - cnt_simd_loop; i += num_pack){
73
+ a = _mm_load_<%=simd_type%>(&((dtype*)p1)[i]);
74
+ a = _mm_<%=name%>_<%=simd_type%>(a);
75
+ _mm_stream_<%=simd_type%>(&((dtype*)p2)[i], a);
76
+ }
77
+ }
58
78
 
59
- // SIMD computation.
60
- if (p1 == p2) { // inplace case
61
- for(; i < n - cnt_simd_loop; i += num_pack){
62
- a = _mm_load_<%=simd_type%>(&((dtype*)p1)[i]);
63
- a = _mm_<%=name%>_<%=simd_type%>(a);
64
- _mm_store_<%=simd_type%>(&((dtype*)p1)[i], a);
65
79
  }
66
- } else {
67
- for(; i < n - cnt_simd_loop; i += num_pack){
68
- a = _mm_load_<%=simd_type%>(&((dtype*)p1)[i]);
69
- a = _mm_<%=name%>_<%=simd_type%>(a);
70
- _mm_stream_<%=simd_type%>(&((dtype*)p2)[i], a);
80
+ // Compute the remainder of the SIMD operation.
81
+ if (cnt_simd_loop != 0){
82
+ //<% end %>
83
+ for (; i<n; i++) {
84
+ ((dtype*)p2)[i] = m_<%=name%>(((dtype*)p1)[i]);
85
+ }
86
+ //<% if is_simd and !is_complex and %w[sqrt].include? name %>
71
87
  }
88
+ //<% end %>
89
+ return;
72
90
  }
73
-
74
- }
75
- // Compute the remainder of the SIMD operation.
76
- if (cnt_simd_loop != 0){
77
- <% end %>
78
- for (; i<n; i++) {
79
- ((dtype*)p2)[i] = m_<%=name%>(((dtype*)p1)[i]);
91
+ if (is_aligned_step(s1,sizeof(dtype)) &&
92
+ is_aligned_step(s2,sizeof(dtype)) ) {
93
+ //<% end %>
94
+ for (i=0; i<n; i++) {
95
+ *(dtype*)p2 = m_<%=name%>(*(dtype*)p1);
96
+ p1 += s1;
97
+ p2 += s2;
98
+ }
99
+ return;
100
+ //<% if need_align %>
80
101
  }
81
- <% if is_simd and !is_complex and %w[sqrt].include? name %>
82
102
  }
83
- <% end %>
84
- return;
103
+ for (i=0; i<n; i++) {
104
+ GET_DATA_STRIDE(p1,s1,dtype,x);
105
+ x = m_<%=name%>(x);
106
+ SET_DATA_STRIDE(p2,s2,dtype,x);
107
+ }
108
+ //<% end %>
85
109
  }
86
110
  }
87
111
  }