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

#### 场景说明

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

```
input0: [5,7,15,3]
input1: [8,6,20,0]
output: [true,false,true,false]
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};                         
    auto *input0 = input0Array;                                   
    auto *input1 = input1Array;                                        
    auto *output = new bool[4];                                  
    int ret = -1;
    //调用Less算子，结果存储于output数组。第一个参数及第二个参数均为数组
    ret = Less(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 Less Op."
    ret = Less(static_cast<int64_t *>(nullptr), input1, output, length); 
    //传入空指针，打印日志"ERROR Parameter verification failed for the Less Op."
    ret = Less(input0, input1, nullptr, length);                   

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