| 59 | |
| 60 | template <typename OperandT> |
| 61 | StatusOr<Literal> Compare(const Shape& shape, ComparisonDirection direction, |
| 62 | LiteralSlice lhs_literal, LiteralSlice rhs_literal) { |
| 63 | std::function<bool(OperandT, OperandT)> compare_op; |
| 64 | switch (direction) { |
| 65 | case ComparisonDirection::kEq: |
| 66 | compare_op = [](OperandT lhs_el, OperandT rhs_el) { |
| 67 | return lhs_el == rhs_el; |
| 68 | }; |
| 69 | break; |
| 70 | case ComparisonDirection::kNe: |
| 71 | compare_op = [](OperandT lhs_el, OperandT rhs_el) { |
| 72 | return lhs_el != rhs_el; |
| 73 | }; |
| 74 | break; |
| 75 | case ComparisonDirection::kGe: |
| 76 | compare_op = [](OperandT lhs_el, OperandT rhs_el) { |
| 77 | return lhs_el >= rhs_el; |
| 78 | }; |
| 79 | break; |
| 80 | case ComparisonDirection::kGt: |
| 81 | compare_op = [](OperandT lhs_el, OperandT rhs_el) { |
| 82 | return lhs_el > rhs_el; |
| 83 | }; |
| 84 | break; |
| 85 | case ComparisonDirection::kLe: |
| 86 | compare_op = [](OperandT lhs_el, OperandT rhs_el) { |
| 87 | return lhs_el <= rhs_el; |
| 88 | }; |
| 89 | break; |
| 90 | case ComparisonDirection::kLt: |
| 91 | compare_op = [](OperandT lhs_el, OperandT rhs_el) { |
| 92 | return lhs_el < rhs_el; |
| 93 | }; |
| 94 | break; |
| 95 | } |
| 96 | |
| 97 | Literal result(shape); |
| 98 | TF_RETURN_IF_ERROR( |
| 99 | result.Populate<bool>([&](absl::Span<const int64> multi_index) { |
| 100 | return compare_op(lhs_literal.Get<OperandT>(multi_index), |
| 101 | rhs_literal.Get<OperandT>(multi_index)); |
| 102 | })); |
| 103 | |
| 104 | return std::move(result); |
| 105 | } |
| 106 | |
| 107 | template <> |
| 108 | StatusOr<Literal> Compare<complex64>(const Shape& shape, |
no outgoing calls