* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
#include <vector>
#include <array>
#include "gtest/gtest.h"
#include "math/less/op_api/aclnn_lt_scalar.h"
#include "op_api_ut_common/tensor_desc.h"
#include "op_api_ut_common/scalar_desc.h"
#include "op_api_ut_common/op_api_ut.h"
using namespace std;
class l2_inplace_lt_scalar_test : public testing::Test {
protected:
static void SetUpTestCase()
{
cout << "lt_scalar_test SetUp" << endl;
}
static void TearDownTestCase()
{
cout << "lt_scalar_test TearDown" << endl;
}
};
TEST_F(l2_inplace_lt_scalar_test, aclnnInplaceLtScalar_001_bool_ND)
{
auto tensor_self = TensorDesc({2, 3, 4, 5}, ACL_BOOL, ACL_FORMAT_ND).ValueRange(-10, 10).Precision(0.001, 0.001);
auto scalar_other = ScalarDesc(static_cast<int64_t>(1));
auto ut = OP_API_UT(aclnnInplaceLtScalar, INPUT(tensor_self, scalar_other), OUTPUT());
uint64_t workspace_size = 5;
aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
EXPECT_EQ(aclRet, ACL_SUCCESS);
}
TEST_F(l2_inplace_lt_scalar_test, aclnnInplaceLtScalar_002_double)
{
auto tensor_self = TensorDesc({2, 3}, ACL_DOUBLE, ACL_FORMAT_ND).ValueRange(-1, 1).Precision(0.0001, 0.0001);
auto scalar_other = ScalarDesc(static_cast<int64_t>(2));
auto ut = OP_API_UT(aclnnInplaceLtScalar, INPUT(tensor_self, scalar_other), OUTPUT());
uint64_t workspace_size = 5;
aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
EXPECT_EQ(aclRet, ACL_SUCCESS);
}
TEST_F(l2_inplace_lt_scalar_test, aclnnInplaceLtScalar_003_input_empty_tensor)
{
auto tensor_self = TensorDesc({2, 0}, ACL_FLOAT, ACL_FORMAT_ND);
auto scalar_other = ScalarDesc(static_cast<int64_t>(2));
auto ut = OP_API_UT(aclnnInplaceLtScalar, INPUT(tensor_self, scalar_other), OUTPUT());
uint64_t workspace_size = 5;
aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
EXPECT_EQ(aclRet, ACL_SUCCESS);
}
TEST_F(l2_inplace_lt_scalar_test, aclnnInplaceLtScalar_004_input_not_contiguous)
{
auto tensor_self =
TensorDesc({5, 4}, ACL_FLOAT, ACL_FORMAT_ND, {1, 5}, 0, {4, 5}).ValueRange(-10, 10).Precision(0.0001, 0.0001);
auto scalar_other = ScalarDesc(1.2f);
auto ut = OP_API_UT(aclnnInplaceLtScalar, INPUT(tensor_self, scalar_other), OUTPUT());
uint64_t workspace_size = 5;
aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
EXPECT_EQ(aclRet, ACL_SUCCESS);
}
TEST_F(l2_inplace_lt_scalar_test, aclnnInplaceLtScalar_005_null_pointer)
{
auto scalar_other = ScalarDesc(1.2f);
auto ut = OP_API_UT(aclnnInplaceLtScalar, INPUT((aclTensor*)nullptr, scalar_other), OUTPUT());
uint64_t workspace_size = 5;
aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
EXPECT_EQ(aclRet, ACLNN_ERR_INNER_NULLPTR);
}
TEST_F(l2_inplace_lt_scalar_test, aclnnInplaceLtScalar_006_test_lt_scalar_other_is_null)
{
auto tensor_self =
TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-10, 10).Value(vector<float>{9, 3, 1, 1, 2, 3});
auto ut = OP_API_UT(aclnnInplaceLtScalar, INPUT(tensor_self, nullptr), OUTPUT());
uint64_t workspace_size = 5;
aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size);
EXPECT_EQ(aclRet, ACLNN_ERR_INNER_NULLPTR);
}