Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion arm_compute/core/QuantizationInfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2025 Arm Limited.
* Copyright (c) 2019-2026 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -203,6 +203,17 @@ class QuantizationInfo
*/
inline bool operator==(const QuantizationInfo &lhs, const QuantizationInfo &rhs)
{
const bool lhs_is_uniform = lhs.scale().size() < 2 && lhs.offset().size() < 2;
const bool rhs_is_uniform = rhs.scale().size() < 2 && rhs.offset().size() < 2;

if (lhs_is_uniform && rhs_is_uniform)
{
const auto lhs_qinfo = lhs.uniform();
const auto rhs_qinfo = rhs.uniform();

return (lhs_qinfo.scale == rhs_qinfo.scale) && (lhs_qinfo.offset == rhs_qinfo.offset);
}

return (lhs.scale() == rhs.scale()) && (lhs.offset() == rhs.offset());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ CpuPool2dAssemblyWrapperKernel::validate(const ITensorInfo *src, const ITensorIn
const auto src_qinfo = src->quantization_info().uniform();
const auto dst_qinfo = dst->quantization_info().uniform();

if (src_qinfo != dst_qinfo)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to touch Pool2d anymore.

if (src->quantization_info() != dst->quantization_info())
{
ARM_COMPUTE_RETURN_ERROR_ON_MSG(info.pool_type != PoolingType::MAX,
"Assembly kernels only support differing src/dst quantization info for "
Expand Down
80 changes: 80 additions & 0 deletions tests/validation/UNIT/QuantizationInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2026 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "arm_compute/core/QuantizationInfo.h"

#include "tests/framework/Asserts.h"
#include "tests/framework/Macros.h"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <vector>

namespace arm_compute
{
namespace test
{
namespace validation
{
TEST_SUITE(UNIT)
TEST_SUITE(QuantizationInfo)

TEST_CASE(EquivalentUniformImplicitAndExplicitZeroOffset, framework::DatasetMode::ALL)
{
const arm_compute::QuantizationInfo implicit_zero(1.0f);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need arm_compute:: prefix (there is more below)

const arm_compute::QuantizationInfo explicit_zero(1.0f, 0);

ARM_COMPUTE_EXPECT(implicit_zero == explicit_zero, framework::LogLevel::ERRORS);
ARM_COMPUTE_EXPECT(!(implicit_zero != explicit_zero), framework::LogLevel::ERRORS);
}

TEST_CASE(DifferentUniformQInfoCompareDifferent, framework::DatasetMode::ALL)
{
const arm_compute::QuantizationInfo unit_scale(1.0f);
const arm_compute::QuantizationInfo half_scale(0.5f, 0);
const arm_compute::QuantizationInfo offset_one(1.0f, 1);
const arm_compute::QuantizationInfo offset_zero(1.0f, 0);

ARM_COMPUTE_EXPECT(unit_scale != half_scale, framework::LogLevel::ERRORS);
ARM_COMPUTE_EXPECT(offset_one != offset_zero, framework::LogLevel::ERRORS);
}

TEST_CASE(PerChannelQInfoUsesStrictVectorEquality, framework::DatasetMode::ALL)
{
const arm_compute::QuantizationInfo matching_per_channel(std::vector<float>{1.0f, 2.0f});
const arm_compute::QuantizationInfo same_per_channel(std::vector<float>{1.0f, 2.0f});
const arm_compute::QuantizationInfo different_per_channel(std::vector<float>{1.0f, 3.0f});

ARM_COMPUTE_EXPECT(matching_per_channel == same_per_channel, framework::LogLevel::ERRORS);
ARM_COMPUTE_EXPECT(matching_per_channel != different_per_channel, framework::LogLevel::ERRORS);
}

TEST_CASE(PerChannelQInfoDoesNotMatchUniformQInfo, framework::DatasetMode::ALL)
{
const arm_compute::QuantizationInfo per_channel(std::vector<float>{1.0f, 2.0f});
const arm_compute::QuantizationInfo uniform(1.0f);

ARM_COMPUTE_EXPECT(per_channel != uniform, framework::LogLevel::ERRORS);
}

TEST_SUITE_END() // QuantizationInfo
TEST_SUITE_END() // UNIT
} // namespace validation
} // namespace test
} // namespace arm_compute