{"record":{"id":"f5219d6bdc825a83","repo":"TheAlgorithms/C-Sharp","slug":"input","errorCode":null,"errorMessage":"input","messagePattern":"input","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"Algorithms/Numeric/Relu.cs","lineNumber":29,"sourceCode":"    ///     Compute the Rectified Linear Unit (ReLU) for a single value.\n    /// </summary>\n    /// <param name=\"input\">The input real number.</param>\n    /// <returns>The output real number (>= 0).</returns>\n    public static double Compute(double input)\n    {\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":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/Algorithms/Numeric/Relu.cs#L11-L47","documentation":"Relu.Compute applies max(0, x) elementwise to a vector of doubles. It throws ArgumentNullException when the input array is null, using the parameter name 'input' as the message. Callers must supply an allocated array; an empty array is separately rejected with 'Array is empty.'.","triggerScenarios":"Calling Relu.Compute(null), typically when an upstream method returned a null array or a deserialization produced null.","commonSituations":"A lookup/parse function returning null instead of an array, or an optional input field not being defaulted before inference-style numeric processing.","solutions":["Ensure the array is allocated before calling; use Array.Empty<double>() if you truly have no data (note empty arrays still throw the sibling error).","Add a null check at the boundary where the array is produced.","Coalesce null to a default vector if that fits your semantics."],"exampleFix":"// before\nvar output = Relu.Compute(data); // data may be null\n// after\nvar output = Relu.Compute(data ?? throw new ArgumentNullException(nameof(data)));","handlingStrategy":"validation","validationCode":"if (input is null) throw new ArgumentNullException(nameof(input));\nvar output = Relu.Compute(input);","typeGuard":"static bool IsValidReluInput(double[]? a) => a is { Length: > 0 };","tryCatchPattern":"try { var out = Relu.Compute(input); }\ncatch (ArgumentNullException) { /* supply a default vector or propagate a domain error */ }","preventionTips":["Coalesce nulls where arrays are produced (data ?? Array.Empty<double>())","Enable nullable reference types to catch null array flow at compile time","Reject null at deserialization/boundary code before numeric processing"],"tags":["null-argument","activation-function","csharp"],"backgroundTag":"null-argument","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"}