multiarray 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/tc_sequence.rb CHANGED
@@ -127,8 +127,8 @@ class TC_Sequence < Test::Unit::TestCase
127
127
  end
128
128
 
129
129
  def test_typecode
130
- assert_equal O, S.new( O, 3 ).typecode
131
- assert_equal I, S.new( I, 3 ).typecode
130
+ assert_equal O, S.object( 3 ).typecode
131
+ assert_equal I, S.int( 3 ).typecode
132
132
  end
133
133
 
134
134
  def test_dimension
@@ -265,6 +265,7 @@ class TC_Sequence < Test::Unit::TestCase
265
265
 
266
266
  def test_collect
267
267
  assert_equal S[ 2, 3 ], S[ 1, 2 ].collect { |x| x + 1 }
268
+ assert_equal S[ 2, 4 ], S[ 1, 2 ].map { |x| 2 * x }
268
269
  end
269
270
 
270
271
  def test_sum
@@ -290,6 +291,13 @@ class TC_Sequence < Test::Unit::TestCase
290
291
  assert_equal C( 3, 2, 3 ), S[ C( 1, 2, 3 ), C( 3, 2, 1 ) ].max
291
292
  end
292
293
 
294
+ def test_sum
295
+ [ S( O, 3 ), S( I, 3 ) ].each do |t|
296
+ assert_equal 9, t[ 4, 2, 3 ].sum
297
+ end
298
+ assert_equal C( 4, 4, 4 ), S[ C( 1, 2, 3 ), C( 3, 2, 1 ) ].sum
299
+ end
300
+
293
301
  def test_convolve
294
302
  [ O, I ].each do |t|
295
303
  assert_equal S( t, 5 )[ 2, 3, 0, 0, 0 ],
@@ -312,6 +320,25 @@ class TC_Sequence < Test::Unit::TestCase
312
320
  convolve( S[ C( 1, 0, 0 ), C( 0, 1, 0 ), C( 0, 0, 1 ) ] )
313
321
  end
314
322
 
323
+ def test_histogram
324
+ [ O, I ].each do |t|
325
+ assert_equal S( t, 5 )[ 0, 1, 2, 1, 1 ],
326
+ S( t, 5 )[ 1, 2, 2, 3, 4 ].histogram( 5, :target => t )
327
+ end
328
+ assert_raise( RuntimeError ) { S[ -1, 0, 1 ].histogram 3 }
329
+ assert_raise( RuntimeError ) { S[ 1, 2, 3 ].histogram 3 }
330
+ assert_raise( RuntimeError ) { S[ 0, 0, 0 ].histogram 3, 2 }
331
+ end
332
+
333
+ def test_lut
334
+ [ O, I ].each do |t|
335
+ assert_equal S( t, 4 )[ 3, 1, 2, 1 ],
336
+ S( t, 4 )[ 0, 2, 1, 2 ].lut( S( t, 3 )[ 3, 2, 1 ] )
337
+ end
338
+ assert_raise( RuntimeError ) { S[ -1, 0 ].lut S[ 0, 1 ] }
339
+ assert_raise( RuntimeError ) { S[ 1, 2 ].lut S[ 0, 1 ] }
340
+ end
341
+
315
342
  def test_zero
316
343
  [ S( O, 3 ), S( I, 3 ) ].each do |t|
317
344
  assert_equal [ false, true, false ], t[ -1, 0, 1 ].zero?.to_a
@@ -456,9 +483,13 @@ class TC_Sequence < Test::Unit::TestCase
456
483
  end
457
484
 
458
485
  def test_arg
459
- assert_equal S[ 0.0, Math::PI ], S[ 1, -1 ].arg
460
- assert_equal S[ 0.0, Math::PI / 2, Math::PI, -Math::PI / 2 ],
461
- S[ X( 1, 0 ), X( 0, 1 ), X( -1, 0 ), X( 0, -1 ) ].arg
486
+ [ 0.0, Math::PI ].zip( S[ 1, -1 ].arg.to_a ).each do |x,y|
487
+ assert_in_delta x, y, 1.0e-5
488
+ end
489
+ r = S[ X( 1, 0 ), X( 0, 1 ), X( -1, 0 ), X( 0, -1 ) ].arg
490
+ [ 0.0, Math::PI / 2, Math::PI, -Math::PI / 2 ].zip( r.to_a ).each do |x,y|
491
+ assert_in_delta x, y, 1.0e-5
492
+ end
462
493
  end
463
494
 
464
495
  def test_mul
@@ -557,6 +588,191 @@ class TC_Sequence < Test::Unit::TestCase
557
588
  def test_sqrt
558
589
  assert_equal S( O, 3 )[ 1, 2, 3 ], Math.sqrt( S( O, 3 )[ 1, 4, 9 ] )
559
590
  assert_equal S[ 1.0, 2.0, 3.0 ], Math.sqrt( S[ 1.0, 4.0, 9.0 ] )
591
+ [ Math.sqrt( X( 1, 2 ) ), Math.sqrt( X( 2, -1 ) ) ].
592
+ zip( Math.sqrt( S[ X( 1, 2 ), X( 2, -1 ) ] ).to_a ).each do |x,y|
593
+ assert_in_delta x.real, y.real, 1.0e-5
594
+ assert_in_delta x.imag, y.imag, 1.0e-5
595
+ end
596
+ end
597
+
598
+ def test_exp
599
+ [ Math.exp( 2 ), Math.exp( 3 ) ].zip( Math.exp( S[ 2, 3 ] ).to_a ).each do |x,y|
600
+ assert_in_delta x, y, 1.0e-5
601
+ end
602
+ [ Math.exp( X( 1, 2 ) ) ].zip( Math.exp( S[ X( 1, 2 ) ] ).to_a ).each do |x,y|
603
+ assert_in_delta x.real, y.real, 1.0e-5
604
+ assert_in_delta x.imag, y.imag, 1.0e-5
605
+ end
606
+ end
607
+
608
+ def test_cos
609
+ [ Math.cos( 2 ), Math.cos( 3 ) ].zip( Math.cos( S[ 2, 3 ] ).to_a ).each do |x,y|
610
+ assert_in_delta x, y, 1.0e-5
611
+ end
612
+ [ Math.cos( X( 1, 2 ) ) ].zip( Math.cos( S[ X( 1, 2 ) ] ).to_a ).each do |x,y|
613
+ assert_in_delta x.real, y.real, 1.0e-5
614
+ assert_in_delta x.imag, y.imag, 1.0e-5
615
+ end
616
+ end
617
+
618
+ def test_sin
619
+ [ Math.sin( 2 ), Math.sin( 3 ) ].zip( Math.sin( S[ 2, 3 ] ).to_a ).each do |x,y|
620
+ assert_in_delta x, y, 1.0e-5
621
+ end
622
+ [ Math.sin( X( 1, 2 ) ) ].zip( Math.sin( S[ X( 1, 2 ) ] ).to_a ).each do |x,y|
623
+ assert_in_delta x.real, y.real, 1.0e-5
624
+ assert_in_delta x.imag, y.imag, 1.0e-5
625
+ end
626
+ end
627
+
628
+ def test_tan
629
+ [ Math.tan( 2 ), Math.tan( 3 ) ].zip( Math.tan( S[ 2, 3 ] ).to_a ).each do |x,y|
630
+ assert_in_delta x, y, 1.0e-5
631
+ end
632
+ [ Math.tan( X( 1, 2 ) ) ].zip( Math.tan( S[ X( 1, 2 ) ] ).to_a ).each do |x,y|
633
+ assert_in_delta x.real, y.real, 1.0e-5
634
+ assert_in_delta x.imag, y.imag, 1.0e-5
635
+ end
636
+ end
637
+
638
+ def test_cosh
639
+ [ Math.cosh( 2 ), Math.cosh( 3 ) ].
640
+ zip( Math.cosh( S[ 2, 3 ] ).to_a ).each do |x,y|
641
+ assert_in_delta x, y, 1.0e-5
642
+ end
643
+ [ Math.cosh( X( 1, 2 ) ) ].zip( Math.cosh( S[ X( 1, 2 ) ] ).to_a ).each do |x,y|
644
+ assert_in_delta x.real, y.real, 1.0e-5
645
+ assert_in_delta x.imag, y.imag, 1.0e-5
646
+ end
647
+ end
648
+
649
+ def test_sinh
650
+ [ Math.sinh( 2 ), Math.sinh( 3 ) ].
651
+ zip( Math.sinh( S[ 2, 3 ] ).to_a ).each do |x,y|
652
+ assert_in_delta x, y, 1.0e-5
653
+ end
654
+ [ Math.sinh( X( 1, 2 ) ) ].zip( Math.sinh( S[ X( 1, 2 ) ] ).to_a ).each do |x,y|
655
+ assert_in_delta x.real, y.real, 1.0e-5
656
+ assert_in_delta x.imag, y.imag, 1.0e-5
657
+ end
658
+ end
659
+
660
+ def test_tanh
661
+ [ Math.tanh( 2 ), Math.tanh( 3 ) ].
662
+ zip( Math.tanh( S[ 2, 3 ] ).to_a ).each do |x,y|
663
+ assert_in_delta x, y, 1.0e-5
664
+ end
665
+ [ Math.tanh( X( 1, 2 ) ) ].zip( Math.tanh( S[ X( 1, 2 ) ] ).to_a ).each do |x,y|
666
+ assert_in_delta x.real, y.real, 1.0e-5
667
+ assert_in_delta x.imag, y.imag, 1.0e-5
668
+ end
669
+ end
670
+
671
+ def test_log
672
+ [ Math.log( 2 ), Math.log( 3 ) ].zip( Math.log( S[ 2, 3 ] ).to_a ).each do |x,y|
673
+ assert_in_delta x, y, 1.0e-5
674
+ end
675
+ [ Math.log( X( 1, 2 ) ) ].zip( Math.log( S[ X( 1, 2 ) ] ).to_a ).each do |x,y|
676
+ assert_in_delta x.real, y.real, 1.0e-5
677
+ assert_in_delta x.imag, y.imag, 1.0e-5
678
+ end
679
+ end
680
+
681
+ def test_log10
682
+ [ Math.log10( 2 ), Math.log10( 3 ) ].
683
+ zip( Math.log10( S[ 2, 3 ] ).to_a ).each do |x,y|
684
+ assert_in_delta x, y, 1.0e-5
685
+ end
686
+ [ Math.log10( X( 1, 2 ) ) ].zip( Math.log10( S[ X( 1, 2 ) ] ).to_a ).each do |x,y|
687
+ assert_in_delta x.real, y.real, 1.0e-5
688
+ assert_in_delta x.imag, y.imag, 1.0e-5
689
+ end
690
+ end
691
+
692
+ def test_acos
693
+ [ Math.acos( 0.3 ), Math.acos( 0.6 ) ].
694
+ zip( Math.acos( S[ 0.3, 0.6 ] ).to_a ).each do |x,y|
695
+ assert_in_delta x, y, 1.0e-5
696
+ end
697
+ [ Math.acos( X( 0.2, 0.3 ) ) ].
698
+ zip( Math.acos( S[ X( 0.2, 0.3 ) ] ).to_a ).each do |x,y|
699
+ assert_in_delta x.real, y.real, 1.0e-5
700
+ assert_in_delta x.imag, y.imag, 1.0e-5
701
+ end
702
+ end
703
+
704
+ def test_asin
705
+ [ Math.asin( 0.3 ), Math.asin( 0.6 ) ].
706
+ zip( Math.asin( S[ 0.3, 0.6 ] ).to_a ).each do |x,y|
707
+ assert_in_delta x, y, 1.0e-5
708
+ end
709
+ [ Math.asin( X( 0.2, 0.3 ) ) ].
710
+ zip( Math.asin( S[ X( 0.2, 0.3 ) ] ).to_a ).each do |x,y|
711
+ assert_in_delta x.real, y.real, 1.0e-5
712
+ assert_in_delta x.imag, y.imag, 1.0e-5
713
+ end
714
+ end
715
+
716
+ def test_atan
717
+ [ Math.atan( 0.3 ), Math.atan( 0.6 ) ].
718
+ zip( Math.atan( S[ 0.3, 0.6 ] ).to_a ).each do |x,y|
719
+ assert_in_delta x, y, 1.0e-5
720
+ end
721
+ [ Math.atan( X( 0.2, 0.3 ) ) ].
722
+ zip( Math.atan( S[ X( 0.2, 0.3 ) ] ).to_a ).each do |x,y|
723
+ assert_in_delta x.real, y.real, 1.0e-5
724
+ assert_in_delta x.imag, y.imag, 1.0e-5
725
+ end
726
+ end
727
+
728
+ def test_acosh
729
+ [ Math.acosh( 1.3 ), Math.acosh( 1.6 ) ].
730
+ zip( Math.acosh( S[ 1.3, 1.6 ] ).to_a ).each do |x,y|
731
+ assert_in_delta x, y, 1.0e-5
732
+ end
733
+ [ Math.acosh( X( 1.2, 1.3 ) ) ].
734
+ zip( Math.acosh( S[ X( 1.2, 1.3 ) ] ).to_a ).each do |x,y|
735
+ assert_in_delta x.real, y.real, 1.0e-5
736
+ assert_in_delta x.imag, y.imag, 1.0e-5
737
+ end
738
+ end
739
+
740
+ def test_asinh
741
+ [ Math.asinh( 1.3 ), Math.asinh( 1.6 ) ].
742
+ zip( Math.asinh( S[ 1.3, 1.6 ] ).to_a ).each do |x,y|
743
+ assert_in_delta x, y, 1.0e-5
744
+ end
745
+ [ Math.asinh( X( 1.2, 1.3 ) ) ].
746
+ zip( Math.asinh( S[ X( 1.2, 1.3 ) ] ).to_a ).each do |x,y|
747
+ assert_in_delta x.real, y.real, 1.0e-5
748
+ assert_in_delta x.imag, y.imag, 1.0e-5
749
+ end
750
+ end
751
+
752
+ def test_atanh
753
+ [ Math.atanh( 0.3 ), Math.atanh( 0.6 ) ].
754
+ zip( Math.atanh( S[ 0.3, 0.6 ] ).to_a ).each do |x,y|
755
+ assert_in_delta x, y, 1.0e-5
756
+ end
757
+ [ Math.atanh( X( 0.2, 0.3 ) ) ].
758
+ zip( Math.atanh( S[ X( 0.2, 0.3 ) ] ).to_a ).each do |x,y|
759
+ assert_in_delta x.real, y.real, 1.0e-5
760
+ assert_in_delta x.imag, y.imag, 1.0e-5
761
+ end
762
+ end
763
+
764
+ def test_atan2
765
+ [ Math.atan2( 3, 4 ), Math.atan2( 4, 3 ) ].
766
+ zip( Math.atan2( S[ 3, 4 ], S[ 4, 3 ] ).to_a ).each do |x,y|
767
+ assert_in_delta x, y, 1.0e-5
768
+ end
769
+ [ Math.atan2( X( 1, 2 ), X( 3, 4 ) ) ].
770
+ zip( Math.atan2( S[ X( 1, 2 ) ], S[ X( 3, 4 ) ] ).to_a ).each do |x,y|
771
+ assert_in_delta x.real, y.real, 1.0e-5
772
+ assert_in_delta x.imag, y.imag, 1.0e-5
773
+ end
774
+ assert_raise( RuntimeError ) { Math.atan2( S[ 3 ], S[ 4, 3 ] ) }
775
+ assert_raise( RuntimeError ) { Math.atan2( S[ 3, 4 ], S[ 4 ] ) }
560
776
  end
561
777
 
562
778
  def test_hypot
@@ -565,10 +781,23 @@ class TC_Sequence < Test::Unit::TestCase
565
781
  assert_raise( RuntimeError ) { Math.hypot( S[ 3, 4 ], S[ 4 ] ) }
566
782
  end
567
783
 
784
+ def test_fill
785
+ [ S( O, 3 ), S( I, 3 ) ].each do |t|
786
+ s = t[ 1, 2, 3 ]
787
+ assert_equal t[ 1, 1, 1 ], s.fill!( 1 )
788
+ assert_equal t[ 1, 1, 1 ], s
789
+ end
790
+ end
791
+
568
792
  def test_to_type
569
- assert_equal S( O, 3 )[ 1, 2, 3 ], S( I, 3 )[ 1, 2, 3 ].to_type( O )
570
- assert_equal S( I, 3 )[ 1, 2, 3 ], S( O, 3 )[ 1, 2, 3 ].to_type( I )
571
- assert_equal S( C, 3 )[ 1, 2, 3 ], S( I, 3 )[ 1, 2, 3 ].to_type( C )
793
+ assert_equal S( O, 3 )[ 1, 2, 3 ], S( I, 3 )[ 1, 2, 3 ].to_object
794
+ assert_equal S( I, 3 )[ 1, 2, 3 ], S( O, 3 )[ 1, 2, 3 ].to_int
795
+ assert_equal S( C, 3 )[ 1, 2, 3 ], S( I, 3 )[ 1, 2, 3 ].to_intrgb
796
+ end
797
+
798
+ def test_integral
799
+ assert_equal S( O, 3 )[ 1, 3, 6 ], S( O, 3 )[ 1, 2, 3 ].integral
800
+ assert_equal S( I, 3 )[ 1, 3, 6 ], S( I, 3 )[ 1, 2, 3 ].integral
572
801
  end
573
802
 
574
803
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiarray
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 5
9
- - 2
10
- version: 0.5.2
7
+ - 6
8
+ - 0
9
+ version: 0.6.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jan Wedekind
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-09-12 00:00:00 +01:00
17
+ date: 2010-09-30 00:00:00 +01:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ~>
28
27
  - !ruby/object:Gem::Version
29
- hash: 13
30
28
  segments:
31
29
  - 1
32
30
  - 1
@@ -41,7 +39,6 @@ dependencies:
41
39
  requirements:
42
40
  - - ">="
43
41
  - !ruby/object:Gem::Version
44
- hash: 3
45
42
  segments:
46
43
  - 0
47
44
  version: "0"
@@ -70,6 +67,7 @@ files:
70
67
  - lib/multiarray/gcccache.rb
71
68
  - lib/multiarray/int.rb
72
69
  - lib/multiarray/gccfunction.rb
70
+ - lib/multiarray/shortcuts.rb
73
71
  - lib/multiarray/float.rb
74
72
  - lib/multiarray/diagonal.rb
75
73
  - lib/multiarray/inject.rb
@@ -78,17 +76,21 @@ files:
78
76
  - lib/multiarray/lambda.rb
79
77
  - lib/multiarray/sequence.rb
80
78
  - lib/multiarray/methods.rb
79
+ - lib/multiarray/integral.rb
81
80
  - lib/multiarray/multiarray.rb
82
81
  - lib/multiarray/node.rb
82
+ - lib/multiarray/histogram.rb
83
83
  - lib/multiarray/malloc.rb
84
84
  - lib/multiarray/index.rb
85
85
  - lib/multiarray/rgb.rb
86
86
  - lib/multiarray/gcccontext.rb
87
87
  - lib/multiarray/composite.rb
88
+ - lib/multiarray/store.rb
88
89
  - lib/multiarray/elementwise.rb
89
90
  - lib/multiarray/lookup.rb
90
91
  - lib/multiarray/gccvalue.rb
91
92
  - lib/multiarray/complex.rb
93
+ - lib/multiarray/lut.rb
92
94
  - lib/multiarray.rb
93
95
  - test/ts_multiarray.rb
94
96
  - test/tc_float.rb
@@ -113,7 +115,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
115
  requirements:
114
116
  - - ">="
115
117
  - !ruby/object:Gem::Version
116
- hash: 3
117
118
  segments:
118
119
  - 0
119
120
  version: "0"
@@ -122,7 +123,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
123
  requirements:
123
124
  - - ">="
124
125
  - !ruby/object:Gem::Version
125
- hash: 3
126
126
  segments:
127
127
  - 0
128
128
  version: "0"