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