vdsp 1.8.0 → 1.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a9bf55ee5ee1699cdd8b6c0ccba7b2a56de452e49a1baf748b446c80c3c2eae
4
- data.tar.gz: a3c3fc40011f79420eec38be24a689db3648915a2fadba7c7e05c5013ec37e85
3
+ metadata.gz: 5c68d2c6fcfd278007d16c59196ef9bc72c6f43119db2a3018230c3f18e16653
4
+ data.tar.gz: cab3b5e5630378581854a1a5e86b1d1bacb2ba9fb17fb5514cced0027d518085
5
5
  SHA512:
6
- metadata.gz: fad7199ff86511a3c3155ed0719fb9240a8fbce9b858694a15186c54b1aabe65a8537a4aa61715a883d7099a8e1321728d0e29f74bd3aa517022d98093dccc35
7
- data.tar.gz: 22ef33d7cdb7fbb4dfb59333d58144b01dd0d9efc230eec3736dfa5d5967ed8baaeb14f8ff6f82c964bad5101ad8e8da1c9234bc1cf6b0c247a6ac0339c1ea58
6
+ metadata.gz: ee4fc1111d826dbc9a8e7cae82700f69fb692c6e06a3ca6cd0e5fa46eca99f9fbc119742f9ebdeacc725b755980c0d55d40789555f7e4c8e78b30af226f4f8e0
7
+ data.tar.gz: '08c66b9d34da6f64c4e7138ca883dc8fc76ec286cd4d84f0bd323fe4867d179d9434b7f94cff1dfbe50601395be7e3186757a79cf456ebd33f427e7df413b0f0'
data/ext/vdsp/vdsp.c CHANGED
@@ -391,76 +391,215 @@ VALUE rb_double_array_div(VALUE self, VALUE other)
391
391
  }
392
392
  }
393
393
 
394
- VALUE rb_double_array_aref(VALUE self, VALUE i)
394
+ VALUE rb_double_array_entry(VALUE self, long offset)
395
395
  {
396
- long _i = NUM2LONG(i);
396
+ VdspArrayNativeResource *_a = get_vdsp_array_native_resource(self);
397
+ long len = _a->length;
397
398
 
398
- VdspArrayNativeResource *p = get_vdsp_array_native_resource(self);
399
- if (0<=_i && (unsigned long)_i<p->length) {
400
- return DBL2NUM(p->v.d[_i]);
401
- } else {
402
- rb_raise(rb_eIndexError, "Index out of range: %ld", _i);
399
+ if (offset < 0) {
400
+ offset += len;
401
+ if (offset < 0) return Qnil;
402
+ }
403
+ else if (len <= offset) {
404
+ return Qnil;
403
405
  }
406
+ return DBL2NUM(_a->v.d[offset]);
404
407
  }
405
408
 
406
- VALUE rb_double_array_aset(VALUE self, VALUE i, VALUE val)
409
+ VALUE rb_double_array_subseq(VALUE self, long beg, long len)
407
410
  {
408
- long _i = NUM2LONG(i);
411
+ VdspArrayNativeResource *_a = get_vdsp_array_native_resource(self);
412
+ long alen = _a->length;
409
413
 
410
- VdspArrayNativeResource *p = get_vdsp_array_native_resource(self);
411
- if (0<=_i && (unsigned long)_i<p->length) {
412
- val = rb_funcall(val, rb_intern("to_f"), 0);
413
- p->v.d[_i] = NUM2DBL(val);
414
- return val;
415
- } else {
416
- rb_raise(rb_eIndexError, "Index out of range: %ld", _i);
414
+ if (beg > alen) return Qnil;
415
+ if (beg < 0 || len < 0) return Qnil;
416
+
417
+ if (alen < len || alen < beg + len) {
418
+ len = alen - beg;
417
419
  }
420
+
421
+ VALUE lenv = LONG2NUM(len);
422
+ VALUE c = rb_class_new_instance(1, &lenv, rb_cDoubleArray);
423
+ VdspArrayNativeResource *_c = get_vdsp_array_native_resource(c);
424
+ memcpy(_c->v.d, _a->v.d+beg, sizeof(double) * len);
425
+
426
+ return c;
418
427
  }
419
428
 
420
- VALUE rb_double_array_coerce(VALUE self, VALUE other)
429
+ VALUE rb_double_array_aref2(VALUE self, VALUE b, VALUE e)
421
430
  {
422
- other = rb_class_new_instance(1, &other, rb_cDoubleScalar);
423
- return rb_assoc_new(other, self);
431
+ VdspArrayNativeResource *_a = get_vdsp_array_native_resource(self);
432
+
433
+ long beg = NUM2LONG(b);
434
+ long len = NUM2LONG(e);
435
+
436
+ if (beg < 0) {
437
+ beg += _a->length;
438
+ }
439
+
440
+ return rb_double_array_subseq(self, beg, len);
424
441
  }
425
442
 
426
- VALUE rb_double_array_slice(int argc, const VALUE *argv, VALUE self)
443
+ VALUE rb_double_array_aref1(VALUE self, VALUE arg)
427
444
  {
428
- rb_check_arity(argc, 1, 2);
445
+ long beg, len;
429
446
 
430
447
  VdspArrayNativeResource *_a = get_vdsp_array_native_resource(self);
431
448
  long alen = _a->length;
432
449
 
433
- long beg = 0;
434
- long len = 0;
450
+ if (FIXNUM_P(arg)) {
451
+ return rb_double_array_entry(self, FIX2LONG(arg));
452
+ }
453
+ switch (rb_range_beg_len(arg, &beg, &len, alen, 0)) {
454
+ case Qfalse:
455
+ break;
456
+ case Qnil:
457
+ return Qnil;
458
+ default:
459
+ return rb_double_array_subseq(self, beg, len);
460
+ }
461
+ return rb_double_array_entry(self, FIX2LONG(arg));
462
+ }
435
463
 
436
- if (argc==2) {
437
- beg = NUM2LONG(argv[0]);
438
- len = NUM2LONG(argv[1]);
439
- } else if (FIXNUM_P(argv[0])){
440
- len = FIX2LONG(argv[0]);
441
- } else {
442
- switch (rb_range_beg_len(argv[0], &beg, &len, alen, 0)) {
443
- case Qfalse:
444
- case Qnil:
445
- return Qnil;
446
- default:
447
- break;
464
+ VALUE rb_double_array_aref(int argc, const VALUE *argv, VALUE self)
465
+ {
466
+ rb_check_arity(argc, 1, 2);
467
+
468
+ if (argc == 2) {
469
+ return rb_double_array_aref2(self, argv[0], argv[1]);
470
+ }
471
+ return rb_double_array_aref1(self, argv[0]);
472
+ }
473
+
474
+ VALUE double_array_aset1(VALUE self, long idx, VALUE val)
475
+ {
476
+ VdspArrayNativeResource *_a = get_vdsp_array_native_resource(self);
477
+ double _val = NUM2DBL(val);
478
+
479
+ long len = _a->length;
480
+
481
+ if (idx < 0) {
482
+ idx += len;
483
+ if (idx < 0) {
484
+ rb_raise(rb_eIndexError, "index %ld too small for array; minimum: %ld", idx - len, -len);
448
485
  }
449
486
  }
450
487
 
451
- if (beg > alen) return Qnil;
452
- if (beg < 0 || len < 0) return Qnil;
488
+ if (idx >= len) {
489
+ //rb_raise(rb_eIndexError, "Index out of range: %ld", idx);
490
+ double_array_resize(_a, idx+1);
491
+ _a->length = idx+1;
492
+ }
453
493
 
494
+ _a->v.d[idx] = _val;
495
+
496
+ return self;
497
+ }
498
+
499
+ VALUE double_array_aset2(VALUE self, long beg, long len, VALUE val)
500
+ {
501
+ VdspArrayNativeResource *_a = get_vdsp_array_native_resource(self);
502
+ long alen = _a->length;
503
+
504
+ if (len<0) {
505
+ len += alen;
506
+ }
507
+ if (len<beg) {
508
+ len = beg;
509
+ }
454
510
  if (alen < len || alen < beg + len) {
455
511
  len = alen - beg;
456
512
  }
457
513
 
458
- VALUE lenv = LONG2NUM(len);
459
- VALUE c = rb_class_new_instance(1, &lenv, rb_cDoubleArray);
460
- VdspArrayNativeResource *_c = get_vdsp_array_native_resource(c);
461
- memcpy(_c->v.d, _a->v.d+beg, sizeof(double) * len);
514
+ if (RB_TYPE_P(val, T_ARRAY)) {
515
+ val = rb_funcall(rb_cDoubleArray, rb_intern("create"), 1, val);
516
+ }
517
+ if (rb_obj_is_kind_of(val, rb_mVdspArray)) {
518
+ val = rb_funcall(val, rb_intern("to_da"), 0);
519
+ if (self==val) {
520
+ val = rb_funcall(val, rb_intern("clone"), 0);
521
+ }
462
522
 
463
- return c;
523
+ VdspArrayNativeResource *_b = get_vdsp_array_native_resource(val);
524
+ long new_len = alen - len + _b->length;
525
+
526
+ bool after_resize = false;
527
+ if (alen==new_len) {
528
+ } else if (alen<new_len) {
529
+ double_array_resize(_a, new_len);
530
+ _a->length = new_len;
531
+ } else {
532
+ after_resize = true;
533
+ }
534
+
535
+ memmove(_a->v.d+beg+_b->length, _a->v.d+beg+len, sizeof(double) * (alen-beg-len));
536
+ memcpy(_a->v.d+beg, _b->v.d, sizeof(double) * _b->length);
537
+
538
+ if (after_resize) {
539
+ double_array_resize(_a, new_len);
540
+ _a->length = new_len;
541
+ }
542
+
543
+ return self;
544
+ } else {
545
+ long new_len = alen - len + 1;
546
+
547
+ bool after_resize = false;
548
+ if (alen==new_len) {
549
+ } else if (alen<new_len) {
550
+ double_array_resize(_a, new_len);
551
+ _a->length = new_len;
552
+ } else {
553
+ after_resize = true;
554
+ }
555
+
556
+ memmove(_a->v.d+beg+1, _a->v.d+len, sizeof(double) * (alen-beg-len));
557
+ _a->v.d[beg] = NUM2DBL(val);
558
+
559
+ if (after_resize) {
560
+ double_array_resize(_a, new_len);
561
+ _a->length = new_len;
562
+ }
563
+
564
+ return self;
565
+ }
566
+ }
567
+
568
+ VALUE rb_double_array_aset(int argc, const VALUE *argv, VALUE self)
569
+ {
570
+ long offset, beg, len;
571
+ VALUE val;
572
+
573
+ if (argc == 3) {
574
+ beg = NUM2LONG(argv[0]);
575
+ len = NUM2LONG(argv[1]);
576
+ val = argv[2];
577
+ return double_array_aset2(self, beg, len, val);
578
+ }
579
+
580
+ rb_check_arity(argc, 2, 2);
581
+
582
+ if (FIXNUM_P(argv[0])) {
583
+ offset = FIX2LONG(argv[0]);
584
+ val = argv[1];
585
+ return double_array_aset1(self, offset, val);
586
+ }
587
+
588
+ VdspArrayNativeResource *_a = get_vdsp_array_native_resource(self);
589
+ if (rb_range_beg_len(argv[0], &beg, &len, _a->length, 1)) {
590
+ val = argv[1];
591
+ return double_array_aset2(self, beg, len, val);
592
+ }
593
+
594
+ offset = NUM2LONG(argv[0]);
595
+ val = argv[1];
596
+ return double_array_aset1(self, offset, val);
597
+ }
598
+
599
+ VALUE rb_double_array_coerce(VALUE self, VALUE other)
600
+ {
601
+ other = rb_class_new_instance(1, &other, rb_cDoubleScalar);
602
+ return rb_assoc_new(other, self);
464
603
  }
465
604
 
466
605
  void double_array_resize(VdspArrayNativeResource *_a, unsigned long len)
@@ -2597,12 +2736,12 @@ void Init_vdsp()
2597
2736
  rb_define_method(rb_cDoubleArray, "-", rb_double_array_minus, 1);
2598
2737
  rb_define_method(rb_cDoubleArray, "*", rb_double_array_mul, 1);
2599
2738
  rb_define_method(rb_cDoubleArray, "/", rb_double_array_div, 1);
2600
- rb_define_method(rb_cDoubleArray, "[]", rb_double_array_aref, 1);
2601
- rb_define_method(rb_cDoubleArray, "[]=", rb_double_array_aset, 2);
2739
+ rb_define_method(rb_cDoubleArray, "[]", rb_double_array_aref, -1);
2740
+ rb_define_method(rb_cDoubleArray, "[]=", rb_double_array_aset, -1);
2602
2741
  rb_define_method(rb_cDoubleArray, "each", rb_double_array_each, 0);
2603
2742
  rb_define_method(rb_cDoubleArray, "to_a", rb_double_array_get_values, 0);
2604
2743
  rb_define_method(rb_cDoubleArray, "coerce", rb_double_array_coerce, 1);
2605
- rb_define_method(rb_cDoubleArray, "slice", rb_double_array_slice, -1);
2744
+ rb_define_method(rb_cDoubleArray, "slice", rb_double_array_aref, -1);
2606
2745
  rb_define_method(rb_cDoubleArray, "resize", rb_double_array_resize, 1);
2607
2746
  rb_define_method(rb_cDoubleArray, "concat", rb_double_array_concat, -1);
2608
2747
  rb_define_method(rb_cDoubleArray, "abs", rb_double_array_abs, 0);
data/ext/vdsp/vdsp.h CHANGED
@@ -47,5 +47,6 @@ typedef struct {
47
47
 
48
48
  extern VALUE rb_double_array_plus(VALUE self, VALUE other);
49
49
  extern VALUE rb_double_array_mul(VALUE self, VALUE other);
50
+ extern void double_array_resize(VdspArrayNativeResource *_a, unsigned long len);
50
51
 
51
52
  extern void Init_vdsp();
data/lib/vdsp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vdsp
2
- VERSION = "1.8.0"
2
+ VERSION = "1.9.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vdsp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshida Tetsuya
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-10 00:00:00.000000000 Z
11
+ date: 2019-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler