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
|
@@ -38,10 +38,19 @@ static ID id_to_a;
|
|
|
38
38
|
VALUE cT;
|
|
39
39
|
extern VALUE cRT;
|
|
40
40
|
|
|
41
|
+
#include "mh/sum.h"
|
|
42
|
+
#include "mh/prod.h"
|
|
41
43
|
#include "mh/mean.h"
|
|
42
44
|
#include "mh/var.h"
|
|
43
45
|
#include "mh/stddev.h"
|
|
44
46
|
#include "mh/rms.h"
|
|
47
|
+
#include "mh/cumsum.h"
|
|
48
|
+
#include "mh/cumprod.h"
|
|
49
|
+
#include "mh/mulsum.h"
|
|
50
|
+
#include "mh/seq.h"
|
|
51
|
+
#include "mh/logseq.h"
|
|
52
|
+
#include "mh/eye.h"
|
|
53
|
+
#include "mh/rand.h"
|
|
45
54
|
#include "mh/math/sqrt.h"
|
|
46
55
|
#include "mh/math/cbrt.h"
|
|
47
56
|
#include "mh/math/log.h"
|
|
@@ -64,10 +73,19 @@ extern VALUE cRT;
|
|
|
64
73
|
#include "mh/math/atanh.h"
|
|
65
74
|
#include "mh/math/sinc.h"
|
|
66
75
|
|
|
76
|
+
DEF_NARRAY_FLT_SUM_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
77
|
+
DEF_NARRAY_FLT_PROD_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
67
78
|
DEF_NARRAY_FLT_MEAN_METHOD_FUNC(dcomplex, numo_cDComplex, dcomplex, numo_cDComplex)
|
|
68
79
|
DEF_NARRAY_FLT_VAR_METHOD_FUNC(dcomplex, numo_cDComplex, double, numo_cDFloat)
|
|
69
80
|
DEF_NARRAY_FLT_STDDEV_METHOD_FUNC(dcomplex, numo_cDComplex, double, numo_cDFloat)
|
|
70
81
|
DEF_NARRAY_FLT_RMS_METHOD_FUNC(dcomplex, numo_cDComplex, double, numo_cDFloat)
|
|
82
|
+
DEF_NARRAY_FLT_CUMSUM_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
83
|
+
DEF_NARRAY_FLT_CUMPROD_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
84
|
+
DEF_NARRAY_FLT_MULSUM_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
85
|
+
DEF_NARRAY_FLT_SEQ_METHOD_FUNC(dcomplex)
|
|
86
|
+
DEF_NARRAY_FLT_LOGSEQ_METHOD_FUNC(dcomplex)
|
|
87
|
+
DEF_NARRAY_EYE_METHOD_FUNC(dcomplex)
|
|
88
|
+
DEF_NARRAY_FLT_RAND_METHOD_FUNC(dcomplex)
|
|
71
89
|
DEF_NARRAY_FLT_SQRT_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
72
90
|
DEF_NARRAY_FLT_CBRT_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
73
91
|
DEF_NARRAY_FLT_LOG_METHOD_FUNC(dcomplex, numo_cDComplex)
|
|
@@ -3999,98 +4017,6 @@ static VALUE dcomplex_isfinite(VALUE self) {
|
|
|
3999
4017
|
return na_ndloop(&ndf, 1, self);
|
|
4000
4018
|
}
|
|
4001
4019
|
|
|
4002
|
-
static void iter_dcomplex_sum(na_loop_t* const lp) {
|
|
4003
|
-
size_t n;
|
|
4004
|
-
char *p1, *p2;
|
|
4005
|
-
ssize_t s1;
|
|
4006
|
-
|
|
4007
|
-
INIT_COUNTER(lp, n);
|
|
4008
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4009
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
4010
|
-
|
|
4011
|
-
*(dtype*)p2 = f_sum(n, p1, s1);
|
|
4012
|
-
}
|
|
4013
|
-
static void iter_dcomplex_sum_nan(na_loop_t* const lp) {
|
|
4014
|
-
size_t n;
|
|
4015
|
-
char *p1, *p2;
|
|
4016
|
-
ssize_t s1;
|
|
4017
|
-
|
|
4018
|
-
INIT_COUNTER(lp, n);
|
|
4019
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4020
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
4021
|
-
|
|
4022
|
-
*(dtype*)p2 = f_sum_nan(n, p1, s1);
|
|
4023
|
-
}
|
|
4024
|
-
|
|
4025
|
-
/*
|
|
4026
|
-
sum of self.
|
|
4027
|
-
@overload sum(axis:nil, keepdims:false, nan:false)
|
|
4028
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or,
|
|
4029
|
-
return NaN for min/max etc).
|
|
4030
|
-
@param [Numeric,Array,Range] axis Performs sum along the axis.
|
|
4031
|
-
@param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
4032
|
-
dimensions with size one.
|
|
4033
|
-
@return [Numo::DComplex] returns result of sum.
|
|
4034
|
-
*/
|
|
4035
|
-
static VALUE dcomplex_sum(int argc, VALUE* argv, VALUE self) {
|
|
4036
|
-
VALUE v, reduce;
|
|
4037
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
4038
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4039
|
-
ndfunc_t ndf = { iter_dcomplex_sum, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
|
4040
|
-
|
|
4041
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_dcomplex_sum_nan);
|
|
4042
|
-
|
|
4043
|
-
v = na_ndloop(&ndf, 2, self, reduce);
|
|
4044
|
-
|
|
4045
|
-
return dcomplex_extract(v);
|
|
4046
|
-
}
|
|
4047
|
-
|
|
4048
|
-
static void iter_dcomplex_prod(na_loop_t* const lp) {
|
|
4049
|
-
size_t n;
|
|
4050
|
-
char *p1, *p2;
|
|
4051
|
-
ssize_t s1;
|
|
4052
|
-
|
|
4053
|
-
INIT_COUNTER(lp, n);
|
|
4054
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4055
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
4056
|
-
|
|
4057
|
-
*(dtype*)p2 = f_prod(n, p1, s1);
|
|
4058
|
-
}
|
|
4059
|
-
static void iter_dcomplex_prod_nan(na_loop_t* const lp) {
|
|
4060
|
-
size_t n;
|
|
4061
|
-
char *p1, *p2;
|
|
4062
|
-
ssize_t s1;
|
|
4063
|
-
|
|
4064
|
-
INIT_COUNTER(lp, n);
|
|
4065
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4066
|
-
p2 = lp->args[1].ptr + lp->args[1].iter[0].pos;
|
|
4067
|
-
|
|
4068
|
-
*(dtype*)p2 = f_prod_nan(n, p1, s1);
|
|
4069
|
-
}
|
|
4070
|
-
|
|
4071
|
-
/*
|
|
4072
|
-
prod of self.
|
|
4073
|
-
@overload prod(axis:nil, keepdims:false, nan:false)
|
|
4074
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN for sum/mean etc, or,
|
|
4075
|
-
return NaN for min/max etc).
|
|
4076
|
-
@param [Numeric,Array,Range] axis Performs prod along the axis.
|
|
4077
|
-
@param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
4078
|
-
dimensions with size one.
|
|
4079
|
-
@return [Numo::DComplex] returns result of prod.
|
|
4080
|
-
*/
|
|
4081
|
-
static VALUE dcomplex_prod(int argc, VALUE* argv, VALUE self) {
|
|
4082
|
-
VALUE v, reduce;
|
|
4083
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
4084
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4085
|
-
ndfunc_t ndf = { iter_dcomplex_prod, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
|
4086
|
-
|
|
4087
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_dcomplex_prod_nan);
|
|
4088
|
-
|
|
4089
|
-
v = na_ndloop(&ndf, 2, self, reduce);
|
|
4090
|
-
|
|
4091
|
-
return dcomplex_extract(v);
|
|
4092
|
-
}
|
|
4093
|
-
|
|
4094
4020
|
static void iter_dcomplex_kahan_sum(na_loop_t* const lp) {
|
|
4095
4021
|
size_t n;
|
|
4096
4022
|
char *p1, *p2;
|
|
@@ -4139,581 +4065,6 @@ static VALUE dcomplex_kahan_sum(int argc, VALUE* argv, VALUE self) {
|
|
|
4139
4065
|
return dcomplex_extract(v);
|
|
4140
4066
|
}
|
|
4141
4067
|
|
|
4142
|
-
static void iter_dcomplex_cumsum(na_loop_t* const lp) {
|
|
4143
|
-
size_t i;
|
|
4144
|
-
char *p1, *p2;
|
|
4145
|
-
ssize_t s1, s2;
|
|
4146
|
-
dtype x, y;
|
|
4147
|
-
|
|
4148
|
-
INIT_COUNTER(lp, i);
|
|
4149
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4150
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4151
|
-
|
|
4152
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4153
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4154
|
-
for (i--; i--;) {
|
|
4155
|
-
GET_DATA_STRIDE(p1, s1, dtype, y);
|
|
4156
|
-
m_cumsum(x, y);
|
|
4157
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4158
|
-
}
|
|
4159
|
-
}
|
|
4160
|
-
static void iter_dcomplex_cumsum_nan(na_loop_t* const lp) {
|
|
4161
|
-
size_t i;
|
|
4162
|
-
char *p1, *p2;
|
|
4163
|
-
ssize_t s1, s2;
|
|
4164
|
-
dtype x, y;
|
|
4165
|
-
|
|
4166
|
-
INIT_COUNTER(lp, i);
|
|
4167
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4168
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4169
|
-
|
|
4170
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4171
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4172
|
-
for (i--; i--;) {
|
|
4173
|
-
GET_DATA_STRIDE(p1, s1, dtype, y);
|
|
4174
|
-
m_cumsum_nan(x, y);
|
|
4175
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4176
|
-
}
|
|
4177
|
-
}
|
|
4178
|
-
|
|
4179
|
-
/*
|
|
4180
|
-
cumsum of self.
|
|
4181
|
-
@overload cumsum(axis:nil, nan:false)
|
|
4182
|
-
@param [Numeric,Array,Range] axis Performs cumsum along the axis.
|
|
4183
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4184
|
-
@return [Numo::DComplex] cumsum of self.
|
|
4185
|
-
*/
|
|
4186
|
-
static VALUE dcomplex_cumsum(int argc, VALUE* argv, VALUE self) {
|
|
4187
|
-
VALUE reduce;
|
|
4188
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
4189
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4190
|
-
ndfunc_t ndf = {
|
|
4191
|
-
iter_dcomplex_cumsum, STRIDE_LOOP | NDF_FLAT_REDUCE | NDF_CUM, 2, 1, ain, aout
|
|
4192
|
-
};
|
|
4193
|
-
|
|
4194
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_dcomplex_cumsum_nan);
|
|
4195
|
-
|
|
4196
|
-
return na_ndloop(&ndf, 2, self, reduce);
|
|
4197
|
-
}
|
|
4198
|
-
|
|
4199
|
-
static void iter_dcomplex_cumprod(na_loop_t* const lp) {
|
|
4200
|
-
size_t i;
|
|
4201
|
-
char *p1, *p2;
|
|
4202
|
-
ssize_t s1, s2;
|
|
4203
|
-
dtype x, y;
|
|
4204
|
-
|
|
4205
|
-
INIT_COUNTER(lp, i);
|
|
4206
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4207
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4208
|
-
|
|
4209
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4210
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4211
|
-
for (i--; i--;) {
|
|
4212
|
-
GET_DATA_STRIDE(p1, s1, dtype, y);
|
|
4213
|
-
m_cumprod(x, y);
|
|
4214
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4215
|
-
}
|
|
4216
|
-
}
|
|
4217
|
-
static void iter_dcomplex_cumprod_nan(na_loop_t* const lp) {
|
|
4218
|
-
size_t i;
|
|
4219
|
-
char *p1, *p2;
|
|
4220
|
-
ssize_t s1, s2;
|
|
4221
|
-
dtype x, y;
|
|
4222
|
-
|
|
4223
|
-
INIT_COUNTER(lp, i);
|
|
4224
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4225
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4226
|
-
|
|
4227
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4228
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4229
|
-
for (i--; i--;) {
|
|
4230
|
-
GET_DATA_STRIDE(p1, s1, dtype, y);
|
|
4231
|
-
m_cumprod_nan(x, y);
|
|
4232
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4233
|
-
}
|
|
4234
|
-
}
|
|
4235
|
-
|
|
4236
|
-
/*
|
|
4237
|
-
cumprod of self.
|
|
4238
|
-
@overload cumprod(axis:nil, nan:false)
|
|
4239
|
-
@param [Numeric,Array,Range] axis Performs cumprod along the axis.
|
|
4240
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4241
|
-
@return [Numo::DComplex] cumprod of self.
|
|
4242
|
-
*/
|
|
4243
|
-
static VALUE dcomplex_cumprod(int argc, VALUE* argv, VALUE self) {
|
|
4244
|
-
VALUE reduce;
|
|
4245
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
4246
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4247
|
-
ndfunc_t ndf = {
|
|
4248
|
-
iter_dcomplex_cumprod, STRIDE_LOOP | NDF_FLAT_REDUCE | NDF_CUM, 2, 1, ain, aout
|
|
4249
|
-
};
|
|
4250
|
-
|
|
4251
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_dcomplex_cumprod_nan);
|
|
4252
|
-
|
|
4253
|
-
return na_ndloop(&ndf, 2, self, reduce);
|
|
4254
|
-
}
|
|
4255
|
-
|
|
4256
|
-
//
|
|
4257
|
-
static void iter_dcomplex_mulsum(na_loop_t* const lp) {
|
|
4258
|
-
size_t i, n;
|
|
4259
|
-
char *p1, *p2, *p3;
|
|
4260
|
-
ssize_t s1, s2, s3;
|
|
4261
|
-
|
|
4262
|
-
INIT_COUNTER(lp, n);
|
|
4263
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4264
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4265
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
4266
|
-
|
|
4267
|
-
if (s3 == 0) {
|
|
4268
|
-
dtype z;
|
|
4269
|
-
// Reduce loop
|
|
4270
|
-
GET_DATA(p3, dtype, z);
|
|
4271
|
-
for (i = 0; i < n; i++) {
|
|
4272
|
-
dtype x, y;
|
|
4273
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4274
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4275
|
-
m_mulsum(x, y, z);
|
|
4276
|
-
}
|
|
4277
|
-
SET_DATA(p3, dtype, z);
|
|
4278
|
-
return;
|
|
4279
|
-
} else {
|
|
4280
|
-
for (i = 0; i < n; i++) {
|
|
4281
|
-
dtype x, y, z;
|
|
4282
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4283
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4284
|
-
GET_DATA(p3, dtype, z);
|
|
4285
|
-
m_mulsum(x, y, z);
|
|
4286
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
4287
|
-
}
|
|
4288
|
-
}
|
|
4289
|
-
}
|
|
4290
|
-
//
|
|
4291
|
-
static void iter_dcomplex_mulsum_nan(na_loop_t* const lp) {
|
|
4292
|
-
size_t i, n;
|
|
4293
|
-
char *p1, *p2, *p3;
|
|
4294
|
-
ssize_t s1, s2, s3;
|
|
4295
|
-
|
|
4296
|
-
INIT_COUNTER(lp, n);
|
|
4297
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4298
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4299
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
4300
|
-
|
|
4301
|
-
if (s3 == 0) {
|
|
4302
|
-
dtype z;
|
|
4303
|
-
// Reduce loop
|
|
4304
|
-
GET_DATA(p3, dtype, z);
|
|
4305
|
-
for (i = 0; i < n; i++) {
|
|
4306
|
-
dtype x, y;
|
|
4307
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4308
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4309
|
-
m_mulsum_nan(x, y, z);
|
|
4310
|
-
}
|
|
4311
|
-
SET_DATA(p3, dtype, z);
|
|
4312
|
-
return;
|
|
4313
|
-
} else {
|
|
4314
|
-
for (i = 0; i < n; i++) {
|
|
4315
|
-
dtype x, y, z;
|
|
4316
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4317
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4318
|
-
GET_DATA(p3, dtype, z);
|
|
4319
|
-
m_mulsum_nan(x, y, z);
|
|
4320
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
4321
|
-
}
|
|
4322
|
-
}
|
|
4323
|
-
}
|
|
4324
|
-
//
|
|
4325
|
-
|
|
4326
|
-
static VALUE dcomplex_mulsum_self(int argc, VALUE* argv, VALUE self) {
|
|
4327
|
-
VALUE v, reduce;
|
|
4328
|
-
VALUE naryv[2];
|
|
4329
|
-
ndfunc_arg_in_t ain[4] = { { cT, 0 }, { cT, 0 }, { sym_reduce, 0 }, { sym_init, 0 } };
|
|
4330
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4331
|
-
ndfunc_t ndf = { iter_dcomplex_mulsum, STRIDE_LOOP_NIP, 4, 1, ain, aout };
|
|
4332
|
-
|
|
4333
|
-
if (argc < 1) {
|
|
4334
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for >=1)", argc);
|
|
4335
|
-
}
|
|
4336
|
-
// should fix below: [self.ndim,other.ndim].max or?
|
|
4337
|
-
naryv[0] = self;
|
|
4338
|
-
naryv[1] = argv[0];
|
|
4339
|
-
//
|
|
4340
|
-
reduce = na_reduce_dimension(argc - 1, argv + 1, 2, naryv, &ndf, iter_dcomplex_mulsum_nan);
|
|
4341
|
-
//
|
|
4342
|
-
|
|
4343
|
-
v = na_ndloop(&ndf, 4, self, argv[0], reduce, m_mulsum_init);
|
|
4344
|
-
return dcomplex_extract(v);
|
|
4345
|
-
}
|
|
4346
|
-
|
|
4347
|
-
/*
|
|
4348
|
-
Binary mulsum.
|
|
4349
|
-
|
|
4350
|
-
@overload mulsum(other, axis:nil, keepdims:false, nan:false)
|
|
4351
|
-
@param [Numo::NArray,Numeric] other
|
|
4352
|
-
@param [Numeric,Array,Range] axis Performs mulsum along the axis.
|
|
4353
|
-
@param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array
|
|
4354
|
-
as dimensions with size one.
|
|
4355
|
-
@param [TrueClass] nan (keyword) If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4356
|
-
@return [Numo::NArray] mulsum of self and other.
|
|
4357
|
-
*/
|
|
4358
|
-
static VALUE dcomplex_mulsum(int argc, VALUE* argv, VALUE self) {
|
|
4359
|
-
//
|
|
4360
|
-
VALUE klass, v;
|
|
4361
|
-
//
|
|
4362
|
-
if (argc < 1) {
|
|
4363
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for >=1)", argc);
|
|
4364
|
-
}
|
|
4365
|
-
//
|
|
4366
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(argv[0]));
|
|
4367
|
-
if (klass == cT) {
|
|
4368
|
-
return dcomplex_mulsum_self(argc, argv, self);
|
|
4369
|
-
} else {
|
|
4370
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
4371
|
-
//
|
|
4372
|
-
return rb_funcallv_kw(v, rb_intern("mulsum"), argc, argv, RB_PASS_CALLED_KEYWORDS);
|
|
4373
|
-
//
|
|
4374
|
-
}
|
|
4375
|
-
//
|
|
4376
|
-
}
|
|
4377
|
-
|
|
4378
|
-
typedef dtype seq_data_t;
|
|
4379
|
-
|
|
4380
|
-
typedef double seq_count_t;
|
|
4381
|
-
|
|
4382
|
-
typedef struct {
|
|
4383
|
-
seq_data_t beg;
|
|
4384
|
-
seq_data_t step;
|
|
4385
|
-
seq_count_t count;
|
|
4386
|
-
} seq_opt_t;
|
|
4387
|
-
|
|
4388
|
-
static void iter_dcomplex_seq(na_loop_t* const lp) {
|
|
4389
|
-
size_t i;
|
|
4390
|
-
char* p1;
|
|
4391
|
-
ssize_t s1;
|
|
4392
|
-
size_t* idx1;
|
|
4393
|
-
dtype x;
|
|
4394
|
-
seq_data_t beg, step;
|
|
4395
|
-
seq_count_t c;
|
|
4396
|
-
seq_opt_t* g;
|
|
4397
|
-
|
|
4398
|
-
INIT_COUNTER(lp, i);
|
|
4399
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
4400
|
-
g = (seq_opt_t*)(lp->opt_ptr);
|
|
4401
|
-
beg = g->beg;
|
|
4402
|
-
step = g->step;
|
|
4403
|
-
c = g->count;
|
|
4404
|
-
if (idx1) {
|
|
4405
|
-
for (; i--;) {
|
|
4406
|
-
x = f_seq(beg, step, c++);
|
|
4407
|
-
*(dtype*)(p1 + *idx1) = x;
|
|
4408
|
-
idx1++;
|
|
4409
|
-
}
|
|
4410
|
-
} else {
|
|
4411
|
-
for (; i--;) {
|
|
4412
|
-
x = f_seq(beg, step, c++);
|
|
4413
|
-
*(dtype*)(p1) = x;
|
|
4414
|
-
p1 += s1;
|
|
4415
|
-
}
|
|
4416
|
-
}
|
|
4417
|
-
g->count = c;
|
|
4418
|
-
}
|
|
4419
|
-
|
|
4420
|
-
/*
|
|
4421
|
-
Set linear sequence of numbers to self. The sequence is obtained from
|
|
4422
|
-
beg+i*step
|
|
4423
|
-
where i is 1-dimensional index.
|
|
4424
|
-
@overload seq([beg,[step]])
|
|
4425
|
-
@param [Numeric] beg beginning of sequence. (default=0)
|
|
4426
|
-
@param [Numeric] step step of sequence. (default=1)
|
|
4427
|
-
@return [Numo::DComplex] self.
|
|
4428
|
-
@example
|
|
4429
|
-
Numo::DFloat.new(6).seq(1,-0.2)
|
|
4430
|
-
# => Numo::DFloat#shape=[6]
|
|
4431
|
-
# [1, 0.8, 0.6, 0.4, 0.2, 0]
|
|
4432
|
-
|
|
4433
|
-
Numo::DComplex.new(6).seq(1,-0.2+0.2i)
|
|
4434
|
-
# => Numo::DComplex#shape=[6]
|
|
4435
|
-
# [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]
|
|
4436
|
-
*/
|
|
4437
|
-
static VALUE dcomplex_seq(int argc, VALUE* argv, VALUE self) {
|
|
4438
|
-
seq_opt_t* g;
|
|
4439
|
-
VALUE vbeg = Qnil, vstep = Qnil;
|
|
4440
|
-
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } };
|
|
4441
|
-
ndfunc_t ndf = { iter_dcomplex_seq, FULL_LOOP, 1, 0, ain, 0 };
|
|
4442
|
-
|
|
4443
|
-
g = ALLOCA_N(seq_opt_t, 1);
|
|
4444
|
-
g->beg = m_zero;
|
|
4445
|
-
g->step = m_one;
|
|
4446
|
-
g->count = 0;
|
|
4447
|
-
rb_scan_args(argc, argv, "02", &vbeg, &vstep);
|
|
4448
|
-
if (vbeg != Qnil) {
|
|
4449
|
-
g->beg = m_num_to_data(vbeg);
|
|
4450
|
-
}
|
|
4451
|
-
if (vstep != Qnil) {
|
|
4452
|
-
g->step = m_num_to_data(vstep);
|
|
4453
|
-
}
|
|
4454
|
-
|
|
4455
|
-
na_ndloop3(&ndf, g, 1, self);
|
|
4456
|
-
return self;
|
|
4457
|
-
}
|
|
4458
|
-
|
|
4459
|
-
typedef struct {
|
|
4460
|
-
seq_data_t beg;
|
|
4461
|
-
seq_data_t step;
|
|
4462
|
-
seq_data_t base;
|
|
4463
|
-
seq_count_t count;
|
|
4464
|
-
} logseq_opt_t;
|
|
4465
|
-
|
|
4466
|
-
static void iter_dcomplex_logseq(na_loop_t* const lp) {
|
|
4467
|
-
size_t i;
|
|
4468
|
-
char* p1;
|
|
4469
|
-
ssize_t s1;
|
|
4470
|
-
size_t* idx1;
|
|
4471
|
-
dtype x;
|
|
4472
|
-
seq_data_t beg, step, base;
|
|
4473
|
-
seq_count_t c;
|
|
4474
|
-
logseq_opt_t* g;
|
|
4475
|
-
|
|
4476
|
-
INIT_COUNTER(lp, i);
|
|
4477
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
4478
|
-
g = (logseq_opt_t*)(lp->opt_ptr);
|
|
4479
|
-
beg = g->beg;
|
|
4480
|
-
step = g->step;
|
|
4481
|
-
base = g->base;
|
|
4482
|
-
c = g->count;
|
|
4483
|
-
if (idx1) {
|
|
4484
|
-
for (; i--;) {
|
|
4485
|
-
x = f_seq(beg, step, c++);
|
|
4486
|
-
*(dtype*)(p1 + *idx1) = m_pow(base, x);
|
|
4487
|
-
idx1++;
|
|
4488
|
-
}
|
|
4489
|
-
} else {
|
|
4490
|
-
for (; i--;) {
|
|
4491
|
-
x = f_seq(beg, step, c++);
|
|
4492
|
-
*(dtype*)(p1) = m_pow(base, x);
|
|
4493
|
-
p1 += s1;
|
|
4494
|
-
}
|
|
4495
|
-
}
|
|
4496
|
-
g->count = c;
|
|
4497
|
-
}
|
|
4498
|
-
|
|
4499
|
-
/*
|
|
4500
|
-
Set logarithmic sequence of numbers to self. The sequence is obtained from
|
|
4501
|
-
`base**(beg+i*step)`
|
|
4502
|
-
where i is 1-dimensional index.
|
|
4503
|
-
Applicable classes: DFloat, SFloat, DComplex, SCopmplex.
|
|
4504
|
-
|
|
4505
|
-
@overload logseq(beg,step,[base])
|
|
4506
|
-
@param [Numeric] beg The beginning of sequence.
|
|
4507
|
-
@param [Numeric] step The step of sequence.
|
|
4508
|
-
@param [Numeric] base The base of log space. (default=10)
|
|
4509
|
-
@return [Numo::DComplex] self.
|
|
4510
|
-
|
|
4511
|
-
@example
|
|
4512
|
-
Numo::DFloat.new(5).logseq(4,-1,2)
|
|
4513
|
-
# => Numo::DFloat#shape=[5]
|
|
4514
|
-
# [16, 8, 4, 2, 1]
|
|
4515
|
-
|
|
4516
|
-
Numo::DComplex.new(5).logseq(0,1i*Math::PI/3,Math::E)
|
|
4517
|
-
# => Numo::DComplex#shape=[5]
|
|
4518
|
-
# [1+7.26156e-310i, 0.5+0.866025i, -0.5+0.866025i, -1+1.22465e-16i, ...]
|
|
4519
|
-
*/
|
|
4520
|
-
static VALUE dcomplex_logseq(int argc, VALUE* argv, VALUE self) {
|
|
4521
|
-
logseq_opt_t* g;
|
|
4522
|
-
VALUE vbeg, vstep, vbase;
|
|
4523
|
-
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } };
|
|
4524
|
-
ndfunc_t ndf = { iter_dcomplex_logseq, FULL_LOOP, 1, 0, ain, 0 };
|
|
4525
|
-
|
|
4526
|
-
g = ALLOCA_N(logseq_opt_t, 1);
|
|
4527
|
-
rb_scan_args(argc, argv, "21", &vbeg, &vstep, &vbase);
|
|
4528
|
-
g->beg = m_num_to_data(vbeg);
|
|
4529
|
-
g->step = m_num_to_data(vstep);
|
|
4530
|
-
if (vbase == Qnil) {
|
|
4531
|
-
g->base = m_from_real(10);
|
|
4532
|
-
} else {
|
|
4533
|
-
g->base = m_num_to_data(vbase);
|
|
4534
|
-
}
|
|
4535
|
-
na_ndloop3(&ndf, g, 1, self);
|
|
4536
|
-
return self;
|
|
4537
|
-
}
|
|
4538
|
-
|
|
4539
|
-
static void iter_dcomplex_eye(na_loop_t* const lp) {
|
|
4540
|
-
size_t n0, n1;
|
|
4541
|
-
size_t i0, i1;
|
|
4542
|
-
ssize_t s0, s1;
|
|
4543
|
-
char *p0, *p1;
|
|
4544
|
-
char* g;
|
|
4545
|
-
ssize_t kofs;
|
|
4546
|
-
dtype data;
|
|
4547
|
-
|
|
4548
|
-
g = (char*)(lp->opt_ptr);
|
|
4549
|
-
kofs = *(ssize_t*)g;
|
|
4550
|
-
data = *(dtype*)(g + sizeof(ssize_t));
|
|
4551
|
-
|
|
4552
|
-
n0 = lp->args[0].shape[0];
|
|
4553
|
-
n1 = lp->args[0].shape[1];
|
|
4554
|
-
s0 = lp->args[0].iter[0].step;
|
|
4555
|
-
s1 = lp->args[0].iter[1].step;
|
|
4556
|
-
p0 = NDL_PTR(lp, 0);
|
|
4557
|
-
|
|
4558
|
-
for (i0 = 0; i0 < n0; i0++) {
|
|
4559
|
-
p1 = p0;
|
|
4560
|
-
for (i1 = 0; i1 < n1; i1++) {
|
|
4561
|
-
*(dtype*)p1 = (i0 + kofs == i1) ? data : m_zero;
|
|
4562
|
-
p1 += s1;
|
|
4563
|
-
}
|
|
4564
|
-
p0 += s0;
|
|
4565
|
-
}
|
|
4566
|
-
}
|
|
4567
|
-
|
|
4568
|
-
/*
|
|
4569
|
-
Eye: Set a value to diagonal components, set 0 to non-diagonal components.
|
|
4570
|
-
@overload eye([element,offset])
|
|
4571
|
-
@param [Numeric] element Diagonal element to be stored. Default is 1.
|
|
4572
|
-
@param [Integer] offset Diagonal offset from the main diagonal. The
|
|
4573
|
-
default is 0. k>0 for diagonals above the main diagonal, and k<0
|
|
4574
|
-
for diagonals below the main diagonal.
|
|
4575
|
-
@return [Numo::DComplex] eye of self.
|
|
4576
|
-
*/
|
|
4577
|
-
static VALUE dcomplex_eye(int argc, VALUE* argv, VALUE self) {
|
|
4578
|
-
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 2 } };
|
|
4579
|
-
ndfunc_t ndf = { iter_dcomplex_eye, NO_LOOP, 1, 0, ain, 0 };
|
|
4580
|
-
ssize_t kofs;
|
|
4581
|
-
dtype data;
|
|
4582
|
-
char* g;
|
|
4583
|
-
int nd;
|
|
4584
|
-
narray_t* na;
|
|
4585
|
-
|
|
4586
|
-
// check arguments
|
|
4587
|
-
if (argc > 2) {
|
|
4588
|
-
rb_raise(rb_eArgError, "too many arguments (%d for 0..2)", argc);
|
|
4589
|
-
} else if (argc == 2) {
|
|
4590
|
-
data = m_num_to_data(argv[0]);
|
|
4591
|
-
kofs = NUM2SSIZET(argv[1]);
|
|
4592
|
-
} else if (argc == 1) {
|
|
4593
|
-
data = m_num_to_data(argv[0]);
|
|
4594
|
-
kofs = 0;
|
|
4595
|
-
} else {
|
|
4596
|
-
data = m_one;
|
|
4597
|
-
kofs = 0;
|
|
4598
|
-
}
|
|
4599
|
-
|
|
4600
|
-
GetNArray(self, na);
|
|
4601
|
-
nd = na->ndim;
|
|
4602
|
-
if (nd < 2) {
|
|
4603
|
-
rb_raise(nary_eDimensionError, "less than 2-d array");
|
|
4604
|
-
}
|
|
4605
|
-
|
|
4606
|
-
// Diagonal offset from the main diagonal.
|
|
4607
|
-
if (kofs >= 0) {
|
|
4608
|
-
if ((size_t)(kofs) >= na->shape[nd - 1]) {
|
|
4609
|
-
rb_raise(
|
|
4610
|
-
rb_eArgError,
|
|
4611
|
-
"invalid diagonal offset(%" SZF "d) for "
|
|
4612
|
-
"last dimension size(%" SZF "d)",
|
|
4613
|
-
kofs, na->shape[nd - 1]
|
|
4614
|
-
);
|
|
4615
|
-
}
|
|
4616
|
-
} else {
|
|
4617
|
-
if ((size_t)(-kofs) >= na->shape[nd - 2]) {
|
|
4618
|
-
rb_raise(
|
|
4619
|
-
rb_eArgError,
|
|
4620
|
-
"invalid diagonal offset(%" SZF "d) for "
|
|
4621
|
-
"last-1 dimension size(%" SZF "d)",
|
|
4622
|
-
kofs, na->shape[nd - 2]
|
|
4623
|
-
);
|
|
4624
|
-
}
|
|
4625
|
-
}
|
|
4626
|
-
|
|
4627
|
-
g = ALLOCA_N(char, sizeof(ssize_t) + sizeof(dtype));
|
|
4628
|
-
*(ssize_t*)g = kofs;
|
|
4629
|
-
*(dtype*)(g + sizeof(ssize_t)) = data;
|
|
4630
|
-
|
|
4631
|
-
na_ndloop3(&ndf, g, 1, self);
|
|
4632
|
-
return self;
|
|
4633
|
-
}
|
|
4634
|
-
|
|
4635
|
-
typedef struct {
|
|
4636
|
-
dtype low;
|
|
4637
|
-
dtype max;
|
|
4638
|
-
} rand_opt_t;
|
|
4639
|
-
|
|
4640
|
-
static void iter_dcomplex_rand(na_loop_t* const lp) {
|
|
4641
|
-
size_t i;
|
|
4642
|
-
char* p1;
|
|
4643
|
-
ssize_t s1;
|
|
4644
|
-
size_t* idx1;
|
|
4645
|
-
dtype x;
|
|
4646
|
-
rand_opt_t* g;
|
|
4647
|
-
dtype low;
|
|
4648
|
-
dtype max;
|
|
4649
|
-
|
|
4650
|
-
INIT_COUNTER(lp, i);
|
|
4651
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
4652
|
-
g = (rand_opt_t*)(lp->opt_ptr);
|
|
4653
|
-
low = g->low;
|
|
4654
|
-
max = g->max;
|
|
4655
|
-
|
|
4656
|
-
if (idx1) {
|
|
4657
|
-
for (; i--;) {
|
|
4658
|
-
x = m_add(m_rand(max), low);
|
|
4659
|
-
SET_DATA_INDEX(p1, idx1, dtype, x);
|
|
4660
|
-
}
|
|
4661
|
-
} else {
|
|
4662
|
-
for (; i--;) {
|
|
4663
|
-
x = m_add(m_rand(max), low);
|
|
4664
|
-
SET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4665
|
-
}
|
|
4666
|
-
}
|
|
4667
|
-
}
|
|
4668
|
-
|
|
4669
|
-
/*
|
|
4670
|
-
Generate uniformly distributed random numbers on self narray.
|
|
4671
|
-
@overload rand([[low],high])
|
|
4672
|
-
@param [Numeric] low lower inclusive boundary of random numbers. (default=0)
|
|
4673
|
-
@param [Numeric] high upper exclusive boundary of random numbers. (default=1 or 1+1i for
|
|
4674
|
-
complex types)
|
|
4675
|
-
@return [Numo::DComplex] self.
|
|
4676
|
-
@example
|
|
4677
|
-
Numo::DFloat.new(6).rand
|
|
4678
|
-
# => Numo::DFloat#shape=[6]
|
|
4679
|
-
# [0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032]
|
|
4680
|
-
|
|
4681
|
-
Numo::DComplex.new(6).rand(5+5i)
|
|
4682
|
-
# => Numo::DComplex#shape=[6]
|
|
4683
|
-
# [2.69974+3.68908i, 0.825443+0.254414i, 0.540323+0.34354i, 4.52061+2.39322i, ...]
|
|
4684
|
-
|
|
4685
|
-
Numo::Int32.new(6).rand(2,5)
|
|
4686
|
-
# => Numo::Int32#shape=[6]
|
|
4687
|
-
# [4, 3, 3, 2, 4, 2]
|
|
4688
|
-
*/
|
|
4689
|
-
static VALUE dcomplex_rand(int argc, VALUE* argv, VALUE self) {
|
|
4690
|
-
rand_opt_t g;
|
|
4691
|
-
VALUE v1 = Qnil, v2 = Qnil;
|
|
4692
|
-
dtype high;
|
|
4693
|
-
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } };
|
|
4694
|
-
ndfunc_t ndf = { iter_dcomplex_rand, FULL_LOOP, 1, 0, ain, 0 };
|
|
4695
|
-
|
|
4696
|
-
rb_scan_args(argc, argv, "02", &v1, &v2);
|
|
4697
|
-
if (v2 == Qnil) {
|
|
4698
|
-
g.low = m_zero;
|
|
4699
|
-
if (v1 == Qnil) {
|
|
4700
|
-
|
|
4701
|
-
g.max = high = c_new(1, 1);
|
|
4702
|
-
|
|
4703
|
-
} else {
|
|
4704
|
-
g.max = high = m_num_to_data(v1);
|
|
4705
|
-
}
|
|
4706
|
-
|
|
4707
|
-
} else {
|
|
4708
|
-
g.low = m_num_to_data(v1);
|
|
4709
|
-
high = m_num_to_data(v2);
|
|
4710
|
-
g.max = m_sub(high, g.low);
|
|
4711
|
-
}
|
|
4712
|
-
|
|
4713
|
-
na_ndloop3(&ndf, &g, 1, self);
|
|
4714
|
-
return self;
|
|
4715
|
-
}
|
|
4716
|
-
|
|
4717
4068
|
typedef struct {
|
|
4718
4069
|
dtype mu;
|
|
4719
4070
|
rtype sigma;
|
|
@@ -4977,7 +4328,27 @@ void Init_numo_dcomplex(void) {
|
|
|
4977
4328
|
rb_define_method(cT, "isposinf", dcomplex_isposinf, 0);
|
|
4978
4329
|
rb_define_method(cT, "isneginf", dcomplex_isneginf, 0);
|
|
4979
4330
|
rb_define_method(cT, "isfinite", dcomplex_isfinite, 0);
|
|
4331
|
+
/**
|
|
4332
|
+
* sum of self.
|
|
4333
|
+
* @overload sum(axis:nil, keepdims:false, nan:false)
|
|
4334
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm
|
|
4335
|
+
* (avoid NaN for sum/mean etc, or, return NaN for min/max etc).
|
|
4336
|
+
* @param [Numeric,Array,Range] axis Performs sum along the axis.
|
|
4337
|
+
* @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
4338
|
+
* dimensions with size one.
|
|
4339
|
+
* @return [Numo::DComplex] returns result of sum.
|
|
4340
|
+
*/
|
|
4980
4341
|
rb_define_method(cT, "sum", dcomplex_sum, -1);
|
|
4342
|
+
/**
|
|
4343
|
+
* prod of self.
|
|
4344
|
+
* @overload prod(axis:nil, keepdims:false, nan:false)
|
|
4345
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm
|
|
4346
|
+
* (avoid NaN for sum/mean etc, or, return NaN for min/max etc).
|
|
4347
|
+
* @param [Numeric,Array,Range] axis Performs prod along the axis.
|
|
4348
|
+
* @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
4349
|
+
* dimensions with size one.
|
|
4350
|
+
* @return [Numo::DComplex] returns result of prod.
|
|
4351
|
+
*/
|
|
4981
4352
|
rb_define_method(cT, "prod", dcomplex_prod, -1);
|
|
4982
4353
|
rb_define_method(cT, "kahan_sum", dcomplex_kahan_sum, -1);
|
|
4983
4354
|
/**
|
|
@@ -5024,13 +4395,106 @@ void Init_numo_dcomplex(void) {
|
|
|
5024
4395
|
* @return [Numo::DFloat] returns result of rms.
|
|
5025
4396
|
*/
|
|
5026
4397
|
rb_define_method(cT, "rms", dcomplex_rms, -1);
|
|
4398
|
+
/**
|
|
4399
|
+
* cumsum of self.
|
|
4400
|
+
* @overload cumsum(axis:nil, nan:false)
|
|
4401
|
+
* @param [Numeric,Array,Range] axis Performs cumsum along the axis.
|
|
4402
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4403
|
+
* @return [Numo::DComplex] cumsum of self.
|
|
4404
|
+
*/
|
|
5027
4405
|
rb_define_method(cT, "cumsum", dcomplex_cumsum, -1);
|
|
4406
|
+
/**
|
|
4407
|
+
* cumprod of self.
|
|
4408
|
+
* @overload cumprod(axis:nil, nan:false)
|
|
4409
|
+
* @param [Numeric,Array,Range] axis Performs cumprod along the axis.
|
|
4410
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4411
|
+
* @return [Numo::DComplex] cumprod of self.
|
|
4412
|
+
*/
|
|
5028
4413
|
rb_define_method(cT, "cumprod", dcomplex_cumprod, -1);
|
|
4414
|
+
/**
|
|
4415
|
+
* Binary mulsum.
|
|
4416
|
+
*
|
|
4417
|
+
* @overload mulsum(other, axis:nil, keepdims:false, nan:false)
|
|
4418
|
+
* @param [Numo::NArray,Numeric] other
|
|
4419
|
+
* @param [Numeric,Array,Range] axis Performs mulsum along the axis.
|
|
4420
|
+
* @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in
|
|
4421
|
+
* the result array as dimensions with size one.
|
|
4422
|
+
* @param [TrueClass] nan (keyword) If true, apply NaN-aware algorithm
|
|
4423
|
+
* (avoid NaN if exists).
|
|
4424
|
+
* @return [Numo::NArray] mulsum of self and other.
|
|
4425
|
+
*/
|
|
5029
4426
|
rb_define_method(cT, "mulsum", dcomplex_mulsum, -1);
|
|
4427
|
+
/**
|
|
4428
|
+
* Set linear sequence of numbers to self. The sequence is obtained from
|
|
4429
|
+
* beg+i*step
|
|
4430
|
+
* where i is 1-dimensional index.
|
|
4431
|
+
* @overload seq([beg,[step]])
|
|
4432
|
+
* @param [Numeric] beg beginning of sequence. (default=0)
|
|
4433
|
+
* @param [Numeric] step step of sequence. (default=1)
|
|
4434
|
+
* @return [Numo::DComplex] self.
|
|
4435
|
+
* @example
|
|
4436
|
+
* Numo::DFloat.new(6).seq(1,-0.2)
|
|
4437
|
+
* # => Numo::DFloat#shape=[6]
|
|
4438
|
+
* # [1, 0.8, 0.6, 0.4, 0.2, 0]
|
|
4439
|
+
*
|
|
4440
|
+
* Numo::DComplex.new(6).seq(1,-0.2+0.2i)
|
|
4441
|
+
* # => Numo::DComplex#shape=[6]
|
|
4442
|
+
* # [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]
|
|
4443
|
+
*/
|
|
5030
4444
|
rb_define_method(cT, "seq", dcomplex_seq, -1);
|
|
4445
|
+
/**
|
|
4446
|
+
* Set logarithmic sequence of numbers to self. The sequence is obtained from
|
|
4447
|
+
* `base**(beg+i*step)`
|
|
4448
|
+
* where i is 1-dimensional index.
|
|
4449
|
+
* Applicable classes: DFloat, SFloat, DComplex, SCopmplex.
|
|
4450
|
+
*
|
|
4451
|
+
* @overload logseq(beg,step,[base])
|
|
4452
|
+
* @param [Numeric] beg The beginning of sequence.
|
|
4453
|
+
* @param [Numeric] step The step of sequence.
|
|
4454
|
+
* @param [Numeric] base The base of log space. (default=10)
|
|
4455
|
+
* @return [Numo::DComplex] self.
|
|
4456
|
+
*
|
|
4457
|
+
* @example
|
|
4458
|
+
* Numo::DFloat.new(5).logseq(4,-1,2)
|
|
4459
|
+
* # => Numo::DFloat#shape=[5]
|
|
4460
|
+
* # [16, 8, 4, 2, 1]
|
|
4461
|
+
*
|
|
4462
|
+
* Numo::DComplex.new(5).logseq(0,1i*Math::PI/3,Math::E)
|
|
4463
|
+
* # => Numo::DComplex#shape=[5]
|
|
4464
|
+
* # [1+7.26156e-310i, 0.5+0.866025i, -0.5+0.866025i, -1+1.22465e-16i, ...]
|
|
4465
|
+
*/
|
|
5031
4466
|
rb_define_method(cT, "logseq", dcomplex_logseq, -1);
|
|
4467
|
+
/**
|
|
4468
|
+
* Eye: Set a value to diagonal components, set 0 to non-diagonal components.
|
|
4469
|
+
* @overload eye([element,offset])
|
|
4470
|
+
* @param [Numeric] element Diagonal element to be stored. Default is 1.
|
|
4471
|
+
* @param [Integer] offset Diagonal offset from the main diagonal. The
|
|
4472
|
+
* default is 0. k>0 for diagonals above the main diagonal, and k<0
|
|
4473
|
+
* for diagonals below the main diagonal.
|
|
4474
|
+
* @return [Numo::DComplex] eye of self.
|
|
4475
|
+
*/
|
|
5032
4476
|
rb_define_method(cT, "eye", dcomplex_eye, -1);
|
|
5033
4477
|
rb_define_alias(cT, "indgen", "seq");
|
|
4478
|
+
/**
|
|
4479
|
+
* Generate uniformly distributed random numbers on self narray.
|
|
4480
|
+
* @overload rand([[low],high])
|
|
4481
|
+
* @param [Numeric] low lower inclusive boundary of random numbers. (default=0)
|
|
4482
|
+
* @param [Numeric] high upper exclusive boundary of random numbers.
|
|
4483
|
+
* (default=1 or 1+1i for complex types)
|
|
4484
|
+
* @return [Numo::DComplex] self.
|
|
4485
|
+
* @example
|
|
4486
|
+
* Numo::DFloat.new(6).rand
|
|
4487
|
+
* # => Numo::DFloat#shape=[6]
|
|
4488
|
+
* # [0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032]
|
|
4489
|
+
*
|
|
4490
|
+
* Numo::DComplex.new(6).rand(5+5i)
|
|
4491
|
+
* # => Numo::DComplex#shape=[6]
|
|
4492
|
+
* # [2.69974+3.68908i, 0.825443+0.254414i, 0.540323+0.34354i, 4.52061+2.39322i, ...]
|
|
4493
|
+
*
|
|
4494
|
+
* Numo::Int32.new(6).rand(2,5)
|
|
4495
|
+
* # => Numo::Int32#shape=[6]
|
|
4496
|
+
* # [4, 3, 3, 2, 4, 2]
|
|
4497
|
+
*/
|
|
5034
4498
|
rb_define_method(cT, "rand", dcomplex_rand, -1);
|
|
5035
4499
|
rb_define_method(cT, "rand_norm", dcomplex_rand_norm, -1);
|
|
5036
4500
|
rb_define_method(cT, "poly", dcomplex_poly, -2);
|