diff options
author | Michael Butler <butlermichael@google.com> | 2020-10-07 20:03:35 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-10-07 20:03:35 +0000 |
commit | 85a2f91d51c4acd80cac6a8515bd862847b58183 (patch) | |
tree | 9be66203707b4ca310f3e7b0098ae5ab12817dc3 | |
parent | 760680e32cdc4fb27e1791c91423ca24dc801cf7 (diff) | |
parent | 521fea4b9885bc21476a8d35ebafc85c515c3701 (diff) | |
download | ml-85a2f91d51c4acd80cac6a8515bd862847b58183.tar.gz |
Merge "Add equality operator to canonical operand and operation types" am: 521fea4b98
Original change: https://android-review.googlesource.com/c/platform/frameworks/ml/+/1451978
Change-Id: I13971cb7efedd12c62eb286160dbcd624356cc33
-rw-r--r-- | nn/common/TypeUtils.cpp | 28 | ||||
-rw-r--r-- | nn/common/include/nnapi/TypeUtils.h | 4 |
2 files changed, 32 insertions, 0 deletions
diff --git a/nn/common/TypeUtils.cpp b/nn/common/TypeUtils.cpp index d997f65a2..ffe2912c3 100644 --- a/nn/common/TypeUtils.cpp +++ b/nn/common/TypeUtils.cpp @@ -846,4 +846,32 @@ bool operator!=(const Operand::SymmPerChannelQuantParams& a, return !(a == b); } +static bool operator==(const DataLocation& a, const DataLocation& b) { + constexpr auto toTuple = [](const DataLocation& location) { + return std::tie(location.pointer, location.poolIndex, location.offset, location.length); + }; + return toTuple(a) == toTuple(b); +} + +bool operator==(const Operand& a, const Operand& b) { + constexpr auto toTuple = [](const Operand& operand) { + return std::tie(operand.type, operand.dimensions, operand.scale, operand.zeroPoint, + operand.lifetime, operand.location, operand.extraParams); + }; + return toTuple(a) == toTuple(b); +} +bool operator!=(const Operand& a, const Operand& b) { + return !(a == b); +} + +bool operator==(const Operation& a, const Operation& b) { + constexpr auto toTuple = [](const Operation& operation) { + return std::tie(operation.type, operation.inputs, operation.outputs); + }; + return toTuple(a) == toTuple(b); +} +bool operator!=(const Operation& a, const Operation& b) { + return !(a == b); +} + } // namespace android::nn diff --git a/nn/common/include/nnapi/TypeUtils.h b/nn/common/include/nnapi/TypeUtils.h index 58021a780..30f1346f4 100644 --- a/nn/common/include/nnapi/TypeUtils.h +++ b/nn/common/include/nnapi/TypeUtils.h @@ -106,6 +106,10 @@ bool operator==(const Operand::SymmPerChannelQuantParams& a, const Operand::SymmPerChannelQuantParams& b); bool operator!=(const Operand::SymmPerChannelQuantParams& a, const Operand::SymmPerChannelQuantParams& b); +bool operator==(const Operand& a, const Operand& b); +bool operator!=(const Operand& a, const Operand& b); +bool operator==(const Operation& a, const Operation& b); +bool operator!=(const Operation& a, const Operation& b); } // namespace android::nn |