---
title: Greater
description: "给出两个输入张量input0，input1以及长度length，逐元素返回一个布尔张量，表示第一个输入是否大于第二个输入，将比较结果存储于输出张量output。例如："
url: https://www.hikunpeng.com/document/detail/zh/boostsra/srainference/SRA_Inference/kunpengsra_inference_16_0025.html
sourcePath: /source/zh/boostsra/srainference/SRA_Inference/kunpengsra_inference_16_0025.html
indexId: 782c4e77bcccde81d4cc9dee80520959cfb187d62b467912104d64e71585317d80
---
# Greater

#### 场景说明

给出两个输入张量input0，input1以及长度length，逐元素返回一个布尔张量，表示第一个输入是否大于第二个输入，将比较结果存储于输出张量output。例如：

```
input0: [5,7,15,3]
input1: [8,6,20,0]
output: [false,true,false,true]
length: 4
```


#### 代码示例

```
#include <cmath>
#include <random>
#include <cstdint>
#include <iostream>

#include "ktfop.h"
int main()
{
    using namespace ktfop;
    size_t length = 4;
    int64_t input0Array[] = {5, 7, 15, 3};                         
    int64_t input1Array[] = {8, 6, 20, 0};                           
    int64_t *input0 = input0Array;                                   
    int64_t *input1 = input1Array;                                         
    auto *output = new bool[4];                                 
    int ret = -1;
    //调用Greater算子，结果存储于output数组。第一个参数和第二个参数均为数组
    ret = Greater(input0, input1, output, length);
    std::cout << "output: [";
    for (int i = 0; i < 4; ++i) {
        std::cout << output[i];
        if (i < 3) {
            std::cout << ", ";
        }
    }
    std::cout << "]" << std::endl;              
    //传入空指针，打印日志"ERROR Parameter verification failed for the Greater Op."
    ret = Greater(static_cast<int64_t *>(nullptr), input1, output, length); 
    //传入空指针，打印日志"ERROR Parameter verification failed for the Greater Op."
    ret = Greater(input0, input1, nullptr, length);        
           
    //情况一：调用Greater算子，结果存储于output数组。第一个参数为数组，第二个参数为一个元素
    ret = Greater(input0, input1[0], output, length);           
    //传入空指针，打印日志"ERROR Parameter verification failed for the Greater Op."
    ret = Greater(static_cast<int64_t *>(nullptr), input1[0], output, length); 

    //情况二：调用Greater算子，结果存储于output数组。第一个参数为一个元素，第二个参数为数组
    ret = Greater(input0[0], input1, output, length);        
    //传入空指针，打印日志"ERROR Parameter verification failed for the Greater Op."
    ret = Greater(input0[0], static_cast<int64_t *>(nullptr), output, length); 
    delete[] output;
}
```
