[Mlir-commits] [mlir] 791ddb7 - Add LogOp to Complex dialect.

Adrian Kuegel llvmlistbot at llvm.org
Fri Jul 2 04:16:15 PDT 2021


Author: Adrian Kuegel
Date: 2021-07-02T13:15:47+02:00
New Revision: 791ddb79f1dde3432f6214c1c8deadc59151b15e

URL: https://github.com/llvm/llvm-project/commit/791ddb79f1dde3432f6214c1c8deadc59151b15e
DIFF: https://github.com/llvm/llvm-project/commit/791ddb79f1dde3432f6214c1c8deadc59151b15e.diff

LOG: Add LogOp to Complex dialect.

Differential Revision: https://reviews.llvm.org/D105337

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td
    mlir/test/Dialect/Complex/ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td b/mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td
index d533b5db6b416..a116242dd0781 100644
--- a/mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td
+++ b/mlir/include/mlir/Dialect/Complex/IR/ComplexOps.td
@@ -159,7 +159,7 @@ def ExpOp : ComplexUnaryOp<"exp", [SameOperandsAndResultType]> {
   let summary = "computes exponential of a complex number";
   let description = [{
     The `exp` op takes a single complex number and computes the exponential of
-    it, i.e. `exp(x)` or `e^(x)`, where `x` is the input tensor.
+    it, i.e. `exp(x)` or `e^(x)`, where `x` is the input value.
     `e` denotes Euler's number and is approximately equal to 2.718281.
 
     Example:
@@ -195,6 +195,27 @@ def ImOp : ComplexUnaryOp<"im",
   let hasFolder = 1;
 }
 
+//===----------------------------------------------------------------------===//
+// LogOp
+//===----------------------------------------------------------------------===//
+
+def LogOp : ComplexUnaryOp<"log", [SameOperandsAndResultType]> {
+  let summary = "computes natural logarithm of a complex number";
+  let description = [{
+    The `log` op takes a single complex number and computes the natural
+    logarithm of it, i.e. `log(x)` or `log_e(x)`, where `x` is the input value.
+    `e` denotes Euler's number and is approximately equal to 2.718281.
+
+    Example:
+
+    ```mlir
+    %a = complex.log %b : complex<f32>
+    ```
+  }];
+
+  let results = (outs Complex<AnyFloat>:$result);
+}
+
 //===----------------------------------------------------------------------===//
 // MulOp
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/test/Dialect/Complex/ops.mlir b/mlir/test/Dialect/Complex/ops.mlir
index 09d31ba400f4f..74b45b8ae230a 100644
--- a/mlir/test/Dialect/Complex/ops.mlir
+++ b/mlir/test/Dialect/Complex/ops.mlir
@@ -26,12 +26,24 @@ func @ops(%f: f32) {
   // CHECK: complex.eq %[[C]], %[[C]] : complex<f32>
   %eq = complex.eq %complex, %complex : complex<f32>
 
-  // CHECK: complex.neq %[[C]], %[[C]] : complex<f32>
-  %neq = complex.neq %complex, %complex : complex<f32>
+  // CHECK: complex.exp %[[C]] : complex<f32>
+  %exp = complex.exp %complex : complex<f32>
+
+  // CHECK: complex.log %[[C]] : complex<f32>
+  %log = complex.log %complex : complex<f32>
 
   // CHECK: complex.mul %[[C]], %[[C]] : complex<f32>
   %prod = complex.mul %complex, %complex : complex<f32>
 
+  // CHECK: complex.neg %[[C]] : complex<f32>
+  %neg = complex.neg %complex : complex<f32>
+
+  // CHECK: complex.neq %[[C]], %[[C]] : complex<f32>
+  %neq = complex.neq %complex, %complex : complex<f32>
+
+  // CHECK: complex.sign %[[C]] : complex<f32>
+  %sign = complex.sign %complex : complex<f32>
+
   // CHECK: complex.sub %[[C]], %[[C]] : complex<f32>
   %
diff  = complex.sub %complex, %complex : complex<f32>
   return


        


More information about the Mlir-commits mailing list