numo-narray-alt 0.9.14 → 0.10.1
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/Gemfile +1 -1
- data/ext/numo/narray/array.c +1 -9
- data/ext/numo/narray/extconf.rb +0 -11
- data/ext/numo/narray/index.c +5 -39
- data/ext/numo/narray/math.c +0 -5
- data/ext/numo/narray/narray.c +20 -24
- data/ext/numo/narray/numo/intern.h +0 -7
- data/ext/numo/narray/numo/narray.h +6 -8
- data/ext/numo/narray/src/mh/aset.h +169 -0
- data/ext/numo/narray/src/mh/median.h +85 -0
- data/ext/numo/narray/src/mh/s_cast.h +80 -0
- data/ext/numo/narray/src/mh/sort.h +484 -0
- data/ext/numo/narray/src/mh/store.h +496 -0
- data/ext/numo/narray/src/t_bit.c +5 -24
- data/ext/numo/narray/src/t_dcomplex.c +34 -1149
- data/ext/numo/narray/src/t_dfloat.c +23 -1850
- data/ext/numo/narray/src/t_int16.c +71 -1529
- data/ext/numo/narray/src/t_int32.c +71 -1529
- data/ext/numo/narray/src/t_int64.c +71 -1529
- data/ext/numo/narray/src/t_int8.c +71 -1529
- data/ext/numo/narray/src/t_robject.c +34 -1018
- data/ext/numo/narray/src/t_scomplex.c +34 -1149
- data/ext/numo/narray/src/t_sfloat.c +23 -1850
- data/ext/numo/narray/src/t_uint16.c +71 -1529
- data/ext/numo/narray/src/t_uint32.c +71 -1529
- data/ext/numo/narray/src/t_uint64.c +71 -1529
- data/ext/numo/narray/src/t_uint8.c +71 -1529
- data/ext/numo/narray/step.c +2 -59
- data/numo-narray-alt.gemspec +1 -1
- metadata +9 -5
- data/ext/numo/narray/kwargs.c +0 -144
|
@@ -38,8 +38,11 @@ static ID id_to_a;
|
|
|
38
38
|
VALUE cT;
|
|
39
39
|
extern VALUE cRT;
|
|
40
40
|
|
|
41
|
+
#include "mh/store.h"
|
|
42
|
+
#include "mh/s_cast.h"
|
|
41
43
|
#include "mh/extract.h"
|
|
42
44
|
#include "mh/aref.h"
|
|
45
|
+
#include "mh/aset.h"
|
|
43
46
|
#include "mh/coerce_cast.h"
|
|
44
47
|
#include "mh/to_a.h"
|
|
45
48
|
#include "mh/fill.h"
|
|
@@ -118,8 +121,12 @@ extern VALUE cRT;
|
|
|
118
121
|
#include "mh/math/atanh.h"
|
|
119
122
|
#include "mh/math/sinc.h"
|
|
120
123
|
|
|
124
|
+
DEF_NARRAY_CMP_STORE_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
125
|
+
DEF_NARRAY_S_CAST_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
121
126
|
DEF_NARRAY_EXTRACT_METHOD_FUNC(scomplex)
|
|
122
127
|
DEF_NARRAY_AREF_METHOD_FUNC(scomplex)
|
|
128
|
+
DEF_CMP_EXTRACT_DATA_FUNC(scomplex, numo_cSComplex)
|
|
129
|
+
DEF_NARRAY_ASET_METHOD_FUNC(scomplex)
|
|
123
130
|
DEF_NARRAY_COERCE_CAST_METHOD_FUNC(scomplex)
|
|
124
131
|
DEF_NARRAY_TO_A_METHOD_FUNC(scomplex)
|
|
125
132
|
DEF_NARRAY_FILL_METHOD_FUNC(scomplex)
|
|
@@ -198,8 +205,6 @@ DEF_NARRAY_FLT_ACOSH_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
|
198
205
|
DEF_NARRAY_FLT_ATANH_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
199
206
|
DEF_NARRAY_FLT_SINC_METHOD_FUNC(scomplex, numo_cSComplex)
|
|
200
207
|
|
|
201
|
-
static VALUE scomplex_store(VALUE, VALUE);
|
|
202
|
-
|
|
203
208
|
static size_t scomplex_memsize(const void* ptr) {
|
|
204
209
|
size_t size = sizeof(narray_data_t);
|
|
205
210
|
const narray_data_t* na = (const narray_data_t*)ptr;
|
|
@@ -229,11 +234,9 @@ static void scomplex_free(void* ptr) {
|
|
|
229
234
|
}
|
|
230
235
|
na->ptr = NULL;
|
|
231
236
|
}
|
|
232
|
-
if (na->base.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
na->base.shape = NULL;
|
|
236
|
-
}
|
|
237
|
+
if (na->base.shape != NULL && na->base.shape != &(na->base.size)) {
|
|
238
|
+
xfree(na->base.shape);
|
|
239
|
+
na->base.shape = NULL;
|
|
237
240
|
}
|
|
238
241
|
xfree(na);
|
|
239
242
|
}
|
|
@@ -301,1141 +304,6 @@ static VALUE scomplex_allocate(VALUE self) {
|
|
|
301
304
|
return self;
|
|
302
305
|
}
|
|
303
306
|
|
|
304
|
-
static VALUE scomplex_new_dim0(dtype x) {
|
|
305
|
-
VALUE v;
|
|
306
|
-
dtype* ptr;
|
|
307
|
-
|
|
308
|
-
v = nary_new(cT, 0, NULL);
|
|
309
|
-
ptr = (dtype*)(char*)na_get_pointer_for_write(v);
|
|
310
|
-
*ptr = x;
|
|
311
|
-
na_release_lock(v);
|
|
312
|
-
return v;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
static VALUE scomplex_store_numeric(VALUE self, VALUE obj) {
|
|
316
|
-
dtype x;
|
|
317
|
-
x = m_num_to_data(obj);
|
|
318
|
-
obj = scomplex_new_dim0(x);
|
|
319
|
-
scomplex_store(self, obj);
|
|
320
|
-
return self;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
static void iter_scomplex_store_bit(na_loop_t* const lp) {
|
|
324
|
-
size_t i;
|
|
325
|
-
char* p1;
|
|
326
|
-
size_t p2;
|
|
327
|
-
ssize_t s1, s2;
|
|
328
|
-
size_t *idx1, *idx2;
|
|
329
|
-
BIT_DIGIT *a2, x;
|
|
330
|
-
dtype y;
|
|
331
|
-
|
|
332
|
-
INIT_COUNTER(lp, i);
|
|
333
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
334
|
-
INIT_PTR_BIT_IDX(lp, 1, a2, p2, s2, idx2);
|
|
335
|
-
if (idx2) {
|
|
336
|
-
if (idx1) {
|
|
337
|
-
for (; i--;) {
|
|
338
|
-
LOAD_BIT(a2, p2 + *idx2, x);
|
|
339
|
-
idx2++;
|
|
340
|
-
y = m_from_sint(x);
|
|
341
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
342
|
-
}
|
|
343
|
-
} else {
|
|
344
|
-
for (; i--;) {
|
|
345
|
-
LOAD_BIT(a2, p2 + *idx2, x);
|
|
346
|
-
idx2++;
|
|
347
|
-
y = m_from_sint(x);
|
|
348
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
} else {
|
|
352
|
-
if (idx1) {
|
|
353
|
-
for (; i--;) {
|
|
354
|
-
LOAD_BIT(a2, p2, x);
|
|
355
|
-
p2 += s2;
|
|
356
|
-
y = m_from_sint(x);
|
|
357
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
358
|
-
}
|
|
359
|
-
} else {
|
|
360
|
-
for (; i--;) {
|
|
361
|
-
LOAD_BIT(a2, p2, x);
|
|
362
|
-
p2 += s2;
|
|
363
|
-
y = m_from_sint(x);
|
|
364
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
static VALUE scomplex_store_bit(VALUE self, VALUE obj) {
|
|
371
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { Qnil, 0 } };
|
|
372
|
-
ndfunc_t ndf = { iter_scomplex_store_bit, FULL_LOOP, 2, 0, ain, 0 };
|
|
373
|
-
|
|
374
|
-
na_ndloop(&ndf, 2, self, obj);
|
|
375
|
-
return self;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
static void iter_scomplex_store_dcomplex(na_loop_t* const lp) {
|
|
379
|
-
size_t i, s1, s2;
|
|
380
|
-
char *p1, *p2;
|
|
381
|
-
size_t *idx1, *idx2;
|
|
382
|
-
dcomplex x;
|
|
383
|
-
dtype y;
|
|
384
|
-
|
|
385
|
-
INIT_COUNTER(lp, i);
|
|
386
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
387
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
388
|
-
if (idx2) {
|
|
389
|
-
if (idx1) {
|
|
390
|
-
for (; i--;) {
|
|
391
|
-
GET_DATA_INDEX(p2, idx2, dcomplex, x);
|
|
392
|
-
y = m_from_dcomplex(x);
|
|
393
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
394
|
-
}
|
|
395
|
-
} else {
|
|
396
|
-
for (; i--;) {
|
|
397
|
-
GET_DATA_INDEX(p2, idx2, dcomplex, x);
|
|
398
|
-
y = m_from_dcomplex(x);
|
|
399
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
} else {
|
|
403
|
-
if (idx1) {
|
|
404
|
-
for (; i--;) {
|
|
405
|
-
GET_DATA_STRIDE(p2, s2, dcomplex, x);
|
|
406
|
-
y = m_from_dcomplex(x);
|
|
407
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
408
|
-
}
|
|
409
|
-
} else {
|
|
410
|
-
for (; i--;) {
|
|
411
|
-
GET_DATA_STRIDE(p2, s2, dcomplex, x);
|
|
412
|
-
y = m_from_dcomplex(x);
|
|
413
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
static VALUE scomplex_store_dcomplex(VALUE self, VALUE obj) {
|
|
420
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { Qnil, 0 } };
|
|
421
|
-
ndfunc_t ndf = { iter_scomplex_store_dcomplex, FULL_LOOP, 2, 0, ain, 0 };
|
|
422
|
-
|
|
423
|
-
na_ndloop(&ndf, 2, self, obj);
|
|
424
|
-
return self;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
static void iter_scomplex_store_scomplex(na_loop_t* const lp) {
|
|
428
|
-
size_t i, s1, s2;
|
|
429
|
-
char *p1, *p2;
|
|
430
|
-
size_t *idx1, *idx2;
|
|
431
|
-
scomplex x;
|
|
432
|
-
dtype y;
|
|
433
|
-
|
|
434
|
-
INIT_COUNTER(lp, i);
|
|
435
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
436
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
437
|
-
if (idx2) {
|
|
438
|
-
if (idx1) {
|
|
439
|
-
for (; i--;) {
|
|
440
|
-
GET_DATA_INDEX(p2, idx2, scomplex, x);
|
|
441
|
-
y = m_from_scomplex(x);
|
|
442
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
443
|
-
}
|
|
444
|
-
} else {
|
|
445
|
-
for (; i--;) {
|
|
446
|
-
GET_DATA_INDEX(p2, idx2, scomplex, x);
|
|
447
|
-
y = m_from_scomplex(x);
|
|
448
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
} else {
|
|
452
|
-
if (idx1) {
|
|
453
|
-
for (; i--;) {
|
|
454
|
-
GET_DATA_STRIDE(p2, s2, scomplex, x);
|
|
455
|
-
y = m_from_scomplex(x);
|
|
456
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
457
|
-
}
|
|
458
|
-
} else {
|
|
459
|
-
for (; i--;) {
|
|
460
|
-
GET_DATA_STRIDE(p2, s2, scomplex, x);
|
|
461
|
-
y = m_from_scomplex(x);
|
|
462
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
static VALUE scomplex_store_scomplex(VALUE self, VALUE obj) {
|
|
469
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { Qnil, 0 } };
|
|
470
|
-
ndfunc_t ndf = { iter_scomplex_store_scomplex, FULL_LOOP, 2, 0, ain, 0 };
|
|
471
|
-
|
|
472
|
-
na_ndloop(&ndf, 2, self, obj);
|
|
473
|
-
return self;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
static void iter_scomplex_store_dfloat(na_loop_t* const lp) {
|
|
477
|
-
size_t i, s1, s2;
|
|
478
|
-
char *p1, *p2;
|
|
479
|
-
size_t *idx1, *idx2;
|
|
480
|
-
double x;
|
|
481
|
-
dtype y;
|
|
482
|
-
|
|
483
|
-
INIT_COUNTER(lp, i);
|
|
484
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
485
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
486
|
-
if (idx2) {
|
|
487
|
-
if (idx1) {
|
|
488
|
-
for (; i--;) {
|
|
489
|
-
GET_DATA_INDEX(p2, idx2, double, x);
|
|
490
|
-
y = m_from_real(x);
|
|
491
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
492
|
-
}
|
|
493
|
-
} else {
|
|
494
|
-
for (; i--;) {
|
|
495
|
-
GET_DATA_INDEX(p2, idx2, double, x);
|
|
496
|
-
y = m_from_real(x);
|
|
497
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
} else {
|
|
501
|
-
if (idx1) {
|
|
502
|
-
for (; i--;) {
|
|
503
|
-
GET_DATA_STRIDE(p2, s2, double, x);
|
|
504
|
-
y = m_from_real(x);
|
|
505
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
506
|
-
}
|
|
507
|
-
} else {
|
|
508
|
-
for (; i--;) {
|
|
509
|
-
GET_DATA_STRIDE(p2, s2, double, x);
|
|
510
|
-
y = m_from_real(x);
|
|
511
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
static VALUE scomplex_store_dfloat(VALUE self, VALUE obj) {
|
|
518
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { Qnil, 0 } };
|
|
519
|
-
ndfunc_t ndf = { iter_scomplex_store_dfloat, FULL_LOOP, 2, 0, ain, 0 };
|
|
520
|
-
|
|
521
|
-
na_ndloop(&ndf, 2, self, obj);
|
|
522
|
-
return self;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
static void iter_scomplex_store_sfloat(na_loop_t* const lp) {
|
|
526
|
-
size_t i, s1, s2;
|
|
527
|
-
char *p1, *p2;
|
|
528
|
-
size_t *idx1, *idx2;
|
|
529
|
-
float x;
|
|
530
|
-
dtype y;
|
|
531
|
-
|
|
532
|
-
INIT_COUNTER(lp, i);
|
|
533
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
534
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
535
|
-
if (idx2) {
|
|
536
|
-
if (idx1) {
|
|
537
|
-
for (; i--;) {
|
|
538
|
-
GET_DATA_INDEX(p2, idx2, float, x);
|
|
539
|
-
y = m_from_real(x);
|
|
540
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
541
|
-
}
|
|
542
|
-
} else {
|
|
543
|
-
for (; i--;) {
|
|
544
|
-
GET_DATA_INDEX(p2, idx2, float, x);
|
|
545
|
-
y = m_from_real(x);
|
|
546
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
} else {
|
|
550
|
-
if (idx1) {
|
|
551
|
-
for (; i--;) {
|
|
552
|
-
GET_DATA_STRIDE(p2, s2, float, x);
|
|
553
|
-
y = m_from_real(x);
|
|
554
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
555
|
-
}
|
|
556
|
-
} else {
|
|
557
|
-
for (; i--;) {
|
|
558
|
-
GET_DATA_STRIDE(p2, s2, float, x);
|
|
559
|
-
y = m_from_real(x);
|
|
560
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
static VALUE scomplex_store_sfloat(VALUE self, VALUE obj) {
|
|
567
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { Qnil, 0 } };
|
|
568
|
-
ndfunc_t ndf = { iter_scomplex_store_sfloat, FULL_LOOP, 2, 0, ain, 0 };
|
|
569
|
-
|
|
570
|
-
na_ndloop(&ndf, 2, self, obj);
|
|
571
|
-
return self;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
static void iter_scomplex_store_int64(na_loop_t* const lp) {
|
|
575
|
-
size_t i, s1, s2;
|
|
576
|
-
char *p1, *p2;
|
|
577
|
-
size_t *idx1, *idx2;
|
|
578
|
-
int64_t x;
|
|
579
|
-
dtype y;
|
|
580
|
-
|
|
581
|
-
INIT_COUNTER(lp, i);
|
|
582
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
583
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
584
|
-
if (idx2) {
|
|
585
|
-
if (idx1) {
|
|
586
|
-
for (; i--;) {
|
|
587
|
-
GET_DATA_INDEX(p2, idx2, int64_t, x);
|
|
588
|
-
y = m_from_int64(x);
|
|
589
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
590
|
-
}
|
|
591
|
-
} else {
|
|
592
|
-
for (; i--;) {
|
|
593
|
-
GET_DATA_INDEX(p2, idx2, int64_t, x);
|
|
594
|
-
y = m_from_int64(x);
|
|
595
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
} else {
|
|
599
|
-
if (idx1) {
|
|
600
|
-
for (; i--;) {
|
|
601
|
-
GET_DATA_STRIDE(p2, s2, int64_t, x);
|
|
602
|
-
y = m_from_int64(x);
|
|
603
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
604
|
-
}
|
|
605
|
-
} else {
|
|
606
|
-
for (; i--;) {
|
|
607
|
-
GET_DATA_STRIDE(p2, s2, int64_t, x);
|
|
608
|
-
y = m_from_int64(x);
|
|
609
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
static VALUE scomplex_store_int64(VALUE self, VALUE obj) {
|
|
616
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { Qnil, 0 } };
|
|
617
|
-
ndfunc_t ndf = { iter_scomplex_store_int64, FULL_LOOP, 2, 0, ain, 0 };
|
|
618
|
-
|
|
619
|
-
na_ndloop(&ndf, 2, self, obj);
|
|
620
|
-
return self;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
static void iter_scomplex_store_int32(na_loop_t* const lp) {
|
|
624
|
-
size_t i, s1, s2;
|
|
625
|
-
char *p1, *p2;
|
|
626
|
-
size_t *idx1, *idx2;
|
|
627
|
-
int32_t x;
|
|
628
|
-
dtype y;
|
|
629
|
-
|
|
630
|
-
INIT_COUNTER(lp, i);
|
|
631
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
632
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
633
|
-
if (idx2) {
|
|
634
|
-
if (idx1) {
|
|
635
|
-
for (; i--;) {
|
|
636
|
-
GET_DATA_INDEX(p2, idx2, int32_t, x);
|
|
637
|
-
y = m_from_int32(x);
|
|
638
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
639
|
-
}
|
|
640
|
-
} else {
|
|
641
|
-
for (; i--;) {
|
|
642
|
-
GET_DATA_INDEX(p2, idx2, int32_t, x);
|
|
643
|
-
y = m_from_int32(x);
|
|
644
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
} else {
|
|
648
|
-
if (idx1) {
|
|
649
|
-
for (; i--;) {
|
|
650
|
-
GET_DATA_STRIDE(p2, s2, int32_t, x);
|
|
651
|
-
y = m_from_int32(x);
|
|
652
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
653
|
-
}
|
|
654
|
-
} else {
|
|
655
|
-
for (; i--;) {
|
|
656
|
-
GET_DATA_STRIDE(p2, s2, int32_t, x);
|
|
657
|
-
y = m_from_int32(x);
|
|
658
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
static VALUE scomplex_store_int32(VALUE self, VALUE obj) {
|
|
665
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { Qnil, 0 } };
|
|
666
|
-
ndfunc_t ndf = { iter_scomplex_store_int32, FULL_LOOP, 2, 0, ain, 0 };
|
|
667
|
-
|
|
668
|
-
na_ndloop(&ndf, 2, self, obj);
|
|
669
|
-
return self;
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
static void iter_scomplex_store_int16(na_loop_t* const lp) {
|
|
673
|
-
size_t i, s1, s2;
|
|
674
|
-
char *p1, *p2;
|
|
675
|
-
size_t *idx1, *idx2;
|
|
676
|
-
int16_t x;
|
|
677
|
-
dtype y;
|
|
678
|
-
|
|
679
|
-
INIT_COUNTER(lp, i);
|
|
680
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
681
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
682
|
-
if (idx2) {
|
|
683
|
-
if (idx1) {
|
|
684
|
-
for (; i--;) {
|
|
685
|
-
GET_DATA_INDEX(p2, idx2, int16_t, x);
|
|
686
|
-
y = m_from_sint(x);
|
|
687
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
688
|
-
}
|
|
689
|
-
} else {
|
|
690
|
-
for (; i--;) {
|
|
691
|
-
GET_DATA_INDEX(p2, idx2, int16_t, x);
|
|
692
|
-
y = m_from_sint(x);
|
|
693
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
} else {
|
|
697
|
-
if (idx1) {
|
|
698
|
-
for (; i--;) {
|
|
699
|
-
GET_DATA_STRIDE(p2, s2, int16_t, x);
|
|
700
|
-
y = m_from_sint(x);
|
|
701
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
702
|
-
}
|
|
703
|
-
} else {
|
|
704
|
-
for (; i--;) {
|
|
705
|
-
GET_DATA_STRIDE(p2, s2, int16_t, x);
|
|
706
|
-
y = m_from_sint(x);
|
|
707
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
static VALUE scomplex_store_int16(VALUE self, VALUE obj) {
|
|
714
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { Qnil, 0 } };
|
|
715
|
-
ndfunc_t ndf = { iter_scomplex_store_int16, FULL_LOOP, 2, 0, ain, 0 };
|
|
716
|
-
|
|
717
|
-
na_ndloop(&ndf, 2, self, obj);
|
|
718
|
-
return self;
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
static void iter_scomplex_store_int8(na_loop_t* const lp) {
|
|
722
|
-
size_t i, s1, s2;
|
|
723
|
-
char *p1, *p2;
|
|
724
|
-
size_t *idx1, *idx2;
|
|
725
|
-
int8_t x;
|
|
726
|
-
dtype y;
|
|
727
|
-
|
|
728
|
-
INIT_COUNTER(lp, i);
|
|
729
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
730
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
731
|
-
if (idx2) {
|
|
732
|
-
if (idx1) {
|
|
733
|
-
for (; i--;) {
|
|
734
|
-
GET_DATA_INDEX(p2, idx2, int8_t, x);
|
|
735
|
-
y = m_from_sint(x);
|
|
736
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
737
|
-
}
|
|
738
|
-
} else {
|
|
739
|
-
for (; i--;) {
|
|
740
|
-
GET_DATA_INDEX(p2, idx2, int8_t, x);
|
|
741
|
-
y = m_from_sint(x);
|
|
742
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
} else {
|
|
746
|
-
if (idx1) {
|
|
747
|
-
for (; i--;) {
|
|
748
|
-
GET_DATA_STRIDE(p2, s2, int8_t, x);
|
|
749
|
-
y = m_from_sint(x);
|
|
750
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
751
|
-
}
|
|
752
|
-
} else {
|
|
753
|
-
for (; i--;) {
|
|
754
|
-
GET_DATA_STRIDE(p2, s2, int8_t, x);
|
|
755
|
-
y = m_from_sint(x);
|
|
756
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
static VALUE scomplex_store_int8(VALUE self, VALUE obj) {
|
|
763
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { Qnil, 0 } };
|
|
764
|
-
ndfunc_t ndf = { iter_scomplex_store_int8, FULL_LOOP, 2, 0, ain, 0 };
|
|
765
|
-
|
|
766
|
-
na_ndloop(&ndf, 2, self, obj);
|
|
767
|
-
return self;
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
static void iter_scomplex_store_uint64(na_loop_t* const lp) {
|
|
771
|
-
size_t i, s1, s2;
|
|
772
|
-
char *p1, *p2;
|
|
773
|
-
size_t *idx1, *idx2;
|
|
774
|
-
u_int64_t x;
|
|
775
|
-
dtype y;
|
|
776
|
-
|
|
777
|
-
INIT_COUNTER(lp, i);
|
|
778
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
779
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
780
|
-
if (idx2) {
|
|
781
|
-
if (idx1) {
|
|
782
|
-
for (; i--;) {
|
|
783
|
-
GET_DATA_INDEX(p2, idx2, u_int64_t, x);
|
|
784
|
-
y = m_from_uint64(x);
|
|
785
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
786
|
-
}
|
|
787
|
-
} else {
|
|
788
|
-
for (; i--;) {
|
|
789
|
-
GET_DATA_INDEX(p2, idx2, u_int64_t, x);
|
|
790
|
-
y = m_from_uint64(x);
|
|
791
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
} else {
|
|
795
|
-
if (idx1) {
|
|
796
|
-
for (; i--;) {
|
|
797
|
-
GET_DATA_STRIDE(p2, s2, u_int64_t, x);
|
|
798
|
-
y = m_from_uint64(x);
|
|
799
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
800
|
-
}
|
|
801
|
-
} else {
|
|
802
|
-
for (; i--;) {
|
|
803
|
-
GET_DATA_STRIDE(p2, s2, u_int64_t, x);
|
|
804
|
-
y = m_from_uint64(x);
|
|
805
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
static VALUE scomplex_store_uint64(VALUE self, VALUE obj) {
|
|
812
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { Qnil, 0 } };
|
|
813
|
-
ndfunc_t ndf = { iter_scomplex_store_uint64, FULL_LOOP, 2, 0, ain, 0 };
|
|
814
|
-
|
|
815
|
-
na_ndloop(&ndf, 2, self, obj);
|
|
816
|
-
return self;
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
static void iter_scomplex_store_uint32(na_loop_t* const lp) {
|
|
820
|
-
size_t i, s1, s2;
|
|
821
|
-
char *p1, *p2;
|
|
822
|
-
size_t *idx1, *idx2;
|
|
823
|
-
u_int32_t x;
|
|
824
|
-
dtype y;
|
|
825
|
-
|
|
826
|
-
INIT_COUNTER(lp, i);
|
|
827
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
828
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
829
|
-
if (idx2) {
|
|
830
|
-
if (idx1) {
|
|
831
|
-
for (; i--;) {
|
|
832
|
-
GET_DATA_INDEX(p2, idx2, u_int32_t, x);
|
|
833
|
-
y = m_from_uint32(x);
|
|
834
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
835
|
-
}
|
|
836
|
-
} else {
|
|
837
|
-
for (; i--;) {
|
|
838
|
-
GET_DATA_INDEX(p2, idx2, u_int32_t, x);
|
|
839
|
-
y = m_from_uint32(x);
|
|
840
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
} else {
|
|
844
|
-
if (idx1) {
|
|
845
|
-
for (; i--;) {
|
|
846
|
-
GET_DATA_STRIDE(p2, s2, u_int32_t, x);
|
|
847
|
-
y = m_from_uint32(x);
|
|
848
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
849
|
-
}
|
|
850
|
-
} else {
|
|
851
|
-
for (; i--;) {
|
|
852
|
-
GET_DATA_STRIDE(p2, s2, u_int32_t, x);
|
|
853
|
-
y = m_from_uint32(x);
|
|
854
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
static VALUE scomplex_store_uint32(VALUE self, VALUE obj) {
|
|
861
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { Qnil, 0 } };
|
|
862
|
-
ndfunc_t ndf = { iter_scomplex_store_uint32, FULL_LOOP, 2, 0, ain, 0 };
|
|
863
|
-
|
|
864
|
-
na_ndloop(&ndf, 2, self, obj);
|
|
865
|
-
return self;
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
static void iter_scomplex_store_uint16(na_loop_t* const lp) {
|
|
869
|
-
size_t i, s1, s2;
|
|
870
|
-
char *p1, *p2;
|
|
871
|
-
size_t *idx1, *idx2;
|
|
872
|
-
u_int16_t x;
|
|
873
|
-
dtype y;
|
|
874
|
-
|
|
875
|
-
INIT_COUNTER(lp, i);
|
|
876
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
877
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
878
|
-
if (idx2) {
|
|
879
|
-
if (idx1) {
|
|
880
|
-
for (; i--;) {
|
|
881
|
-
GET_DATA_INDEX(p2, idx2, u_int16_t, x);
|
|
882
|
-
y = m_from_sint(x);
|
|
883
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
884
|
-
}
|
|
885
|
-
} else {
|
|
886
|
-
for (; i--;) {
|
|
887
|
-
GET_DATA_INDEX(p2, idx2, u_int16_t, x);
|
|
888
|
-
y = m_from_sint(x);
|
|
889
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
} else {
|
|
893
|
-
if (idx1) {
|
|
894
|
-
for (; i--;) {
|
|
895
|
-
GET_DATA_STRIDE(p2, s2, u_int16_t, x);
|
|
896
|
-
y = m_from_sint(x);
|
|
897
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
898
|
-
}
|
|
899
|
-
} else {
|
|
900
|
-
for (; i--;) {
|
|
901
|
-
GET_DATA_STRIDE(p2, s2, u_int16_t, x);
|
|
902
|
-
y = m_from_sint(x);
|
|
903
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
static VALUE scomplex_store_uint16(VALUE self, VALUE obj) {
|
|
910
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { Qnil, 0 } };
|
|
911
|
-
ndfunc_t ndf = { iter_scomplex_store_uint16, FULL_LOOP, 2, 0, ain, 0 };
|
|
912
|
-
|
|
913
|
-
na_ndloop(&ndf, 2, self, obj);
|
|
914
|
-
return self;
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
static void iter_scomplex_store_uint8(na_loop_t* const lp) {
|
|
918
|
-
size_t i, s1, s2;
|
|
919
|
-
char *p1, *p2;
|
|
920
|
-
size_t *idx1, *idx2;
|
|
921
|
-
u_int8_t x;
|
|
922
|
-
dtype y;
|
|
923
|
-
|
|
924
|
-
INIT_COUNTER(lp, i);
|
|
925
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
926
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
927
|
-
if (idx2) {
|
|
928
|
-
if (idx1) {
|
|
929
|
-
for (; i--;) {
|
|
930
|
-
GET_DATA_INDEX(p2, idx2, u_int8_t, x);
|
|
931
|
-
y = m_from_sint(x);
|
|
932
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
933
|
-
}
|
|
934
|
-
} else {
|
|
935
|
-
for (; i--;) {
|
|
936
|
-
GET_DATA_INDEX(p2, idx2, u_int8_t, x);
|
|
937
|
-
y = m_from_sint(x);
|
|
938
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
} else {
|
|
942
|
-
if (idx1) {
|
|
943
|
-
for (; i--;) {
|
|
944
|
-
GET_DATA_STRIDE(p2, s2, u_int8_t, x);
|
|
945
|
-
y = m_from_sint(x);
|
|
946
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
947
|
-
}
|
|
948
|
-
} else {
|
|
949
|
-
for (; i--;) {
|
|
950
|
-
GET_DATA_STRIDE(p2, s2, u_int8_t, x);
|
|
951
|
-
y = m_from_sint(x);
|
|
952
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
static VALUE scomplex_store_uint8(VALUE self, VALUE obj) {
|
|
959
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { Qnil, 0 } };
|
|
960
|
-
ndfunc_t ndf = { iter_scomplex_store_uint8, FULL_LOOP, 2, 0, ain, 0 };
|
|
961
|
-
|
|
962
|
-
na_ndloop(&ndf, 2, self, obj);
|
|
963
|
-
return self;
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
static void iter_scomplex_store_robject(na_loop_t* const lp) {
|
|
967
|
-
size_t i, s1, s2;
|
|
968
|
-
char *p1, *p2;
|
|
969
|
-
size_t *idx1, *idx2;
|
|
970
|
-
VALUE x;
|
|
971
|
-
dtype y;
|
|
972
|
-
|
|
973
|
-
INIT_COUNTER(lp, i);
|
|
974
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
975
|
-
INIT_PTR_IDX(lp, 1, p2, s2, idx2);
|
|
976
|
-
if (idx2) {
|
|
977
|
-
if (idx1) {
|
|
978
|
-
for (; i--;) {
|
|
979
|
-
GET_DATA_INDEX(p2, idx2, VALUE, x);
|
|
980
|
-
y = m_num_to_data(x);
|
|
981
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
982
|
-
}
|
|
983
|
-
} else {
|
|
984
|
-
for (; i--;) {
|
|
985
|
-
GET_DATA_INDEX(p2, idx2, VALUE, x);
|
|
986
|
-
y = m_num_to_data(x);
|
|
987
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
} else {
|
|
991
|
-
if (idx1) {
|
|
992
|
-
for (; i--;) {
|
|
993
|
-
GET_DATA_STRIDE(p2, s2, VALUE, x);
|
|
994
|
-
y = m_num_to_data(x);
|
|
995
|
-
SET_DATA_INDEX(p1, idx1, dtype, y);
|
|
996
|
-
}
|
|
997
|
-
} else {
|
|
998
|
-
for (; i--;) {
|
|
999
|
-
GET_DATA_STRIDE(p2, s2, VALUE, x);
|
|
1000
|
-
y = m_num_to_data(x);
|
|
1001
|
-
SET_DATA_STRIDE(p1, s1, dtype, y);
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
static VALUE scomplex_store_robject(VALUE self, VALUE obj) {
|
|
1008
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { Qnil, 0 } };
|
|
1009
|
-
ndfunc_t ndf = { iter_scomplex_store_robject, FULL_LOOP, 2, 0, ain, 0 };
|
|
1010
|
-
|
|
1011
|
-
na_ndloop(&ndf, 2, self, obj);
|
|
1012
|
-
return self;
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
static void iter_scomplex_store_array(na_loop_t* const lp) {
|
|
1016
|
-
size_t i, n;
|
|
1017
|
-
size_t i1, n1;
|
|
1018
|
-
VALUE v1, *ptr;
|
|
1019
|
-
char* p1;
|
|
1020
|
-
size_t s1, *idx1;
|
|
1021
|
-
VALUE x;
|
|
1022
|
-
double y;
|
|
1023
|
-
dtype z;
|
|
1024
|
-
size_t len, c;
|
|
1025
|
-
double beg, step;
|
|
1026
|
-
|
|
1027
|
-
INIT_COUNTER(lp, n);
|
|
1028
|
-
INIT_PTR_IDX(lp, 0, p1, s1, idx1);
|
|
1029
|
-
v1 = lp->args[1].value;
|
|
1030
|
-
i = 0;
|
|
1031
|
-
|
|
1032
|
-
if (lp->args[1].ptr) {
|
|
1033
|
-
if (v1 == Qtrue) {
|
|
1034
|
-
iter_scomplex_store_scomplex(lp);
|
|
1035
|
-
i = lp->args[1].shape[0];
|
|
1036
|
-
if (idx1) {
|
|
1037
|
-
idx1 += i;
|
|
1038
|
-
} else {
|
|
1039
|
-
p1 += s1 * i;
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
goto loop_end;
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
ptr = &v1;
|
|
1046
|
-
|
|
1047
|
-
switch (TYPE(v1)) {
|
|
1048
|
-
case T_ARRAY:
|
|
1049
|
-
n1 = RARRAY_LEN(v1);
|
|
1050
|
-
ptr = RARRAY_PTR(v1);
|
|
1051
|
-
break;
|
|
1052
|
-
case T_NIL:
|
|
1053
|
-
n1 = 0;
|
|
1054
|
-
break;
|
|
1055
|
-
default:
|
|
1056
|
-
n1 = 1;
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
if (idx1) {
|
|
1060
|
-
for (i = i1 = 0; i1 < n1 && i < n; i++, i1++) {
|
|
1061
|
-
x = ptr[i1];
|
|
1062
|
-
if (rb_obj_is_kind_of(x, rb_cRange)
|
|
1063
|
-
#ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
|
|
1064
|
-
|| rb_obj_is_kind_of(x, rb_cArithSeq)
|
|
1065
|
-
#else
|
|
1066
|
-
|| rb_obj_is_kind_of(x, rb_cEnumerator)
|
|
1067
|
-
#endif
|
|
1068
|
-
) {
|
|
1069
|
-
nary_step_sequence(x, &len, &beg, &step);
|
|
1070
|
-
for (c = 0; c < len && i < n; c++, i++) {
|
|
1071
|
-
y = beg + step * c;
|
|
1072
|
-
z = m_from_double(y);
|
|
1073
|
-
SET_DATA_INDEX(p1, idx1, dtype, z);
|
|
1074
|
-
}
|
|
1075
|
-
} else if (TYPE(x) != T_ARRAY) {
|
|
1076
|
-
z = m_num_to_data(x);
|
|
1077
|
-
SET_DATA_INDEX(p1, idx1, dtype, z);
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
} else {
|
|
1081
|
-
for (i = i1 = 0; i1 < n1 && i < n; i++, i1++) {
|
|
1082
|
-
x = ptr[i1];
|
|
1083
|
-
if (rb_obj_is_kind_of(x, rb_cRange)
|
|
1084
|
-
#ifdef HAVE_RB_ARITHMETIC_SEQUENCE_EXTRACT
|
|
1085
|
-
|| rb_obj_is_kind_of(x, rb_cArithSeq)
|
|
1086
|
-
#else
|
|
1087
|
-
|| rb_obj_is_kind_of(x, rb_cEnumerator)
|
|
1088
|
-
#endif
|
|
1089
|
-
) {
|
|
1090
|
-
nary_step_sequence(x, &len, &beg, &step);
|
|
1091
|
-
for (c = 0; c < len && i < n; c++, i++) {
|
|
1092
|
-
y = beg + step * c;
|
|
1093
|
-
z = m_from_double(y);
|
|
1094
|
-
SET_DATA_STRIDE(p1, s1, dtype, z);
|
|
1095
|
-
}
|
|
1096
|
-
} else if (TYPE(x) != T_ARRAY) {
|
|
1097
|
-
z = m_num_to_data(x);
|
|
1098
|
-
SET_DATA_STRIDE(p1, s1, dtype, z);
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
loop_end:
|
|
1104
|
-
z = m_zero;
|
|
1105
|
-
if (idx1) {
|
|
1106
|
-
for (; i < n; i++) {
|
|
1107
|
-
SET_DATA_INDEX(p1, idx1, dtype, z);
|
|
1108
|
-
}
|
|
1109
|
-
} else {
|
|
1110
|
-
for (; i < n; i++) {
|
|
1111
|
-
SET_DATA_STRIDE(p1, s1, dtype, z);
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
static VALUE scomplex_store_array(VALUE self, VALUE rary) {
|
|
1117
|
-
ndfunc_arg_in_t ain[2] = { { OVERWRITE, 0 }, { rb_cArray, 0 } };
|
|
1118
|
-
ndfunc_t ndf = { iter_scomplex_store_array, FULL_LOOP, 2, 0, ain, 0 };
|
|
1119
|
-
|
|
1120
|
-
na_ndloop_store_rarray(&ndf, self, rary);
|
|
1121
|
-
return self;
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
/*
|
|
1125
|
-
Store elements to Numo::SComplex from other.
|
|
1126
|
-
@overload store(other)
|
|
1127
|
-
@param [Object] other
|
|
1128
|
-
@return [Numo::SComplex] self
|
|
1129
|
-
*/
|
|
1130
|
-
static VALUE scomplex_store(VALUE self, VALUE obj) {
|
|
1131
|
-
VALUE r, klass;
|
|
1132
|
-
|
|
1133
|
-
klass = rb_obj_class(obj);
|
|
1134
|
-
|
|
1135
|
-
if (klass == numo_cSComplex) {
|
|
1136
|
-
scomplex_store_scomplex(self, obj);
|
|
1137
|
-
return self;
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
if (IS_INTEGER_CLASS(klass) || klass == rb_cFloat || klass == rb_cComplex) {
|
|
1141
|
-
scomplex_store_numeric(self, obj);
|
|
1142
|
-
return self;
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
if (klass == numo_cBit) {
|
|
1146
|
-
scomplex_store_bit(self, obj);
|
|
1147
|
-
return self;
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
if (klass == numo_cDComplex) {
|
|
1151
|
-
scomplex_store_dcomplex(self, obj);
|
|
1152
|
-
return self;
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
if (klass == numo_cDFloat) {
|
|
1156
|
-
scomplex_store_dfloat(self, obj);
|
|
1157
|
-
return self;
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
if (klass == numo_cSFloat) {
|
|
1161
|
-
scomplex_store_sfloat(self, obj);
|
|
1162
|
-
return self;
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
if (klass == numo_cInt64) {
|
|
1166
|
-
scomplex_store_int64(self, obj);
|
|
1167
|
-
return self;
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
if (klass == numo_cInt32) {
|
|
1171
|
-
scomplex_store_int32(self, obj);
|
|
1172
|
-
return self;
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
if (klass == numo_cInt16) {
|
|
1176
|
-
scomplex_store_int16(self, obj);
|
|
1177
|
-
return self;
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
if (klass == numo_cInt8) {
|
|
1181
|
-
scomplex_store_int8(self, obj);
|
|
1182
|
-
return self;
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
if (klass == numo_cUInt64) {
|
|
1186
|
-
scomplex_store_uint64(self, obj);
|
|
1187
|
-
return self;
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
if (klass == numo_cUInt32) {
|
|
1191
|
-
scomplex_store_uint32(self, obj);
|
|
1192
|
-
return self;
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
if (klass == numo_cUInt16) {
|
|
1196
|
-
scomplex_store_uint16(self, obj);
|
|
1197
|
-
return self;
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
if (klass == numo_cUInt8) {
|
|
1201
|
-
scomplex_store_uint8(self, obj);
|
|
1202
|
-
return self;
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
if (klass == numo_cRObject) {
|
|
1206
|
-
scomplex_store_robject(self, obj);
|
|
1207
|
-
return self;
|
|
1208
|
-
}
|
|
1209
|
-
|
|
1210
|
-
if (klass == rb_cArray) {
|
|
1211
|
-
scomplex_store_array(self, obj);
|
|
1212
|
-
return self;
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
if (IsNArray(obj)) {
|
|
1216
|
-
r = rb_funcall(obj, rb_intern("coerce_cast"), 1, cT);
|
|
1217
|
-
if (rb_obj_class(r) == cT) {
|
|
1218
|
-
scomplex_store(self, r);
|
|
1219
|
-
return self;
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
rb_raise(
|
|
1224
|
-
nary_eCastError, "unknown conversion from %s to %s", rb_class2name(rb_obj_class(obj)),
|
|
1225
|
-
rb_class2name(rb_obj_class(self))
|
|
1226
|
-
);
|
|
1227
|
-
|
|
1228
|
-
return self;
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
/*
|
|
1232
|
-
Convert a data value of obj (with a single element) to dtype.
|
|
1233
|
-
*/
|
|
1234
|
-
static dtype scomplex_extract_data(VALUE obj) {
|
|
1235
|
-
narray_t* na;
|
|
1236
|
-
dtype x;
|
|
1237
|
-
char* ptr;
|
|
1238
|
-
size_t pos;
|
|
1239
|
-
VALUE r, klass;
|
|
1240
|
-
|
|
1241
|
-
if (IsNArray(obj)) {
|
|
1242
|
-
GetNArray(obj, na);
|
|
1243
|
-
if (na->size != 1) {
|
|
1244
|
-
rb_raise(nary_eShapeError, "narray size should be 1");
|
|
1245
|
-
}
|
|
1246
|
-
klass = rb_obj_class(obj);
|
|
1247
|
-
ptr = na_get_pointer_for_read(obj);
|
|
1248
|
-
pos = na_get_offset(obj);
|
|
1249
|
-
|
|
1250
|
-
if (klass == numo_cSComplex) {
|
|
1251
|
-
{
|
|
1252
|
-
scomplex* p = (scomplex*)(ptr + pos);
|
|
1253
|
-
x = c_new(REAL(*p), IMAG(*p));
|
|
1254
|
-
};
|
|
1255
|
-
return x;
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
|
-
if (klass == numo_cBit) {
|
|
1259
|
-
{
|
|
1260
|
-
BIT_DIGIT b;
|
|
1261
|
-
LOAD_BIT(ptr, pos, b);
|
|
1262
|
-
x = m_from_sint(b);
|
|
1263
|
-
};
|
|
1264
|
-
return x;
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
if (klass == numo_cDComplex) {
|
|
1268
|
-
{
|
|
1269
|
-
dcomplex* p = (dcomplex*)(ptr + pos);
|
|
1270
|
-
x = c_new(REAL(*p), IMAG(*p));
|
|
1271
|
-
};
|
|
1272
|
-
return x;
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
|
-
if (klass == numo_cDFloat) {
|
|
1276
|
-
x = m_from_real(*(double*)(ptr + pos));
|
|
1277
|
-
return x;
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
if (klass == numo_cSFloat) {
|
|
1281
|
-
x = m_from_real(*(float*)(ptr + pos));
|
|
1282
|
-
return x;
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
if (klass == numo_cInt64) {
|
|
1286
|
-
x = m_from_int64(*(int64_t*)(ptr + pos));
|
|
1287
|
-
return x;
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
if (klass == numo_cInt32) {
|
|
1291
|
-
x = m_from_int32(*(int32_t*)(ptr + pos));
|
|
1292
|
-
return x;
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
if (klass == numo_cInt16) {
|
|
1296
|
-
x = m_from_sint(*(int16_t*)(ptr + pos));
|
|
1297
|
-
return x;
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
if (klass == numo_cInt8) {
|
|
1301
|
-
x = m_from_sint(*(int8_t*)(ptr + pos));
|
|
1302
|
-
return x;
|
|
1303
|
-
}
|
|
1304
|
-
|
|
1305
|
-
if (klass == numo_cUInt64) {
|
|
1306
|
-
x = m_from_uint64(*(u_int64_t*)(ptr + pos));
|
|
1307
|
-
return x;
|
|
1308
|
-
}
|
|
1309
|
-
|
|
1310
|
-
if (klass == numo_cUInt32) {
|
|
1311
|
-
x = m_from_uint32(*(u_int32_t*)(ptr + pos));
|
|
1312
|
-
return x;
|
|
1313
|
-
}
|
|
1314
|
-
|
|
1315
|
-
if (klass == numo_cUInt16) {
|
|
1316
|
-
x = m_from_sint(*(u_int16_t*)(ptr + pos));
|
|
1317
|
-
return x;
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
if (klass == numo_cUInt8) {
|
|
1321
|
-
x = m_from_sint(*(u_int8_t*)(ptr + pos));
|
|
1322
|
-
return x;
|
|
1323
|
-
}
|
|
1324
|
-
|
|
1325
|
-
if (klass == numo_cRObject) {
|
|
1326
|
-
x = m_num_to_data(*(VALUE*)(ptr + pos));
|
|
1327
|
-
return x;
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
|
-
// coerce
|
|
1331
|
-
r = rb_funcall(obj, rb_intern("coerce_cast"), 1, cT);
|
|
1332
|
-
if (rb_obj_class(r) == cT) {
|
|
1333
|
-
return scomplex_extract_data(r);
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
rb_raise(
|
|
1337
|
-
nary_eCastError, "unknown conversion from %s to %s", rb_class2name(rb_obj_class(obj)),
|
|
1338
|
-
rb_class2name(cT)
|
|
1339
|
-
);
|
|
1340
|
-
}
|
|
1341
|
-
if (TYPE(obj) == T_ARRAY) {
|
|
1342
|
-
if (RARRAY_LEN(obj) != 1) {
|
|
1343
|
-
rb_raise(nary_eShapeError, "array size should be 1");
|
|
1344
|
-
}
|
|
1345
|
-
return m_num_to_data(RARRAY_AREF(obj, 0));
|
|
1346
|
-
}
|
|
1347
|
-
return m_num_to_data(obj);
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
static VALUE scomplex_cast_array(VALUE rary) {
|
|
1351
|
-
VALUE nary;
|
|
1352
|
-
narray_t* na;
|
|
1353
|
-
|
|
1354
|
-
nary = na_s_new_like(cT, rary);
|
|
1355
|
-
GetNArray(nary, na);
|
|
1356
|
-
if (na->size > 0) {
|
|
1357
|
-
scomplex_store_array(nary, rary);
|
|
1358
|
-
}
|
|
1359
|
-
return nary;
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
/*
|
|
1363
|
-
Cast object to Numo::SComplex.
|
|
1364
|
-
@overload [](elements)
|
|
1365
|
-
@overload cast(array)
|
|
1366
|
-
@param [Numeric,Array] elements
|
|
1367
|
-
@param [Array] array
|
|
1368
|
-
@return [Numo::SComplex]
|
|
1369
|
-
*/
|
|
1370
|
-
static VALUE scomplex_s_cast(VALUE type, VALUE obj) {
|
|
1371
|
-
VALUE v;
|
|
1372
|
-
narray_t* na;
|
|
1373
|
-
dtype x;
|
|
1374
|
-
|
|
1375
|
-
if (rb_obj_class(obj) == cT) {
|
|
1376
|
-
return obj;
|
|
1377
|
-
}
|
|
1378
|
-
if (RTEST(rb_obj_is_kind_of(obj, rb_cNumeric))) {
|
|
1379
|
-
x = m_num_to_data(obj);
|
|
1380
|
-
return scomplex_new_dim0(x);
|
|
1381
|
-
}
|
|
1382
|
-
if (RTEST(rb_obj_is_kind_of(obj, rb_cArray))) {
|
|
1383
|
-
return scomplex_cast_array(obj);
|
|
1384
|
-
}
|
|
1385
|
-
if (IsNArray(obj)) {
|
|
1386
|
-
GetNArray(obj, na);
|
|
1387
|
-
v = nary_new(cT, NA_NDIM(na), NA_SHAPE(na));
|
|
1388
|
-
if (NA_SIZE(na) > 0) {
|
|
1389
|
-
scomplex_store(v, obj);
|
|
1390
|
-
}
|
|
1391
|
-
return v;
|
|
1392
|
-
}
|
|
1393
|
-
if (rb_respond_to(obj, id_to_a)) {
|
|
1394
|
-
obj = rb_funcall(obj, id_to_a, 0);
|
|
1395
|
-
if (TYPE(obj) != T_ARRAY) {
|
|
1396
|
-
rb_raise(rb_eTypeError, "`to_a' did not return Array");
|
|
1397
|
-
}
|
|
1398
|
-
return scomplex_cast_array(obj);
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
rb_raise(nary_eCastError, "cannot cast to %s", rb_class2name(type));
|
|
1402
|
-
return Qnil;
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
/*
|
|
1406
|
-
Multi-dimensional element assignment.
|
|
1407
|
-
@overload []=(dim0,...,dimL,val)
|
|
1408
|
-
@param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,Symbol]
|
|
1409
|
-
dim0,...,dimL multi-dimensional indices.
|
|
1410
|
-
@param [Numeric,Numo::NArray,Array] val Value(s) to be set to self.
|
|
1411
|
-
@return [Numeric,Numo::NArray,Array] returns `val` (last argument).
|
|
1412
|
-
@see Numo::NArray#[]=
|
|
1413
|
-
@see #[]
|
|
1414
|
-
*/
|
|
1415
|
-
static VALUE scomplex_aset(int argc, VALUE* argv, VALUE self) {
|
|
1416
|
-
int nd;
|
|
1417
|
-
size_t pos;
|
|
1418
|
-
char* ptr;
|
|
1419
|
-
VALUE a;
|
|
1420
|
-
dtype x;
|
|
1421
|
-
|
|
1422
|
-
argc--;
|
|
1423
|
-
if (argc == 0) {
|
|
1424
|
-
scomplex_store(self, argv[argc]);
|
|
1425
|
-
} else {
|
|
1426
|
-
nd = na_get_result_dimension(self, argc, argv, sizeof(dtype), &pos);
|
|
1427
|
-
if (nd) {
|
|
1428
|
-
a = na_aref_main(argc, argv, self, 0, nd);
|
|
1429
|
-
scomplex_store(a, argv[argc]);
|
|
1430
|
-
} else {
|
|
1431
|
-
x = scomplex_extract_data(argv[argc]);
|
|
1432
|
-
ptr = na_get_pointer_for_read_write(self) + pos;
|
|
1433
|
-
*(dtype*)ptr = x;
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
return argv[argc];
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
307
|
VALUE mTM;
|
|
1440
308
|
|
|
1441
309
|
void Init_numo_scomplex(void) {
|
|
@@ -1469,12 +337,7 @@ void Init_numo_scomplex(void) {
|
|
|
1469
337
|
rb_define_const(cT, "UPCAST", hCast);
|
|
1470
338
|
rb_hash_aset(hCast, rb_cArray, cT);
|
|
1471
339
|
|
|
1472
|
-
#ifdef RUBY_INTEGER_UNIFICATION
|
|
1473
340
|
rb_hash_aset(hCast, rb_cInteger, cT);
|
|
1474
|
-
#else
|
|
1475
|
-
rb_hash_aset(hCast, rb_cFixnum, cT);
|
|
1476
|
-
rb_hash_aset(hCast, rb_cBignum, cT);
|
|
1477
|
-
#endif
|
|
1478
341
|
rb_hash_aset(hCast, rb_cFloat, cT);
|
|
1479
342
|
rb_hash_aset(hCast, rb_cComplex, cT);
|
|
1480
343
|
rb_hash_aset(hCast, numo_cRObject, numo_cRObject);
|
|
@@ -1514,9 +377,21 @@ void Init_numo_scomplex(void) {
|
|
|
1514
377
|
* otherwise returns self.
|
|
1515
378
|
*/
|
|
1516
379
|
rb_define_method(cT, "extract", scomplex_extract, 0);
|
|
1517
|
-
|
|
380
|
+
/**
|
|
381
|
+
* Store elements to Numo::SComplex from other.
|
|
382
|
+
* @overload store(other)
|
|
383
|
+
* @param [Object] other
|
|
384
|
+
* @return [Numo::SComplex] self
|
|
385
|
+
*/
|
|
1518
386
|
rb_define_method(cT, "store", scomplex_store, 1);
|
|
1519
|
-
|
|
387
|
+
/**
|
|
388
|
+
* Cast object to Numo::SComplex.
|
|
389
|
+
* @overload [](elements)
|
|
390
|
+
* @overload cast(array)
|
|
391
|
+
* @param [Numeric,Array] elements
|
|
392
|
+
* @param [Array] array
|
|
393
|
+
* @return [Numo::SComplex]
|
|
394
|
+
*/
|
|
1520
395
|
rb_define_singleton_method(cT, "cast", scomplex_s_cast, 1);
|
|
1521
396
|
/**
|
|
1522
397
|
* Multi-dimensional element reference.
|
|
@@ -1528,6 +403,16 @@ void Init_numo_scomplex(void) {
|
|
|
1528
403
|
* @see #[]=
|
|
1529
404
|
*/
|
|
1530
405
|
rb_define_method(cT, "[]", scomplex_aref, -1);
|
|
406
|
+
/**
|
|
407
|
+
* Multi-dimensional element assignment.
|
|
408
|
+
* @overload []=(dim0,...,dimL,val)
|
|
409
|
+
* @param [Numeric,Range,Array,Numo::Int32,Numo::Int64,Numo::Bit,TrueClass,FalseClass,
|
|
410
|
+
* Symbol] dim0,...,dimL multi-dimensional indices.
|
|
411
|
+
* @param [Numeric,Numo::NArray,Array] val Value(s) to be set to self.
|
|
412
|
+
* @return [Numeric,Numo::NArray,Array] returns `val` (last argument).
|
|
413
|
+
* @see Numo::NArray#[]=
|
|
414
|
+
* @see #[]
|
|
415
|
+
*/
|
|
1531
416
|
rb_define_method(cT, "[]=", scomplex_aset, -1);
|
|
1532
417
|
/**
|
|
1533
418
|
* return NArray with cast to the type of self.
|