diff --git a/src/ImageSharp/Common/Helpers/Numerics.cs b/src/ImageSharp/Common/Helpers/Numerics.cs index 21883bfb4..e5a6b4549 100644 --- a/src/ImageSharp/Common/Helpers/Numerics.cs +++ b/src/ImageSharp/Common/Helpers/Numerics.cs @@ -1,4 +1,4 @@ -// Copyright (c) Six Labors. +// Copyright (c) Six Labors. // Licensed under the Six Labors Split License. using System.Numerics; @@ -1033,13 +1033,4 @@ internal static class Numerics public static nuint Vector512Count(int length) where TVector : struct => (uint)length / (uint)Vector512.Count; - - /// - /// Normalizes the values in a given . - /// - /// The sequence of values to normalize. - /// The sum of the values in . - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Normalize(Span span, float sum) - => TensorPrimitives.Divide(span, sum, span); } diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs index 0b8106e0b..b397b9999 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs @@ -3,6 +3,7 @@ using System.Buffers; using System.Diagnostics; +using System.Numerics.Tensors; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using SixLabors.ImageSharp.Memory; @@ -243,7 +244,7 @@ internal partial class ResizeKernelMap : IDisposable // Normalize, best to do it here rather than in the pixel loop later on. if (sum > 0) { - Numerics.Normalize(kernelValues, sum); + TensorPrimitives.Divide(kernelValues, sum, kernelValues); } kernel.FillOrCopyAndExpand(kernelValues); diff --git a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj index e060e1f33..c3733c73c 100644 --- a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj +++ b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj @@ -69,7 +69,6 @@ - diff --git a/tests/ImageSharp.Tests/Common/NumericsTests.cs b/tests/ImageSharp.Tests/Common/NumericsTests.cs index 4b2ac003a..6f35118e2 100644 --- a/tests/ImageSharp.Tests/Common/NumericsTests.cs +++ b/tests/ImageSharp.Tests/Common/NumericsTests.cs @@ -5,42 +5,12 @@ namespace SixLabors.ImageSharp.Tests.Common; public class NumericsTests { - private static readonly int[] NormalizeSpanLengthValues = - [ - 0, - 1, - 3, - 4, - 5, - 7, - 8, - 9, - 15, - 16, - 17, - 31, - 32, - 33, - 63, - 64, - 65, - 127, - 128, - 129, - 2048 - ]; - private ITestOutputHelper Output { get; } public NumericsTests(ITestOutputHelper output) => this.Output = output; public static TheoryData IsOutOfRangeTestData = new() { int.MinValue, -1, 0, 1, 6, 7, 8, 91, 92, 93, int.MaxValue }; - /// - /// Gets lengths that exercise scalar execution and the supported SIMD widths. - /// - public static TheoryData NormalizeSpanLengths => new(NormalizeSpanLengthValues); - private static uint DivideCeil_ReferenceImplementation(uint value, uint divisor) => (uint)MathF.Ceiling((float)value / divisor); [Fact] @@ -84,30 +54,4 @@ public class NumericsTests Assert.True(expected == actual, $"IsOutOfRange({value}, {min}, {max})"); } - /// - /// Verifies that normalization divides every element by the supplied sum. - /// - /// The input length. - [Theory] - [MemberData(nameof(NormalizeSpanLengths))] - public void NormalizeMatchesScalarFormula(int length) - { - float[] actual = new float[length]; - float[] expected = new float[length]; - - for (int i = 0; i < actual.Length; i++) - { - actual[i] = (i + 1) * 0.125F; - expected[i] = actual[i] / 7.5F; - } - - Numerics.Normalize(actual, 7.5F); - - Assert.Equal(expected.Length, actual.Length); - - for (int i = 0; i < expected.Length; i++) - { - Assert.Equal(BitConverter.SingleToInt32Bits(expected[i]), BitConverter.SingleToInt32Bits(actual[i])); - } - } }