numo-narray 0.9.1.4 → 0.9.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -4
- data/ext/numo/narray/array.c +17 -7
- data/ext/numo/narray/data.c +39 -36
- data/ext/numo/narray/extconf.rb +1 -0
- data/ext/numo/narray/gen/narray_def.rb +4 -0
- data/ext/numo/narray/gen/spec.rb +5 -1
- data/ext/numo/narray/gen/tmpl/accum.c +2 -2
- data/ext/numo/narray/gen/tmpl/accum_arg.c +88 -0
- data/ext/numo/narray/gen/tmpl/accum_binary.c +1 -1
- data/ext/numo/narray/gen/tmpl/accum_index.c +25 -14
- data/ext/numo/narray/gen/tmpl/aref.c +5 -35
- data/ext/numo/narray/gen/tmpl/aset.c +7 -37
- data/ext/numo/narray/gen/tmpl/bincount.c +7 -7
- data/ext/numo/narray/gen/tmpl/clip.c +11 -15
- data/ext/numo/narray/gen/tmpl/cum.c +1 -1
- data/ext/numo/narray/gen/tmpl/each.c +4 -2
- data/ext/numo/narray/gen/tmpl/each_with_index.c +5 -2
- data/ext/numo/narray/gen/tmpl/lib.c +2 -2
- data/ext/numo/narray/gen/tmpl/logseq.c +6 -5
- data/ext/numo/narray/gen/tmpl/map_with_index.c +5 -6
- data/ext/numo/narray/gen/tmpl/median.c +2 -2
- data/ext/numo/narray/gen/tmpl/minmax.c +1 -1
- data/ext/numo/narray/gen/tmpl/poly.c +4 -4
- data/ext/numo/narray/gen/tmpl/qsort.c +1 -1
- data/ext/numo/narray/gen/tmpl/rand.c +8 -6
- data/ext/numo/narray/gen/tmpl/rand_norm.c +18 -16
- data/ext/numo/narray/gen/tmpl/seq.c +5 -4
- data/ext/numo/narray/gen/tmpl/sort.c +3 -3
- data/ext/numo/narray/gen/tmpl/sort_index.c +2 -2
- data/ext/numo/narray/gen/tmpl/store_array.c +14 -2
- data/ext/numo/narray/gen/tmpl/unary_s.c +55 -31
- data/ext/numo/narray/gen/tmpl_bit/aref.c +22 -30
- data/ext/numo/narray/gen/tmpl_bit/aset.c +20 -34
- data/ext/numo/narray/gen/tmpl_bit/binary.c +42 -14
- data/ext/numo/narray/gen/tmpl_bit/bit_count.c +5 -0
- data/ext/numo/narray/gen/tmpl_bit/bit_reduce.c +5 -0
- data/ext/numo/narray/gen/tmpl_bit/store_array.c +14 -2
- data/ext/numo/narray/gen/tmpl_bit/store_bit.c +21 -7
- data/ext/numo/narray/gen/tmpl_bit/unary.c +21 -7
- data/ext/numo/narray/index.c +369 -59
- data/ext/numo/narray/math.c +2 -2
- data/ext/numo/narray/narray.c +45 -27
- data/ext/numo/narray/ndloop.c +2 -2
- data/ext/numo/narray/numo/intern.h +3 -2
- data/ext/numo/narray/numo/narray.h +24 -5
- data/ext/numo/narray/numo/ndloop.h +2 -2
- data/ext/numo/narray/numo/template.h +4 -6
- data/ext/numo/narray/numo/types/complex.h +2 -2
- data/ext/numo/narray/step.c +58 -252
- data/ext/numo/narray/struct.c +2 -2
- data/lib/numo/narray/extra.rb +172 -212
- data/numo-narray.gemspec +9 -5
- metadata +18 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2723cec3e04deedc561c54a0d4f6af799dd93fc8a32079d06a074f00f07f466c
|
4
|
+
data.tar.gz: 5548cfa23b0ac7227b62ab8edd00ba040805c0563befeb32591179dc090eff66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19a91712b943da6f57f2cda4fa178adcb5a0c845c2b0ce8190f46c5c1a0d83a331fd32d71e9b2b85c960222f4a01940926bacba63eb882ea1b27aebb7a09c7a3
|
7
|
+
data.tar.gz: 4ee3a88369439ccf964fd23358a84530973c5355d4c71b35eda516bd655966ce127d494159c942bf0a82045b3f05a6be7ed16f4d9d30b96916df651c9a5ec0cb
|
data/README.md
CHANGED
@@ -11,17 +11,17 @@ for fast processing and easy manipulation of multi-dimensional numerical data,
|
|
11
11
|
similar to numpy.ndaray.
|
12
12
|
This project is the successor to [Ruby/NArray](http://masa16.github.io/narray/).
|
13
13
|
|
14
|
-
under development
|
15
|
-
|
16
14
|
## Documentation
|
15
|
+
|
17
16
|
All documents are primitive.
|
18
17
|
|
19
|
-
* [Numo::NArray API Doc](http://ruby-numo.github.io/narray/
|
18
|
+
* [Numo::NArray API Doc](http://ruby-numo.github.io/numo-narray/yard/index.html)
|
20
19
|
* [Numo::NArray vs numpy](https://github.com/ruby-numo/numo-narray/wiki/Numo-vs-numpy)
|
21
20
|
* [Numo::NArray vs ndarray](https://github.com/ruby-numo/numo-narray/wiki/Numo-vs-ndarray)
|
22
21
|
* [Numo::NArray Overview](https://github.com/ruby-numo/numo-narray/wiki/Numo::NArray%E6%A6%82%E8%A6%81) (in Japanese)
|
23
22
|
|
24
23
|
## Related Projects
|
24
|
+
|
25
25
|
* [Numo::Linalg](https://github.com/ruby-numo/numo-linalg) - Linear Algebra library with [LAPACK](http://www.netlib.org/lapack/).
|
26
26
|
* [Numo::GSL](https://github.com/ruby-numo/numo-gsl) - Ruby interface for [GSL (GNU Scientific Library)](http://www.gnu.org/software/gsl/).
|
27
27
|
* [Numo::FFTW](https://github.com/ruby-numo/numo-fftw) - Ruby/Numo interface to [FFTW (A Discrete Fourier Transform library](http://www.fftw.org/).
|
@@ -29,10 +29,13 @@ All documents are primitive.
|
|
29
29
|
* [Numo::Gnuplot](https://github.com/ruby-numo/numo-gnuplot) - Simple and easy-to-use Gnuplot interface.
|
30
30
|
|
31
31
|
## Installation
|
32
|
+
|
32
33
|
### Requirement
|
33
|
-
|
34
|
+
|
35
|
+
Ruby ver 2.2 and later.
|
34
36
|
|
35
37
|
### Ubuntu, Debian, Bash on Windows
|
38
|
+
|
36
39
|
```shell
|
37
40
|
apt install -y git ruby gcc ruby-dev rake make
|
38
41
|
gem install specific_install
|
@@ -40,7 +43,9 @@ gem specific_install https://github.com/ruby-numo/numo-narray.git
|
|
40
43
|
```
|
41
44
|
|
42
45
|
## Quick start
|
46
|
+
|
43
47
|
An example
|
48
|
+
|
44
49
|
```ruby
|
45
50
|
[1] pry(main)> require "numo/narray"
|
46
51
|
=> true
|
@@ -58,6 +63,7 @@ An example
|
|
58
63
|
[6] pry(main)> a.size
|
59
64
|
=> 15
|
60
65
|
```
|
66
|
+
|
61
67
|
For more examples, check out this [narray version of 100 numpy exercises](https://github.com/ruby-numo/numo-narray/wiki/100-narray-exercises) (and the [IRuby Notebook](https://github.com/ruby-numo/numo-narray/blob/master/100-narray-exercises.ipynb)).
|
62
68
|
|
63
69
|
## Development
|
data/ext/numo/narray/array.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
array.c
|
3
|
-
Numerical Array
|
4
|
-
(C)
|
3
|
+
Ruby/Numo::NArray - Numerical Array class for Ruby
|
4
|
+
Copyright (C) 1999-2019 Masahiro TANAKA
|
5
5
|
*/
|
6
6
|
#include <ruby.h>
|
7
7
|
#include "numo/narray.h"
|
@@ -122,10 +122,12 @@ static int na_mdai_object_type(int type, VALUE v)
|
|
122
122
|
if (rb_obj_is_kind_of(v, rb_cRange)) {
|
123
123
|
MDAI_ATTR_TYPE(type,v,begin);
|
124
124
|
MDAI_ATTR_TYPE(type,v,end);
|
125
|
-
|
125
|
+
#ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
|
126
|
+
} else if (rb_obj_is_kind_of(v, rb_cArithSeq)) {
|
126
127
|
MDAI_ATTR_TYPE(type,v,begin);
|
127
128
|
MDAI_ATTR_TYPE(type,v,end);
|
128
129
|
MDAI_ATTR_TYPE(type,v,step);
|
130
|
+
#endif
|
129
131
|
} else {
|
130
132
|
type = na_object_type(type,v);
|
131
133
|
}
|
@@ -210,7 +212,13 @@ na_mdai_investigate(na_mdai_t *mdai, int ndim)
|
|
210
212
|
}
|
211
213
|
}
|
212
214
|
else
|
213
|
-
if (rb_obj_is_kind_of(v, rb_cRange)
|
215
|
+
if (rb_obj_is_kind_of(v, rb_cRange)
|
216
|
+
#ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
|
217
|
+
|| rb_obj_is_kind_of(v, rb_cArithSeq)
|
218
|
+
#else
|
219
|
+
|| rb_obj_is_kind_of(v, rb_cEnumerator)
|
220
|
+
#endif
|
221
|
+
) {
|
214
222
|
nary_step_sequence(v,&length,&dbeg,&dstep);
|
215
223
|
len += length-1;
|
216
224
|
mdai->type = na_mdai_object_type(mdai->type, v);
|
@@ -465,11 +473,13 @@ na_s_array_shape(VALUE mod, VALUE ary)
|
|
465
473
|
@return [Numo::NArray]
|
466
474
|
@example
|
467
475
|
Numo::NArray.new_like([[1,2,3],[4,5,6]])
|
468
|
-
=> Numo::Int32#shape=[2,3](empty)
|
476
|
+
# => Numo::Int32#shape=[2,3](empty)
|
477
|
+
|
469
478
|
Numo::DFloat.new_like([[1,2],[3,4]])
|
470
|
-
=> Numo::DFloat#shape=[2,2](empty)
|
479
|
+
# => Numo::DFloat#shape=[2,2](empty)
|
480
|
+
|
471
481
|
Numo::NArray.new_like([1,2i,3])
|
472
|
-
=> Numo::DComplex#shape=[3](empty)
|
482
|
+
# => Numo::DComplex#shape=[3](empty)
|
473
483
|
*/
|
474
484
|
VALUE
|
475
485
|
na_s_new_like(VALUE type, VALUE obj)
|
data/ext/numo/narray/data.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
data.c
|
3
|
-
Numerical Array
|
4
|
-
(C)
|
3
|
+
Ruby/Numo::NArray - Numerical Array class for Ruby
|
4
|
+
Copyright (C) 1999-2019 Masahiro TANAKA
|
5
5
|
*/
|
6
6
|
|
7
7
|
#include <ruby.h>
|
@@ -186,21 +186,21 @@ check_axis(int axis, int ndim)
|
|
186
186
|
@example
|
187
187
|
x = Numo::Int32[[1,2,3]]
|
188
188
|
|
189
|
-
|
190
|
-
# Numo::Int32(view)#shape=[3,1]
|
189
|
+
x.swapaxes(0,1)
|
190
|
+
# => Numo::Int32(view)#shape=[3,1]
|
191
191
|
# [[1],
|
192
192
|
# [2],
|
193
193
|
# [3]]
|
194
194
|
|
195
|
-
|
196
|
-
# Numo::Int32#shape=[2,2,2]
|
195
|
+
x = Numo::Int32[[[0,1],[2,3]],[[4,5],[6,7]]]
|
196
|
+
# => Numo::Int32#shape=[2,2,2]
|
197
197
|
# [[[0, 1],
|
198
198
|
# [2, 3]],
|
199
199
|
# [[4, 5],
|
200
200
|
# [6, 7]]]
|
201
201
|
|
202
|
-
|
203
|
-
# Numo::Int32(view)#shape=[2,2,2]
|
202
|
+
x.swapaxes(0,2)
|
203
|
+
# => Numo::Int32(view)#shape=[2,2,2]
|
204
204
|
# [[[0, 4],
|
205
205
|
# [2, 6]],
|
206
206
|
# [[1, 5],
|
@@ -457,7 +457,7 @@ VALUE
|
|
457
457
|
na_flatten_dim(VALUE self, int sd)
|
458
458
|
{
|
459
459
|
int i, nd, fd;
|
460
|
-
size_t j;
|
460
|
+
size_t j, ofs;
|
461
461
|
size_t *c, *pos, *idx1, *idx2;
|
462
462
|
size_t stride;
|
463
463
|
size_t *shape, size;
|
@@ -501,7 +501,6 @@ na_flatten_dim(VALUE self, int sd)
|
|
501
501
|
case NARRAY_FILEMAP_T:
|
502
502
|
stride = nary_element_stride(self);
|
503
503
|
for (i=sd+1; i--; ) {
|
504
|
-
//printf("data: i=%d shpae[i]=%ld stride=%ld\n",i,shape[i],stride);
|
505
504
|
SDX_SET_STRIDE(na2->stridx[i],stride);
|
506
505
|
stride *= shape[i];
|
507
506
|
}
|
@@ -522,32 +521,35 @@ na_flatten_dim(VALUE self, int sd)
|
|
522
521
|
SDX_SET_INDEX(na2->stridx[i],idx2);
|
523
522
|
} else {
|
524
523
|
na2->stridx[i] = na1->stridx[i];
|
525
|
-
//printf("view: i=%d stridx=%d\n",i,SDX_GET_STRIDE(sdx));
|
526
524
|
}
|
527
525
|
}
|
528
526
|
// flat dimenion == last dimension
|
529
527
|
if (RTEST(na_check_ladder(self,sd))) {
|
530
|
-
//if (0) {
|
531
528
|
na2->stridx[sd] = na1->stridx[nd-1];
|
532
529
|
} else {
|
533
530
|
// set index
|
534
|
-
idx2 = ALLOC_N(size_t, shape[sd]);
|
531
|
+
idx2 = ALLOC_N(size_t, (shape[sd]==0) ? 1 : shape[sd]);
|
535
532
|
SDX_SET_INDEX(na2->stridx[sd],idx2);
|
536
533
|
// init for md-loop
|
537
534
|
fd = nd-sd;
|
538
|
-
c =
|
535
|
+
c = ALLOCA_N(size_t, fd);
|
539
536
|
for (i=0; i<fd; i++) c[i]=0;
|
540
|
-
pos =
|
537
|
+
pos = ALLOCA_N(size_t, fd+1);
|
541
538
|
pos[0] = 0;
|
542
539
|
// md-loop
|
543
540
|
for (i=j=0;;) {
|
544
541
|
for (; i<fd; i++) {
|
545
542
|
sdx = na1->stridx[i+sd];
|
546
543
|
if (SDX_IS_INDEX(sdx)) {
|
547
|
-
|
544
|
+
if (SDX_GET_INDEX(sdx)) {
|
545
|
+
ofs = SDX_GET_INDEX(sdx)[c[i]];
|
546
|
+
} else {
|
547
|
+
ofs = 0;
|
548
|
+
}
|
548
549
|
} else {
|
549
|
-
|
550
|
+
ofs = SDX_GET_STRIDE(sdx)*c[i];
|
550
551
|
}
|
552
|
+
pos[i+1] = pos[i] + ofs;
|
551
553
|
}
|
552
554
|
idx2[j++] = pos[i];
|
553
555
|
for (;;) {
|
@@ -559,8 +561,7 @@ na_flatten_dim(VALUE self, int sd)
|
|
559
561
|
}
|
560
562
|
}
|
561
563
|
loop_end:
|
562
|
-
|
563
|
-
xfree(c);
|
564
|
+
;
|
564
565
|
}
|
565
566
|
break;
|
566
567
|
}
|
@@ -589,28 +590,30 @@ na_flatten(VALUE self)
|
|
589
590
|
@return [Numo::NArray] diagonal view of NArray.
|
590
591
|
@example
|
591
592
|
a = Numo::DFloat.new(4,5).seq
|
592
|
-
=> Numo::DFloat#shape=[4,5]
|
593
|
-
[[0, 1, 2, 3, 4],
|
594
|
-
|
595
|
-
|
596
|
-
|
593
|
+
# => Numo::DFloat#shape=[4,5]
|
594
|
+
# [[0, 1, 2, 3, 4],
|
595
|
+
# [5, 6, 7, 8, 9],
|
596
|
+
# [10, 11, 12, 13, 14],
|
597
|
+
# [15, 16, 17, 18, 19]]
|
597
598
|
b = a.diagonal(1)
|
598
|
-
=> Numo::DFloat(view)#shape=[4]
|
599
|
-
[1, 7, 13, 19]
|
599
|
+
# => Numo::DFloat(view)#shape=[4]
|
600
|
+
# [1, 7, 13, 19]
|
601
|
+
|
600
602
|
b.store(0)
|
601
603
|
a
|
602
|
-
=> Numo::DFloat#shape=[4,5]
|
603
|
-
[[0, 0, 2, 3, 4],
|
604
|
-
|
605
|
-
|
606
|
-
|
604
|
+
# => Numo::DFloat#shape=[4,5]
|
605
|
+
# [[0, 0, 2, 3, 4],
|
606
|
+
# [5, 6, 0, 8, 9],
|
607
|
+
# [10, 11, 12, 0, 14],
|
608
|
+
# [15, 16, 17, 18, 0]]
|
609
|
+
|
607
610
|
b.store([1,2,3,4])
|
608
611
|
a
|
609
|
-
=> Numo::DFloat#shape=[4,5]
|
610
|
-
[[0, 1, 2, 3, 4],
|
611
|
-
|
612
|
-
|
613
|
-
|
612
|
+
# => Numo::DFloat#shape=[4,5]
|
613
|
+
# [[0, 1, 2, 3, 4],
|
614
|
+
# [5, 6, 2, 8, 9],
|
615
|
+
# [10, 11, 12, 3, 14],
|
616
|
+
# [15, 16, 17, 18, 4]]
|
614
617
|
*/
|
615
618
|
static VALUE
|
616
619
|
na_diagonal(int argc, VALUE *argv, VALUE self)
|
data/ext/numo/narray/extconf.rb
CHANGED
data/ext/numo/narray/gen/spec.rb
CHANGED
@@ -303,6 +303,8 @@ if is_comparable
|
|
303
303
|
accum "ptp","dtype","cT"
|
304
304
|
accum_index "max_index"
|
305
305
|
accum_index "min_index"
|
306
|
+
accum_arg "argmax"
|
307
|
+
accum_arg "argmin"
|
306
308
|
def_method "minmax"
|
307
309
|
def_module_function "maximum", "ewcomp", n_arg:2
|
308
310
|
def_module_function "minimum", "ewcomp", n_arg:2
|
@@ -366,6 +368,7 @@ cn = get(:class_name)
|
|
366
368
|
nm = get(:name)
|
367
369
|
st = get(:simd_type)
|
368
370
|
dp = get(:is_double_precision)
|
371
|
+
algn = get(:need_align)
|
369
372
|
is_c = is_complex
|
370
373
|
|
371
374
|
def_module do
|
@@ -377,8 +380,9 @@ def_module do
|
|
377
380
|
set module_name: "Math"
|
378
381
|
set module_var: "mTM"
|
379
382
|
set simd_type: st
|
380
|
-
set is_double_precision: dp
|
383
|
+
set is_double_precision: dp
|
381
384
|
set is_complex: is_c
|
385
|
+
set need_align: algn
|
382
386
|
|
383
387
|
math "sqrt"
|
384
388
|
math "cbrt"
|
@@ -22,8 +22,8 @@ static void
|
|
22
22
|
<% else %>
|
23
23
|
@overload <%=name%>(axis:nil, keepdims:false)
|
24
24
|
<% end %>
|
25
|
-
@param [Numeric,Array,Range] axis
|
26
|
-
@param [TrueClass] keepdims
|
25
|
+
@param [Numeric,Array,Range] axis Performs <%=name%> along the axis.
|
26
|
+
@param [TrueClass] keepdims If true, the reduced axes are left in the result array as dimensions with size one.
|
27
27
|
@return [Numo::<%=class_name%>] returns result of <%=name%>.
|
28
28
|
*/
|
29
29
|
static VALUE
|
@@ -0,0 +1,88 @@
|
|
1
|
+
<% (is_float ? ["","_nan"] : [""]).each do |j|
|
2
|
+
[64,32].each do |i| %>
|
3
|
+
#define idx_t int<%=i%>_t
|
4
|
+
static void
|
5
|
+
<%=c_iter%>_arg<%=i%><%=j%>(na_loop_t *const lp)
|
6
|
+
{
|
7
|
+
size_t n, idx;
|
8
|
+
char *d_ptr, *o_ptr;
|
9
|
+
ssize_t d_step;
|
10
|
+
|
11
|
+
INIT_COUNTER(lp, n);
|
12
|
+
INIT_PTR(lp, 0, d_ptr, d_step);
|
13
|
+
|
14
|
+
idx = f_<%=name[3..5]%>_index<%=j%>(n,d_ptr,d_step);
|
15
|
+
|
16
|
+
o_ptr = NDL_PTR(lp,1);
|
17
|
+
*(idx_t*)o_ptr = (idx_t)idx;
|
18
|
+
}
|
19
|
+
#undef idx_t
|
20
|
+
<% end;end %>
|
21
|
+
|
22
|
+
/*
|
23
|
+
Index of the <%=name[3..5]%>imum value.
|
24
|
+
<% if is_float %>
|
25
|
+
@overload <%=name%>(axis:nil, nan:false)
|
26
|
+
@param [TrueClass] nan If true, apply NaN-aware algorithm (return NaN posision if exist).
|
27
|
+
<% else %>
|
28
|
+
@overload <%=name%>(axis:nil)
|
29
|
+
<% end %>
|
30
|
+
@param [Numeric,Array,Range] axis Finds <%=name[3..5]%>imum values along the axis and returns **indices along the axis**.
|
31
|
+
@return [Integer,Numo::Int] returns the result indices.
|
32
|
+
@see #<%=name[3..5]%>_index
|
33
|
+
@see #<%=name[3..5]%>
|
34
|
+
|
35
|
+
@example
|
36
|
+
<% case name; when /min/ %>
|
37
|
+
a = Numo::NArray[3,4,1,2]
|
38
|
+
a.argmin #=> 2
|
39
|
+
|
40
|
+
b = Numo::NArray[[3,4,1],[2,0,5]]
|
41
|
+
b.argmin #=> 4
|
42
|
+
b.argmin(axis:1) #=> [2, 1]
|
43
|
+
b.argmin(axis:0) #=> [1, 1, 0]
|
44
|
+
b.at(b.argmin(axis:0), 0..-1) #=> [2, 0, 1]
|
45
|
+
<% when /max/ %>
|
46
|
+
a = Numo::NArray[3,4,1,2]
|
47
|
+
a.argmax #=> 1
|
48
|
+
|
49
|
+
b = Numo::NArray[[3,4,1],[2,0,5]]
|
50
|
+
b.argmax #=> 5
|
51
|
+
b.argmax(axis:1) #=> [1, 2]
|
52
|
+
b.argmax(axis:0) #=> [0, 0, 1]
|
53
|
+
b.at(b.argmax(axis:0), 0..-1) #=> [3, 4, 5]
|
54
|
+
<% end %>
|
55
|
+
*/
|
56
|
+
static VALUE
|
57
|
+
<%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
|
58
|
+
{
|
59
|
+
narray_t *na;
|
60
|
+
VALUE reduce;
|
61
|
+
ndfunc_arg_in_t ain[2] = {{Qnil,0},{sym_reduce,0}};
|
62
|
+
ndfunc_arg_out_t aout[1] = {{0,0,0}};
|
63
|
+
ndfunc_t ndf = {0, STRIDE_LOOP_NIP|NDF_FLAT_REDUCE|NDF_EXTRACT, 2,1, ain,aout};
|
64
|
+
|
65
|
+
GetNArray(self,na);
|
66
|
+
if (na->ndim==0) {
|
67
|
+
return INT2FIX(0);
|
68
|
+
}
|
69
|
+
if (na->size > (~(u_int32_t)0)) {
|
70
|
+
aout[0].type = numo_cInt64;
|
71
|
+
ndf.func = <%=c_iter%>_arg64;
|
72
|
+
<% if is_float %>
|
73
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, <%=c_iter%>_arg64_nan);
|
74
|
+
<% else %>
|
75
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
76
|
+
<% end %>
|
77
|
+
} else {
|
78
|
+
aout[0].type = numo_cInt32;
|
79
|
+
ndf.func = <%=c_iter%>_arg32;
|
80
|
+
<% if is_float %>
|
81
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, <%=c_iter%>_arg32_nan);
|
82
|
+
<% else %>
|
83
|
+
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, 0);
|
84
|
+
<% end %>
|
85
|
+
}
|
86
|
+
|
87
|
+
return na_ndloop(&ndf, 2, self, reduce);
|
88
|
+
}
|
@@ -70,7 +70,7 @@ static VALUE
|
|
70
70
|
@overload <%=op_map%>(other, axis:nil, keepdims:false)
|
71
71
|
<% end %>
|
72
72
|
@param [Numo::NArray,Numeric] other
|
73
|
-
@param [Numeric,Array,Range] axis
|
73
|
+
@param [Numeric,Array,Range] axis Performs <%=name%> along the axis.
|
74
74
|
@param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array as dimensions with size one.
|
75
75
|
<% if is_float %>
|
76
76
|
@param [TrueClass] nan (keyword) If true, apply NaN-aware algorithm (avoid NaN if exists).
|
@@ -21,27 +21,38 @@ static void
|
|
21
21
|
<% end;end %>
|
22
22
|
|
23
23
|
/*
|
24
|
-
|
24
|
+
Index of the <%=name[0..2]%>imum value.
|
25
25
|
<% if is_float %>
|
26
26
|
@overload <%=name%>(axis:nil, nan:false)
|
27
27
|
@param [TrueClass] nan If true, apply NaN-aware algorithm (return NaN posision if exist).
|
28
28
|
<% else %>
|
29
29
|
@overload <%=name%>(axis:nil)
|
30
30
|
<% end %>
|
31
|
-
@param [Numeric,Array,Range] axis
|
32
|
-
@return [Integer,Numo::Int] returns result
|
31
|
+
@param [Numeric,Array,Range] axis Finds <%=name[0..2]%>imum values along the axis and returns **flat 1-d indices**.
|
32
|
+
@return [Integer,Numo::Int] returns result indices.
|
33
|
+
@see #arg<%=name[0..2]%>
|
34
|
+
@see #<%=name[0..2]%>
|
35
|
+
|
33
36
|
@example
|
34
|
-
|
35
|
-
Numo::NArray[3,4,1,2]
|
36
|
-
|
37
|
-
|
38
|
-
Numo::NArray[[3,4,1],[2,0,5]]
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
37
|
+
<% case name; when /min/ %>
|
38
|
+
a = Numo::NArray[3,4,1,2]
|
39
|
+
a.min_index #=> 2
|
40
|
+
|
41
|
+
b = Numo::NArray[[3,4,1],[2,0,5]]
|
42
|
+
b.min_index #=> 4
|
43
|
+
b.min_index(axis:1) #=> [2, 4]
|
44
|
+
b.min_index(axis:0) #=> [3, 4, 2]
|
45
|
+
b[b.min_index(axis:0)] #=> [2, 0, 1]
|
46
|
+
<% when /max/ %>
|
47
|
+
a = Numo::NArray[3,4,1,2]
|
48
|
+
a.max_index #=> 1
|
49
|
+
|
50
|
+
b = Numo::NArray[[3,4,1],[2,0,5]]
|
51
|
+
b.max_index #=> 5
|
52
|
+
b.max_index(axis:1) #=> [1, 5]
|
53
|
+
b.max_index(axis:0) #=> [0, 1, 5]
|
54
|
+
b[b.max_index(axis:0)] #=> [3, 4, 5]
|
55
|
+
<% end %>
|
45
56
|
*/
|
46
57
|
static VALUE
|
47
58
|
<%=c_func(-1)%>(int argc, VALUE *argv, VALUE self)
|