From 0b86cad38338da9a9dc96fba7dcac5074acb1e3f Mon Sep 17 00:00:00 2001 From: Gunhyun Park Date: Mon, 12 Sep 2022 13:12:29 -0700 Subject: [PATCH] Add specification for logistic operator (#107) * Add specification for logistic operator * fix constraints * rewrite formula to use IEEE-754 operations --- docs/spec_draft.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/docs/spec_draft.md b/docs/spec_draft.md index ec7265e67c7..98d80fb609c 100644 --- a/docs/spec_draft.md +++ b/docs/spec_draft.md @@ -94,6 +94,7 @@ The specification of an op comprises of the following components (in the order * [cosine](#stablehlocosine) * [floor](#stablehlofloor) * [log](#stablehlolog) + * [logistic](#stablehlologistic) * [max](#stablehlomaximum) * [min](#stablehlominimum) * [negate](#stablehlonegate) @@ -454,6 +455,49 @@ implementation-defined. [Back to Ops](#index-of-documented-ops) +## stablehlo.logistic + +`stablehlo.logistic(operand) -> result` + +### Semantics + +Performs element-wise logistic (sigmoid) function on `operand` tensor and +produces a `result` tensor. For floating-point element types, it implements: +$$logistic(x) = division(1, addition(1, exp(-x)))$$ +where `addition`, `division`, and `exp` are operations from IEEE-754 +specification. For complex element types, computes a complex logistic function, +with corner cases TBD. Numeric precision is implementation-defined. + +### Operands + +| Name | Type | +|-|-| +| `operand` | tensor of floating-point or complex element types | + +### Results + +| Name | Type | +|-|-| +| `result` | tensor of floating-point or complex element types | + +### Constraints + + * (C1) `operand` and `result` have the same type. + +### Examples + +```mlir +// %operand: [[0.0, 1.0], [2.0, 3.0]] +%result = stablehlo.logistic %operand : tensor<2x2xf32> +// %result: [[0.5, 0.73105858], [0.88079708, 0.95257413]] + +// %operand: (1.0, 2.0) +%result = stablehlo.logistic %operand : tensor> +// %result: (1.02141536, 0.40343871) +``` + +[Back to Ops](#index-of-documented-ops) + ## stablehlo.maximum `stablehlo.maximum(lhs, rhs) -> result`