From 6ab1a647679b608d7e2c38b09122f8af265c12df Mon Sep 17 00:00:00 2001 From: Sonu0305 Date: Mon, 14 Sep 2026 15:30:43 +0400 Subject: [PATCH 1/4] Fix empty array edge cases in mnrfit --- inst/Regression/mnrfit.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/inst/Regression/mnrfit.m b/inst/Regression/mnrfit.m index 9f1c3d71e..1847ee438 100644 --- a/inst/Regression/mnrfit.m +++ b/inst/Regression/mnrfit.m @@ -198,7 +198,9 @@ [UY, ~, YN] = unique (Y); ## find unique categories in the response n = numel (UY); ## number of unique response categories endif - + if (isempty (Y)) + error ("mnrfit: X and Y must contain at least one valid observation."); + endif if (isnumeric (Y)) if (! (all (Y > 0) && all (fix (Y) == Y))) error ("mnrfit: Y must contain positive integer category numbers.") @@ -661,3 +663,10 @@ %!error ... %! mnrfit (ones (5, 4), [1; 2; 1; 2; 1], 'estdisp', 'maybe') +%!test +%! ## Edge cases with empty arrays +%!fail ("mnrfit ([], [])", ... +%! "mnrfit: X and Y must contain at least one valid observation.") +%!fail ("mnrfit (zeros(0,3), zeros(0,1))", ... +%! "mnrfit: X and Y must contain at least one valid observation.") + From f733d646d1ccc6f6f902d6abe25ae50e7e0af4a0 Mon Sep 17 00:00:00 2001 From: Sonu0305 Date: Mon, 14 Sep 2026 15:55:29 +0400 Subject: [PATCH 2/4] Refactor tests to use %!error instead of %!fail --- inst/Regression/mnrfit.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inst/Regression/mnrfit.m b/inst/Regression/mnrfit.m index 1847ee438..1831953e8 100644 --- a/inst/Regression/mnrfit.m +++ b/inst/Regression/mnrfit.m @@ -665,8 +665,8 @@ %!test %! ## Edge cases with empty arrays -%!fail ("mnrfit ([], [])", ... -%! "mnrfit: X and Y must contain at least one valid observation.") -%!fail ("mnrfit (zeros(0,3), zeros(0,1))", ... -%! "mnrfit: X and Y must contain at least one valid observation.") +%!error ... +%! mnrfit ([], []) +%!error ... +%! mnrfit (zeros(0,3), zeros(0,1)) From 6a9663518476886ea99170996e92a9dcbb1b4bf5 Mon Sep 17 00:00:00 2001 From: Sonu0305 Date: Tue, 15 Sep 2026 21:02:03 +0400 Subject: [PATCH 3/4] Update empty array error message for mnrfit --- inst/Regression/mnrfit.m | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/inst/Regression/mnrfit.m b/inst/Regression/mnrfit.m index 1831953e8..18aeeb908 100644 --- a/inst/Regression/mnrfit.m +++ b/inst/Regression/mnrfit.m @@ -199,7 +199,7 @@ n = numel (UY); ## number of unique response categories endif if (isempty (Y)) - error ("mnrfit: X and Y must contain at least one valid observation."); + error ("mnrfit: x and y must contain at least one observation."); endif if (isnumeric (Y)) if (! (all (Y > 0) && all (fix (Y) == Y))) @@ -663,10 +663,8 @@ %!error ... %! mnrfit (ones (5, 4), [1; 2; 1; 2; 1], 'estdisp', 'maybe') -%!test -%! ## Edge cases with empty arrays -%!error ... +## Edge cases with empty arrays +%!error ... %! mnrfit ([], []) -%!error ... +%!error ... %! mnrfit (zeros(0,3), zeros(0,1)) - From 90e40c2c9069a04ae506ebd5c5ddfe3394f22c04 Mon Sep 17 00:00:00 2001 From: Sonu0305 Date: Wed, 16 Sep 2026 06:27:03 +0400 Subject: [PATCH 4/4] Fix case in mnrfit error and formatting --- inst/Regression/mnrfit.m | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/inst/Regression/mnrfit.m b/inst/Regression/mnrfit.m index 18aeeb908..9cc6a3ac6 100644 --- a/inst/Regression/mnrfit.m +++ b/inst/Regression/mnrfit.m @@ -198,9 +198,11 @@ [UY, ~, YN] = unique (Y); ## find unique categories in the response n = numel (UY); ## number of unique response categories endif + if (isempty (Y)) - error ("mnrfit: x and y must contain at least one observation."); + error ("mnrfit: X and Y must contain at least one observation."); endif + if (isnumeric (Y)) if (! (all (Y > 0) && all (fix (Y) == Y))) error ("mnrfit: Y must contain positive integer category numbers.") @@ -664,7 +666,7 @@ %! mnrfit (ones (5, 4), [1; 2; 1; 2; 1], 'estdisp', 'maybe') ## Edge cases with empty arrays -%!error ... +%!error ... %! mnrfit ([], []) -%!error ... -%! mnrfit (zeros(0,3), zeros(0,1)) +%!error ... +%! mnrfit (zeros (0, 3), zeros (0, 1))