From 43c214b519d3b3e1017dc7e6c52115de93350d62 Mon Sep 17 00:00:00 2001 From: Sonu0305 Date: Mon, 14 Sep 2026 15:44:08 +0400 Subject: [PATCH 1/2] Fix empty array edge cases in robustfit --- inst/Regression/robustfit.m | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/inst/Regression/robustfit.m b/inst/Regression/robustfit.m index 43d4d8d96..72316075f 100644 --- a/inst/Regression/robustfit.m +++ b/inst/Regression/robustfit.m @@ -70,7 +70,7 @@ if (! (isnumeric (X) && isreal (X) && ismatrix (X))) error ("robustfit: X must be a real matrix."); endif - if (! (isnumeric (y) && isreal (y) && isvector (y))) + if (! (isnumeric (y) && isreal (y) && (isvector (y) || isempty (y)))) error ("robustfit: Y must be a real vector."); endif y = y(:); @@ -114,7 +114,7 @@ endif [n, p] = size (X); if (n <= p) - error ("robustfit: not enough observations for the number of parameters."); + error ("robustfit: Not enough points to perform robust estimation."); endif ## Ordinary least squares start, leverages, and the OLS scale. @@ -322,3 +322,10 @@ %! robustfit (X, y, "huber", -1) %!error ... %! robustfit (X, y, "huber", 1.345, "maybe") + +%!test +%! ## Edge cases with empty arrays +%!fail ("robustfit ([], [])", ... +%! "robustfit: Not enough points to perform robust estimation.") +%!fail ("robustfit (zeros(0,3), zeros(0,1))", ... +%! "robustfit: Not enough points to perform robust estimation.") From 0ccc7b713bc36c9a886b133afd591fd7d56463de Mon Sep 17 00:00:00 2001 From: Sonu0305 Date: Mon, 14 Sep 2026 15:58:33 +0400 Subject: [PATCH 2/2] Refactor tests to use %!error instead of %!fail --- inst/Regression/robustfit.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inst/Regression/robustfit.m b/inst/Regression/robustfit.m index 72316075f..849e29f90 100644 --- a/inst/Regression/robustfit.m +++ b/inst/Regression/robustfit.m @@ -325,7 +325,7 @@ %!test %! ## Edge cases with empty arrays -%!fail ("robustfit ([], [])", ... -%! "robustfit: Not enough points to perform robust estimation.") -%!fail ("robustfit (zeros(0,3), zeros(0,1))", ... -%! "robustfit: Not enough points to perform robust estimation.") +%!error ... +%! robustfit ([], []) +%!error ... +%! robustfit (zeros(0,3), zeros(0,1))