numo-narray-alt 0.9.9 → 0.9.11
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.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/ext/numo/narray/numo/narray.h +2 -2
- data/ext/numo/narray/numo/types/robject.h +1 -1
- data/ext/numo/narray/src/mh/argmax.h +154 -0
- data/ext/numo/narray/src/mh/argmin.h +154 -0
- data/ext/numo/narray/src/mh/clip.h +115 -0
- data/ext/numo/narray/src/mh/cumprod.h +98 -0
- data/ext/numo/narray/src/mh/cumsum.h +98 -0
- data/ext/numo/narray/src/mh/eye.h +82 -0
- data/ext/numo/narray/src/mh/logseq.h +69 -0
- data/ext/numo/narray/src/mh/max.h +69 -0
- data/ext/numo/narray/src/mh/max_index.h +184 -0
- data/ext/numo/narray/src/mh/maximum.h +116 -0
- data/ext/numo/narray/src/mh/min.h +69 -0
- data/ext/numo/narray/src/mh/min_index.h +184 -0
- data/ext/numo/narray/src/mh/minimum.h +116 -0
- data/ext/numo/narray/src/mh/minmax.h +77 -0
- data/ext/numo/narray/src/mh/mulsum.h +185 -0
- data/ext/numo/narray/src/mh/prod.h +69 -0
- data/ext/numo/narray/src/mh/ptp.h +69 -0
- data/ext/numo/narray/src/mh/rand.h +315 -0
- data/ext/numo/narray/src/mh/seq.h +130 -0
- data/ext/numo/narray/src/mh/sum.h +69 -0
- data/ext/numo/narray/src/t_dcomplex.c +131 -667
- data/ext/numo/narray/src/t_dfloat.c +40 -1288
- data/ext/numo/narray/src/t_int16.c +262 -1161
- data/ext/numo/narray/src/t_int32.c +263 -1161
- data/ext/numo/narray/src/t_int64.c +262 -1163
- data/ext/numo/narray/src/t_int8.c +262 -1159
- data/ext/numo/narray/src/t_robject.c +427 -1675
- data/ext/numo/narray/src/t_scomplex.c +131 -667
- data/ext/numo/narray/src/t_sfloat.c +40 -1288
- data/ext/numo/narray/src/t_uint16.c +262 -1161
- data/ext/numo/narray/src/t_uint32.c +262 -1161
- data/ext/numo/narray/src/t_uint64.c +262 -1163
- data/ext/numo/narray/src/t_uint8.c +262 -1161
- data/lib/numo/narray.rb +3 -1
- metadata +23 -3
|
@@ -60,17 +60,57 @@ static ID id_truncate;
|
|
|
60
60
|
VALUE cT;
|
|
61
61
|
extern VALUE cRT;
|
|
62
62
|
|
|
63
|
+
#include "mh/clip.h"
|
|
64
|
+
#include "mh/sum.h"
|
|
65
|
+
#include "mh/prod.h"
|
|
63
66
|
#include "mh/mean.h"
|
|
64
67
|
#include "mh/var.h"
|
|
65
68
|
#include "mh/stddev.h"
|
|
66
69
|
#include "mh/rms.h"
|
|
70
|
+
#include "mh/min.h"
|
|
71
|
+
#include "mh/max.h"
|
|
72
|
+
#include "mh/ptp.h"
|
|
73
|
+
#include "mh/max_index.h"
|
|
74
|
+
#include "mh/min_index.h"
|
|
75
|
+
#include "mh/argmax.h"
|
|
76
|
+
#include "mh/argmin.h"
|
|
77
|
+
#include "mh/maximum.h"
|
|
78
|
+
#include "mh/minimum.h"
|
|
79
|
+
#include "mh/minmax.h"
|
|
80
|
+
#include "mh/cumsum.h"
|
|
81
|
+
#include "mh/cumprod.h"
|
|
82
|
+
#include "mh/mulsum.h"
|
|
83
|
+
#include "mh/seq.h"
|
|
84
|
+
#include "mh/logseq.h"
|
|
85
|
+
#include "mh/eye.h"
|
|
86
|
+
#include "mh/rand.h"
|
|
67
87
|
|
|
68
88
|
typedef VALUE robject; // Type aliases for shorter notation
|
|
69
89
|
// following the codebase naming convention.
|
|
90
|
+
DEF_NARRAY_CLIP_METHOD_FUNC(robject, numo_cRObject)
|
|
91
|
+
DEF_NARRAY_FLT_SUM_METHOD_FUNC(robject, numo_cRObject)
|
|
92
|
+
DEF_NARRAY_FLT_PROD_METHOD_FUNC(robject, numo_cRObject)
|
|
70
93
|
DEF_NARRAY_FLT_MEAN_METHOD_FUNC(robject, numo_cRObject, VALUE, numo_cRObject)
|
|
71
94
|
DEF_NARRAY_FLT_VAR_METHOD_FUNC(robject, numo_cRObject, VALUE, numo_cRObject)
|
|
72
95
|
DEF_NARRAY_FLT_STDDEV_METHOD_FUNC(robject, numo_cRObject, VALUE, numo_cRObject)
|
|
73
96
|
DEF_NARRAY_FLT_RMS_METHOD_FUNC(robject, numo_cRObject, VALUE, numo_cRObject)
|
|
97
|
+
DEF_NARRAY_FLT_MIN_METHOD_FUNC(robject, numo_cRObject)
|
|
98
|
+
DEF_NARRAY_FLT_MAX_METHOD_FUNC(robject, numo_cRObject)
|
|
99
|
+
DEF_NARRAY_FLT_PTP_METHOD_FUNC(robject, numo_cRObject)
|
|
100
|
+
DEF_NARRAY_FLT_MAX_INDEX_METHOD_FUNC(robject)
|
|
101
|
+
DEF_NARRAY_FLT_MIN_INDEX_METHOD_FUNC(robject)
|
|
102
|
+
DEF_NARRAY_FLT_ARGMAX_METHOD_FUNC(robject)
|
|
103
|
+
DEF_NARRAY_FLT_ARGMIN_METHOD_FUNC(robject)
|
|
104
|
+
DEF_NARRAY_FLT_MAXIMUM_METHOD_FUNC(robject, numo_cRObject)
|
|
105
|
+
DEF_NARRAY_FLT_MINIMUM_METHOD_FUNC(robject, numo_cRObject)
|
|
106
|
+
DEF_NARRAY_FLT_MINMAX_METHOD_FUNC(robject, numo_cRObject)
|
|
107
|
+
DEF_NARRAY_FLT_CUMSUM_METHOD_FUNC(robject, numo_cRObject)
|
|
108
|
+
DEF_NARRAY_FLT_CUMPROD_METHOD_FUNC(robject, numo_cRObject)
|
|
109
|
+
DEF_NARRAY_FLT_MULSUM_METHOD_FUNC(robject, numo_cRObject)
|
|
110
|
+
DEF_NARRAY_FLT_SEQ_METHOD_FUNC(robject)
|
|
111
|
+
DEF_NARRAY_FLT_LOGSEQ_METHOD_FUNC(robject)
|
|
112
|
+
DEF_NARRAY_EYE_METHOD_FUNC(robject)
|
|
113
|
+
DEF_NARRAY_FLT_RAND_METHOD_FUNC(robject)
|
|
74
114
|
|
|
75
115
|
static VALUE robject_store(VALUE, VALUE);
|
|
76
116
|
|
|
@@ -3425,123 +3465,6 @@ static VALUE robject_le(VALUE self, VALUE other) {
|
|
|
3425
3465
|
return robject_le_self(self, other);
|
|
3426
3466
|
}
|
|
3427
3467
|
|
|
3428
|
-
static void iter_robject_clip(na_loop_t* const lp) {
|
|
3429
|
-
size_t i;
|
|
3430
|
-
char *p1, *p2, *p3, *p4;
|
|
3431
|
-
ssize_t s1, s2, s3, s4;
|
|
3432
|
-
dtype x, min, max;
|
|
3433
|
-
INIT_COUNTER(lp, i);
|
|
3434
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3435
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3436
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3437
|
-
INIT_PTR(lp, 3, p4, s4);
|
|
3438
|
-
for (; i--;) {
|
|
3439
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3440
|
-
GET_DATA_STRIDE(p2, s2, dtype, min);
|
|
3441
|
-
GET_DATA_STRIDE(p3, s3, dtype, max);
|
|
3442
|
-
if (m_gt(min, max)) {
|
|
3443
|
-
rb_raise(nary_eOperationError, "min is greater than max");
|
|
3444
|
-
}
|
|
3445
|
-
if (m_lt(x, min)) {
|
|
3446
|
-
x = min;
|
|
3447
|
-
}
|
|
3448
|
-
if (m_gt(x, max)) {
|
|
3449
|
-
x = max;
|
|
3450
|
-
}
|
|
3451
|
-
SET_DATA_STRIDE(p4, s4, dtype, x);
|
|
3452
|
-
}
|
|
3453
|
-
}
|
|
3454
|
-
|
|
3455
|
-
static void iter_robject_clip_min(na_loop_t* const lp) {
|
|
3456
|
-
size_t i;
|
|
3457
|
-
char *p1, *p2, *p3;
|
|
3458
|
-
ssize_t s1, s2, s3;
|
|
3459
|
-
dtype x, min;
|
|
3460
|
-
INIT_COUNTER(lp, i);
|
|
3461
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3462
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3463
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3464
|
-
for (; i--;) {
|
|
3465
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3466
|
-
GET_DATA_STRIDE(p2, s2, dtype, min);
|
|
3467
|
-
if (m_lt(x, min)) {
|
|
3468
|
-
x = min;
|
|
3469
|
-
}
|
|
3470
|
-
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
3471
|
-
}
|
|
3472
|
-
}
|
|
3473
|
-
|
|
3474
|
-
static void iter_robject_clip_max(na_loop_t* const lp) {
|
|
3475
|
-
size_t i;
|
|
3476
|
-
char *p1, *p2, *p3;
|
|
3477
|
-
ssize_t s1, s2, s3;
|
|
3478
|
-
dtype x, max;
|
|
3479
|
-
INIT_COUNTER(lp, i);
|
|
3480
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3481
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
3482
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
3483
|
-
for (; i--;) {
|
|
3484
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3485
|
-
GET_DATA_STRIDE(p2, s2, dtype, max);
|
|
3486
|
-
if (m_gt(x, max)) {
|
|
3487
|
-
x = max;
|
|
3488
|
-
}
|
|
3489
|
-
SET_DATA_STRIDE(p3, s3, dtype, x);
|
|
3490
|
-
}
|
|
3491
|
-
}
|
|
3492
|
-
|
|
3493
|
-
/*
|
|
3494
|
-
Clip array elements by [min,max].
|
|
3495
|
-
If either of min or max is nil, one side is clipped.
|
|
3496
|
-
@overload clip(min,max)
|
|
3497
|
-
@param [Numo::NArray,Numeric] min
|
|
3498
|
-
@param [Numo::NArray,Numeric] max
|
|
3499
|
-
@return [Numo::NArray] result of clip.
|
|
3500
|
-
|
|
3501
|
-
@example
|
|
3502
|
-
a = Numo::Int32.new(10).seq
|
|
3503
|
-
# => Numo::Int32#shape=[10]
|
|
3504
|
-
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
3505
|
-
|
|
3506
|
-
a.clip(1,8)
|
|
3507
|
-
# => Numo::Int32#shape=[10]
|
|
3508
|
-
# [1, 1, 2, 3, 4, 5, 6, 7, 8, 8]
|
|
3509
|
-
|
|
3510
|
-
a.inplace.clip(3,6)
|
|
3511
|
-
a
|
|
3512
|
-
# => Numo::Int32#shape=[10]
|
|
3513
|
-
# [3, 3, 3, 3, 4, 5, 6, 6, 6, 6]
|
|
3514
|
-
|
|
3515
|
-
b = Numo::Int32.new(10).seq
|
|
3516
|
-
# => Numo::Int32#shape=[10]
|
|
3517
|
-
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
3518
|
-
|
|
3519
|
-
b.clip([3,4,1,1,1,4,4,4,4,4], 8)
|
|
3520
|
-
# => Numo::Int32#shape=[10]
|
|
3521
|
-
# [3, 4, 2, 3, 4, 5, 6, 7, 8, 8]
|
|
3522
|
-
*/
|
|
3523
|
-
static VALUE robject_clip(VALUE self, VALUE min, VALUE max) {
|
|
3524
|
-
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { cT, 0 }, { cT, 0 } };
|
|
3525
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3526
|
-
ndfunc_t ndf_min = { iter_robject_clip_min, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3527
|
-
ndfunc_t ndf_max = { iter_robject_clip_max, STRIDE_LOOP, 2, 1, ain, aout };
|
|
3528
|
-
ndfunc_t ndf_both = { iter_robject_clip, STRIDE_LOOP, 3, 1, ain, aout };
|
|
3529
|
-
|
|
3530
|
-
if (RTEST(min)) {
|
|
3531
|
-
if (RTEST(max)) {
|
|
3532
|
-
return na_ndloop(&ndf_both, 3, self, min, max);
|
|
3533
|
-
} else {
|
|
3534
|
-
return na_ndloop(&ndf_min, 2, self, min);
|
|
3535
|
-
}
|
|
3536
|
-
} else {
|
|
3537
|
-
if (RTEST(max)) {
|
|
3538
|
-
return na_ndloop(&ndf_max, 2, self, max);
|
|
3539
|
-
}
|
|
3540
|
-
}
|
|
3541
|
-
rb_raise(rb_eArgError, "min and max are not given");
|
|
3542
|
-
return Qnil;
|
|
3543
|
-
}
|
|
3544
|
-
|
|
3545
3468
|
static void iter_robject_isnan(na_loop_t* const lp) {
|
|
3546
3469
|
size_t i;
|
|
3547
3470
|
char* p1;
|
|
@@ -3551,1641 +3474,205 @@ static void iter_robject_isnan(na_loop_t* const lp) {
|
|
|
3551
3474
|
size_t* idx1;
|
|
3552
3475
|
dtype x;
|
|
3553
3476
|
BIT_DIGIT b;
|
|
3554
|
-
INIT_COUNTER(lp, i);
|
|
3555
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3556
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3557
|
-
if (idx1) {
|
|
3558
|
-
for (; i--;) {
|
|
3559
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3560
|
-
b = (m_isnan(x)) ? 1 : 0;
|
|
3561
|
-
STORE_BIT(a2, p2, b);
|
|
3562
|
-
p2 += s2;
|
|
3563
|
-
}
|
|
3564
|
-
} else {
|
|
3565
|
-
for (; i--;) {
|
|
3566
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3567
|
-
b = (m_isnan(x)) ? 1 : 0;
|
|
3568
|
-
STORE_BIT(a2, p2, b);
|
|
3569
|
-
p2 += s2;
|
|
3570
|
-
}
|
|
3571
|
-
}
|
|
3572
|
-
}
|
|
3573
|
-
|
|
3574
|
-
/*
|
|
3575
|
-
Condition of isnan.
|
|
3576
|
-
@overload isnan
|
|
3577
|
-
@return [Numo::Bit] Condition of isnan.
|
|
3578
|
-
*/
|
|
3579
|
-
static VALUE robject_isnan(VALUE self) {
|
|
3580
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3581
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3582
|
-
ndfunc_t ndf = { iter_robject_isnan, FULL_LOOP, 1, 1, ain, aout };
|
|
3583
|
-
|
|
3584
|
-
return na_ndloop(&ndf, 1, self);
|
|
3585
|
-
}
|
|
3586
|
-
|
|
3587
|
-
static void iter_robject_isinf(na_loop_t* const lp) {
|
|
3588
|
-
size_t i;
|
|
3589
|
-
char* p1;
|
|
3590
|
-
BIT_DIGIT* a2;
|
|
3591
|
-
size_t p2;
|
|
3592
|
-
ssize_t s1, s2;
|
|
3593
|
-
size_t* idx1;
|
|
3594
|
-
dtype x;
|
|
3595
|
-
BIT_DIGIT b;
|
|
3596
|
-
INIT_COUNTER(lp, i);
|
|
3597
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3598
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3599
|
-
if (idx1) {
|
|
3600
|
-
for (; i--;) {
|
|
3601
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3602
|
-
b = (m_isinf(x)) ? 1 : 0;
|
|
3603
|
-
STORE_BIT(a2, p2, b);
|
|
3604
|
-
p2 += s2;
|
|
3605
|
-
}
|
|
3606
|
-
} else {
|
|
3607
|
-
for (; i--;) {
|
|
3608
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3609
|
-
b = (m_isinf(x)) ? 1 : 0;
|
|
3610
|
-
STORE_BIT(a2, p2, b);
|
|
3611
|
-
p2 += s2;
|
|
3612
|
-
}
|
|
3613
|
-
}
|
|
3614
|
-
}
|
|
3615
|
-
|
|
3616
|
-
/*
|
|
3617
|
-
Condition of isinf.
|
|
3618
|
-
@overload isinf
|
|
3619
|
-
@return [Numo::Bit] Condition of isinf.
|
|
3620
|
-
*/
|
|
3621
|
-
static VALUE robject_isinf(VALUE self) {
|
|
3622
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3623
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3624
|
-
ndfunc_t ndf = { iter_robject_isinf, FULL_LOOP, 1, 1, ain, aout };
|
|
3625
|
-
|
|
3626
|
-
return na_ndloop(&ndf, 1, self);
|
|
3627
|
-
}
|
|
3628
|
-
|
|
3629
|
-
static void iter_robject_isposinf(na_loop_t* const lp) {
|
|
3630
|
-
size_t i;
|
|
3631
|
-
char* p1;
|
|
3632
|
-
BIT_DIGIT* a2;
|
|
3633
|
-
size_t p2;
|
|
3634
|
-
ssize_t s1, s2;
|
|
3635
|
-
size_t* idx1;
|
|
3636
|
-
dtype x;
|
|
3637
|
-
BIT_DIGIT b;
|
|
3638
|
-
INIT_COUNTER(lp, i);
|
|
3639
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3640
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3641
|
-
if (idx1) {
|
|
3642
|
-
for (; i--;) {
|
|
3643
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3644
|
-
b = (m_isposinf(x)) ? 1 : 0;
|
|
3645
|
-
STORE_BIT(a2, p2, b);
|
|
3646
|
-
p2 += s2;
|
|
3647
|
-
}
|
|
3648
|
-
} else {
|
|
3649
|
-
for (; i--;) {
|
|
3650
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3651
|
-
b = (m_isposinf(x)) ? 1 : 0;
|
|
3652
|
-
STORE_BIT(a2, p2, b);
|
|
3653
|
-
p2 += s2;
|
|
3654
|
-
}
|
|
3655
|
-
}
|
|
3656
|
-
}
|
|
3657
|
-
|
|
3658
|
-
/*
|
|
3659
|
-
Condition of isposinf.
|
|
3660
|
-
@overload isposinf
|
|
3661
|
-
@return [Numo::Bit] Condition of isposinf.
|
|
3662
|
-
*/
|
|
3663
|
-
static VALUE robject_isposinf(VALUE self) {
|
|
3664
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3665
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3666
|
-
ndfunc_t ndf = { iter_robject_isposinf, FULL_LOOP, 1, 1, ain, aout };
|
|
3667
|
-
|
|
3668
|
-
return na_ndloop(&ndf, 1, self);
|
|
3669
|
-
}
|
|
3670
|
-
|
|
3671
|
-
static void iter_robject_isneginf(na_loop_t* const lp) {
|
|
3672
|
-
size_t i;
|
|
3673
|
-
char* p1;
|
|
3674
|
-
BIT_DIGIT* a2;
|
|
3675
|
-
size_t p2;
|
|
3676
|
-
ssize_t s1, s2;
|
|
3677
|
-
size_t* idx1;
|
|
3678
|
-
dtype x;
|
|
3679
|
-
BIT_DIGIT b;
|
|
3680
|
-
INIT_COUNTER(lp, i);
|
|
3681
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3682
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3683
|
-
if (idx1) {
|
|
3684
|
-
for (; i--;) {
|
|
3685
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3686
|
-
b = (m_isneginf(x)) ? 1 : 0;
|
|
3687
|
-
STORE_BIT(a2, p2, b);
|
|
3688
|
-
p2 += s2;
|
|
3689
|
-
}
|
|
3690
|
-
} else {
|
|
3691
|
-
for (; i--;) {
|
|
3692
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3693
|
-
b = (m_isneginf(x)) ? 1 : 0;
|
|
3694
|
-
STORE_BIT(a2, p2, b);
|
|
3695
|
-
p2 += s2;
|
|
3696
|
-
}
|
|
3697
|
-
}
|
|
3698
|
-
}
|
|
3699
|
-
|
|
3700
|
-
/*
|
|
3701
|
-
Condition of isneginf.
|
|
3702
|
-
@overload isneginf
|
|
3703
|
-
@return [Numo::Bit] Condition of isneginf.
|
|
3704
|
-
*/
|
|
3705
|
-
static VALUE robject_isneginf(VALUE self) {
|
|
3706
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3707
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3708
|
-
ndfunc_t ndf = { iter_robject_isneginf, FULL_LOOP, 1, 1, ain, aout };
|
|
3709
|
-
|
|
3710
|
-
return na_ndloop(&ndf, 1, self);
|
|
3711
|
-
}
|
|
3712
|
-
|
|
3713
|
-
static void iter_robject_isfinite(na_loop_t* const lp) {
|
|
3714
|
-
size_t i;
|
|
3715
|
-
char* p1;
|
|
3716
|
-
BIT_DIGIT* a2;
|
|
3717
|
-
size_t p2;
|
|
3718
|
-
ssize_t s1, s2;
|
|
3719
|
-
size_t* idx1;
|
|
3720
|
-
dtype x;
|
|
3721
|
-
BIT_DIGIT b;
|
|
3722
|
-
INIT_COUNTER(lp, i);
|
|
3723
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3724
|
-
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3725
|
-
if (idx1) {
|
|
3726
|
-
for (; i--;) {
|
|
3727
|
-
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3728
|
-
b = (m_isfinite(x)) ? 1 : 0;
|
|
3729
|
-
STORE_BIT(a2, p2, b);
|
|
3730
|
-
p2 += s2;
|
|
3731
|
-
}
|
|
3732
|
-
} else {
|
|
3733
|
-
for (; i--;) {
|
|
3734
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3735
|
-
b = (m_isfinite(x)) ? 1 : 0;
|
|
3736
|
-
STORE_BIT(a2, p2, b);
|
|
3737
|
-
p2 += s2;
|
|
3738
|
-
}
|
|
3739
|
-
}
|
|
3740
|
-
}
|
|
3741
|
-
|
|
3742
|
-
/*
|
|
3743
|
-
Condition of isfinite.
|
|
3744
|
-
@overload isfinite
|
|
3745
|
-
@return [Numo::Bit] Condition of isfinite.
|
|
3746
|
-
*/
|
|
3747
|
-
static VALUE robject_isfinite(VALUE self) {
|
|
3748
|
-
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3749
|
-
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3750
|
-
ndfunc_t ndf = { iter_robject_isfinite, FULL_LOOP, 1, 1, ain, aout };
|
|
3751
|
-
|
|
3752
|
-
return na_ndloop(&ndf, 1, self);
|
|
3753
|
-
}
|
|
3754
|
-
|
|
3755
|
-
static void iter_robject_sum(na_loop_t* const lp) {
|
|
3756
|
-
size_t n;
|
|
3757
|
-
char *p1, *p2;
|
|
3758
|
-
ssize_t s1;
|
|
3759
|
-
|
|
3760
|
-
INIT_COUNTER(lp, n);
|
|
3761
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3762
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
3763
|
-
|
|
3764
|
-
*(dtype*)p2 = f_sum(n, p1, s1);
|
|
3765
|
-
}
|
|
3766
|
-
static void iter_robject_sum_nan(na_loop_t* const lp) {
|
|
3767
|
-
size_t n;
|
|
3768
|
-
char *p1, *p2;
|
|
3769
|
-
ssize_t s1;
|
|
3770
|
-
|
|
3771
|
-
INIT_COUNTER(lp, n);
|
|
3772
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3773
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
3774
|
-
|
|
3775
|
-
*(dtype*)p2 = f_sum_nan(n, p1, s1);
|
|
3776
|
-
}
|
|
3777
|
-
|
|
3778
|
-
/*
|
|
3779
|
-
sum of self.
|
|
3780
|
-
@overload sum(axis:nil, keepdims:false, nan:false)
|
|
3781
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or,
|
|
3782
|
-
return NaN for min/max etc).
|
|
3783
|
-
@param [Numeric,Array,Range] axis Performs sum along the axis.
|
|
3784
|
-
@param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
3785
|
-
dimensions with size one.
|
|
3786
|
-
@return [Numo::RObject] returns result of sum.
|
|
3787
|
-
*/
|
|
3788
|
-
static VALUE robject_sum(int argc, VALUE* argv, VALUE self) {
|
|
3789
|
-
VALUE v, reduce;
|
|
3790
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
3791
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3792
|
-
ndfunc_t ndf = { iter_robject_sum, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
|
3793
|
-
|
|
3794
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_sum_nan);
|
|
3795
|
-
|
|
3796
|
-
v = na_ndloop(&ndf, 2, self, reduce);
|
|
3797
|
-
|
|
3798
|
-
return robject_extract(v);
|
|
3799
|
-
}
|
|
3800
|
-
|
|
3801
|
-
static void iter_robject_prod(na_loop_t* const lp) {
|
|
3802
|
-
size_t n;
|
|
3803
|
-
char *p1, *p2;
|
|
3804
|
-
ssize_t s1;
|
|
3805
|
-
|
|
3806
|
-
INIT_COUNTER(lp, n);
|
|
3807
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3808
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
3809
|
-
|
|
3810
|
-
*(dtype*)p2 = f_prod(n, p1, s1);
|
|
3811
|
-
}
|
|
3812
|
-
static void iter_robject_prod_nan(na_loop_t* const lp) {
|
|
3813
|
-
size_t n;
|
|
3814
|
-
char *p1, *p2;
|
|
3815
|
-
ssize_t s1;
|
|
3816
|
-
|
|
3817
|
-
INIT_COUNTER(lp, n);
|
|
3818
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3819
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
3820
|
-
|
|
3821
|
-
*(dtype*)p2 = f_prod_nan(n, p1, s1);
|
|
3822
|
-
}
|
|
3823
|
-
|
|
3824
|
-
/*
|
|
3825
|
-
prod of self.
|
|
3826
|
-
@overload prod(axis:nil, keepdims:false, nan:false)
|
|
3827
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or,
|
|
3828
|
-
return NaN for min/max etc).
|
|
3829
|
-
@param [Numeric,Array,Range] axis Performs prod along the axis.
|
|
3830
|
-
@param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
3831
|
-
dimensions with size one.
|
|
3832
|
-
@return [Numo::RObject] returns result of prod.
|
|
3833
|
-
*/
|
|
3834
|
-
static VALUE robject_prod(int argc, VALUE* argv, VALUE self) {
|
|
3835
|
-
VALUE v, reduce;
|
|
3836
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
3837
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3838
|
-
ndfunc_t ndf = { iter_robject_prod, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
|
3839
|
-
|
|
3840
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_prod_nan);
|
|
3841
|
-
|
|
3842
|
-
v = na_ndloop(&ndf, 2, self, reduce);
|
|
3843
|
-
|
|
3844
|
-
return robject_extract(v);
|
|
3845
|
-
}
|
|
3846
|
-
|
|
3847
|
-
static void iter_robject_min(na_loop_t* const lp) {
|
|
3848
|
-
size_t n;
|
|
3849
|
-
char *p1, *p2;
|
|
3850
|
-
ssize_t s1;
|
|
3851
|
-
|
|
3852
|
-
INIT_COUNTER(lp, n);
|
|
3853
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3854
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
3855
|
-
|
|
3856
|
-
*(dtype*)p2 = f_min(n, p1, s1);
|
|
3857
|
-
}
|
|
3858
|
-
static void iter_robject_min_nan(na_loop_t* const lp) {
|
|
3859
|
-
size_t n;
|
|
3860
|
-
char *p1, *p2;
|
|
3861
|
-
ssize_t s1;
|
|
3862
|
-
|
|
3863
|
-
INIT_COUNTER(lp, n);
|
|
3864
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3865
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
3866
|
-
|
|
3867
|
-
*(dtype*)p2 = f_min_nan(n, p1, s1);
|
|
3868
|
-
}
|
|
3869
|
-
|
|
3870
|
-
/*
|
|
3871
|
-
min of self.
|
|
3872
|
-
@overload min(axis:nil, keepdims:false, nan:false)
|
|
3873
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or,
|
|
3874
|
-
return NaN for min/max etc).
|
|
3875
|
-
@param [Numeric,Array,Range] axis Performs min along the axis.
|
|
3876
|
-
@param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
3877
|
-
dimensions with size one.
|
|
3878
|
-
@return [Numo::RObject] returns result of min.
|
|
3879
|
-
*/
|
|
3880
|
-
static VALUE robject_min(int argc, VALUE* argv, VALUE self) {
|
|
3881
|
-
VALUE v, reduce;
|
|
3882
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
3883
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3884
|
-
ndfunc_t ndf = { iter_robject_min, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
|
3885
|
-
|
|
3886
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_min_nan);
|
|
3887
|
-
|
|
3888
|
-
v = na_ndloop(&ndf, 2, self, reduce);
|
|
3889
|
-
|
|
3890
|
-
return robject_extract(v);
|
|
3891
|
-
}
|
|
3892
|
-
|
|
3893
|
-
static void iter_robject_max(na_loop_t* const lp) {
|
|
3894
|
-
size_t n;
|
|
3895
|
-
char *p1, *p2;
|
|
3896
|
-
ssize_t s1;
|
|
3897
|
-
|
|
3898
|
-
INIT_COUNTER(lp, n);
|
|
3899
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3900
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
3901
|
-
|
|
3902
|
-
*(dtype*)p2 = f_max(n, p1, s1);
|
|
3903
|
-
}
|
|
3904
|
-
static void iter_robject_max_nan(na_loop_t* const lp) {
|
|
3905
|
-
size_t n;
|
|
3906
|
-
char *p1, *p2;
|
|
3907
|
-
ssize_t s1;
|
|
3908
|
-
|
|
3909
|
-
INIT_COUNTER(lp, n);
|
|
3910
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3911
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
3912
|
-
|
|
3913
|
-
*(dtype*)p2 = f_max_nan(n, p1, s1);
|
|
3914
|
-
}
|
|
3915
|
-
|
|
3916
|
-
/*
|
|
3917
|
-
max of self.
|
|
3918
|
-
@overload max(axis:nil, keepdims:false, nan:false)
|
|
3919
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or,
|
|
3920
|
-
return NaN for min/max etc).
|
|
3921
|
-
@param [Numeric,Array,Range] axis Performs max along the axis.
|
|
3922
|
-
@param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
3923
|
-
dimensions with size one.
|
|
3924
|
-
@return [Numo::RObject] returns result of max.
|
|
3925
|
-
*/
|
|
3926
|
-
static VALUE robject_max(int argc, VALUE* argv, VALUE self) {
|
|
3927
|
-
VALUE v, reduce;
|
|
3928
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
3929
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3930
|
-
ndfunc_t ndf = { iter_robject_max, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
|
3931
|
-
|
|
3932
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_max_nan);
|
|
3933
|
-
|
|
3934
|
-
v = na_ndloop(&ndf, 2, self, reduce);
|
|
3935
|
-
|
|
3936
|
-
return robject_extract(v);
|
|
3937
|
-
}
|
|
3938
|
-
|
|
3939
|
-
static void iter_robject_ptp(na_loop_t* const lp) {
|
|
3940
|
-
size_t n;
|
|
3941
|
-
char *p1, *p2;
|
|
3942
|
-
ssize_t s1;
|
|
3943
|
-
|
|
3944
|
-
INIT_COUNTER(lp, n);
|
|
3945
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3946
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
3947
|
-
|
|
3948
|
-
*(dtype*)p2 = f_ptp(n, p1, s1);
|
|
3949
|
-
}
|
|
3950
|
-
static void iter_robject_ptp_nan(na_loop_t* const lp) {
|
|
3951
|
-
size_t n;
|
|
3952
|
-
char *p1, *p2;
|
|
3953
|
-
ssize_t s1;
|
|
3954
|
-
|
|
3955
|
-
INIT_COUNTER(lp, n);
|
|
3956
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
3957
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
3958
|
-
|
|
3959
|
-
*(dtype*)p2 = f_ptp_nan(n, p1, s1);
|
|
3960
|
-
}
|
|
3961
|
-
|
|
3962
|
-
/*
|
|
3963
|
-
ptp of self.
|
|
3964
|
-
@overload ptp(axis:nil, keepdims:false, nan:false)
|
|
3965
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or,
|
|
3966
|
-
return NaN for min/max etc).
|
|
3967
|
-
@param [Numeric,Array,Range] axis Performs ptp along the axis.
|
|
3968
|
-
@param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
3969
|
-
dimensions with size one.
|
|
3970
|
-
@return [Numo::RObject] returns result of ptp.
|
|
3971
|
-
*/
|
|
3972
|
-
static VALUE robject_ptp(int argc, VALUE* argv, VALUE self) {
|
|
3973
|
-
VALUE v, reduce;
|
|
3974
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
3975
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
3976
|
-
ndfunc_t ndf = { iter_robject_ptp, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
|
3977
|
-
|
|
3978
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_ptp_nan);
|
|
3979
|
-
|
|
3980
|
-
v = na_ndloop(&ndf, 2, self, reduce);
|
|
3981
|
-
|
|
3982
|
-
return robject_extract(v);
|
|
3983
|
-
}
|
|
3984
|
-
|
|
3985
|
-
#define idx_t int64_t
|
|
3986
|
-
static void iter_robject_max_index_index64(na_loop_t* const lp) {
|
|
3987
|
-
size_t n, idx;
|
|
3988
|
-
char *d_ptr, *i_ptr, *o_ptr;
|
|
3989
|
-
ssize_t d_step, i_step;
|
|
3990
|
-
|
|
3991
|
-
INIT_COUNTER(lp, n);
|
|
3992
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
3993
|
-
|
|
3994
|
-
idx = f_max_index(n, d_ptr, d_step);
|
|
3995
|
-
|
|
3996
|
-
INIT_PTR(lp, 1, i_ptr, i_step);
|
|
3997
|
-
o_ptr = NDL_PTR(lp, 2);
|
|
3998
|
-
*(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
|
|
3999
|
-
}
|
|
4000
|
-
#undef idx_t
|
|
4001
|
-
|
|
4002
|
-
#define idx_t int32_t
|
|
4003
|
-
static void iter_robject_max_index_index32(na_loop_t* const lp) {
|
|
4004
|
-
size_t n, idx;
|
|
4005
|
-
char *d_ptr, *i_ptr, *o_ptr;
|
|
4006
|
-
ssize_t d_step, i_step;
|
|
4007
|
-
|
|
4008
|
-
INIT_COUNTER(lp, n);
|
|
4009
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
4010
|
-
|
|
4011
|
-
idx = f_max_index(n, d_ptr, d_step);
|
|
4012
|
-
|
|
4013
|
-
INIT_PTR(lp, 1, i_ptr, i_step);
|
|
4014
|
-
o_ptr = NDL_PTR(lp, 2);
|
|
4015
|
-
*(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
|
|
4016
|
-
}
|
|
4017
|
-
#undef idx_t
|
|
4018
|
-
|
|
4019
|
-
#define idx_t int64_t
|
|
4020
|
-
static void iter_robject_max_index_index64_nan(na_loop_t* const lp) {
|
|
4021
|
-
size_t n, idx;
|
|
4022
|
-
char *d_ptr, *i_ptr, *o_ptr;
|
|
4023
|
-
ssize_t d_step, i_step;
|
|
4024
|
-
|
|
4025
|
-
INIT_COUNTER(lp, n);
|
|
4026
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
4027
|
-
|
|
4028
|
-
idx = f_max_index_nan(n, d_ptr, d_step);
|
|
4029
|
-
|
|
4030
|
-
INIT_PTR(lp, 1, i_ptr, i_step);
|
|
4031
|
-
o_ptr = NDL_PTR(lp, 2);
|
|
4032
|
-
*(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
|
|
4033
|
-
}
|
|
4034
|
-
#undef idx_t
|
|
4035
|
-
|
|
4036
|
-
#define idx_t int32_t
|
|
4037
|
-
static void iter_robject_max_index_index32_nan(na_loop_t* const lp) {
|
|
4038
|
-
size_t n, idx;
|
|
4039
|
-
char *d_ptr, *i_ptr, *o_ptr;
|
|
4040
|
-
ssize_t d_step, i_step;
|
|
4041
|
-
|
|
4042
|
-
INIT_COUNTER(lp, n);
|
|
4043
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
4044
|
-
|
|
4045
|
-
idx = f_max_index_nan(n, d_ptr, d_step);
|
|
4046
|
-
|
|
4047
|
-
INIT_PTR(lp, 1, i_ptr, i_step);
|
|
4048
|
-
o_ptr = NDL_PTR(lp, 2);
|
|
4049
|
-
*(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
|
|
4050
|
-
}
|
|
4051
|
-
#undef idx_t
|
|
4052
|
-
|
|
4053
|
-
/*
|
|
4054
|
-
Index of the maximum value.
|
|
4055
|
-
@overload max_index(axis:nil, nan:false)
|
|
4056
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (return NaN posision if exist).
|
|
4057
|
-
@param [Numeric,Array,Range] axis Finds maximum values along the axis and returns **flat
|
|
4058
|
-
1-d indices**.
|
|
4059
|
-
@return [Integer,Numo::Int] returns result indices.
|
|
4060
|
-
@see #argmax
|
|
4061
|
-
@see #max
|
|
4062
|
-
|
|
4063
|
-
@example
|
|
4064
|
-
a = Numo::NArray[3,4,1,2]
|
|
4065
|
-
a.max_index #=> 1
|
|
4066
|
-
|
|
4067
|
-
b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
4068
|
-
b.max_index #=> 5
|
|
4069
|
-
b.max_index(axis:1) #=> [1, 5]
|
|
4070
|
-
b.max_index(axis:0) #=> [0, 1, 5]
|
|
4071
|
-
b[b.max_index(axis:0)] #=> [3, 4, 5]
|
|
4072
|
-
*/
|
|
4073
|
-
static VALUE robject_max_index(int argc, VALUE* argv, VALUE self) {
|
|
4074
|
-
narray_t* na;
|
|
4075
|
-
VALUE idx, reduce;
|
|
4076
|
-
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { Qnil, 0 }, { sym_reduce, 0 } };
|
|
4077
|
-
ndfunc_arg_out_t aout[1] = { { 0, 0, 0 } };
|
|
4078
|
-
ndfunc_t ndf = { 0, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 3, 1, ain, aout };
|
|
4079
|
-
|
|
4080
|
-
GetNArray(self, na);
|
|
4081
|
-
if (na->ndim == 0) {
|
|
4082
|
-
return INT2FIX(0);
|
|
4083
|
-
}
|
|
4084
|
-
if (na->size > (~(u_int32_t)0)) {
|
|
4085
|
-
aout[0].type = numo_cInt64;
|
|
4086
|
-
idx = nary_new(numo_cInt64, na->ndim, na->shape);
|
|
4087
|
-
ndf.func = iter_robject_max_index_index64;
|
|
4088
|
-
|
|
4089
|
-
reduce =
|
|
4090
|
-
na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_max_index_index64_nan);
|
|
4091
|
-
|
|
4092
|
-
} else {
|
|
4093
|
-
aout[0].type = numo_cInt32;
|
|
4094
|
-
idx = nary_new(numo_cInt32, na->ndim, na->shape);
|
|
4095
|
-
ndf.func = iter_robject_max_index_index32;
|
|
4096
|
-
|
|
4097
|
-
reduce =
|
|
4098
|
-
na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_max_index_index32_nan);
|
|
4099
|
-
}
|
|
4100
|
-
rb_funcall(idx, rb_intern("seq"), 0);
|
|
4101
|
-
|
|
4102
|
-
return na_ndloop(&ndf, 3, self, idx, reduce);
|
|
4103
|
-
}
|
|
4104
|
-
|
|
4105
|
-
#define idx_t int64_t
|
|
4106
|
-
static void iter_robject_min_index_index64(na_loop_t* const lp) {
|
|
4107
|
-
size_t n, idx;
|
|
4108
|
-
char *d_ptr, *i_ptr, *o_ptr;
|
|
4109
|
-
ssize_t d_step, i_step;
|
|
4110
|
-
|
|
4111
|
-
INIT_COUNTER(lp, n);
|
|
4112
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
4113
|
-
|
|
4114
|
-
idx = f_min_index(n, d_ptr, d_step);
|
|
4115
|
-
|
|
4116
|
-
INIT_PTR(lp, 1, i_ptr, i_step);
|
|
4117
|
-
o_ptr = NDL_PTR(lp, 2);
|
|
4118
|
-
*(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
|
|
4119
|
-
}
|
|
4120
|
-
#undef idx_t
|
|
4121
|
-
|
|
4122
|
-
#define idx_t int32_t
|
|
4123
|
-
static void iter_robject_min_index_index32(na_loop_t* const lp) {
|
|
4124
|
-
size_t n, idx;
|
|
4125
|
-
char *d_ptr, *i_ptr, *o_ptr;
|
|
4126
|
-
ssize_t d_step, i_step;
|
|
4127
|
-
|
|
4128
|
-
INIT_COUNTER(lp, n);
|
|
4129
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
4130
|
-
|
|
4131
|
-
idx = f_min_index(n, d_ptr, d_step);
|
|
4132
|
-
|
|
4133
|
-
INIT_PTR(lp, 1, i_ptr, i_step);
|
|
4134
|
-
o_ptr = NDL_PTR(lp, 2);
|
|
4135
|
-
*(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
|
|
4136
|
-
}
|
|
4137
|
-
#undef idx_t
|
|
4138
|
-
|
|
4139
|
-
#define idx_t int64_t
|
|
4140
|
-
static void iter_robject_min_index_index64_nan(na_loop_t* const lp) {
|
|
4141
|
-
size_t n, idx;
|
|
4142
|
-
char *d_ptr, *i_ptr, *o_ptr;
|
|
4143
|
-
ssize_t d_step, i_step;
|
|
4144
|
-
|
|
4145
|
-
INIT_COUNTER(lp, n);
|
|
4146
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
4147
|
-
|
|
4148
|
-
idx = f_min_index_nan(n, d_ptr, d_step);
|
|
4149
|
-
|
|
4150
|
-
INIT_PTR(lp, 1, i_ptr, i_step);
|
|
4151
|
-
o_ptr = NDL_PTR(lp, 2);
|
|
4152
|
-
*(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
|
|
4153
|
-
}
|
|
4154
|
-
#undef idx_t
|
|
4155
|
-
|
|
4156
|
-
#define idx_t int32_t
|
|
4157
|
-
static void iter_robject_min_index_index32_nan(na_loop_t* const lp) {
|
|
4158
|
-
size_t n, idx;
|
|
4159
|
-
char *d_ptr, *i_ptr, *o_ptr;
|
|
4160
|
-
ssize_t d_step, i_step;
|
|
4161
|
-
|
|
4162
|
-
INIT_COUNTER(lp, n);
|
|
4163
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
4164
|
-
|
|
4165
|
-
idx = f_min_index_nan(n, d_ptr, d_step);
|
|
4166
|
-
|
|
4167
|
-
INIT_PTR(lp, 1, i_ptr, i_step);
|
|
4168
|
-
o_ptr = NDL_PTR(lp, 2);
|
|
4169
|
-
*(idx_t*)o_ptr = *(idx_t*)(i_ptr + i_step * idx);
|
|
4170
|
-
}
|
|
4171
|
-
#undef idx_t
|
|
4172
|
-
|
|
4173
|
-
/*
|
|
4174
|
-
Index of the minimum value.
|
|
4175
|
-
@overload min_index(axis:nil, nan:false)
|
|
4176
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (return NaN posision if exist).
|
|
4177
|
-
@param [Numeric,Array,Range] axis Finds minimum values along the axis and returns **flat
|
|
4178
|
-
1-d indices**.
|
|
4179
|
-
@return [Integer,Numo::Int] returns result indices.
|
|
4180
|
-
@see #argmin
|
|
4181
|
-
@see #min
|
|
4182
|
-
|
|
4183
|
-
@example
|
|
4184
|
-
a = Numo::NArray[3,4,1,2]
|
|
4185
|
-
a.min_index #=> 2
|
|
4186
|
-
|
|
4187
|
-
b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
4188
|
-
b.min_index #=> 4
|
|
4189
|
-
b.min_index(axis:1) #=> [2, 4]
|
|
4190
|
-
b.min_index(axis:0) #=> [3, 4, 2]
|
|
4191
|
-
b[b.min_index(axis:0)] #=> [2, 0, 1]
|
|
4192
|
-
*/
|
|
4193
|
-
static VALUE robject_min_index(int argc, VALUE* argv, VALUE self) {
|
|
4194
|
-
narray_t* na;
|
|
4195
|
-
VALUE idx, reduce;
|
|
4196
|
-
ndfunc_arg_in_t ain[3] = { { Qnil, 0 }, { Qnil, 0 }, { sym_reduce, 0 } };
|
|
4197
|
-
ndfunc_arg_out_t aout[1] = { { 0, 0, 0 } };
|
|
4198
|
-
ndfunc_t ndf = { 0, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 3, 1, ain, aout };
|
|
4199
|
-
|
|
4200
|
-
GetNArray(self, na);
|
|
4201
|
-
if (na->ndim == 0) {
|
|
4202
|
-
return INT2FIX(0);
|
|
4203
|
-
}
|
|
4204
|
-
if (na->size > (~(u_int32_t)0)) {
|
|
4205
|
-
aout[0].type = numo_cInt64;
|
|
4206
|
-
idx = nary_new(numo_cInt64, na->ndim, na->shape);
|
|
4207
|
-
ndf.func = iter_robject_min_index_index64;
|
|
4208
|
-
|
|
4209
|
-
reduce =
|
|
4210
|
-
na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_min_index_index64_nan);
|
|
4211
|
-
|
|
4212
|
-
} else {
|
|
4213
|
-
aout[0].type = numo_cInt32;
|
|
4214
|
-
idx = nary_new(numo_cInt32, na->ndim, na->shape);
|
|
4215
|
-
ndf.func = iter_robject_min_index_index32;
|
|
4216
|
-
|
|
4217
|
-
reduce =
|
|
4218
|
-
na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_min_index_index32_nan);
|
|
4219
|
-
}
|
|
4220
|
-
rb_funcall(idx, rb_intern("seq"), 0);
|
|
4221
|
-
|
|
4222
|
-
return na_ndloop(&ndf, 3, self, idx, reduce);
|
|
4223
|
-
}
|
|
4224
|
-
|
|
4225
|
-
#define idx_t int64_t
|
|
4226
|
-
static void iter_robject_argmax_arg64(na_loop_t* const lp) {
|
|
4227
|
-
size_t n, idx;
|
|
4228
|
-
char *d_ptr, *o_ptr;
|
|
4229
|
-
ssize_t d_step;
|
|
4230
|
-
|
|
4231
|
-
INIT_COUNTER(lp, n);
|
|
4232
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
4233
|
-
|
|
4234
|
-
idx = f_max_index(n, d_ptr, d_step);
|
|
4235
|
-
|
|
4236
|
-
o_ptr = NDL_PTR(lp, 1);
|
|
4237
|
-
*(idx_t*)o_ptr = (idx_t)idx;
|
|
4238
|
-
}
|
|
4239
|
-
#undef idx_t
|
|
4240
|
-
|
|
4241
|
-
#define idx_t int32_t
|
|
4242
|
-
static void iter_robject_argmax_arg32(na_loop_t* const lp) {
|
|
4243
|
-
size_t n, idx;
|
|
4244
|
-
char *d_ptr, *o_ptr;
|
|
4245
|
-
ssize_t d_step;
|
|
4246
|
-
|
|
4247
|
-
INIT_COUNTER(lp, n);
|
|
4248
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
4249
|
-
|
|
4250
|
-
idx = f_max_index(n, d_ptr, d_step);
|
|
4251
|
-
|
|
4252
|
-
o_ptr = NDL_PTR(lp, 1);
|
|
4253
|
-
*(idx_t*)o_ptr = (idx_t)idx;
|
|
4254
|
-
}
|
|
4255
|
-
#undef idx_t
|
|
4256
|
-
|
|
4257
|
-
#define idx_t int64_t
|
|
4258
|
-
static void iter_robject_argmax_arg64_nan(na_loop_t* const lp) {
|
|
4259
|
-
size_t n, idx;
|
|
4260
|
-
char *d_ptr, *o_ptr;
|
|
4261
|
-
ssize_t d_step;
|
|
4262
|
-
|
|
4263
|
-
INIT_COUNTER(lp, n);
|
|
4264
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
4265
|
-
|
|
4266
|
-
idx = f_max_index_nan(n, d_ptr, d_step);
|
|
4267
|
-
|
|
4268
|
-
o_ptr = NDL_PTR(lp, 1);
|
|
4269
|
-
*(idx_t*)o_ptr = (idx_t)idx;
|
|
4270
|
-
}
|
|
4271
|
-
#undef idx_t
|
|
4272
|
-
|
|
4273
|
-
#define idx_t int32_t
|
|
4274
|
-
static void iter_robject_argmax_arg32_nan(na_loop_t* const lp) {
|
|
4275
|
-
size_t n, idx;
|
|
4276
|
-
char *d_ptr, *o_ptr;
|
|
4277
|
-
ssize_t d_step;
|
|
4278
|
-
|
|
4279
|
-
INIT_COUNTER(lp, n);
|
|
4280
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
4281
|
-
|
|
4282
|
-
idx = f_max_index_nan(n, d_ptr, d_step);
|
|
4283
|
-
|
|
4284
|
-
o_ptr = NDL_PTR(lp, 1);
|
|
4285
|
-
*(idx_t*)o_ptr = (idx_t)idx;
|
|
4286
|
-
}
|
|
4287
|
-
#undef idx_t
|
|
4288
|
-
|
|
4289
|
-
/*
|
|
4290
|
-
Index of the maximum value.
|
|
4291
|
-
@overload argmax(axis:nil, nan:false)
|
|
4292
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (return NaN posision if exist).
|
|
4293
|
-
@param [Numeric,Array,Range] axis Finds maximum values along the axis and returns **indices
|
|
4294
|
-
along the axis**.
|
|
4295
|
-
@return [Integer,Numo::Int] returns the result indices.
|
|
4296
|
-
@see #max_index
|
|
4297
|
-
@see #max
|
|
4298
|
-
|
|
4299
|
-
@example
|
|
4300
|
-
a = Numo::NArray[3,4,1,2]
|
|
4301
|
-
a.argmax #=> 1
|
|
4302
|
-
|
|
4303
|
-
b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
4304
|
-
b.argmax #=> 5
|
|
4305
|
-
b.argmax(axis:1) #=> [1, 2]
|
|
4306
|
-
b.argmax(axis:0) #=> [0, 0, 1]
|
|
4307
|
-
b.at(b.argmax(axis:0), 0..-1) #=> [3, 4, 5]
|
|
4308
|
-
*/
|
|
4309
|
-
static VALUE robject_argmax(int argc, VALUE* argv, VALUE self) {
|
|
4310
|
-
narray_t* na;
|
|
4311
|
-
VALUE reduce;
|
|
4312
|
-
ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_reduce, 0 } };
|
|
4313
|
-
ndfunc_arg_out_t aout[1] = { { 0, 0, 0 } };
|
|
4314
|
-
ndfunc_t ndf = { 0, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 2, 1, ain, aout };
|
|
4315
|
-
|
|
4316
|
-
GetNArray(self, na);
|
|
4317
|
-
if (na->ndim == 0) {
|
|
4318
|
-
return INT2FIX(0);
|
|
4319
|
-
}
|
|
4320
|
-
if (na->size > (~(u_int32_t)0)) {
|
|
4321
|
-
aout[0].type = numo_cInt64;
|
|
4322
|
-
ndf.func = iter_robject_argmax_arg64;
|
|
4323
|
-
|
|
4324
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_argmax_arg64_nan);
|
|
4325
|
-
|
|
4326
|
-
} else {
|
|
4327
|
-
aout[0].type = numo_cInt32;
|
|
4328
|
-
ndf.func = iter_robject_argmax_arg32;
|
|
4329
|
-
|
|
4330
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_argmax_arg32_nan);
|
|
4331
|
-
}
|
|
4332
|
-
|
|
4333
|
-
return na_ndloop(&ndf, 2, self, reduce);
|
|
4334
|
-
}
|
|
4335
|
-
|
|
4336
|
-
#define idx_t int64_t
|
|
4337
|
-
static void iter_robject_argmin_arg64(na_loop_t* const lp) {
|
|
4338
|
-
size_t n, idx;
|
|
4339
|
-
char *d_ptr, *o_ptr;
|
|
4340
|
-
ssize_t d_step;
|
|
4341
|
-
|
|
4342
|
-
INIT_COUNTER(lp, n);
|
|
4343
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
4344
|
-
|
|
4345
|
-
idx = f_min_index(n, d_ptr, d_step);
|
|
4346
|
-
|
|
4347
|
-
o_ptr = NDL_PTR(lp, 1);
|
|
4348
|
-
*(idx_t*)o_ptr = (idx_t)idx;
|
|
4349
|
-
}
|
|
4350
|
-
#undef idx_t
|
|
4351
|
-
|
|
4352
|
-
#define idx_t int32_t
|
|
4353
|
-
static void iter_robject_argmin_arg32(na_loop_t* const lp) {
|
|
4354
|
-
size_t n, idx;
|
|
4355
|
-
char *d_ptr, *o_ptr;
|
|
4356
|
-
ssize_t d_step;
|
|
4357
|
-
|
|
4358
|
-
INIT_COUNTER(lp, n);
|
|
4359
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
4360
|
-
|
|
4361
|
-
idx = f_min_index(n, d_ptr, d_step);
|
|
4362
|
-
|
|
4363
|
-
o_ptr = NDL_PTR(lp, 1);
|
|
4364
|
-
*(idx_t*)o_ptr = (idx_t)idx;
|
|
4365
|
-
}
|
|
4366
|
-
#undef idx_t
|
|
4367
|
-
|
|
4368
|
-
#define idx_t int64_t
|
|
4369
|
-
static void iter_robject_argmin_arg64_nan(na_loop_t* const lp) {
|
|
4370
|
-
size_t n, idx;
|
|
4371
|
-
char *d_ptr, *o_ptr;
|
|
4372
|
-
ssize_t d_step;
|
|
4373
|
-
|
|
4374
|
-
INIT_COUNTER(lp, n);
|
|
4375
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
4376
|
-
|
|
4377
|
-
idx = f_min_index_nan(n, d_ptr, d_step);
|
|
4378
|
-
|
|
4379
|
-
o_ptr = NDL_PTR(lp, 1);
|
|
4380
|
-
*(idx_t*)o_ptr = (idx_t)idx;
|
|
4381
|
-
}
|
|
4382
|
-
#undef idx_t
|
|
4383
|
-
|
|
4384
|
-
#define idx_t int32_t
|
|
4385
|
-
static void iter_robject_argmin_arg32_nan(na_loop_t* const lp) {
|
|
4386
|
-
size_t n, idx;
|
|
4387
|
-
char *d_ptr, *o_ptr;
|
|
4388
|
-
ssize_t d_step;
|
|
4389
|
-
|
|
4390
|
-
INIT_COUNTER(lp, n);
|
|
4391
|
-
INIT_PTR(lp, 0, d_ptr, d_step);
|
|
4392
|
-
|
|
4393
|
-
idx = f_min_index_nan(n, d_ptr, d_step);
|
|
4394
|
-
|
|
4395
|
-
o_ptr = NDL_PTR(lp, 1);
|
|
4396
|
-
*(idx_t*)o_ptr = (idx_t)idx;
|
|
4397
|
-
}
|
|
4398
|
-
#undef idx_t
|
|
4399
|
-
|
|
4400
|
-
/*
|
|
4401
|
-
Index of the minimum value.
|
|
4402
|
-
@overload argmin(axis:nil, nan:false)
|
|
4403
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (return NaN posision if exist).
|
|
4404
|
-
@param [Numeric,Array,Range] axis Finds minimum values along the axis and returns **indices
|
|
4405
|
-
along the axis**.
|
|
4406
|
-
@return [Integer,Numo::Int] returns the result indices.
|
|
4407
|
-
@see #min_index
|
|
4408
|
-
@see #min
|
|
4409
|
-
|
|
4410
|
-
@example
|
|
4411
|
-
a = Numo::NArray[3,4,1,2]
|
|
4412
|
-
a.argmin #=> 2
|
|
4413
|
-
|
|
4414
|
-
b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
4415
|
-
b.argmin #=> 4
|
|
4416
|
-
b.argmin(axis:1) #=> [2, 1]
|
|
4417
|
-
b.argmin(axis:0) #=> [1, 1, 0]
|
|
4418
|
-
b.at(b.argmin(axis:0), 0..-1) #=> [2, 0, 1]
|
|
4419
|
-
*/
|
|
4420
|
-
static VALUE robject_argmin(int argc, VALUE* argv, VALUE self) {
|
|
4421
|
-
narray_t* na;
|
|
4422
|
-
VALUE reduce;
|
|
4423
|
-
ndfunc_arg_in_t ain[2] = { { Qnil, 0 }, { sym_reduce, 0 } };
|
|
4424
|
-
ndfunc_arg_out_t aout[1] = { { 0, 0, 0 } };
|
|
4425
|
-
ndfunc_t ndf = { 0, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 2, 1, ain, aout };
|
|
4426
|
-
|
|
4427
|
-
GetNArray(self, na);
|
|
4428
|
-
if (na->ndim == 0) {
|
|
4429
|
-
return INT2FIX(0);
|
|
4430
|
-
}
|
|
4431
|
-
if (na->size > (~(u_int32_t)0)) {
|
|
4432
|
-
aout[0].type = numo_cInt64;
|
|
4433
|
-
ndf.func = iter_robject_argmin_arg64;
|
|
4434
|
-
|
|
4435
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_argmin_arg64_nan);
|
|
4436
|
-
|
|
4437
|
-
} else {
|
|
4438
|
-
aout[0].type = numo_cInt32;
|
|
4439
|
-
ndf.func = iter_robject_argmin_arg32;
|
|
4440
|
-
|
|
4441
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_argmin_arg32_nan);
|
|
4442
|
-
}
|
|
4443
|
-
|
|
4444
|
-
return na_ndloop(&ndf, 2, self, reduce);
|
|
4445
|
-
}
|
|
4446
|
-
|
|
4447
|
-
static void iter_robject_minmax(na_loop_t* const lp) {
|
|
4448
|
-
size_t n;
|
|
4449
|
-
char* p1;
|
|
4450
|
-
ssize_t s1;
|
|
4451
|
-
dtype xmin, xmax;
|
|
4452
|
-
|
|
4453
|
-
INIT_COUNTER(lp, n);
|
|
4454
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4455
|
-
|
|
4456
|
-
f_minmax(n, p1, s1, &xmin, &xmax);
|
|
4457
|
-
|
|
4458
|
-
*(dtype*)(lp->args[1].ptr + lp->args[1].iter[0].pos) = xmin;
|
|
4459
|
-
*(dtype*)(lp->args[2].ptr + lp->args[2].iter[0].pos) = xmax;
|
|
4460
|
-
}
|
|
4461
|
-
static void iter_robject_minmax_nan(na_loop_t* const lp) {
|
|
4462
|
-
size_t n;
|
|
4463
|
-
char* p1;
|
|
4464
|
-
ssize_t s1;
|
|
4465
|
-
dtype xmin, xmax;
|
|
4466
|
-
|
|
4467
|
-
INIT_COUNTER(lp, n);
|
|
4468
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4469
|
-
|
|
4470
|
-
f_minmax_nan(n, p1, s1, &xmin, &xmax);
|
|
4471
|
-
|
|
4472
|
-
*(dtype*)(lp->args[1].ptr + lp->args[1].iter[0].pos) = xmin;
|
|
4473
|
-
*(dtype*)(lp->args[2].ptr + lp->args[2].iter[0].pos) = xmax;
|
|
4474
|
-
}
|
|
4475
|
-
|
|
4476
|
-
/*
|
|
4477
|
-
minmax of self.
|
|
4478
|
-
@overload minmax(axis:nil, keepdims:false, nan:false)
|
|
4479
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (return NaN if exist).
|
|
4480
|
-
@param [Numeric,Array,Range] axis Finds min-max along the axis.
|
|
4481
|
-
@param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array
|
|
4482
|
-
as dimensions with size one.
|
|
4483
|
-
@return [Numo::RObject,Numo::RObject] min and max of self.
|
|
4484
|
-
*/
|
|
4485
|
-
static VALUE robject_minmax(int argc, VALUE* argv, VALUE self) {
|
|
4486
|
-
VALUE reduce;
|
|
4487
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
4488
|
-
ndfunc_arg_out_t aout[2] = { { cT, 0 }, { cT, 0 } };
|
|
4489
|
-
ndfunc_t ndf = {
|
|
4490
|
-
iter_robject_minmax, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE | NDF_EXTRACT, 2, 2, ain, aout
|
|
4491
|
-
};
|
|
4492
|
-
|
|
4493
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_minmax_nan);
|
|
4494
|
-
|
|
4495
|
-
return na_ndloop(&ndf, 2, self, reduce);
|
|
4496
|
-
}
|
|
4497
|
-
|
|
4498
|
-
static void iter_robject_s_maximum(na_loop_t* const lp) {
|
|
4499
|
-
size_t i, n;
|
|
4500
|
-
char *p1, *p2, *p3;
|
|
4501
|
-
ssize_t s1, s2, s3;
|
|
4502
|
-
|
|
4503
|
-
INIT_COUNTER(lp, n);
|
|
4504
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4505
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4506
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
4507
|
-
|
|
4508
|
-
for (i = 0; i < n; i++) {
|
|
4509
|
-
dtype x, y, z;
|
|
4510
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4511
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4512
|
-
GET_DATA(p3, dtype, z);
|
|
4513
|
-
z = f_maximum(x, y);
|
|
4514
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
4515
|
-
}
|
|
4516
|
-
}
|
|
4517
|
-
static void iter_robject_s_maximum_nan(na_loop_t* const lp) {
|
|
4518
|
-
size_t i, n;
|
|
4519
|
-
char *p1, *p2, *p3;
|
|
4520
|
-
ssize_t s1, s2, s3;
|
|
4521
|
-
|
|
4522
|
-
INIT_COUNTER(lp, n);
|
|
4523
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4524
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4525
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
4526
|
-
|
|
4527
|
-
for (i = 0; i < n; i++) {
|
|
4528
|
-
dtype x, y, z;
|
|
4529
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4530
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4531
|
-
GET_DATA(p3, dtype, z);
|
|
4532
|
-
z = f_maximum_nan(x, y);
|
|
4533
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
4534
|
-
}
|
|
4535
|
-
}
|
|
4536
|
-
|
|
4537
|
-
static VALUE robject_s_maximum(int argc, VALUE* argv, VALUE mod) {
|
|
4538
|
-
VALUE a1 = Qnil;
|
|
4539
|
-
VALUE a2 = Qnil;
|
|
4540
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
4541
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4542
|
-
ndfunc_t ndf = { iter_robject_s_maximum, STRIDE_LOOP_NIP, 2, 1, ain, aout };
|
|
4543
|
-
|
|
4544
|
-
VALUE kw_hash = Qnil;
|
|
4545
|
-
ID kw_table[1] = { id_nan };
|
|
4546
|
-
VALUE opts[1] = { Qundef };
|
|
4547
|
-
|
|
4548
|
-
rb_scan_args(argc, argv, "20:", &a1, &a2, &kw_hash);
|
|
4549
|
-
rb_get_kwargs(kw_hash, kw_table, 0, 1, opts);
|
|
4550
|
-
if (opts[0] != Qundef) {
|
|
4551
|
-
ndf.func = iter_robject_s_maximum_nan;
|
|
4552
|
-
}
|
|
4553
|
-
|
|
4554
|
-
return na_ndloop(&ndf, 2, a1, a2);
|
|
4555
|
-
}
|
|
4556
|
-
|
|
4557
|
-
/*
|
|
4558
|
-
Element-wise minimum of two arrays.
|
|
4559
|
-
|
|
4560
|
-
@overload minimum(a1, a2, nan:false)
|
|
4561
|
-
@param [Numo::NArray,Numeric] a1 The array to be compared.
|
|
4562
|
-
@param [Numo::NArray,Numeric] a2 The array to be compared.
|
|
4563
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (return NaN if exist).
|
|
4564
|
-
@return [Numo::RObject]
|
|
4565
|
-
*/
|
|
4566
|
-
|
|
4567
|
-
static void iter_robject_s_minimum(na_loop_t* const lp) {
|
|
4568
|
-
size_t i, n;
|
|
4569
|
-
char *p1, *p2, *p3;
|
|
4570
|
-
ssize_t s1, s2, s3;
|
|
4571
|
-
|
|
4572
|
-
INIT_COUNTER(lp, n);
|
|
4573
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4574
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4575
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
4576
|
-
|
|
4577
|
-
for (i = 0; i < n; i++) {
|
|
4578
|
-
dtype x, y, z;
|
|
4579
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4580
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4581
|
-
GET_DATA(p3, dtype, z);
|
|
4582
|
-
z = f_minimum(x, y);
|
|
4583
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
4584
|
-
}
|
|
4585
|
-
}
|
|
4586
|
-
static void iter_robject_s_minimum_nan(na_loop_t* const lp) {
|
|
4587
|
-
size_t i, n;
|
|
4588
|
-
char *p1, *p2, *p3;
|
|
4589
|
-
ssize_t s1, s2, s3;
|
|
4590
|
-
|
|
4591
|
-
INIT_COUNTER(lp, n);
|
|
4592
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4593
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4594
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
4595
|
-
|
|
4596
|
-
for (i = 0; i < n; i++) {
|
|
4597
|
-
dtype x, y, z;
|
|
4598
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4599
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4600
|
-
GET_DATA(p3, dtype, z);
|
|
4601
|
-
z = f_minimum_nan(x, y);
|
|
4602
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
4603
|
-
}
|
|
4604
|
-
}
|
|
4605
|
-
|
|
4606
|
-
static VALUE robject_s_minimum(int argc, VALUE* argv, VALUE mod) {
|
|
4607
|
-
VALUE a1 = Qnil;
|
|
4608
|
-
VALUE a2 = Qnil;
|
|
4609
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { cT, 0 } };
|
|
4610
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4611
|
-
ndfunc_t ndf = { iter_robject_s_minimum, STRIDE_LOOP_NIP, 2, 1, ain, aout };
|
|
4612
|
-
|
|
4613
|
-
VALUE kw_hash = Qnil;
|
|
4614
|
-
ID kw_table[1] = { id_nan };
|
|
4615
|
-
VALUE opts[1] = { Qundef };
|
|
4616
|
-
|
|
4617
|
-
rb_scan_args(argc, argv, "20:", &a1, &a2, &kw_hash);
|
|
4618
|
-
rb_get_kwargs(kw_hash, kw_table, 0, 1, opts);
|
|
4619
|
-
if (opts[0] != Qundef) {
|
|
4620
|
-
ndf.func = iter_robject_s_minimum_nan;
|
|
4621
|
-
}
|
|
4622
|
-
|
|
4623
|
-
return na_ndloop(&ndf, 2, a1, a2);
|
|
4624
|
-
}
|
|
4625
|
-
|
|
4626
|
-
static void iter_robject_cumsum(na_loop_t* const lp) {
|
|
4627
|
-
size_t i;
|
|
4628
|
-
char *p1, *p2;
|
|
4629
|
-
ssize_t s1, s2;
|
|
4630
|
-
dtype x, y;
|
|
4631
|
-
|
|
4632
|
-
INIT_COUNTER(lp, i);
|
|
4633
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4634
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4635
|
-
|
|
4636
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4637
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4638
|
-
for (i--; i--;) {
|
|
4639
|
-
GET_DATA_STRIDE(p1, s1, dtype, y);
|
|
4640
|
-
m_cumsum(x, y);
|
|
4641
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4642
|
-
}
|
|
4643
|
-
}
|
|
4644
|
-
static void iter_robject_cumsum_nan(na_loop_t* const lp) {
|
|
4645
|
-
size_t i;
|
|
4646
|
-
char *p1, *p2;
|
|
4647
|
-
ssize_t s1, s2;
|
|
4648
|
-
dtype x, y;
|
|
4649
|
-
|
|
4650
|
-
INIT_COUNTER(lp, i);
|
|
4651
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4652
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4653
|
-
|
|
4654
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4655
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4656
|
-
for (i--; i--;) {
|
|
4657
|
-
GET_DATA_STRIDE(p1, s1, dtype, y);
|
|
4658
|
-
m_cumsum_nan(x, y);
|
|
4659
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4660
|
-
}
|
|
4661
|
-
}
|
|
4662
|
-
|
|
4663
|
-
/*
|
|
4664
|
-
cumsum of self.
|
|
4665
|
-
@overload cumsum(axis:nil, nan:false)
|
|
4666
|
-
@param [Numeric,Array,Range] axis Performs cumsum along the axis.
|
|
4667
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4668
|
-
@return [Numo::RObject] cumsum of self.
|
|
4669
|
-
*/
|
|
4670
|
-
static VALUE robject_cumsum(int argc, VALUE* argv, VALUE self) {
|
|
4671
|
-
VALUE reduce;
|
|
4672
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
4673
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4674
|
-
ndfunc_t ndf = {
|
|
4675
|
-
iter_robject_cumsum, STRIDE_LOOP | NDF_FLAT_REDUCE | NDF_CUM, 2, 1, ain, aout
|
|
4676
|
-
};
|
|
4677
|
-
|
|
4678
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_cumsum_nan);
|
|
4679
|
-
|
|
4680
|
-
return na_ndloop(&ndf, 2, self, reduce);
|
|
4681
|
-
}
|
|
4682
|
-
|
|
4683
|
-
static void iter_robject_cumprod(na_loop_t* const lp) {
|
|
4684
|
-
size_t i;
|
|
4685
|
-
char *p1, *p2;
|
|
4686
|
-
ssize_t s1, s2;
|
|
4687
|
-
dtype x, y;
|
|
4688
|
-
|
|
4689
|
-
INIT_COUNTER(lp, i);
|
|
4690
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4691
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4692
|
-
|
|
4693
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4694
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4695
|
-
for (i--; i--;) {
|
|
4696
|
-
GET_DATA_STRIDE(p1, s1, dtype, y);
|
|
4697
|
-
m_cumprod(x, y);
|
|
4698
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4699
|
-
}
|
|
4700
|
-
}
|
|
4701
|
-
static void iter_robject_cumprod_nan(na_loop_t* const lp) {
|
|
4702
|
-
size_t i;
|
|
4703
|
-
char *p1, *p2;
|
|
4704
|
-
ssize_t s1, s2;
|
|
4705
|
-
dtype x, y;
|
|
4706
|
-
|
|
4707
|
-
INIT_COUNTER(lp, i);
|
|
4708
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4709
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4710
|
-
|
|
4711
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4712
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4713
|
-
for (i--; i--;) {
|
|
4714
|
-
GET_DATA_STRIDE(p1, s1, dtype, y);
|
|
4715
|
-
m_cumprod_nan(x, y);
|
|
4716
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4717
|
-
}
|
|
4718
|
-
}
|
|
4719
|
-
|
|
4720
|
-
/*
|
|
4721
|
-
cumprod of self.
|
|
4722
|
-
@overload cumprod(axis:nil, nan:false)
|
|
4723
|
-
@param [Numeric,Array,Range] axis Performs cumprod along the axis.
|
|
4724
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4725
|
-
@return [Numo::RObject] cumprod of self.
|
|
4726
|
-
*/
|
|
4727
|
-
static VALUE robject_cumprod(int argc, VALUE* argv, VALUE self) {
|
|
4728
|
-
VALUE reduce;
|
|
4729
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
4730
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4731
|
-
ndfunc_t ndf = {
|
|
4732
|
-
iter_robject_cumprod, STRIDE_LOOP | NDF_FLAT_REDUCE | NDF_CUM, 2, 1, ain, aout
|
|
4733
|
-
};
|
|
4734
|
-
|
|
4735
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_robject_cumprod_nan);
|
|
4736
|
-
|
|
4737
|
-
return na_ndloop(&ndf, 2, self, reduce);
|
|
4738
|
-
}
|
|
4739
|
-
|
|
4740
|
-
//
|
|
4741
|
-
static void iter_robject_mulsum(na_loop_t* const lp) {
|
|
4742
|
-
size_t i, n;
|
|
4743
|
-
char *p1, *p2, *p3;
|
|
4744
|
-
ssize_t s1, s2, s3;
|
|
4745
|
-
|
|
4746
|
-
INIT_COUNTER(lp, n);
|
|
4747
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4748
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4749
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
4750
|
-
|
|
4751
|
-
if (s3 == 0) {
|
|
4752
|
-
dtype z;
|
|
4753
|
-
// Reduce loop
|
|
4754
|
-
GET_DATA(p3, dtype, z);
|
|
4755
|
-
for (i = 0; i < n; i++) {
|
|
4756
|
-
dtype x, y;
|
|
4757
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4758
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4759
|
-
m_mulsum(x, y, z);
|
|
4760
|
-
}
|
|
4761
|
-
SET_DATA(p3, dtype, z);
|
|
4762
|
-
return;
|
|
4763
|
-
} else {
|
|
4764
|
-
for (i = 0; i < n; i++) {
|
|
4765
|
-
dtype x, y, z;
|
|
4766
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4767
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4768
|
-
GET_DATA(p3, dtype, z);
|
|
4769
|
-
m_mulsum(x, y, z);
|
|
4770
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
4771
|
-
}
|
|
4772
|
-
}
|
|
4773
|
-
}
|
|
4774
|
-
//
|
|
4775
|
-
static void iter_robject_mulsum_nan(na_loop_t* const lp) {
|
|
4776
|
-
size_t i, n;
|
|
4777
|
-
char *p1, *p2, *p3;
|
|
4778
|
-
ssize_t s1, s2, s3;
|
|
4779
|
-
|
|
4780
|
-
INIT_COUNTER(lp, n);
|
|
4781
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4782
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4783
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
4784
|
-
|
|
4785
|
-
if (s3 == 0) {
|
|
4786
|
-
dtype z;
|
|
4787
|
-
// Reduce loop
|
|
4788
|
-
GET_DATA(p3, dtype, z);
|
|
4789
|
-
for (i = 0; i < n; i++) {
|
|
4790
|
-
dtype x, y;
|
|
4791
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4792
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4793
|
-
m_mulsum_nan(x, y, z);
|
|
3477
|
+
INIT_COUNTER(lp, i);
|
|
3478
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3479
|
+
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3480
|
+
if (idx1) {
|
|
3481
|
+
for (; i--;) {
|
|
3482
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3483
|
+
b = (m_isnan(x)) ? 1 : 0;
|
|
3484
|
+
STORE_BIT(a2, p2, b);
|
|
3485
|
+
p2 += s2;
|
|
4794
3486
|
}
|
|
4795
|
-
SET_DATA(p3, dtype, z);
|
|
4796
|
-
return;
|
|
4797
3487
|
} else {
|
|
4798
|
-
for (
|
|
4799
|
-
dtype x, y, z;
|
|
3488
|
+
for (; i--;) {
|
|
4800
3489
|
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
3490
|
+
b = (m_isnan(x)) ? 1 : 0;
|
|
3491
|
+
STORE_BIT(a2, p2, b);
|
|
3492
|
+
p2 += s2;
|
|
4805
3493
|
}
|
|
4806
3494
|
}
|
|
4807
3495
|
}
|
|
4808
|
-
//
|
|
4809
|
-
|
|
4810
|
-
static VALUE robject_mulsum_self(int argc, VALUE* argv, VALUE self) {
|
|
4811
|
-
VALUE v, reduce;
|
|
4812
|
-
VALUE naryv[2];
|
|
4813
|
-
ndfunc_arg_in_t ain[4] = { { cT, 0 }, { cT, 0 }, { sym_reduce, 0 }, { sym_init, 0 } };
|
|
4814
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4815
|
-
ndfunc_t ndf = { iter_robject_mulsum, STRIDE_LOOP_NIP, 4, 1, ain, aout };
|
|
4816
|
-
|
|
4817
|
-
if (argc < 1) {
|
|
4818
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for >=1)", argc);
|
|
4819
|
-
}
|
|
4820
|
-
// should fix below: [self.ndim,other.ndim].max or?
|
|
4821
|
-
naryv[0] = self;
|
|
4822
|
-
naryv[1] = argv[0];
|
|
4823
|
-
//
|
|
4824
|
-
reduce = na_reduce_dimension(argc - 1, argv + 1, 2, naryv, &ndf, iter_robject_mulsum_nan);
|
|
4825
|
-
//
|
|
4826
|
-
|
|
4827
|
-
v = na_ndloop(&ndf, 4, self, argv[0], reduce, m_mulsum_init);
|
|
4828
|
-
return robject_extract(v);
|
|
4829
|
-
}
|
|
4830
3496
|
|
|
4831
3497
|
/*
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
@param [Numo::NArray,Numeric] other
|
|
4836
|
-
@param [Numeric,Array,Range] axis Performs mulsum along the axis.
|
|
4837
|
-
@param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array
|
|
4838
|
-
as dimensions with size one.
|
|
4839
|
-
@param [TrueClass] nan (keyword) If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4840
|
-
@return [Numo::NArray] mulsum of self and other.
|
|
3498
|
+
Condition of isnan.
|
|
3499
|
+
@overload isnan
|
|
3500
|
+
@return [Numo::Bit] Condition of isnan.
|
|
4841
3501
|
*/
|
|
4842
|
-
static VALUE
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
}
|
|
4847
|
-
//
|
|
4848
|
-
return robject_mulsum_self(argc, argv, self);
|
|
4849
|
-
//
|
|
4850
|
-
}
|
|
4851
|
-
|
|
4852
|
-
typedef dtype seq_data_t;
|
|
4853
|
-
|
|
4854
|
-
typedef size_t seq_count_t;
|
|
3502
|
+
static VALUE robject_isnan(VALUE self) {
|
|
3503
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3504
|
+
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3505
|
+
ndfunc_t ndf = { iter_robject_isnan, FULL_LOOP, 1, 1, ain, aout };
|
|
4855
3506
|
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
seq_data_t step;
|
|
4859
|
-
seq_count_t count;
|
|
4860
|
-
} seq_opt_t;
|
|
3507
|
+
return na_ndloop(&ndf, 1, self);
|
|
3508
|
+
}
|
|
4861
3509
|
|
|
4862
|
-
static void
|
|
3510
|
+
static void iter_robject_isinf(na_loop_t* const lp) {
|
|
4863
3511
|
size_t i;
|
|
4864
3512
|
char* p1;
|
|
4865
|
-
|
|
3513
|
+
BIT_DIGIT* a2;
|
|
3514
|
+
size_t p2;
|
|
3515
|
+
ssize_t s1, s2;
|
|
4866
3516
|
size_t* idx1;
|
|
4867
3517
|
dtype x;
|
|
4868
|
-
|
|
4869
|
-
seq_count_t c;
|
|
4870
|
-
seq_opt_t* g;
|
|
4871
|
-
|
|
3518
|
+
BIT_DIGIT b;
|
|
4872
3519
|
INIT_COUNTER(lp, i);
|
|
4873
3520
|
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
4874
|
-
|
|
4875
|
-
beg = g->beg;
|
|
4876
|
-
step = g->step;
|
|
4877
|
-
c = g->count;
|
|
3521
|
+
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
4878
3522
|
if (idx1) {
|
|
4879
3523
|
for (; i--;) {
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
3524
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3525
|
+
b = (m_isinf(x)) ? 1 : 0;
|
|
3526
|
+
STORE_BIT(a2, p2, b);
|
|
3527
|
+
p2 += s2;
|
|
4883
3528
|
}
|
|
4884
3529
|
} else {
|
|
4885
3530
|
for (; i--;) {
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
3531
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3532
|
+
b = (m_isinf(x)) ? 1 : 0;
|
|
3533
|
+
STORE_BIT(a2, p2, b);
|
|
3534
|
+
p2 += s2;
|
|
4889
3535
|
}
|
|
4890
3536
|
}
|
|
4891
|
-
g->count = c;
|
|
4892
3537
|
}
|
|
4893
3538
|
|
|
4894
3539
|
/*
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
@overload seq([beg,[step]])
|
|
4899
|
-
@param [Numeric] beg beginning of sequence. (default=0)
|
|
4900
|
-
@param [Numeric] step step of sequence. (default=1)
|
|
4901
|
-
@return [Numo::RObject] self.
|
|
4902
|
-
@example
|
|
4903
|
-
Numo::DFloat.new(6).seq(1,-0.2)
|
|
4904
|
-
# => Numo::DFloat#shape=[6]
|
|
4905
|
-
# [1, 0.8, 0.6, 0.4, 0.2, 0]
|
|
4906
|
-
|
|
4907
|
-
Numo::DComplex.new(6).seq(1,-0.2+0.2i)
|
|
4908
|
-
# => Numo::DComplex#shape=[6]
|
|
4909
|
-
# [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]
|
|
3540
|
+
Condition of isinf.
|
|
3541
|
+
@overload isinf
|
|
3542
|
+
@return [Numo::Bit] Condition of isinf.
|
|
4910
3543
|
*/
|
|
4911
|
-
static VALUE
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
ndfunc_t ndf = { iter_robject_seq, FULL_LOOP, 1, 0, ain, 0 };
|
|
4916
|
-
|
|
4917
|
-
g = ALLOCA_N(seq_opt_t, 1);
|
|
4918
|
-
g->beg = m_zero;
|
|
4919
|
-
g->step = m_one;
|
|
4920
|
-
g->count = 0;
|
|
4921
|
-
rb_scan_args(argc, argv, "02", &vbeg, &vstep);
|
|
4922
|
-
if (vbeg != Qnil) {
|
|
4923
|
-
g->beg = m_num_to_data(vbeg);
|
|
4924
|
-
}
|
|
4925
|
-
if (vstep != Qnil) {
|
|
4926
|
-
g->step = m_num_to_data(vstep);
|
|
4927
|
-
}
|
|
3544
|
+
static VALUE robject_isinf(VALUE self) {
|
|
3545
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3546
|
+
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3547
|
+
ndfunc_t ndf = { iter_robject_isinf, FULL_LOOP, 1, 1, ain, aout };
|
|
4928
3548
|
|
|
4929
|
-
|
|
4930
|
-
return self;
|
|
3549
|
+
return na_ndloop(&ndf, 1, self);
|
|
4931
3550
|
}
|
|
4932
3551
|
|
|
4933
|
-
|
|
4934
|
-
seq_data_t beg;
|
|
4935
|
-
seq_data_t step;
|
|
4936
|
-
seq_data_t base;
|
|
4937
|
-
seq_count_t count;
|
|
4938
|
-
} logseq_opt_t;
|
|
4939
|
-
|
|
4940
|
-
static void iter_robject_logseq(na_loop_t* const lp) {
|
|
3552
|
+
static void iter_robject_isposinf(na_loop_t* const lp) {
|
|
4941
3553
|
size_t i;
|
|
4942
3554
|
char* p1;
|
|
4943
|
-
|
|
3555
|
+
BIT_DIGIT* a2;
|
|
3556
|
+
size_t p2;
|
|
3557
|
+
ssize_t s1, s2;
|
|
4944
3558
|
size_t* idx1;
|
|
4945
3559
|
dtype x;
|
|
4946
|
-
|
|
4947
|
-
seq_count_t c;
|
|
4948
|
-
logseq_opt_t* g;
|
|
4949
|
-
|
|
3560
|
+
BIT_DIGIT b;
|
|
4950
3561
|
INIT_COUNTER(lp, i);
|
|
4951
3562
|
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
4952
|
-
|
|
4953
|
-
beg = g->beg;
|
|
4954
|
-
step = g->step;
|
|
4955
|
-
base = g->base;
|
|
4956
|
-
c = g->count;
|
|
3563
|
+
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
4957
3564
|
if (idx1) {
|
|
4958
3565
|
for (; i--;) {
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
3566
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3567
|
+
b = (m_isposinf(x)) ? 1 : 0;
|
|
3568
|
+
STORE_BIT(a2, p2, b);
|
|
3569
|
+
p2 += s2;
|
|
4962
3570
|
}
|
|
4963
3571
|
} else {
|
|
4964
3572
|
for (; i--;) {
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
3573
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3574
|
+
b = (m_isposinf(x)) ? 1 : 0;
|
|
3575
|
+
STORE_BIT(a2, p2, b);
|
|
3576
|
+
p2 += s2;
|
|
4968
3577
|
}
|
|
4969
3578
|
}
|
|
4970
|
-
g->count = c;
|
|
4971
3579
|
}
|
|
4972
3580
|
|
|
4973
3581
|
/*
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
Applicable classes: DFloat, SFloat, DComplex, SCopmplex.
|
|
4978
|
-
|
|
4979
|
-
@overload logseq(beg,step,[base])
|
|
4980
|
-
@param [Numeric] beg The beginning of sequence.
|
|
4981
|
-
@param [Numeric] step The step of sequence.
|
|
4982
|
-
@param [Numeric] base The base of log space. (default=10)
|
|
4983
|
-
@return [Numo::RObject] self.
|
|
4984
|
-
|
|
4985
|
-
@example
|
|
4986
|
-
Numo::DFloat.new(5).logseq(4,-1,2)
|
|
4987
|
-
# => Numo::DFloat#shape=[5]
|
|
4988
|
-
# [16, 8, 4, 2, 1]
|
|
4989
|
-
|
|
4990
|
-
Numo::DComplex.new(5).logseq(0,1i*Math::PI/3,Math::E)
|
|
4991
|
-
# => Numo::DComplex#shape=[5]
|
|
4992
|
-
# [1+7.26156e-310i, 0.5+0.866025i, -0.5+0.866025i, -1+1.22465e-16i, ...]
|
|
3582
|
+
Condition of isposinf.
|
|
3583
|
+
@overload isposinf
|
|
3584
|
+
@return [Numo::Bit] Condition of isposinf.
|
|
4993
3585
|
*/
|
|
4994
|
-
static VALUE
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
ndfunc_t ndf = { iter_robject_logseq, FULL_LOOP, 1, 0, ain, 0 };
|
|
4999
|
-
|
|
5000
|
-
g = ALLOCA_N(logseq_opt_t, 1);
|
|
5001
|
-
rb_scan_args(argc, argv, "21", &vbeg, &vstep, &vbase);
|
|
5002
|
-
g->beg = m_num_to_data(vbeg);
|
|
5003
|
-
g->step = m_num_to_data(vstep);
|
|
5004
|
-
if (vbase == Qnil) {
|
|
5005
|
-
g->base = m_from_real(10);
|
|
5006
|
-
} else {
|
|
5007
|
-
g->base = m_num_to_data(vbase);
|
|
5008
|
-
}
|
|
5009
|
-
na_ndloop3(&ndf, g, 1, self);
|
|
5010
|
-
return self;
|
|
5011
|
-
}
|
|
3586
|
+
static VALUE robject_isposinf(VALUE self) {
|
|
3587
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3588
|
+
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3589
|
+
ndfunc_t ndf = { iter_robject_isposinf, FULL_LOOP, 1, 1, ain, aout };
|
|
5012
3590
|
|
|
5013
|
-
|
|
5014
|
-
size_t n0, n1;
|
|
5015
|
-
size_t i0, i1;
|
|
5016
|
-
ssize_t s0, s1;
|
|
5017
|
-
char *p0, *p1;
|
|
5018
|
-
char* g;
|
|
5019
|
-
ssize_t kofs;
|
|
5020
|
-
dtype data;
|
|
5021
|
-
|
|
5022
|
-
g = (char*)(lp->opt_ptr);
|
|
5023
|
-
kofs = *(ssize_t*)g;
|
|
5024
|
-
data = *(dtype*)(g + sizeof(ssize_t));
|
|
5025
|
-
|
|
5026
|
-
n0 = lp->args[0].shape[0];
|
|
5027
|
-
n1 = lp->args[0].shape[1];
|
|
5028
|
-
s0 = lp->args[0].iter[0].step;
|
|
5029
|
-
s1 = lp->args[0].iter[1].step;
|
|
5030
|
-
p0 = NDL_PTR(lp, 0);
|
|
5031
|
-
|
|
5032
|
-
for (i0 = 0; i0 < n0; i0++) {
|
|
5033
|
-
p1 = p0;
|
|
5034
|
-
for (i1 = 0; i1 < n1; i1++) {
|
|
5035
|
-
*(dtype*)p1 = (i0 + kofs == i1) ? data : m_zero;
|
|
5036
|
-
p1 += s1;
|
|
5037
|
-
}
|
|
5038
|
-
p0 += s0;
|
|
5039
|
-
}
|
|
3591
|
+
return na_ndloop(&ndf, 1, self);
|
|
5040
3592
|
}
|
|
5041
3593
|
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
// check arguments
|
|
5061
|
-
if (argc > 2) {
|
|
5062
|
-
rb_raise(rb_eArgError, "too many arguments (%d for 0..2)", argc);
|
|
5063
|
-
} else if (argc == 2) {
|
|
5064
|
-
data = m_num_to_data(argv[0]);
|
|
5065
|
-
kofs = NUM2SSIZET(argv[1]);
|
|
5066
|
-
} else if (argc == 1) {
|
|
5067
|
-
data = m_num_to_data(argv[0]);
|
|
5068
|
-
kofs = 0;
|
|
5069
|
-
} else {
|
|
5070
|
-
data = m_one;
|
|
5071
|
-
kofs = 0;
|
|
5072
|
-
}
|
|
5073
|
-
|
|
5074
|
-
GetNArray(self, na);
|
|
5075
|
-
nd = na->ndim;
|
|
5076
|
-
if (nd < 2) {
|
|
5077
|
-
rb_raise(nary_eDimensionError, "less than 2-d array");
|
|
5078
|
-
}
|
|
5079
|
-
|
|
5080
|
-
// Diagonal offset from the main diagonal.
|
|
5081
|
-
if (kofs >= 0) {
|
|
5082
|
-
if ((size_t)(kofs) >= na->shape[nd - 1]) {
|
|
5083
|
-
rb_raise(
|
|
5084
|
-
rb_eArgError,
|
|
5085
|
-
"invalid diagonal offset(%" SZF "d) for "
|
|
5086
|
-
"last dimension size(%" SZF "d)",
|
|
5087
|
-
kofs, na->shape[nd - 1]
|
|
5088
|
-
);
|
|
3594
|
+
static void iter_robject_isneginf(na_loop_t* const lp) {
|
|
3595
|
+
size_t i;
|
|
3596
|
+
char* p1;
|
|
3597
|
+
BIT_DIGIT* a2;
|
|
3598
|
+
size_t p2;
|
|
3599
|
+
ssize_t s1, s2;
|
|
3600
|
+
size_t* idx1;
|
|
3601
|
+
dtype x;
|
|
3602
|
+
BIT_DIGIT b;
|
|
3603
|
+
INIT_COUNTER(lp, i);
|
|
3604
|
+
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
3605
|
+
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
3606
|
+
if (idx1) {
|
|
3607
|
+
for (; i--;) {
|
|
3608
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3609
|
+
b = (m_isneginf(x)) ? 1 : 0;
|
|
3610
|
+
STORE_BIT(a2, p2, b);
|
|
3611
|
+
p2 += s2;
|
|
5089
3612
|
}
|
|
5090
3613
|
} else {
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
kofs, na->shape[nd - 2]
|
|
5097
|
-
);
|
|
3614
|
+
for (; i--;) {
|
|
3615
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3616
|
+
b = (m_isneginf(x)) ? 1 : 0;
|
|
3617
|
+
STORE_BIT(a2, p2, b);
|
|
3618
|
+
p2 += s2;
|
|
5098
3619
|
}
|
|
5099
3620
|
}
|
|
3621
|
+
}
|
|
5100
3622
|
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
3623
|
+
/*
|
|
3624
|
+
Condition of isneginf.
|
|
3625
|
+
@overload isneginf
|
|
3626
|
+
@return [Numo::Bit] Condition of isneginf.
|
|
3627
|
+
*/
|
|
3628
|
+
static VALUE robject_isneginf(VALUE self) {
|
|
3629
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3630
|
+
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3631
|
+
ndfunc_t ndf = { iter_robject_isneginf, FULL_LOOP, 1, 1, ain, aout };
|
|
5104
3632
|
|
|
5105
|
-
|
|
5106
|
-
return self;
|
|
3633
|
+
return na_ndloop(&ndf, 1, self);
|
|
5107
3634
|
}
|
|
5108
3635
|
|
|
5109
|
-
|
|
5110
|
-
dtype low;
|
|
5111
|
-
dtype max;
|
|
5112
|
-
} rand_opt_t;
|
|
5113
|
-
|
|
5114
|
-
static void iter_robject_rand(na_loop_t* const lp) {
|
|
3636
|
+
static void iter_robject_isfinite(na_loop_t* const lp) {
|
|
5115
3637
|
size_t i;
|
|
5116
3638
|
char* p1;
|
|
5117
|
-
|
|
3639
|
+
BIT_DIGIT* a2;
|
|
3640
|
+
size_t p2;
|
|
3641
|
+
ssize_t s1, s2;
|
|
5118
3642
|
size_t* idx1;
|
|
5119
3643
|
dtype x;
|
|
5120
|
-
|
|
5121
|
-
dtype low;
|
|
5122
|
-
dtype max;
|
|
5123
|
-
|
|
3644
|
+
BIT_DIGIT b;
|
|
5124
3645
|
INIT_COUNTER(lp, i);
|
|
5125
3646
|
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
5126
|
-
|
|
5127
|
-
low = g->low;
|
|
5128
|
-
max = g->max;
|
|
5129
|
-
|
|
3647
|
+
INIT_PTR_BIT(lp, 1, a2, p2, s2);
|
|
5130
3648
|
if (idx1) {
|
|
5131
3649
|
for (; i--;) {
|
|
5132
|
-
|
|
5133
|
-
|
|
3650
|
+
GET_DATA_INDEX(p1, idx1, dtype, x);
|
|
3651
|
+
b = (m_isfinite(x)) ? 1 : 0;
|
|
3652
|
+
STORE_BIT(a2, p2, b);
|
|
3653
|
+
p2 += s2;
|
|
5134
3654
|
}
|
|
5135
3655
|
} else {
|
|
5136
3656
|
for (; i--;) {
|
|
5137
|
-
|
|
5138
|
-
|
|
3657
|
+
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
3658
|
+
b = (m_isfinite(x)) ? 1 : 0;
|
|
3659
|
+
STORE_BIT(a2, p2, b);
|
|
3660
|
+
p2 += s2;
|
|
5139
3661
|
}
|
|
5140
3662
|
}
|
|
5141
3663
|
}
|
|
5142
3664
|
|
|
5143
3665
|
/*
|
|
5144
|
-
|
|
5145
|
-
@overload
|
|
5146
|
-
@
|
|
5147
|
-
@param [Numeric] high upper exclusive boundary of random numbers. (default=1 or 1+1i for
|
|
5148
|
-
complex types)
|
|
5149
|
-
@return [Numo::RObject] self.
|
|
5150
|
-
@example
|
|
5151
|
-
Numo::DFloat.new(6).rand
|
|
5152
|
-
# => Numo::DFloat#shape=[6]
|
|
5153
|
-
# [0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032]
|
|
5154
|
-
|
|
5155
|
-
Numo::DComplex.new(6).rand(5+5i)
|
|
5156
|
-
# => Numo::DComplex#shape=[6]
|
|
5157
|
-
# [2.69974+3.68908i, 0.825443+0.254414i, 0.540323+0.34354i, 4.52061+2.39322i, ...]
|
|
5158
|
-
|
|
5159
|
-
Numo::Int32.new(6).rand(2,5)
|
|
5160
|
-
# => Numo::Int32#shape=[6]
|
|
5161
|
-
# [4, 3, 3, 2, 4, 2]
|
|
3666
|
+
Condition of isfinite.
|
|
3667
|
+
@overload isfinite
|
|
3668
|
+
@return [Numo::Bit] Condition of isfinite.
|
|
5162
3669
|
*/
|
|
5163
|
-
static VALUE
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } };
|
|
5168
|
-
ndfunc_t ndf = { iter_robject_rand, FULL_LOOP, 1, 0, ain, 0 };
|
|
5169
|
-
|
|
5170
|
-
rb_scan_args(argc, argv, "02", &v1, &v2);
|
|
5171
|
-
if (v2 == Qnil) {
|
|
5172
|
-
g.low = m_zero;
|
|
5173
|
-
if (v1 == Qnil) {
|
|
5174
|
-
|
|
5175
|
-
g.max = high = m_one;
|
|
5176
|
-
|
|
5177
|
-
} else {
|
|
5178
|
-
g.max = high = m_num_to_data(v1);
|
|
5179
|
-
}
|
|
5180
|
-
|
|
5181
|
-
} else {
|
|
5182
|
-
g.low = m_num_to_data(v1);
|
|
5183
|
-
high = m_num_to_data(v2);
|
|
5184
|
-
g.max = m_sub(high, g.low);
|
|
5185
|
-
}
|
|
3670
|
+
static VALUE robject_isfinite(VALUE self) {
|
|
3671
|
+
ndfunc_arg_in_t ain[1] = { { cT, 0 } };
|
|
3672
|
+
ndfunc_arg_out_t aout[1] = { { numo_cBit, 0 } };
|
|
3673
|
+
ndfunc_t ndf = { iter_robject_isfinite, FULL_LOOP, 1, 1, ain, aout };
|
|
5186
3674
|
|
|
5187
|
-
|
|
5188
|
-
return self;
|
|
3675
|
+
return na_ndloop(&ndf, 1, self);
|
|
5189
3676
|
}
|
|
5190
3677
|
|
|
5191
3678
|
static void iter_robject_poly(na_loop_t* const lp) {
|
|
@@ -5376,13 +3863,63 @@ void Init_numo_robject(void) {
|
|
|
5376
3863
|
rb_define_alias(cT, ">=", "ge");
|
|
5377
3864
|
rb_define_alias(cT, "<", "lt");
|
|
5378
3865
|
rb_define_alias(cT, "<=", "le");
|
|
3866
|
+
/**
|
|
3867
|
+
* Clip array elements by [min,max].
|
|
3868
|
+
* If either of min or max is nil, one side is clipped.
|
|
3869
|
+
* @overload clip(min,max)
|
|
3870
|
+
* @param [Numo::NArray,Numeric] min
|
|
3871
|
+
* @param [Numo::NArray,Numeric] max
|
|
3872
|
+
* @return [Numo::NArray] result of clip.
|
|
3873
|
+
*
|
|
3874
|
+
* @example
|
|
3875
|
+
* a = Numo::Int32.new(10).seq
|
|
3876
|
+
* # => Numo::Int32#shape=[10]
|
|
3877
|
+
* # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
3878
|
+
*
|
|
3879
|
+
* a.clip(1,8)
|
|
3880
|
+
* # => Numo::Int32#shape=[10]
|
|
3881
|
+
* # [1, 1, 2, 3, 4, 5, 6, 7, 8, 8]
|
|
3882
|
+
*
|
|
3883
|
+
* a.inplace.clip(3,6)
|
|
3884
|
+
* a
|
|
3885
|
+
* # => Numo::Int32#shape=[10]
|
|
3886
|
+
* # [3, 3, 3, 3, 4, 5, 6, 6, 6, 6]
|
|
3887
|
+
*
|
|
3888
|
+
* b = Numo::Int32.new(10).seq
|
|
3889
|
+
* # => Numo::Int32#shape=[10]
|
|
3890
|
+
* # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
3891
|
+
*
|
|
3892
|
+
* b.clip([3,4,1,1,1,4,4,4,4,4], 8)
|
|
3893
|
+
* # => Numo::Int32#shape=[10]
|
|
3894
|
+
* # [3, 4, 2, 3, 4, 5, 6, 7, 8, 8]
|
|
3895
|
+
*/
|
|
5379
3896
|
rb_define_method(cT, "clip", robject_clip, 2);
|
|
5380
3897
|
rb_define_method(cT, "isnan", robject_isnan, 0);
|
|
5381
3898
|
rb_define_method(cT, "isinf", robject_isinf, 0);
|
|
5382
3899
|
rb_define_method(cT, "isposinf", robject_isposinf, 0);
|
|
5383
3900
|
rb_define_method(cT, "isneginf", robject_isneginf, 0);
|
|
5384
3901
|
rb_define_method(cT, "isfinite", robject_isfinite, 0);
|
|
3902
|
+
/**
|
|
3903
|
+
* sum of self.
|
|
3904
|
+
* @overload sum(axis:nil, keepdims:false, nan:false)
|
|
3905
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm
|
|
3906
|
+
* (avoid NaN for sum/mean etc, or, return NaN for min/max etc).
|
|
3907
|
+
* @param [Numeric,Array,Range] axis Performs sum along the axis.
|
|
3908
|
+
* @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
3909
|
+
* dimensions with size one.
|
|
3910
|
+
* @return [Numo::RObject] returns result of sum.
|
|
3911
|
+
*/
|
|
5385
3912
|
rb_define_method(cT, "sum", robject_sum, -1);
|
|
3913
|
+
/**
|
|
3914
|
+
* prod of self.
|
|
3915
|
+
* @overload prod(axis:nil, keepdims:false, nan:false)
|
|
3916
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm
|
|
3917
|
+
* (avoid NaN for sum/mean etc, or, return NaN for min/max etc).
|
|
3918
|
+
* @param [Numeric,Array,Range] axis Performs prod along the axis.
|
|
3919
|
+
* @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
3920
|
+
* dimensions with size one.
|
|
3921
|
+
* @return [Numo::RObject] returns result of prod.
|
|
3922
|
+
*/
|
|
5386
3923
|
rb_define_method(cT, "prod", robject_prod, -1);
|
|
5387
3924
|
/**
|
|
5388
3925
|
* mean of self.
|
|
@@ -5428,13 +3965,135 @@ void Init_numo_robject(void) {
|
|
|
5428
3965
|
* @return [Numo::RObject] returns result of rms.
|
|
5429
3966
|
*/
|
|
5430
3967
|
rb_define_method(cT, "rms", robject_rms, -1);
|
|
3968
|
+
/**
|
|
3969
|
+
* min of self.
|
|
3970
|
+
* @overload min(axis:nil, keepdims:false, nan:false)
|
|
3971
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm
|
|
3972
|
+
* (avoid NaN for sum/mean etc, or, return NaN for min/max etc).
|
|
3973
|
+
* @param [Numeric,Array,Range] axis Performs min along the axis.
|
|
3974
|
+
* @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
3975
|
+
* dimensions with size one.
|
|
3976
|
+
* @return [Numo::RObject] returns result of min.
|
|
3977
|
+
*/
|
|
5431
3978
|
rb_define_method(cT, "min", robject_min, -1);
|
|
3979
|
+
/**
|
|
3980
|
+
* max of self.
|
|
3981
|
+
* @overload max(axis:nil, keepdims:false, nan:false)
|
|
3982
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm
|
|
3983
|
+
* (avoid NaN for sum/mean etc, or, return NaN for min/max etc).
|
|
3984
|
+
* @param [Numeric,Array,Range] axis Performs max along the axis.
|
|
3985
|
+
* @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
3986
|
+
* dimensions with size one.
|
|
3987
|
+
* @return [Numo::RObject] returns result of max.
|
|
3988
|
+
*/
|
|
5432
3989
|
rb_define_method(cT, "max", robject_max, -1);
|
|
3990
|
+
/**
|
|
3991
|
+
* ptp of self.
|
|
3992
|
+
* @overload ptp(axis:nil, keepdims:false, nan:false)
|
|
3993
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm
|
|
3994
|
+
* (avoid NaN for sum/mean etc, or, return NaN for min/max etc).
|
|
3995
|
+
* @param [Numeric,Array,Range] axis Performs ptp along the axis.
|
|
3996
|
+
* @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
3997
|
+
* dimensions with size one.
|
|
3998
|
+
* @return [Numo::RObject] returns result of ptp.
|
|
3999
|
+
*/
|
|
5433
4000
|
rb_define_method(cT, "ptp", robject_ptp, -1);
|
|
4001
|
+
/**
|
|
4002
|
+
* Index of the maximum value.
|
|
4003
|
+
* @overload max_index(axis:nil, nan:false)
|
|
4004
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm (return
|
|
4005
|
+
* NaN posision if exist).
|
|
4006
|
+
* @param [Numeric,Array,Range] axis Finds maximum values along the axis and
|
|
4007
|
+
* returns **flat 1-d indices**.
|
|
4008
|
+
* @return [Integer,Numo::Int] returns result indices.
|
|
4009
|
+
* @see #argmax
|
|
4010
|
+
* @see #max
|
|
4011
|
+
*
|
|
4012
|
+
* @example
|
|
4013
|
+
* a = Numo::NArray[3,4,1,2]
|
|
4014
|
+
* a.max_index #=> 1
|
|
4015
|
+
*
|
|
4016
|
+
* b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
4017
|
+
* b.max_index #=> 5
|
|
4018
|
+
* b.max_index(axis:1) #=> [1, 5]
|
|
4019
|
+
* b.max_index(axis:0) #=> [0, 1, 5]
|
|
4020
|
+
* b[b.max_index(axis:0)] #=> [3, 4, 5]
|
|
4021
|
+
*/
|
|
5434
4022
|
rb_define_method(cT, "max_index", robject_max_index, -1);
|
|
4023
|
+
/**
|
|
4024
|
+
* Index of the minimum value.
|
|
4025
|
+
* @overload min_index(axis:nil, nan:false)
|
|
4026
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm (returnNaN posision if exist).
|
|
4027
|
+
* @param [Numeric,Array,Range] axis Finds minimum values along the axis and
|
|
4028
|
+
* returns **flat 1-d indices**.
|
|
4029
|
+
* @return [Integer,Numo::Int] returns result indices.
|
|
4030
|
+
* @see #argmin
|
|
4031
|
+
* @see #min
|
|
4032
|
+
*
|
|
4033
|
+
* @example
|
|
4034
|
+
* a = Numo::NArray[3,4,1,2]
|
|
4035
|
+
* a.min_index #=> 2
|
|
4036
|
+
*
|
|
4037
|
+
* b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
4038
|
+
* b.min_index #=> 4
|
|
4039
|
+
* b.min_index(axis:1) #=> [2, 4]
|
|
4040
|
+
* b.min_index(axis:0) #=> [3, 4, 2]
|
|
4041
|
+
* b[b.min_index(axis:0)] #=> [2, 0, 1]
|
|
4042
|
+
*/
|
|
5435
4043
|
rb_define_method(cT, "min_index", robject_min_index, -1);
|
|
4044
|
+
/**
|
|
4045
|
+
* Index of the maximum value.
|
|
4046
|
+
* @overload argmax(axis:nil, nan:false)
|
|
4047
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm (return NaN posision
|
|
4048
|
+
* if exist).
|
|
4049
|
+
* @param [Numeric,Array,Range] axis Finds maximum values along the axis and
|
|
4050
|
+
* returns **indices along the axis**.
|
|
4051
|
+
* @return [Integer,Numo::Int] returns the result indices.
|
|
4052
|
+
* @see #max_index
|
|
4053
|
+
* @see #max
|
|
4054
|
+
*
|
|
4055
|
+
* @example
|
|
4056
|
+
* a = Numo::NArray[3,4,1,2]
|
|
4057
|
+
* a.argmax #=> 1
|
|
4058
|
+
*
|
|
4059
|
+
* b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
4060
|
+
* b.argmax #=> 5
|
|
4061
|
+
* b.argmax(axis:1) #=> [1, 2]
|
|
4062
|
+
* b.argmax(axis:0) #=> [0, 0, 1]
|
|
4063
|
+
* b.at(b.argmax(axis:0), 0..-1) #=> [3, 4, 5]
|
|
4064
|
+
*/
|
|
5436
4065
|
rb_define_method(cT, "argmax", robject_argmax, -1);
|
|
4066
|
+
/**
|
|
4067
|
+
* Index of the minimum value.
|
|
4068
|
+
* @overload argmin(axis:nil, nan:false)
|
|
4069
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm (return
|
|
4070
|
+
* NaN posision if exist).
|
|
4071
|
+
* @param [Numeric,Array,Range] axis Finds minimum values along the axis and
|
|
4072
|
+
* returns **indices along the axis**.
|
|
4073
|
+
* @return [Integer,Numo::Int] returns the result indices.
|
|
4074
|
+
* @see #min_index
|
|
4075
|
+
* @see #min
|
|
4076
|
+
*
|
|
4077
|
+
* @example
|
|
4078
|
+
* a = Numo::NArray[3,4,1,2]
|
|
4079
|
+
* a.argmin #=> 2
|
|
4080
|
+
*
|
|
4081
|
+
* b = Numo::NArray[[3,4,1],[2,0,5]]
|
|
4082
|
+
* b.argmin #=> 4
|
|
4083
|
+
* b.argmin(axis:1) #=> [2, 1]
|
|
4084
|
+
* b.argmin(axis:0) #=> [1, 1, 0]
|
|
4085
|
+
* b.at(b.argmin(axis:0), 0..-1) #=> [2, 0, 1]
|
|
4086
|
+
*/
|
|
5437
4087
|
rb_define_method(cT, "argmin", robject_argmin, -1);
|
|
4088
|
+
/**
|
|
4089
|
+
* minmax of self.
|
|
4090
|
+
* @overload minmax(axis:nil, keepdims:false, nan:false)
|
|
4091
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm (return NaN if exist).
|
|
4092
|
+
* @param [Numeric,Array,Range] axis Finds min-max along the axis.
|
|
4093
|
+
* @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in
|
|
4094
|
+
* the result array as dimensions with size one.
|
|
4095
|
+
* @return [Numo::RObject,Numo::RObject] min and max of self.
|
|
4096
|
+
*/
|
|
5438
4097
|
rb_define_method(cT, "minmax", robject_minmax, -1);
|
|
5439
4098
|
/**
|
|
5440
4099
|
* Element-wise maximum of two arrays.
|
|
@@ -5454,13 +4113,106 @@ void Init_numo_robject(void) {
|
|
|
5454
4113
|
* @return [Numo::RObject]
|
|
5455
4114
|
*/
|
|
5456
4115
|
rb_define_module_function(cT, "minimum", robject_s_minimum, -1);
|
|
4116
|
+
/**
|
|
4117
|
+
* cumsum of self.
|
|
4118
|
+
* @overload cumsum(axis:nil, nan:false)
|
|
4119
|
+
* @param [Numeric,Array,Range] axis Performs cumsum along the axis.
|
|
4120
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4121
|
+
* @return [Numo::RObject] cumsum of self.
|
|
4122
|
+
*/
|
|
5457
4123
|
rb_define_method(cT, "cumsum", robject_cumsum, -1);
|
|
4124
|
+
/**
|
|
4125
|
+
* cumprod of self.
|
|
4126
|
+
* @overload cumprod(axis:nil, nan:false)
|
|
4127
|
+
* @param [Numeric,Array,Range] axis Performs cumprod along the axis.
|
|
4128
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4129
|
+
* @return [Numo::RObject] cumprod of self.
|
|
4130
|
+
*/
|
|
5458
4131
|
rb_define_method(cT, "cumprod", robject_cumprod, -1);
|
|
4132
|
+
/**
|
|
4133
|
+
* Binary mulsum.
|
|
4134
|
+
*
|
|
4135
|
+
* @overload mulsum(other, axis:nil, keepdims:false, nan:false)
|
|
4136
|
+
* @param [Numo::NArray,Numeric] other
|
|
4137
|
+
* @param [Numeric,Array,Range] axis Performs mulsum along the axis.
|
|
4138
|
+
* @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in
|
|
4139
|
+
* the result array as dimensions with size one.
|
|
4140
|
+
* @param [TrueClass] nan (keyword) If true, apply NaN-aware algorithm
|
|
4141
|
+
* (avoid NaN if exists).
|
|
4142
|
+
* @return [Numo::NArray] mulsum of self and other.
|
|
4143
|
+
*/
|
|
5459
4144
|
rb_define_method(cT, "mulsum", robject_mulsum, -1);
|
|
4145
|
+
/**
|
|
4146
|
+
* Set linear sequence of numbers to self. The sequence is obtained from
|
|
4147
|
+
* beg+i*step
|
|
4148
|
+
* where i is 1-dimensional index.
|
|
4149
|
+
* @overload seq([beg,[step]])
|
|
4150
|
+
* @param [Numeric] beg beginning of sequence. (default=0)
|
|
4151
|
+
* @param [Numeric] step step of sequence. (default=1)
|
|
4152
|
+
* @return [Numo::RObject] self.
|
|
4153
|
+
* @example
|
|
4154
|
+
* Numo::DFloat.new(6).seq(1,-0.2)
|
|
4155
|
+
* # => Numo::DFloat#shape=[6]
|
|
4156
|
+
* # [1, 0.8, 0.6, 0.4, 0.2, 0]
|
|
4157
|
+
*
|
|
4158
|
+
* Numo::DComplex.new(6).seq(1,-0.2+0.2i)
|
|
4159
|
+
* # => Numo::DComplex#shape=[6]
|
|
4160
|
+
* # [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]
|
|
4161
|
+
*/
|
|
5460
4162
|
rb_define_method(cT, "seq", robject_seq, -1);
|
|
4163
|
+
/**
|
|
4164
|
+
* Set logarithmic sequence of numbers to self. The sequence is obtained from
|
|
4165
|
+
* `base**(beg+i*step)`
|
|
4166
|
+
* where i is 1-dimensional index.
|
|
4167
|
+
* Applicable classes: DFloat, SFloat, DComplex, SCopmplex.
|
|
4168
|
+
*
|
|
4169
|
+
* @overload logseq(beg,step,[base])
|
|
4170
|
+
* @param [Numeric] beg The beginning of sequence.
|
|
4171
|
+
* @param [Numeric] step The step of sequence.
|
|
4172
|
+
* @param [Numeric] base The base of log space. (default=10)
|
|
4173
|
+
* @return [Numo::RObject] self.
|
|
4174
|
+
*
|
|
4175
|
+
* @example
|
|
4176
|
+
* Numo::DFloat.new(5).logseq(4,-1,2)
|
|
4177
|
+
* # => Numo::DFloat#shape=[5]
|
|
4178
|
+
* # [16, 8, 4, 2, 1]
|
|
4179
|
+
*
|
|
4180
|
+
* Numo::DComplex.new(5).logseq(0,1i*Math::PI/3,Math::E)
|
|
4181
|
+
* # => Numo::DComplex#shape=[5]
|
|
4182
|
+
* # [1+7.26156e-310i, 0.5+0.866025i, -0.5+0.866025i, -1+1.22465e-16i, ...]
|
|
4183
|
+
*/
|
|
5461
4184
|
rb_define_method(cT, "logseq", robject_logseq, -1);
|
|
4185
|
+
/**
|
|
4186
|
+
* Eye: Set a value to diagonal components, set 0 to non-diagonal components.
|
|
4187
|
+
* @overload eye([element,offset])
|
|
4188
|
+
* @param [Numeric] element Diagonal element to be stored. Default is 1.
|
|
4189
|
+
* @param [Integer] offset Diagonal offset from the main diagonal. The
|
|
4190
|
+
* default is 0. k>0 for diagonals above the main diagonal, and k<0
|
|
4191
|
+
* for diagonals below the main diagonal.
|
|
4192
|
+
* @return [Numo::RObject] eye of self.
|
|
4193
|
+
*/
|
|
5462
4194
|
rb_define_method(cT, "eye", robject_eye, -1);
|
|
5463
4195
|
rb_define_alias(cT, "indgen", "seq");
|
|
4196
|
+
/**
|
|
4197
|
+
* Generate uniformly distributed random numbers on self narray.
|
|
4198
|
+
* @overload rand([[low],high])
|
|
4199
|
+
* @param [Numeric] low lower inclusive boundary of random numbers. (default=0)
|
|
4200
|
+
* @param [Numeric] high upper exclusive boundary of random numbers.
|
|
4201
|
+
* (default=1 or 1+1i for complex types)
|
|
4202
|
+
* @return [Numo::RObject] self.
|
|
4203
|
+
* @example
|
|
4204
|
+
* Numo::DFloat.new(6).rand
|
|
4205
|
+
* # => Numo::DFloat#shape=[6]
|
|
4206
|
+
* # [0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032]
|
|
4207
|
+
*
|
|
4208
|
+
* Numo::DComplex.new(6).rand(5+5i)
|
|
4209
|
+
* # => Numo::DComplex#shape=[6]
|
|
4210
|
+
* # [2.69974+3.68908i, 0.825443+0.254414i, 0.540323+0.34354i, 4.52061+2.39322i, ...]
|
|
4211
|
+
*
|
|
4212
|
+
* Numo::Int32.new(6).rand(2,5)
|
|
4213
|
+
* # => Numo::Int32#shape=[6]
|
|
4214
|
+
* # [4, 3, 3, 2, 4, 2]
|
|
4215
|
+
*/
|
|
5464
4216
|
rb_define_method(cT, "rand", robject_rand, -1);
|
|
5465
4217
|
rb_define_method(cT, "poly", robject_poly, -2);
|
|
5466
4218
|
rb_define_singleton_method(cT, "[]", robject_s_cast, -2);
|