{"record":{"id":"caf352fa524af7c9","repo":"TheAlgorithms/C-Sharp","slug":"array-is-empty-relu","errorCode":null,"errorMessage":"Array is empty.","messagePattern":"Array is empty\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Algorithms/Numeric/Relu.cs","lineNumber":34,"sourceCode":"    {\n        return Math.Max(0.0, input);\n    }\n\n    /// <summary>\n    ///     Compute the Rectified Linear Unit (ReLU) element-wise for a vector.\n    /// </summary>\n    /// <param name=\"input\">The input vector of real numbers.</param>\n    /// <returns>The output vector where each element is max(0, input[i]).</returns>\n    public static double[] Compute(double[] input)\n    {\n        if (input is null)\n        {\n            throw new ArgumentNullException(nameof(input));\n        }\n\n        if (input.Length == 0)\n        {\n            throw new ArgumentException(\"Array is empty.\");\n        }\n\n        var output = new double[input.Length];\n\n        for (var i = 0; i < input.Length; i++)\n        {\n            output[i] = Math.Max(0.0, input[i]);\n        }\n\n        return output;\n    }\n}\n","sourceCodeStart":16,"sourceCodeEnd":47,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Numeric/Relu.cs#L16-L47","documentation":"Relu.Compute rejects zero-length input arrays with ArgumentException('Array is empty.') because the ReLU output of an empty vector is undefined by this API. The null case is a separate ArgumentNullException. Callers must pass at least one element.","triggerScenarios":"Calling Relu.Compute(Array.Empty<double>()) or Compute(new double[0]), or Compute on an array produced by filtering that removed all elements.","commonSituations":"Empty CSV/data rows, a filter step (Where) yielding no items followed by ToArray, or splitting an empty string into a zero-length array.","solutions":["Check input.Length > 0 before calling Compute.","Decide the desired result for empty input (return empty array yourself) and bypass the call.","Guard upstream filters so empty results are handled before numeric processing."],"exampleFix":"// before\nvar output = Relu.Compute(filtered);\n// after\nvar output = filtered.Length == 0 ? Array.Empty<double>() : Relu.Compute(filtered);","handlingStrategy":"validation","validationCode":"var output = input.Length == 0 ? Array.Empty<double>() : Relu.Compute(input);","typeGuard":"static bool IsNonEmpty(double[]? a) => a is { Length: > 0 };","tryCatchPattern":"try { var out = Relu.Compute(input); }\ncatch (ArgumentException ex) when (ex.Message == \"Array is empty.\") { return Array.Empty<double>(); }","preventionTips":["Handle empty results of filtering/splitting before calling Compute","Define empty-input semantics explicitly (pass-through empty) in your pipeline","Test the empty-array path in unit tests"],"tags":["empty-input","activation-function","csharp"],"backgroundTag":"empty-required-field","analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}