@@ -551,19 +551,24 @@ def test_simulate_rir_ism_multi_band(self, channel):
551
551
[
552
552
(0.1 , 0.2 , (2 , 1 , 2500 )), # both float
553
553
# Per-wall
554
- (torch .rand (4 ), 0.2 , (2 , 1 , 2500 )),
555
- (0.1 , torch .rand (4 ), (2 , 1 , 2500 )),
556
- (torch .rand (4 ), torch .rand (4 ), (2 , 1 , 2500 )),
554
+ (torch .rand (6 ), 0.2 , (2 , 1 , 2500 )),
555
+ (0.1 , torch .rand (6 ), (2 , 1 , 2500 )),
556
+ (torch .rand (6 ), torch .rand (6 ), (2 , 1 , 2500 )),
557
557
# Per-band and per-wall
558
- (torch .rand (6 , 4 ), 0.2 , (2 , 6 , 2500 )),
559
- (0.1 , torch .rand (6 , 4 ), (2 , 6 , 2500 )),
560
- (torch .rand (6 , 4 ), torch .rand (6 , 4 ), (2 , 6 , 2500 )),
558
+ (torch .rand (4 , 6 ), 0.2 , (2 , 4 , 2500 )),
559
+ (0.1 , torch .rand (4 , 6 ), (2 , 4 , 2500 )),
560
+ (torch .rand (4 , 6 ), torch .rand (4 , 6 ), (2 , 4 , 2500 )),
561
561
]
562
562
)
563
563
def test_ray_tracing_output_shape (self , absorption , scattering , expected_shape ):
564
- room_dim = torch .tensor ([20 , 25 ], dtype = self .dtype )
565
- mic_array = torch .tensor ([[2 , 2 ], [8 , 8 ]], dtype = self .dtype )
566
- source = torch .tensor ([7 , 6 ], dtype = self .dtype )
564
+ room_dim = torch .tensor ([20 , 25 , 30 ], dtype = self .dtype )
565
+ mic_array = torch .tensor ([[2 , 2 , 2 ], [8 , 8 , 8 ]], dtype = self .dtype )
566
+ source = torch .tensor ([7 , 6 , 5 ], dtype = self .dtype )
567
+ if isinstance (absorption , torch .Tensor ):
568
+ absorption = absorption .to (self .dtype )
569
+ if isinstance (scattering , torch .Tensor ):
570
+ scattering = scattering .to (self .dtype )
571
+
567
572
num_rays = 100
568
573
569
574
hist = F .ray_tracing (
@@ -578,143 +583,125 @@ def test_ray_tracing_output_shape(self, absorption, scattering, expected_shape):
578
583
assert hist .shape == expected_shape
579
584
580
585
def test_ray_tracing_input_errors (self ):
581
- with self .assertRaisesRegex (ValueError , "room must be a 1D tensor " ):
586
+ with self .assertRaisesRegex (ValueError , "room must be a 1D Tensor. " ):
582
587
F .ray_tracing (
583
588
room = torch .tensor ([[4 , 5 ]]), source = torch .tensor ([0 , 0 ]), mic_array = torch .tensor ([[3 , 4 ]]), num_rays = 10
584
589
)
585
- with self .assertRaisesRegex (ValueError , "room must be a 1D tensor " ):
590
+ with self .assertRaisesRegex (ValueError , "The shape of room must be " ):
586
591
F .ray_tracing (
587
592
room = torch .tensor ([4 , 5 , 4 , 5 ]),
588
593
source = torch .tensor ([0 , 0 ]),
589
594
mic_array = torch .tensor ([[3 , 4 ]]),
590
595
num_rays = 10 ,
591
596
)
592
- with self .assertRaisesRegex (ValueError , r"mic_array must be 1D tensor of shape \(D,\), or 2D tensor " ):
597
+ with self .assertRaisesRegex (ValueError , "The second dimension of mic_array must be 3 " ):
593
598
F .ray_tracing (
594
- room = torch .tensor ([4 , 5 ]), source = torch .tensor ([0 , 0 ]), mic_array = torch .tensor ([[[3 , 4 ]]]), num_rays = 10
599
+ room = torch .tensor ([4 , 5 , 6 ]),
600
+ source = torch .tensor ([0 , 0 , 0 ]),
601
+ mic_array = torch .tensor ([[3 , 4 ]]),
602
+ num_rays = 10 ,
595
603
)
596
604
with self .assertRaisesRegex (ValueError , "room must be of float32 or float64 dtype" ):
597
605
F .ray_tracing (
598
- room = torch .tensor ([4 , 5 ]).to (torch .int ),
599
- source = torch .tensor ([0 , 0 ]),
600
- mic_array = torch .tensor ([3 , 4 ]),
606
+ room = torch .tensor ([4 , 5 , 6 ]).to (torch .int ),
607
+ source = torch .tensor ([0 , 0 , 0 ]),
608
+ mic_array = torch .tensor ([[ 3 , 4 , 5 ] ]),
601
609
num_rays = 10 ,
602
610
)
603
611
with self .assertRaisesRegex (ValueError , "dtype of room, source and mic_array must be the same" ):
604
612
F .ray_tracing (
605
- room = torch .tensor ([4 , 5 ]).to (torch .float64 ),
606
- source = torch .tensor ([0 , 0 ]).to (torch .float32 ),
607
- mic_array = torch .tensor ([3 , 4 ]),
608
- num_rays = 10 ,
609
- )
610
- with self .assertRaisesRegex (ValueError , "Room dimension D must match with source and mic_array" ):
611
- F .ray_tracing (
612
- room = torch .tensor ([4 , 5 , 10 ], dtype = torch .float ),
613
- source = torch .tensor ([0 , 0 ], dtype = torch .float ),
614
- mic_array = torch .tensor ([3 , 4 ], dtype = torch .float ),
615
- num_rays = 10 ,
616
- )
617
- with self .assertRaisesRegex (ValueError , "Room dimension D must match with source and mic_array" ):
618
- F .ray_tracing (
619
- room = torch .tensor ([4 , 5 ], dtype = torch .float ),
620
- source = torch .tensor ([0 , 0 , 0 ], dtype = torch .float ),
621
- mic_array = torch .tensor ([3 , 4 ], dtype = torch .float ),
622
- num_rays = 10 ,
623
- )
624
- with self .assertRaisesRegex (ValueError , "Room dimension D must match with source and mic_array" ):
625
- F .ray_tracing (
626
- room = torch .tensor ([4 , 5 , 10 ], dtype = torch .float ),
627
- source = torch .tensor ([0 , 0 , 0 ], dtype = torch .float ),
628
- mic_array = torch .tensor ([3 , 4 ], dtype = torch .float ),
613
+ room = torch .tensor ([4 , 5 , 6 ]).to (torch .float64 ),
614
+ source = torch .tensor ([0 , 0 , 0 ]).to (torch .float32 ),
615
+ mic_array = torch .tensor ([[3 , 4 , 5 ]]),
629
616
num_rays = 10 ,
630
617
)
631
618
with self .assertRaisesRegex (ValueError , "time_thres=10 must be at least greater than hist_bin_size=11" ):
632
619
F .ray_tracing (
633
- room = torch .tensor ([4 , 5 ], dtype = torch .float ),
634
- source = torch .tensor ([0 , 0 ], dtype = torch .float ),
635
- mic_array = torch .tensor ([3 , 4 ], dtype = torch .float ),
620
+ room = torch .tensor ([4 , 5 , 6 ], dtype = torch .float ),
621
+ source = torch .tensor ([0 , 0 , 0 ], dtype = torch .float ),
622
+ mic_array = torch .tensor ([[ 3 , 4 , 5 ] ], dtype = torch .float ),
636
623
num_rays = 10 ,
637
624
time_thres = 10 ,
638
625
hist_bin_size = 11 ,
639
626
)
640
- with self .assertRaisesRegex (ValueError , "The shape of absorption must be" ):
627
+ with self .assertRaisesRegex (ValueError , "The shape of coefficient must be" ):
641
628
F .ray_tracing (
642
- room = torch .tensor ([4 , 5 ], dtype = torch .float ),
643
- source = torch .tensor ([0 , 0 ], dtype = torch .float ),
644
- mic_array = torch .tensor ([3 , 4 ], dtype = torch .float ),
629
+ room = torch .tensor ([4 , 5 , 6 ], dtype = torch .float ),
630
+ source = torch .tensor ([0 , 0 , 0 ], dtype = torch .float ),
631
+ mic_array = torch .tensor ([[ 3 , 4 , 5 ] ], dtype = torch .float ),
645
632
num_rays = 10 ,
646
633
absorption = torch .rand (5 , dtype = torch .float ),
647
634
)
648
- with self .assertRaisesRegex (ValueError , "The shape of scattering must be" ):
635
+ with self .assertRaisesRegex (ValueError , "The shape of coefficient must be" ):
649
636
F .ray_tracing (
650
- room = torch .tensor ([4 , 5 ], dtype = torch .float ),
651
- source = torch .tensor ([0 , 0 ], dtype = torch .float ),
652
- mic_array = torch .tensor ([3 , 4 ], dtype = torch .float ),
637
+ room = torch .tensor ([4 , 5 , 6 ], dtype = torch .float ),
638
+ source = torch .tensor ([0 , 0 , 0 ], dtype = torch .float ),
639
+ mic_array = torch .tensor ([[ 3 , 4 , 5 ] ], dtype = torch .float ),
653
640
num_rays = 10 ,
654
641
scattering = torch .rand (5 , 5 , dtype = torch .float ),
655
642
)
656
- with self .assertRaisesRegex (ValueError , "The shape of absorption must be" ):
643
+ with self .assertRaisesRegex (ValueError , "The shape of coefficient must be" ):
657
644
F .ray_tracing (
658
- room = torch .tensor ([4 , 5 ], dtype = torch .float ),
659
- source = torch .tensor ([0 , 0 ], dtype = torch .float ),
660
- mic_array = torch .tensor ([3 , 4 ], dtype = torch .float ),
645
+ room = torch .tensor ([4 , 5 , 6 ], dtype = torch .float ),
646
+ source = torch .tensor ([0 , 0 , 0 ], dtype = torch .float ),
647
+ mic_array = torch .tensor ([[ 3 , 4 , 5 ] ], dtype = torch .float ),
661
648
num_rays = 10 ,
662
649
absorption = torch .rand (5 , 5 , dtype = torch .float ),
663
650
)
664
- with self .assertRaisesRegex (ValueError , "The shape of scattering must be" ):
651
+ with self .assertRaisesRegex (ValueError , "The shape of coefficient must be" ):
665
652
F .ray_tracing (
666
- room = torch .tensor ([4 , 5 ], dtype = torch .float ),
667
- source = torch .tensor ([0 , 0 ], dtype = torch .float ),
668
- mic_array = torch .tensor ([3 , 4 ], dtype = torch .float ),
653
+ room = torch .tensor ([4 , 5 , 6 ], dtype = torch .float ),
654
+ source = torch .tensor ([0 , 0 , 0 ], dtype = torch .float ),
655
+ mic_array = torch .tensor ([[ 3 , 4 , 5 ] ], dtype = torch .float ),
669
656
num_rays = 10 ,
670
657
scattering = torch .rand (5 , dtype = torch .float ),
671
658
)
672
659
with self .assertRaisesRegex (
673
660
ValueError , "absorption and scattering must have the same number of bands and walls"
674
661
):
675
662
F .ray_tracing (
676
- room = torch .tensor ([4 , 5 ], dtype = torch .float ),
677
- source = torch .tensor ([0 , 0 ], dtype = torch .float ),
678
- mic_array = torch .tensor ([3 , 4 ], dtype = torch .float ),
663
+ room = torch .tensor ([4 , 5 , 6 ], dtype = torch .float ),
664
+ source = torch .tensor ([0 , 0 , 0 ], dtype = torch .float ),
665
+ mic_array = torch .tensor ([[ 3 , 4 , 5 ] ], dtype = torch .float ),
679
666
num_rays = 10 ,
680
- absorption = torch .rand (6 , 4 , dtype = torch .float ),
681
- scattering = torch .rand (5 , 4 , dtype = torch .float ),
667
+ absorption = torch .rand (6 , 6 , dtype = torch .float ),
668
+ scattering = torch .rand (5 , 6 , dtype = torch .float ),
682
669
)
683
670
684
671
# Make sure passing different shapes for absorption or scattering doesn't raise an error
685
672
# float and tensor
686
673
F .ray_tracing (
687
- room = torch .tensor ([4 , 5 ], dtype = torch .float ),
688
- source = torch .tensor ([0 , 0 ], dtype = torch .float ),
689
- mic_array = torch .tensor ([3 , 4 ], dtype = torch .float ),
674
+ room = torch .tensor ([4 , 5 , 6 ], dtype = torch .float ),
675
+ source = torch .tensor ([0 , 0 , 0 ], dtype = torch .float ),
676
+ mic_array = torch .tensor ([[ 3 , 4 , 5 ] ], dtype = torch .float ),
690
677
num_rays = 10 ,
691
678
absorption = 0.1 ,
692
- scattering = torch .rand (5 , 4 , dtype = torch .float ),
679
+ scattering = torch .rand (5 , 6 , dtype = torch .float ),
693
680
)
694
681
F .ray_tracing (
695
- room = torch .tensor ([4 , 5 ], dtype = torch .float ),
696
- source = torch .tensor ([0 , 0 ], dtype = torch .float ),
697
- mic_array = torch .tensor ([3 , 4 ], dtype = torch .float ),
682
+ room = torch .tensor ([4 , 5 , 6 ], dtype = torch .float ),
683
+ source = torch .tensor ([0 , 0 , 0 ], dtype = torch .float ),
684
+ mic_array = torch .tensor ([[ 3 , 4 , 5 ] ], dtype = torch .float ),
698
685
num_rays = 10 ,
699
- absorption = torch .rand (5 , 4 , dtype = torch .float ),
686
+ absorption = torch .rand (5 , 6 , dtype = torch .float ),
700
687
scattering = 0.1 ,
701
688
)
702
689
# per-wall only and per-band + per-wall
703
690
F .ray_tracing (
704
- room = torch .tensor ([4 , 5 ], dtype = torch .float ),
705
- source = torch .tensor ([0 , 0 ], dtype = torch .float ),
706
- mic_array = torch .tensor ([3 , 4 ], dtype = torch .float ),
691
+ room = torch .tensor ([4 , 5 , 6 ], dtype = torch .float ),
692
+ source = torch .tensor ([0 , 0 , 0 ], dtype = torch .float ),
693
+ mic_array = torch .tensor ([[ 3 , 4 , 5 ] ], dtype = torch .float ),
707
694
num_rays = 10 ,
708
- absorption = torch .rand (4 , dtype = torch .float ),
709
- scattering = torch .rand (6 , 4 , dtype = torch .float ),
695
+ absorption = torch .rand (6 , dtype = torch .float ),
696
+ scattering = torch .rand (6 , 6 , dtype = torch .float ),
710
697
)
711
698
F .ray_tracing (
712
- room = torch .tensor ([4 , 5 ], dtype = torch .float ),
713
- source = torch .tensor ([0 , 0 ], dtype = torch .float ),
714
- mic_array = torch .tensor ([3 , 4 ], dtype = torch .float ),
699
+ room = torch .tensor ([4 , 5 , 6 ], dtype = torch .float ),
700
+ source = torch .tensor ([0 , 0 , 0 ], dtype = torch .float ),
701
+ mic_array = torch .tensor ([[ 3 , 4 , 5 ] ], dtype = torch .float ),
715
702
num_rays = 10 ,
716
- absorption = torch .rand (6 , 4 , dtype = torch .float ),
717
- scattering = torch .rand (4 , dtype = torch .float ),
703
+ absorption = torch .rand (6 , 6 , dtype = torch .float ),
704
+ scattering = torch .rand (6 , dtype = torch .float ),
718
705
)
719
706
720
707
def test_ray_tracing_per_band_per_wall_absorption (self ):
@@ -725,14 +712,14 @@ def test_ray_tracing_per_band_per_wall_absorption(self):
725
712
(D,) tensor.
726
713
"""
727
714
728
- room_dim = torch .tensor ([20 , 25 ], dtype = self .dtype )
729
- mic_array = torch .tensor ([[2 , 2 ], [8 , 8 ]], dtype = self .dtype )
730
- source = torch .tensor ([7 , 6 ], dtype = self .dtype )
715
+ room_dim = torch .tensor ([20 , 25 , 30 ], dtype = self .dtype )
716
+ mic_array = torch .tensor ([[2 , 2 , 2 ], [8 , 8 , 8 ]], dtype = self .dtype )
717
+ source = torch .tensor ([7 , 6 , 5 ], dtype = self .dtype )
731
718
num_rays = 1_000
732
719
ABS , SCAT = 0.1 , 0.2
733
720
734
- absorption = torch .full (fill_value = ABS , size = (6 , 4 ), dtype = self .dtype )
735
- scattering = torch .full (fill_value = SCAT , size = (6 , 4 ), dtype = self .dtype )
721
+ absorption = torch .full (fill_value = ABS , size = (4 , 6 ), dtype = self .dtype )
722
+ scattering = torch .full (fill_value = SCAT , size = (4 , 6 ), dtype = self .dtype )
736
723
hist_per_band_per_wall = F .ray_tracing (
737
724
room = room_dim ,
738
725
source = source ,
@@ -741,8 +728,8 @@ def test_ray_tracing_per_band_per_wall_absorption(self):
741
728
absorption = absorption ,
742
729
scattering = scattering ,
743
730
)
744
- absorption = torch .full (fill_value = ABS , size = (4 ,), dtype = self .dtype )
745
- scattering = torch .full (fill_value = SCAT , size = (4 ,), dtype = self .dtype )
731
+ absorption = torch .full (fill_value = ABS , size = (6 ,), dtype = self .dtype )
732
+ scattering = torch .full (fill_value = SCAT , size = (6 ,), dtype = self .dtype )
746
733
hist_per_wall = F .ray_tracing (
747
734
room = room_dim ,
748
735
source = source ,
@@ -762,22 +749,20 @@ def test_ray_tracing_per_band_per_wall_absorption(self):
762
749
absorption = absorption ,
763
750
scattering = scattering ,
764
751
)
765
- assert hist_per_band_per_wall .shape == (2 , 6 , 2500 )
752
+ assert hist_per_band_per_wall .shape == (2 , 4 , 2500 )
766
753
assert hist_per_wall .shape == (2 , 1 , 2500 )
767
754
assert hist_single .shape == (2 , 1 , 2500 )
768
755
torch .testing .assert_close (hist_single , hist_per_wall )
769
756
770
- hist_single = hist_single .expand (2 , 6 , 2500 )
757
+ hist_single = hist_single .expand (2 , 4 , 2500 )
771
758
torch .testing .assert_close (hist_single , hist_per_band_per_wall )
772
759
773
760
@parameterized .expand (
774
761
[
775
- ([20 , 25 ], [2 , 2 ], [[8 , 8 ], [7 , 6 ]], 10_000 ), # 2D with 2 mics
776
762
([20 , 25 , 30 ], [1 , 10 , 5 ], [[8 , 8 , 22 ]], 1_000 ), # 3D with 1 mic
777
763
]
778
764
)
779
765
def test_ray_tracing_same_results_as_pyroomacoustics (self , room_dim , source , mic_array , num_rays ):
780
-
781
766
walls = ["west" , "east" , "south" , "north" ]
782
767
if len (room_dim ) == 3 :
783
768
walls += ["floor" , "ceiling" ]
0 commit comments