numo-narray-alt 0.9.10 → 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 +2 -3
- 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(scomplex, numo_cSComplex)
|
|
77
|
+
DEF_NARRAY_FLT_PROD_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
67
78
|
DEF_NARRAY_FLT_MEAN_METHOD_FUNC(scomplex, numo_cSComplex, scomplex, numo_cSComplex)
|
|
68
79
|
DEF_NARRAY_FLT_VAR_METHOD_FUNC(scomplex, numo_cSComplex, float, numo_cSFloat)
|
|
69
80
|
DEF_NARRAY_FLT_STDDEV_METHOD_FUNC(scomplex, numo_cSComplex, float, numo_cSFloat)
|
|
70
81
|
DEF_NARRAY_FLT_RMS_METHOD_FUNC(scomplex, numo_cSComplex, float, numo_cSFloat)
|
|
82
|
+
DEF_NARRAY_FLT_CUMSUM_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
83
|
+
DEF_NARRAY_FLT_CUMPROD_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
84
|
+
DEF_NARRAY_FLT_MULSUM_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
85
|
+
DEF_NARRAY_FLT_SEQ_METHOD_FUNC(scomplex)
|
|
86
|
+
DEF_NARRAY_FLT_LOGSEQ_METHOD_FUNC(scomplex)
|
|
87
|
+
DEF_NARRAY_EYE_METHOD_FUNC(scomplex)
|
|
88
|
+
DEF_NARRAY_CMP_RAND_METHOD_FUNC(scomplex)
|
|
71
89
|
DEF_NARRAY_FLT_SQRT_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
72
90
|
DEF_NARRAY_FLT_CBRT_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
73
91
|
DEF_NARRAY_FLT_LOG_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
@@ -3999,673 +4017,6 @@ static VALUE scomplex_isfinite(VALUE self) {
|
|
|
3999
4017
|
return na_ndloop(&ndf, 1, self);
|
|
4000
4018
|
}
|
|
4001
4019
|
|
|
4002
|
-
static void iter_scomplex_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_scomplex_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::SComplex] returns result of sum.
|
|
4034
|
-
*/
|
|
4035
|
-
static VALUE scomplex_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_scomplex_sum, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
|
4040
|
-
|
|
4041
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_scomplex_sum_nan);
|
|
4042
|
-
|
|
4043
|
-
v = na_ndloop(&ndf, 2, self, reduce);
|
|
4044
|
-
|
|
4045
|
-
return scomplex_extract(v);
|
|
4046
|
-
}
|
|
4047
|
-
|
|
4048
|
-
static void iter_scomplex_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_scomplex_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::SComplex] returns result of prod.
|
|
4080
|
-
*/
|
|
4081
|
-
static VALUE scomplex_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_scomplex_prod, STRIDE_LOOP_NIP | NDF_FLAT_REDUCE, 2, 1, ain, aout };
|
|
4086
|
-
|
|
4087
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_scomplex_prod_nan);
|
|
4088
|
-
|
|
4089
|
-
v = na_ndloop(&ndf, 2, self, reduce);
|
|
4090
|
-
|
|
4091
|
-
return scomplex_extract(v);
|
|
4092
|
-
}
|
|
4093
|
-
|
|
4094
|
-
static void iter_scomplex_cumsum(na_loop_t* const lp) {
|
|
4095
|
-
size_t i;
|
|
4096
|
-
char *p1, *p2;
|
|
4097
|
-
ssize_t s1, s2;
|
|
4098
|
-
dtype x, y;
|
|
4099
|
-
|
|
4100
|
-
INIT_COUNTER(lp, i);
|
|
4101
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4102
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4103
|
-
|
|
4104
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4105
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4106
|
-
for (i--; i--;) {
|
|
4107
|
-
GET_DATA_STRIDE(p1, s1, dtype, y);
|
|
4108
|
-
m_cumsum(x, y);
|
|
4109
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4110
|
-
}
|
|
4111
|
-
}
|
|
4112
|
-
static void iter_scomplex_cumsum_nan(na_loop_t* const lp) {
|
|
4113
|
-
size_t i;
|
|
4114
|
-
char *p1, *p2;
|
|
4115
|
-
ssize_t s1, s2;
|
|
4116
|
-
dtype x, y;
|
|
4117
|
-
|
|
4118
|
-
INIT_COUNTER(lp, i);
|
|
4119
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4120
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4121
|
-
|
|
4122
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4123
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4124
|
-
for (i--; i--;) {
|
|
4125
|
-
GET_DATA_STRIDE(p1, s1, dtype, y);
|
|
4126
|
-
m_cumsum_nan(x, y);
|
|
4127
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4128
|
-
}
|
|
4129
|
-
}
|
|
4130
|
-
|
|
4131
|
-
/*
|
|
4132
|
-
cumsum of self.
|
|
4133
|
-
@overload cumsum(axis:nil, nan:false)
|
|
4134
|
-
@param [Numeric,Array,Range] axis Performs cumsum along the axis.
|
|
4135
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4136
|
-
@return [Numo::SComplex] cumsum of self.
|
|
4137
|
-
*/
|
|
4138
|
-
static VALUE scomplex_cumsum(int argc, VALUE* argv, VALUE self) {
|
|
4139
|
-
VALUE reduce;
|
|
4140
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
4141
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4142
|
-
ndfunc_t ndf = {
|
|
4143
|
-
iter_scomplex_cumsum, STRIDE_LOOP | NDF_FLAT_REDUCE | NDF_CUM, 2, 1, ain, aout
|
|
4144
|
-
};
|
|
4145
|
-
|
|
4146
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_scomplex_cumsum_nan);
|
|
4147
|
-
|
|
4148
|
-
return na_ndloop(&ndf, 2, self, reduce);
|
|
4149
|
-
}
|
|
4150
|
-
|
|
4151
|
-
static void iter_scomplex_cumprod(na_loop_t* const lp) {
|
|
4152
|
-
size_t i;
|
|
4153
|
-
char *p1, *p2;
|
|
4154
|
-
ssize_t s1, s2;
|
|
4155
|
-
dtype x, y;
|
|
4156
|
-
|
|
4157
|
-
INIT_COUNTER(lp, i);
|
|
4158
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4159
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4160
|
-
|
|
4161
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4162
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4163
|
-
for (i--; i--;) {
|
|
4164
|
-
GET_DATA_STRIDE(p1, s1, dtype, y);
|
|
4165
|
-
m_cumprod(x, y);
|
|
4166
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4167
|
-
}
|
|
4168
|
-
}
|
|
4169
|
-
static void iter_scomplex_cumprod_nan(na_loop_t* const lp) {
|
|
4170
|
-
size_t i;
|
|
4171
|
-
char *p1, *p2;
|
|
4172
|
-
ssize_t s1, s2;
|
|
4173
|
-
dtype x, y;
|
|
4174
|
-
|
|
4175
|
-
INIT_COUNTER(lp, i);
|
|
4176
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4177
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4178
|
-
|
|
4179
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4180
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4181
|
-
for (i--; i--;) {
|
|
4182
|
-
GET_DATA_STRIDE(p1, s1, dtype, y);
|
|
4183
|
-
m_cumprod_nan(x, y);
|
|
4184
|
-
SET_DATA_STRIDE(p2, s2, dtype, x);
|
|
4185
|
-
}
|
|
4186
|
-
}
|
|
4187
|
-
|
|
4188
|
-
/*
|
|
4189
|
-
cumprod of self.
|
|
4190
|
-
@overload cumprod(axis:nil, nan:false)
|
|
4191
|
-
@param [Numeric,Array,Range] axis Performs cumprod along the axis.
|
|
4192
|
-
@param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4193
|
-
@return [Numo::SComplex] cumprod of self.
|
|
4194
|
-
*/
|
|
4195
|
-
static VALUE scomplex_cumprod(int argc, VALUE* argv, VALUE self) {
|
|
4196
|
-
VALUE reduce;
|
|
4197
|
-
ndfunc_arg_in_t ain[2] = { { cT, 0 }, { sym_reduce, 0 } };
|
|
4198
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4199
|
-
ndfunc_t ndf = {
|
|
4200
|
-
iter_scomplex_cumprod, STRIDE_LOOP | NDF_FLAT_REDUCE | NDF_CUM, 2, 1, ain, aout
|
|
4201
|
-
};
|
|
4202
|
-
|
|
4203
|
-
reduce = na_reduce_dimension(argc, argv, 1, &self, &ndf, iter_scomplex_cumprod_nan);
|
|
4204
|
-
|
|
4205
|
-
return na_ndloop(&ndf, 2, self, reduce);
|
|
4206
|
-
}
|
|
4207
|
-
|
|
4208
|
-
//
|
|
4209
|
-
static void iter_scomplex_mulsum(na_loop_t* const lp) {
|
|
4210
|
-
size_t i, n;
|
|
4211
|
-
char *p1, *p2, *p3;
|
|
4212
|
-
ssize_t s1, s2, s3;
|
|
4213
|
-
|
|
4214
|
-
INIT_COUNTER(lp, n);
|
|
4215
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4216
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4217
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
4218
|
-
|
|
4219
|
-
if (s3 == 0) {
|
|
4220
|
-
dtype z;
|
|
4221
|
-
// Reduce loop
|
|
4222
|
-
GET_DATA(p3, dtype, z);
|
|
4223
|
-
for (i = 0; i < n; i++) {
|
|
4224
|
-
dtype x, y;
|
|
4225
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4226
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4227
|
-
m_mulsum(x, y, z);
|
|
4228
|
-
}
|
|
4229
|
-
SET_DATA(p3, dtype, z);
|
|
4230
|
-
return;
|
|
4231
|
-
} else {
|
|
4232
|
-
for (i = 0; i < n; i++) {
|
|
4233
|
-
dtype x, y, z;
|
|
4234
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4235
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4236
|
-
GET_DATA(p3, dtype, z);
|
|
4237
|
-
m_mulsum(x, y, z);
|
|
4238
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
4239
|
-
}
|
|
4240
|
-
}
|
|
4241
|
-
}
|
|
4242
|
-
//
|
|
4243
|
-
static void iter_scomplex_mulsum_nan(na_loop_t* const lp) {
|
|
4244
|
-
size_t i, n;
|
|
4245
|
-
char *p1, *p2, *p3;
|
|
4246
|
-
ssize_t s1, s2, s3;
|
|
4247
|
-
|
|
4248
|
-
INIT_COUNTER(lp, n);
|
|
4249
|
-
INIT_PTR(lp, 0, p1, s1);
|
|
4250
|
-
INIT_PTR(lp, 1, p2, s2);
|
|
4251
|
-
INIT_PTR(lp, 2, p3, s3);
|
|
4252
|
-
|
|
4253
|
-
if (s3 == 0) {
|
|
4254
|
-
dtype z;
|
|
4255
|
-
// Reduce loop
|
|
4256
|
-
GET_DATA(p3, dtype, z);
|
|
4257
|
-
for (i = 0; i < n; i++) {
|
|
4258
|
-
dtype x, y;
|
|
4259
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4260
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4261
|
-
m_mulsum_nan(x, y, z);
|
|
4262
|
-
}
|
|
4263
|
-
SET_DATA(p3, dtype, z);
|
|
4264
|
-
return;
|
|
4265
|
-
} else {
|
|
4266
|
-
for (i = 0; i < n; i++) {
|
|
4267
|
-
dtype x, y, z;
|
|
4268
|
-
GET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4269
|
-
GET_DATA_STRIDE(p2, s2, dtype, y);
|
|
4270
|
-
GET_DATA(p3, dtype, z);
|
|
4271
|
-
m_mulsum_nan(x, y, z);
|
|
4272
|
-
SET_DATA_STRIDE(p3, s3, dtype, z);
|
|
4273
|
-
}
|
|
4274
|
-
}
|
|
4275
|
-
}
|
|
4276
|
-
//
|
|
4277
|
-
|
|
4278
|
-
static VALUE scomplex_mulsum_self(int argc, VALUE* argv, VALUE self) {
|
|
4279
|
-
VALUE v, reduce;
|
|
4280
|
-
VALUE naryv[2];
|
|
4281
|
-
ndfunc_arg_in_t ain[4] = { { cT, 0 }, { cT, 0 }, { sym_reduce, 0 }, { sym_init, 0 } };
|
|
4282
|
-
ndfunc_arg_out_t aout[1] = { { cT, 0 } };
|
|
4283
|
-
ndfunc_t ndf = { iter_scomplex_mulsum, STRIDE_LOOP_NIP, 4, 1, ain, aout };
|
|
4284
|
-
|
|
4285
|
-
if (argc < 1) {
|
|
4286
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for >=1)", argc);
|
|
4287
|
-
}
|
|
4288
|
-
// should fix below: [self.ndim,other.ndim].max or?
|
|
4289
|
-
naryv[0] = self;
|
|
4290
|
-
naryv[1] = argv[0];
|
|
4291
|
-
//
|
|
4292
|
-
reduce = na_reduce_dimension(argc - 1, argv + 1, 2, naryv, &ndf, iter_scomplex_mulsum_nan);
|
|
4293
|
-
//
|
|
4294
|
-
|
|
4295
|
-
v = na_ndloop(&ndf, 4, self, argv[0], reduce, m_mulsum_init);
|
|
4296
|
-
return scomplex_extract(v);
|
|
4297
|
-
}
|
|
4298
|
-
|
|
4299
|
-
/*
|
|
4300
|
-
Binary mulsum.
|
|
4301
|
-
|
|
4302
|
-
@overload mulsum(other, axis:nil, keepdims:false, nan:false)
|
|
4303
|
-
@param [Numo::NArray,Numeric] other
|
|
4304
|
-
@param [Numeric,Array,Range] axis Performs mulsum along the axis.
|
|
4305
|
-
@param [TrueClass] keepdims (keyword) If true, the reduced axes are left in the result array
|
|
4306
|
-
as dimensions with size one.
|
|
4307
|
-
@param [TrueClass] nan (keyword) If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4308
|
-
@return [Numo::NArray] mulsum of self and other.
|
|
4309
|
-
*/
|
|
4310
|
-
static VALUE scomplex_mulsum(int argc, VALUE* argv, VALUE self) {
|
|
4311
|
-
//
|
|
4312
|
-
VALUE klass, v;
|
|
4313
|
-
//
|
|
4314
|
-
if (argc < 1) {
|
|
4315
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for >=1)", argc);
|
|
4316
|
-
}
|
|
4317
|
-
//
|
|
4318
|
-
klass = na_upcast(rb_obj_class(self), rb_obj_class(argv[0]));
|
|
4319
|
-
if (klass == cT) {
|
|
4320
|
-
return scomplex_mulsum_self(argc, argv, self);
|
|
4321
|
-
} else {
|
|
4322
|
-
v = rb_funcall(klass, id_cast, 1, self);
|
|
4323
|
-
//
|
|
4324
|
-
return rb_funcallv_kw(v, rb_intern("mulsum"), argc, argv, RB_PASS_CALLED_KEYWORDS);
|
|
4325
|
-
//
|
|
4326
|
-
}
|
|
4327
|
-
//
|
|
4328
|
-
}
|
|
4329
|
-
|
|
4330
|
-
typedef dtype seq_data_t;
|
|
4331
|
-
|
|
4332
|
-
typedef double seq_count_t;
|
|
4333
|
-
|
|
4334
|
-
typedef struct {
|
|
4335
|
-
seq_data_t beg;
|
|
4336
|
-
seq_data_t step;
|
|
4337
|
-
seq_count_t count;
|
|
4338
|
-
} seq_opt_t;
|
|
4339
|
-
|
|
4340
|
-
static void iter_scomplex_seq(na_loop_t* const lp) {
|
|
4341
|
-
size_t i;
|
|
4342
|
-
char* p1;
|
|
4343
|
-
ssize_t s1;
|
|
4344
|
-
size_t* idx1;
|
|
4345
|
-
dtype x;
|
|
4346
|
-
seq_data_t beg, step;
|
|
4347
|
-
seq_count_t c;
|
|
4348
|
-
seq_opt_t* g;
|
|
4349
|
-
|
|
4350
|
-
INIT_COUNTER(lp, i);
|
|
4351
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
4352
|
-
g = (seq_opt_t*)(lp->opt_ptr);
|
|
4353
|
-
beg = g->beg;
|
|
4354
|
-
step = g->step;
|
|
4355
|
-
c = g->count;
|
|
4356
|
-
if (idx1) {
|
|
4357
|
-
for (; i--;) {
|
|
4358
|
-
x = f_seq(beg, step, c++);
|
|
4359
|
-
*(dtype*)(p1 + *idx1) = x;
|
|
4360
|
-
idx1++;
|
|
4361
|
-
}
|
|
4362
|
-
} else {
|
|
4363
|
-
for (; i--;) {
|
|
4364
|
-
x = f_seq(beg, step, c++);
|
|
4365
|
-
*(dtype*)(p1) = x;
|
|
4366
|
-
p1 += s1;
|
|
4367
|
-
}
|
|
4368
|
-
}
|
|
4369
|
-
g->count = c;
|
|
4370
|
-
}
|
|
4371
|
-
|
|
4372
|
-
/*
|
|
4373
|
-
Set linear sequence of numbers to self. The sequence is obtained from
|
|
4374
|
-
beg+i*step
|
|
4375
|
-
where i is 1-dimensional index.
|
|
4376
|
-
@overload seq([beg,[step]])
|
|
4377
|
-
@param [Numeric] beg beginning of sequence. (default=0)
|
|
4378
|
-
@param [Numeric] step step of sequence. (default=1)
|
|
4379
|
-
@return [Numo::SComplex] self.
|
|
4380
|
-
@example
|
|
4381
|
-
Numo::DFloat.new(6).seq(1,-0.2)
|
|
4382
|
-
# => Numo::DFloat#shape=[6]
|
|
4383
|
-
# [1, 0.8, 0.6, 0.4, 0.2, 0]
|
|
4384
|
-
|
|
4385
|
-
Numo::DComplex.new(6).seq(1,-0.2+0.2i)
|
|
4386
|
-
# => Numo::DComplex#shape=[6]
|
|
4387
|
-
# [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]
|
|
4388
|
-
*/
|
|
4389
|
-
static VALUE scomplex_seq(int argc, VALUE* argv, VALUE self) {
|
|
4390
|
-
seq_opt_t* g;
|
|
4391
|
-
VALUE vbeg = Qnil, vstep = Qnil;
|
|
4392
|
-
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } };
|
|
4393
|
-
ndfunc_t ndf = { iter_scomplex_seq, FULL_LOOP, 1, 0, ain, 0 };
|
|
4394
|
-
|
|
4395
|
-
g = ALLOCA_N(seq_opt_t, 1);
|
|
4396
|
-
g->beg = m_zero;
|
|
4397
|
-
g->step = m_one;
|
|
4398
|
-
g->count = 0;
|
|
4399
|
-
rb_scan_args(argc, argv, "02", &vbeg, &vstep);
|
|
4400
|
-
if (vbeg != Qnil) {
|
|
4401
|
-
g->beg = m_num_to_data(vbeg);
|
|
4402
|
-
}
|
|
4403
|
-
if (vstep != Qnil) {
|
|
4404
|
-
g->step = m_num_to_data(vstep);
|
|
4405
|
-
}
|
|
4406
|
-
|
|
4407
|
-
na_ndloop3(&ndf, g, 1, self);
|
|
4408
|
-
return self;
|
|
4409
|
-
}
|
|
4410
|
-
|
|
4411
|
-
typedef struct {
|
|
4412
|
-
seq_data_t beg;
|
|
4413
|
-
seq_data_t step;
|
|
4414
|
-
seq_data_t base;
|
|
4415
|
-
seq_count_t count;
|
|
4416
|
-
} logseq_opt_t;
|
|
4417
|
-
|
|
4418
|
-
static void iter_scomplex_logseq(na_loop_t* const lp) {
|
|
4419
|
-
size_t i;
|
|
4420
|
-
char* p1;
|
|
4421
|
-
ssize_t s1;
|
|
4422
|
-
size_t* idx1;
|
|
4423
|
-
dtype x;
|
|
4424
|
-
seq_data_t beg, step, base;
|
|
4425
|
-
seq_count_t c;
|
|
4426
|
-
logseq_opt_t* g;
|
|
4427
|
-
|
|
4428
|
-
INIT_COUNTER(lp, i);
|
|
4429
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
4430
|
-
g = (logseq_opt_t*)(lp->opt_ptr);
|
|
4431
|
-
beg = g->beg;
|
|
4432
|
-
step = g->step;
|
|
4433
|
-
base = g->base;
|
|
4434
|
-
c = g->count;
|
|
4435
|
-
if (idx1) {
|
|
4436
|
-
for (; i--;) {
|
|
4437
|
-
x = f_seq(beg, step, c++);
|
|
4438
|
-
*(dtype*)(p1 + *idx1) = m_pow(base, x);
|
|
4439
|
-
idx1++;
|
|
4440
|
-
}
|
|
4441
|
-
} else {
|
|
4442
|
-
for (; i--;) {
|
|
4443
|
-
x = f_seq(beg, step, c++);
|
|
4444
|
-
*(dtype*)(p1) = m_pow(base, x);
|
|
4445
|
-
p1 += s1;
|
|
4446
|
-
}
|
|
4447
|
-
}
|
|
4448
|
-
g->count = c;
|
|
4449
|
-
}
|
|
4450
|
-
|
|
4451
|
-
/*
|
|
4452
|
-
Set logarithmic sequence of numbers to self. The sequence is obtained from
|
|
4453
|
-
`base**(beg+i*step)`
|
|
4454
|
-
where i is 1-dimensional index.
|
|
4455
|
-
Applicable classes: DFloat, SFloat, DComplex, SCopmplex.
|
|
4456
|
-
|
|
4457
|
-
@overload logseq(beg,step,[base])
|
|
4458
|
-
@param [Numeric] beg The beginning of sequence.
|
|
4459
|
-
@param [Numeric] step The step of sequence.
|
|
4460
|
-
@param [Numeric] base The base of log space. (default=10)
|
|
4461
|
-
@return [Numo::SComplex] self.
|
|
4462
|
-
|
|
4463
|
-
@example
|
|
4464
|
-
Numo::DFloat.new(5).logseq(4,-1,2)
|
|
4465
|
-
# => Numo::DFloat#shape=[5]
|
|
4466
|
-
# [16, 8, 4, 2, 1]
|
|
4467
|
-
|
|
4468
|
-
Numo::DComplex.new(5).logseq(0,1i*Math::PI/3,Math::E)
|
|
4469
|
-
# => Numo::DComplex#shape=[5]
|
|
4470
|
-
# [1+7.26156e-310i, 0.5+0.866025i, -0.5+0.866025i, -1+1.22465e-16i, ...]
|
|
4471
|
-
*/
|
|
4472
|
-
static VALUE scomplex_logseq(int argc, VALUE* argv, VALUE self) {
|
|
4473
|
-
logseq_opt_t* g;
|
|
4474
|
-
VALUE vbeg, vstep, vbase;
|
|
4475
|
-
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } };
|
|
4476
|
-
ndfunc_t ndf = { iter_scomplex_logseq, FULL_LOOP, 1, 0, ain, 0 };
|
|
4477
|
-
|
|
4478
|
-
g = ALLOCA_N(logseq_opt_t, 1);
|
|
4479
|
-
rb_scan_args(argc, argv, "21", &vbeg, &vstep, &vbase);
|
|
4480
|
-
g->beg = m_num_to_data(vbeg);
|
|
4481
|
-
g->step = m_num_to_data(vstep);
|
|
4482
|
-
if (vbase == Qnil) {
|
|
4483
|
-
g->base = m_from_real(10);
|
|
4484
|
-
} else {
|
|
4485
|
-
g->base = m_num_to_data(vbase);
|
|
4486
|
-
}
|
|
4487
|
-
na_ndloop3(&ndf, g, 1, self);
|
|
4488
|
-
return self;
|
|
4489
|
-
}
|
|
4490
|
-
|
|
4491
|
-
static void iter_scomplex_eye(na_loop_t* const lp) {
|
|
4492
|
-
size_t n0, n1;
|
|
4493
|
-
size_t i0, i1;
|
|
4494
|
-
ssize_t s0, s1;
|
|
4495
|
-
char *p0, *p1;
|
|
4496
|
-
char* g;
|
|
4497
|
-
ssize_t kofs;
|
|
4498
|
-
dtype data;
|
|
4499
|
-
|
|
4500
|
-
g = (char*)(lp->opt_ptr);
|
|
4501
|
-
kofs = *(ssize_t*)g;
|
|
4502
|
-
data = *(dtype*)(g + sizeof(ssize_t));
|
|
4503
|
-
|
|
4504
|
-
n0 = lp->args[0].shape[0];
|
|
4505
|
-
n1 = lp->args[0].shape[1];
|
|
4506
|
-
s0 = lp->args[0].iter[0].step;
|
|
4507
|
-
s1 = lp->args[0].iter[1].step;
|
|
4508
|
-
p0 = NDL_PTR(lp, 0);
|
|
4509
|
-
|
|
4510
|
-
for (i0 = 0; i0 < n0; i0++) {
|
|
4511
|
-
p1 = p0;
|
|
4512
|
-
for (i1 = 0; i1 < n1; i1++) {
|
|
4513
|
-
*(dtype*)p1 = (i0 + kofs == i1) ? data : m_zero;
|
|
4514
|
-
p1 += s1;
|
|
4515
|
-
}
|
|
4516
|
-
p0 += s0;
|
|
4517
|
-
}
|
|
4518
|
-
}
|
|
4519
|
-
|
|
4520
|
-
/*
|
|
4521
|
-
Eye: Set a value to diagonal components, set 0 to non-diagonal components.
|
|
4522
|
-
@overload eye([element,offset])
|
|
4523
|
-
@param [Numeric] element Diagonal element to be stored. Default is 1.
|
|
4524
|
-
@param [Integer] offset Diagonal offset from the main diagonal. The
|
|
4525
|
-
default is 0. k>0 for diagonals above the main diagonal, and k<0
|
|
4526
|
-
for diagonals below the main diagonal.
|
|
4527
|
-
@return [Numo::SComplex] eye of self.
|
|
4528
|
-
*/
|
|
4529
|
-
static VALUE scomplex_eye(int argc, VALUE* argv, VALUE self) {
|
|
4530
|
-
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 2 } };
|
|
4531
|
-
ndfunc_t ndf = { iter_scomplex_eye, NO_LOOP, 1, 0, ain, 0 };
|
|
4532
|
-
ssize_t kofs;
|
|
4533
|
-
dtype data;
|
|
4534
|
-
char* g;
|
|
4535
|
-
int nd;
|
|
4536
|
-
narray_t* na;
|
|
4537
|
-
|
|
4538
|
-
// check arguments
|
|
4539
|
-
if (argc > 2) {
|
|
4540
|
-
rb_raise(rb_eArgError, "too many arguments (%d for 0..2)", argc);
|
|
4541
|
-
} else if (argc == 2) {
|
|
4542
|
-
data = m_num_to_data(argv[0]);
|
|
4543
|
-
kofs = NUM2SSIZET(argv[1]);
|
|
4544
|
-
} else if (argc == 1) {
|
|
4545
|
-
data = m_num_to_data(argv[0]);
|
|
4546
|
-
kofs = 0;
|
|
4547
|
-
} else {
|
|
4548
|
-
data = m_one;
|
|
4549
|
-
kofs = 0;
|
|
4550
|
-
}
|
|
4551
|
-
|
|
4552
|
-
GetNArray(self, na);
|
|
4553
|
-
nd = na->ndim;
|
|
4554
|
-
if (nd < 2) {
|
|
4555
|
-
rb_raise(nary_eDimensionError, "less than 2-d array");
|
|
4556
|
-
}
|
|
4557
|
-
|
|
4558
|
-
// Diagonal offset from the main diagonal.
|
|
4559
|
-
if (kofs >= 0) {
|
|
4560
|
-
if ((size_t)(kofs) >= na->shape[nd - 1]) {
|
|
4561
|
-
rb_raise(
|
|
4562
|
-
rb_eArgError,
|
|
4563
|
-
"invalid diagonal offset(%" SZF "d) for "
|
|
4564
|
-
"last dimension size(%" SZF "d)",
|
|
4565
|
-
kofs, na->shape[nd - 1]
|
|
4566
|
-
);
|
|
4567
|
-
}
|
|
4568
|
-
} else {
|
|
4569
|
-
if ((size_t)(-kofs) >= na->shape[nd - 2]) {
|
|
4570
|
-
rb_raise(
|
|
4571
|
-
rb_eArgError,
|
|
4572
|
-
"invalid diagonal offset(%" SZF "d) for "
|
|
4573
|
-
"last-1 dimension size(%" SZF "d)",
|
|
4574
|
-
kofs, na->shape[nd - 2]
|
|
4575
|
-
);
|
|
4576
|
-
}
|
|
4577
|
-
}
|
|
4578
|
-
|
|
4579
|
-
g = ALLOCA_N(char, sizeof(ssize_t) + sizeof(dtype));
|
|
4580
|
-
*(ssize_t*)g = kofs;
|
|
4581
|
-
*(dtype*)(g + sizeof(ssize_t)) = data;
|
|
4582
|
-
|
|
4583
|
-
na_ndloop3(&ndf, g, 1, self);
|
|
4584
|
-
return self;
|
|
4585
|
-
}
|
|
4586
|
-
|
|
4587
|
-
typedef struct {
|
|
4588
|
-
dtype low;
|
|
4589
|
-
dtype max;
|
|
4590
|
-
} rand_opt_t;
|
|
4591
|
-
|
|
4592
|
-
static void iter_scomplex_rand(na_loop_t* const lp) {
|
|
4593
|
-
size_t i;
|
|
4594
|
-
char* p1;
|
|
4595
|
-
ssize_t s1;
|
|
4596
|
-
size_t* idx1;
|
|
4597
|
-
dtype x;
|
|
4598
|
-
rand_opt_t* g;
|
|
4599
|
-
dtype low;
|
|
4600
|
-
dtype max;
|
|
4601
|
-
|
|
4602
|
-
INIT_COUNTER(lp, i);
|
|
4603
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
4604
|
-
g = (rand_opt_t*)(lp->opt_ptr);
|
|
4605
|
-
low = g->low;
|
|
4606
|
-
max = g->max;
|
|
4607
|
-
|
|
4608
|
-
if (idx1) {
|
|
4609
|
-
for (; i--;) {
|
|
4610
|
-
x = m_add(m_rand(max), low);
|
|
4611
|
-
SET_DATA_INDEX(p1, idx1, dtype, x);
|
|
4612
|
-
}
|
|
4613
|
-
} else {
|
|
4614
|
-
for (; i--;) {
|
|
4615
|
-
x = m_add(m_rand(max), low);
|
|
4616
|
-
SET_DATA_STRIDE(p1, s1, dtype, x);
|
|
4617
|
-
}
|
|
4618
|
-
}
|
|
4619
|
-
}
|
|
4620
|
-
|
|
4621
|
-
/*
|
|
4622
|
-
Generate uniformly distributed random numbers on self narray.
|
|
4623
|
-
@overload rand([[low],high])
|
|
4624
|
-
@param [Numeric] low lower inclusive boundary of random numbers. (default=0)
|
|
4625
|
-
@param [Numeric] high upper exclusive boundary of random numbers. (default=1 or 1+1i for
|
|
4626
|
-
complex types)
|
|
4627
|
-
@return [Numo::SComplex] self.
|
|
4628
|
-
@example
|
|
4629
|
-
Numo::DFloat.new(6).rand
|
|
4630
|
-
# => Numo::DFloat#shape=[6]
|
|
4631
|
-
# [0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032]
|
|
4632
|
-
|
|
4633
|
-
Numo::DComplex.new(6).rand(5+5i)
|
|
4634
|
-
# => Numo::DComplex#shape=[6]
|
|
4635
|
-
# [2.69974+3.68908i, 0.825443+0.254414i, 0.540323+0.34354i, 4.52061+2.39322i, ...]
|
|
4636
|
-
|
|
4637
|
-
Numo::Int32.new(6).rand(2,5)
|
|
4638
|
-
# => Numo::Int32#shape=[6]
|
|
4639
|
-
# [4, 3, 3, 2, 4, 2]
|
|
4640
|
-
*/
|
|
4641
|
-
static VALUE scomplex_rand(int argc, VALUE* argv, VALUE self) {
|
|
4642
|
-
rand_opt_t g;
|
|
4643
|
-
VALUE v1 = Qnil, v2 = Qnil;
|
|
4644
|
-
dtype high;
|
|
4645
|
-
ndfunc_arg_in_t ain[1] = { { OVERWRITE, 0 } };
|
|
4646
|
-
ndfunc_t ndf = { iter_scomplex_rand, FULL_LOOP, 1, 0, ain, 0 };
|
|
4647
|
-
|
|
4648
|
-
rb_scan_args(argc, argv, "02", &v1, &v2);
|
|
4649
|
-
if (v2 == Qnil) {
|
|
4650
|
-
g.low = m_zero;
|
|
4651
|
-
if (v1 == Qnil) {
|
|
4652
|
-
|
|
4653
|
-
g.max = high = c_new(1, 1);
|
|
4654
|
-
|
|
4655
|
-
} else {
|
|
4656
|
-
g.max = high = m_num_to_data(v1);
|
|
4657
|
-
}
|
|
4658
|
-
|
|
4659
|
-
} else {
|
|
4660
|
-
g.low = m_num_to_data(v1);
|
|
4661
|
-
high = m_num_to_data(v2);
|
|
4662
|
-
g.max = m_sub(high, g.low);
|
|
4663
|
-
}
|
|
4664
|
-
|
|
4665
|
-
na_ndloop3(&ndf, &g, 1, self);
|
|
4666
|
-
return self;
|
|
4667
|
-
}
|
|
4668
|
-
|
|
4669
4020
|
typedef struct {
|
|
4670
4021
|
dtype mu;
|
|
4671
4022
|
rtype sigma;
|
|
@@ -4908,7 +4259,27 @@ void Init_numo_scomplex(void) {
|
|
|
4908
4259
|
rb_define_method(cT, "isposinf", scomplex_isposinf, 0);
|
|
4909
4260
|
rb_define_method(cT, "isneginf", scomplex_isneginf, 0);
|
|
4910
4261
|
rb_define_method(cT, "isfinite", scomplex_isfinite, 0);
|
|
4262
|
+
/**
|
|
4263
|
+
* sum of self.
|
|
4264
|
+
* @overload sum(axis:nil, keepdims:false, nan:false)
|
|
4265
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm
|
|
4266
|
+
* (avoid NaN for sum/mean etc, or, return NaN for min/max etc).
|
|
4267
|
+
* @param [Numeric,Array,Range] axis Performs sum along the axis.
|
|
4268
|
+
* @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
4269
|
+
* dimensions with size one.
|
|
4270
|
+
* @return [Numo::SComplex] returns result of sum.
|
|
4271
|
+
*/
|
|
4911
4272
|
rb_define_method(cT, "sum", scomplex_sum, -1);
|
|
4273
|
+
/**
|
|
4274
|
+
* prod of self.
|
|
4275
|
+
* @overload prod(axis:nil, keepdims:false, nan:false)
|
|
4276
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm
|
|
4277
|
+
* (avoid NaN for sum/mean etc, or, return NaN for min/max etc).
|
|
4278
|
+
* @param [Numeric,Array,Range] axis Performs prod along the axis.
|
|
4279
|
+
* @param [TrueClass] keepdims If true, the reduced axes are left in the result array as
|
|
4280
|
+
* dimensions with size one.
|
|
4281
|
+
* @return [Numo::SComplex] returns result of prod.
|
|
4282
|
+
*/
|
|
4912
4283
|
rb_define_method(cT, "prod", scomplex_prod, -1);
|
|
4913
4284
|
/**
|
|
4914
4285
|
* mean of self.
|
|
@@ -4954,13 +4325,106 @@ void Init_numo_scomplex(void) {
|
|
|
4954
4325
|
* @return [Numo::SFloat] returns result of rms.
|
|
4955
4326
|
*/
|
|
4956
4327
|
rb_define_method(cT, "rms", scomplex_rms, -1);
|
|
4328
|
+
/**
|
|
4329
|
+
* cumsum of self.
|
|
4330
|
+
* @overload cumsum(axis:nil, nan:false)
|
|
4331
|
+
* @param [Numeric,Array,Range] axis Performs cumsum along the axis.
|
|
4332
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4333
|
+
* @return [Numo::SComplex] cumsum of self.
|
|
4334
|
+
*/
|
|
4957
4335
|
rb_define_method(cT, "cumsum", scomplex_cumsum, -1);
|
|
4336
|
+
/**
|
|
4337
|
+
* cumprod of self.
|
|
4338
|
+
* @overload cumprod(axis:nil, nan:false)
|
|
4339
|
+
* @param [Numeric,Array,Range] axis Performs cumprod along the axis.
|
|
4340
|
+
* @param [TrueClass] nan If true, apply NaN-aware algorithm (avoid NaN if exists).
|
|
4341
|
+
* @return [Numo::SComplex] cumprod of self.
|
|
4342
|
+
*/
|
|
4958
4343
|
rb_define_method(cT, "cumprod", scomplex_cumprod, -1);
|
|
4344
|
+
/**
|
|
4345
|
+
* Binary mulsum.
|
|
4346
|
+
*
|
|
4347
|
+
* @overload mulsum(other, axis:nil, keepdims:false, nan:false)
|
|
4348
|
+
* @param [Numo::NArray,Numeric] other
|
|
4349
|
+
* @param [Numeric,Array,Range] axis Performs mulsum along the axis.
|
|
4350
|
+
* @param [TrueClass] keepdims (keyword) If true, the reduced axes are left in
|
|
4351
|
+
* the result array as dimensions with size one.
|
|
4352
|
+
* @param [TrueClass] nan (keyword) If true, apply NaN-aware algorithm
|
|
4353
|
+
* (avoid NaN if exists).
|
|
4354
|
+
* @return [Numo::NArray] mulsum of self and other.
|
|
4355
|
+
*/
|
|
4959
4356
|
rb_define_method(cT, "mulsum", scomplex_mulsum, -1);
|
|
4357
|
+
/**
|
|
4358
|
+
* Set linear sequence of numbers to self. The sequence is obtained from
|
|
4359
|
+
* beg+i*step
|
|
4360
|
+
* where i is 1-dimensional index.
|
|
4361
|
+
* @overload seq([beg,[step]])
|
|
4362
|
+
* @param [Numeric] beg beginning of sequence. (default=0)
|
|
4363
|
+
* @param [Numeric] step step of sequence. (default=1)
|
|
4364
|
+
* @return [Numo::SComplex] self.
|
|
4365
|
+
* @example
|
|
4366
|
+
* Numo::DFloat.new(6).seq(1,-0.2)
|
|
4367
|
+
* # => Numo::DFloat#shape=[6]
|
|
4368
|
+
* # [1, 0.8, 0.6, 0.4, 0.2, 0]
|
|
4369
|
+
*
|
|
4370
|
+
* Numo::DComplex.new(6).seq(1,-0.2+0.2i)
|
|
4371
|
+
* # => Numo::DComplex#shape=[6]
|
|
4372
|
+
* # [1+0i, 0.8+0.2i, 0.6+0.4i, 0.4+0.6i, 0.2+0.8i, 0+1i]
|
|
4373
|
+
*/
|
|
4960
4374
|
rb_define_method(cT, "seq", scomplex_seq, -1);
|
|
4375
|
+
/**
|
|
4376
|
+
* Set logarithmic sequence of numbers to self. The sequence is obtained from
|
|
4377
|
+
* `base**(beg+i*step)`
|
|
4378
|
+
* where i is 1-dimensional index.
|
|
4379
|
+
* Applicable classes: DFloat, SFloat, DComplex, SCopmplex.
|
|
4380
|
+
*
|
|
4381
|
+
* @overload logseq(beg,step,[base])
|
|
4382
|
+
* @param [Numeric] beg The beginning of sequence.
|
|
4383
|
+
* @param [Numeric] step The step of sequence.
|
|
4384
|
+
* @param [Numeric] base The base of log space. (default=10)
|
|
4385
|
+
* @return [Numo::SComplex] self.
|
|
4386
|
+
*
|
|
4387
|
+
* @example
|
|
4388
|
+
* Numo::DFloat.new(5).logseq(4,-1,2)
|
|
4389
|
+
* # => Numo::DFloat#shape=[5]
|
|
4390
|
+
* # [16, 8, 4, 2, 1]
|
|
4391
|
+
*
|
|
4392
|
+
* Numo::DComplex.new(5).logseq(0,1i*Math::PI/3,Math::E)
|
|
4393
|
+
* # => Numo::DComplex#shape=[5]
|
|
4394
|
+
* # [1+7.26156e-310i, 0.5+0.866025i, -0.5+0.866025i, -1+1.22465e-16i, ...]
|
|
4395
|
+
*/
|
|
4961
4396
|
rb_define_method(cT, "logseq", scomplex_logseq, -1);
|
|
4397
|
+
/**
|
|
4398
|
+
* Eye: Set a value to diagonal components, set 0 to non-diagonal components.
|
|
4399
|
+
* @overload eye([element,offset])
|
|
4400
|
+
* @param [Numeric] element Diagonal element to be stored. Default is 1.
|
|
4401
|
+
* @param [Integer] offset Diagonal offset from the main diagonal. The
|
|
4402
|
+
* default is 0. k>0 for diagonals above the main diagonal, and k<0
|
|
4403
|
+
* for diagonals below the main diagonal.
|
|
4404
|
+
* @return [Numo::SComplex] eye of self.
|
|
4405
|
+
*/
|
|
4962
4406
|
rb_define_method(cT, "eye", scomplex_eye, -1);
|
|
4963
4407
|
rb_define_alias(cT, "indgen", "seq");
|
|
4408
|
+
/**
|
|
4409
|
+
* Generate uniformly distributed random numbers on self narray.
|
|
4410
|
+
* @overload rand([[low],high])
|
|
4411
|
+
* @param [Numeric] low lower inclusive boundary of random numbers. (default=0)
|
|
4412
|
+
* @param [Numeric] high upper exclusive boundary of random numbers.
|
|
4413
|
+
* (default=1 or 1+1i for complex types)
|
|
4414
|
+
* @return [Numo::SComplex] self.
|
|
4415
|
+
* @example
|
|
4416
|
+
* Numo::DFloat.new(6).rand
|
|
4417
|
+
* # => Numo::DFloat#shape=[6]
|
|
4418
|
+
* # [0.0617545, 0.373067, 0.794815, 0.201042, 0.116041, 0.344032]
|
|
4419
|
+
*
|
|
4420
|
+
* Numo::DComplex.new(6).rand(5+5i)
|
|
4421
|
+
* # => Numo::DComplex#shape=[6]
|
|
4422
|
+
* # [2.69974+3.68908i, 0.825443+0.254414i, 0.540323+0.34354i, 4.52061+2.39322i, ...]
|
|
4423
|
+
*
|
|
4424
|
+
* Numo::Int32.new(6).rand(2,5)
|
|
4425
|
+
* # => Numo::Int32#shape=[6]
|
|
4426
|
+
* # [4, 3, 3, 2, 4, 2]
|
|
4427
|
+
*/
|
|
4964
4428
|
rb_define_method(cT, "rand", scomplex_rand, -1);
|
|
4965
4429
|
rb_define_method(cT, "rand_norm", scomplex_rand_norm, -1);
|
|
4966
4430
|
rb_define_method(cT, "poly", scomplex_poly, -2);
|