@@ -180,6 +180,50 @@ subtest 'Test if Matrix is in (R)REF' => sub {
180180 ok !$B4 -> isRREF, " $B4 is not in RREF" ;
181181};
182182
183+ subtest ' Check if two matrices are (fuzzy) row equivalent' => sub {
184+ my $A1 = Matrix(1, 2, 3);
185+ my $A2 = Matrix([ 1, 2, 3 ], [ 4, 5, 6 ]);
186+ my $A3 = Matrix([ [ 1, 2 ], [ 3, 4 ] ], [ [ 5, 6 ], [ 7, 8 ] ]);
187+ my $B1 = Matrix(2, 4, 6);
188+ my $B2 = Matrix([ 1, 2 ], [ 3, 4 ], [ 5, 6 ]);
189+ my $C1 = Matrix(0, 4, 6);
190+ my $Z1 = Matrix([ 0, 0, 0 ], [ 0, 0, 0 ]);
191+ my $Z2 = Matrix([ 0, 0, 0 ], [ 0, 0, 10**-14 ]);
192+
193+ my $M1 = Matrix([ 3, 1 ], [ 1, 1 / 3 ]);
194+ my $M2 = Matrix([ 3, 1 ], [ 0, 0 ]);
195+ my $M3 = Matrix([ 1, 0.3333 ], [ 0, 0 ]);
196+ my $M4 = Matrix([ 1, 0.33 ], [ 0, 0 ]);
197+ my $M5 = Matrix([ 6, 2 ], [ 9, 3 ]);
198+ my $M6 = Matrix([ 3, 1 ], [ 1, 3 ]);
199+
200+ my $N1 = Matrix([ [ 1, 2 ], [ 2, 4 ] ], [ [ 1, 2 ], [ 3, 4 ] ]);
201+ my $N2 = Matrix([ [ 3, 6 ], [ 0, 0 ] ], [ [ 1, 0 ], [ 0, 1 ] ]);
202+ my $N3 = Matrix([ [ 3, 6 ], [ 1, 0 ] ], [ [ 1, 0 ], [ 0, 1 ] ]);
203+
204+ ok $Z1 -> isREQ($Z2 ), ' Zero matrices are row equivalent' ;
205+ ok !$Z1 -> isREQ($A2 ), ' A zero matrix is not row equivalent to a nonzero matrix' ;
206+ ok $A1 -> isREQ($B1 ), ' Parallel degree 1 matrices are row equivalent' ;
207+ ok !$C1 -> isREQ($B1 ), ' Non-parallel degree 1 matrices are not row equivalent' ;
208+ ok $M2 -> isREQ($M5 ), ' Row equivalent matrices are row equivalent' ;
209+ ok $M2 -> isREQ($M1 ), ' Row equivalent matrices are row equivalent, even with some machine rounding' ;
210+ ok $M2 -> isREQ($M3 ), ' Row equivalent matrices are row equivalent, even with student rounding' ;
211+ ok !$M2 -> isREQ($M4 ), ' Matrices are not row equivalent if rounding is too much' ;
212+ ok !$M2 -> isREQ($M6 ), ' Non-row equivalent matrices are not row equivalent' ;
213+ ok $N1 -> isREQ($N2 ), ' Row equivalent matrices are row equivalent, even at degree above 2' ;
214+ ok !$N1 -> isREQ($N3 ), ' Non-row equivalent matrices are not row equivalent, even at degree above 2' ;
215+
216+ like dies {
217+ $A2 -> isREQ($A3 );
218+ }, qr / Cannot compare row equivalency of matrices of different degree/ ,
219+ ' Test that error is thrown for comparing matrices of differing degrees' ;
220+ like dies {
221+ $A2 -> isREQ($B2 );
222+ }, qr / Cannot compare row equivalency because matrices differ in the first dimension/ ,
223+ ' Test that error is thrown for comparing matrices of differing dimensioon' ;
224+
225+ };
226+
183227subtest ' Transpose a Matrix' => sub {
184228 my $A = Matrix([ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9, 10, 11, 12 ] ]);
185229 my $B = Matrix([ [ 1, 5, 9 ], [ 2, 6, 10 ], [ 3, 7, 11 ], [ 4, 8, 12 ] ]);
0 commit comments