From 8811928f83ac4902713308c0b62b65035a18a5fa Mon Sep 17 00:00:00 2001 From: Sychev Vadim Date: Wed, 27 Oct 2021 11:59:43 +0300 Subject: [PATCH 1/3] Use generic math in System.Numerics.Vectors (#60365) --- .../System.Numerics.Vectors.sln | 137 ++++---- .../tests/GenericVectorTests.cs | 323 ++++++++++++++++-- .../System.Numerics.Vectors.Tests.csproj | 4 + .../System.Numerics.Vectors/tests/Util.cs | 200 +++-------- 4 files changed, 416 insertions(+), 248 deletions(-) diff --git a/src/libraries/System.Numerics.Vectors/System.Numerics.Vectors.sln b/src/libraries/System.Numerics.Vectors/System.Numerics.Vectors.sln index 8bb2aa3fc8c11..57c2683dea528 100644 --- a/src/libraries/System.Numerics.Vectors/System.Numerics.Vectors.sln +++ b/src/libraries/System.Numerics.Vectors/System.Numerics.Vectors.sln @@ -26,18 +26,27 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{ED90FF1C-59D4-4AB0-860E-2872ECA1BFEC}" EndProject Global + GlobalSection(SharedMSBuildProjectFiles) = preSolution + ..\System.Private.CoreLib\src\System.Private.CoreLib.Shared.projitems*{634a3b2b-09f5-4810-b630-ade4d36c47df}*SharedItemsImports = 5 + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution + Checked|Any CPU = Checked|Any CPU + Checked|x64 = Checked|x64 + Checked|x86 = Checked|x86 Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 Release|x86 = Release|x86 - Checked|Any CPU = Checked|Any CPU - Checked|x64 = Checked|x64 - Checked|x86 = Checked|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|Any CPU.ActiveCfg = Checked|x64 + {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|Any CPU.Build.0 = Checked|x64 + {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x64.ActiveCfg = Checked|x64 + {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x64.Build.0 = Checked|x64 + {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x86.ActiveCfg = Checked|x86 + {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x86.Build.0 = Checked|x86 {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Debug|Any CPU.ActiveCfg = Debug|x64 {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Debug|Any CPU.Build.0 = Debug|x64 {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Debug|x64.ActiveCfg = Debug|x64 @@ -50,12 +59,12 @@ Global {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Release|x64.Build.0 = Release|x64 {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Release|x86.ActiveCfg = Release|x86 {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Release|x86.Build.0 = Release|x86 - {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|Any CPU.ActiveCfg = Checked|x64 - {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|Any CPU.Build.0 = Checked|x64 - {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x64.ActiveCfg = Checked|x64 - {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x64.Build.0 = Checked|x64 - {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x86.ActiveCfg = Checked|x86 - {634A3B2B-09F5-4810-B630-ADE4D36C47DF}.Checked|x86.Build.0 = Checked|x86 + {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|Any CPU.Build.0 = Debug|Any CPU + {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x64.ActiveCfg = Debug|Any CPU + {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x64.Build.0 = Debug|Any CPU + {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x86.ActiveCfg = Debug|Any CPU + {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x86.Build.0 = Debug|Any CPU {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Debug|Any CPU.Build.0 = Debug|Any CPU {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -68,12 +77,12 @@ Global {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Release|x64.Build.0 = Release|Any CPU {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Release|x86.ActiveCfg = Release|Any CPU {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Release|x86.Build.0 = Release|Any CPU - {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|Any CPU.Build.0 = Debug|Any CPU - {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x64.ActiveCfg = Debug|Any CPU - {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x64.Build.0 = Debug|Any CPU - {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x86.ActiveCfg = Debug|Any CPU - {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F}.Checked|x86.Build.0 = Debug|Any CPU + {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|Any CPU.Build.0 = Debug|Any CPU + {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x64.ActiveCfg = Debug|Any CPU + {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x64.Build.0 = Debug|Any CPU + {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x86.ActiveCfg = Debug|Any CPU + {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x86.Build.0 = Debug|Any CPU {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Debug|Any CPU.Build.0 = Debug|Any CPU {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -86,12 +95,12 @@ Global {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Release|x64.Build.0 = Release|Any CPU {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Release|x86.ActiveCfg = Release|Any CPU {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Release|x86.Build.0 = Release|Any CPU - {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|Any CPU.Build.0 = Debug|Any CPU - {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x64.ActiveCfg = Debug|Any CPU - {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x64.Build.0 = Debug|Any CPU - {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x86.ActiveCfg = Debug|Any CPU - {5B2027FA-F43A-4E80-880F-B3A7A2720AA7}.Checked|x86.Build.0 = Debug|Any CPU + {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|Any CPU.Build.0 = Debug|Any CPU + {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x64.ActiveCfg = Debug|Any CPU + {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x64.Build.0 = Debug|Any CPU + {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x86.ActiveCfg = Debug|Any CPU + {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x86.Build.0 = Debug|Any CPU {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Debug|Any CPU.Build.0 = Debug|Any CPU {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -104,12 +113,12 @@ Global {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Release|x64.Build.0 = Release|Any CPU {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Release|x86.ActiveCfg = Release|Any CPU {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Release|x86.Build.0 = Release|Any CPU - {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|Any CPU.Build.0 = Debug|Any CPU - {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x64.ActiveCfg = Debug|Any CPU - {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x64.Build.0 = Debug|Any CPU - {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x86.ActiveCfg = Debug|Any CPU - {ED450846-85A0-4CED-B4D9-9EB769CF794B}.Checked|x86.Build.0 = Debug|Any CPU + {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|Any CPU.Build.0 = Debug|Any CPU + {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x64.ActiveCfg = Debug|Any CPU + {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x64.Build.0 = Debug|Any CPU + {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x86.ActiveCfg = Debug|Any CPU + {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x86.Build.0 = Debug|Any CPU {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Debug|Any CPU.Build.0 = Debug|Any CPU {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -122,12 +131,12 @@ Global {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Release|x64.Build.0 = Release|Any CPU {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Release|x86.ActiveCfg = Release|Any CPU {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Release|x86.Build.0 = Release|Any CPU - {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|Any CPU.Build.0 = Debug|Any CPU - {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x64.ActiveCfg = Debug|Any CPU - {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x64.Build.0 = Debug|Any CPU - {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x86.ActiveCfg = Debug|Any CPU - {B38797B1-BB45-4B30-9D4F-79D9F4B3735B}.Checked|x86.Build.0 = Debug|Any CPU + {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|Any CPU.Build.0 = Debug|Any CPU + {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x64.ActiveCfg = Debug|Any CPU + {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x64.Build.0 = Debug|Any CPU + {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x86.ActiveCfg = Debug|Any CPU + {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x86.Build.0 = Debug|Any CPU {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Debug|Any CPU.Build.0 = Debug|Any CPU {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -140,12 +149,12 @@ Global {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Release|x64.Build.0 = Release|Any CPU {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Release|x86.ActiveCfg = Release|Any CPU {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Release|x86.Build.0 = Release|Any CPU - {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|Any CPU.Build.0 = Debug|Any CPU - {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x64.ActiveCfg = Debug|Any CPU - {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x64.Build.0 = Debug|Any CPU - {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x86.ActiveCfg = Debug|Any CPU - {88F4A78E-4EF9-4EB6-995E-CD24152C4704}.Checked|x86.Build.0 = Debug|Any CPU + {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|Any CPU.Build.0 = Debug|Any CPU + {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x64.ActiveCfg = Debug|Any CPU + {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x64.Build.0 = Debug|Any CPU + {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x86.ActiveCfg = Debug|Any CPU + {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x86.Build.0 = Debug|Any CPU {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Debug|Any CPU.Build.0 = Debug|Any CPU {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -158,12 +167,12 @@ Global {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Release|x64.Build.0 = Release|Any CPU {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Release|x86.ActiveCfg = Release|Any CPU {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Release|x86.Build.0 = Release|Any CPU - {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|Any CPU.Build.0 = Debug|Any CPU - {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x64.ActiveCfg = Debug|Any CPU - {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x64.Build.0 = Debug|Any CPU - {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x86.ActiveCfg = Debug|Any CPU - {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237}.Checked|x86.Build.0 = Debug|Any CPU + {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|Any CPU.Build.0 = Debug|Any CPU + {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x64.ActiveCfg = Debug|Any CPU + {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x64.Build.0 = Debug|Any CPU + {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x86.ActiveCfg = Debug|Any CPU + {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x86.Build.0 = Debug|Any CPU {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Debug|Any CPU.Build.0 = Debug|Any CPU {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -176,12 +185,12 @@ Global {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Release|x64.Build.0 = Release|Any CPU {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Release|x86.ActiveCfg = Release|Any CPU {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Release|x86.Build.0 = Release|Any CPU - {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|Any CPU.Build.0 = Debug|Any CPU - {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x64.ActiveCfg = Debug|Any CPU - {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x64.Build.0 = Debug|Any CPU - {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x86.ActiveCfg = Debug|Any CPU - {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598}.Checked|x86.Build.0 = Debug|Any CPU + {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|Any CPU.Build.0 = Debug|Any CPU + {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x64.ActiveCfg = Debug|Any CPU + {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x64.Build.0 = Debug|Any CPU + {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x86.ActiveCfg = Debug|Any CPU + {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x86.Build.0 = Debug|Any CPU {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Debug|Any CPU.Build.0 = Debug|Any CPU {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -194,12 +203,12 @@ Global {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Release|x64.Build.0 = Release|Any CPU {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Release|x86.ActiveCfg = Release|Any CPU {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Release|x86.Build.0 = Release|Any CPU - {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|Any CPU.Build.0 = Debug|Any CPU - {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x64.ActiveCfg = Debug|Any CPU - {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x64.Build.0 = Debug|Any CPU - {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x86.ActiveCfg = Debug|Any CPU - {C6EDFA8A-956E-4398-B31F-FA87312BDF9B}.Checked|x86.Build.0 = Debug|Any CPU + {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|Any CPU.ActiveCfg = Debug|Any CPU + {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|Any CPU.Build.0 = Debug|Any CPU + {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x64.ActiveCfg = Debug|Any CPU + {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x64.Build.0 = Debug|Any CPU + {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x86.ActiveCfg = Debug|Any CPU + {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x86.Build.0 = Debug|Any CPU {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Debug|Any CPU.Build.0 = Debug|Any CPU {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -212,27 +221,21 @@ Global {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Release|x64.Build.0 = Release|Any CPU {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Release|x86.ActiveCfg = Release|Any CPU {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Release|x86.Build.0 = Release|Any CPU - {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|Any CPU.ActiveCfg = Debug|Any CPU - {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|Any CPU.Build.0 = Debug|Any CPU - {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x64.ActiveCfg = Debug|Any CPU - {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x64.Build.0 = Debug|Any CPU - {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x86.ActiveCfg = Debug|Any CPU - {F99EAF58-533E-4941-A0C5-5101309D8AB9}.Checked|x86.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {634A3B2B-09F5-4810-B630-ADE4D36C47DF} = {FC10C682-DF71-4EEA-A3A5-E716C1C88AC0} + {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F} = {2C4425BA-8478-4BCB-B616-E6FC28ADEAB9} + {5B2027FA-F43A-4E80-880F-B3A7A2720AA7} = {ED90FF1C-59D4-4AB0-860E-2872ECA1BFEC} {ED450846-85A0-4CED-B4D9-9EB769CF794B} = {FC10C682-DF71-4EEA-A3A5-E716C1C88AC0} + {B38797B1-BB45-4B30-9D4F-79D9F4B3735B} = {2C4425BA-8478-4BCB-B616-E6FC28ADEAB9} {88F4A78E-4EF9-4EB6-995E-CD24152C4704} = {FC10C682-DF71-4EEA-A3A5-E716C1C88AC0} + {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237} = {ED90FF1C-59D4-4AB0-860E-2872ECA1BFEC} {7FAD5E59-D362-4ED6-B3D5-FAD9CD5A2598} = {FC10C682-DF71-4EEA-A3A5-E716C1C88AC0} {C6EDFA8A-956E-4398-B31F-FA87312BDF9B} = {FC10C682-DF71-4EEA-A3A5-E716C1C88AC0} {F99EAF58-533E-4941-A0C5-5101309D8AB9} = {FC10C682-DF71-4EEA-A3A5-E716C1C88AC0} - {9EDBE037-EFE0-4B72-B602-E4C3F0C05F2F} = {2C4425BA-8478-4BCB-B616-E6FC28ADEAB9} - {B38797B1-BB45-4B30-9D4F-79D9F4B3735B} = {2C4425BA-8478-4BCB-B616-E6FC28ADEAB9} - {5B2027FA-F43A-4E80-880F-B3A7A2720AA7} = {ED90FF1C-59D4-4AB0-860E-2872ECA1BFEC} - {DFC21F4E-EC4F-4310-A4DA-B7094AA4D237} = {ED90FF1C-59D4-4AB0-860E-2872ECA1BFEC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F9EDC1DC-52BE-4C40-90D2-41EE6FB7FA5C} diff --git a/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs b/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs index 556e6672b806c..101ed97d0e352 100644 --- a/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs +++ b/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using Xunit; using Xunit.Sdk; @@ -941,29 +942,40 @@ private void TestToString(string format, IFormatProvider provider) where T : #endregion System.Object Overloads #region Arithmetic Operator Tests + [RequiresPreviewFeatures] [Fact] public void AdditionByte() { TestAddition(); } + [RequiresPreviewFeatures] [Fact] public void AdditionSByte() { TestAddition(); } + [RequiresPreviewFeatures] [Fact] public void AdditionUInt16() { TestAddition(); } + [RequiresPreviewFeatures] [Fact] public void AdditionInt16() { TestAddition(); } + [RequiresPreviewFeatures] [Fact] public void AdditionUInt32() { TestAddition(); } + [RequiresPreviewFeatures] [Fact] public void AdditionInt32() { TestAddition(); } + [RequiresPreviewFeatures] [Fact] public void AdditionUInt64() { TestAddition(); } + [RequiresPreviewFeatures] [Fact] public void AdditionInt64() { TestAddition(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void AdditionSingle() { TestAddition(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void AdditionDouble() { TestAddition(); } - private void TestAddition() where T : struct + [RequiresPreviewFeatures] + private void TestAddition() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); T[] values2 = GenerateRandomValuesForVector(); @@ -977,23 +989,32 @@ private void TestAddition() where T : struct }); } + [RequiresPreviewFeatures] [Fact] public void AdditionOverflowByte() { TestAdditionOverflow(); } + [RequiresPreviewFeatures] [Fact] public void AdditionOverflowSByte() { TestAdditionOverflow(); } + [RequiresPreviewFeatures] [Fact] public void AdditionOverflowUInt16() { TestAdditionOverflow(); } + [RequiresPreviewFeatures] [Fact] public void AdditionOverflowInt16() { TestAdditionOverflow(); } + [RequiresPreviewFeatures] [Fact] public void AdditionOverflowUInt32() { TestAdditionOverflow(); } + [RequiresPreviewFeatures] [Fact] public void AdditionOverflowInt32() { TestAdditionOverflow(); } + [RequiresPreviewFeatures] [Fact] public void AdditionOverflowUInt64() { TestAdditionOverflow(); } + [RequiresPreviewFeatures] [Fact] public void AdditionOverflowInt64() { TestAdditionOverflow(); } - private void TestAdditionOverflow() where T : struct + [RequiresPreviewFeatures] + private void TestAdditionOverflow() where T : struct, INumber { T maxValue = GetMaxValueExact(); Vector maxValueVector = new Vector(maxValue); @@ -1008,29 +1029,40 @@ private void TestAdditionOverflow() where T : struct }); } + [RequiresPreviewFeatures] [Fact] public void SubtractionByte() { TestSubtraction(); } + [RequiresPreviewFeatures] [Fact] public void SubtractionSByte() { TestSubtraction(); } + [RequiresPreviewFeatures] [Fact] public void SubtractionUInt16() { TestSubtraction(); } + [RequiresPreviewFeatures] [Fact] public void SubtractionInt16() { TestSubtraction(); } + [RequiresPreviewFeatures] [Fact] public void SubtractionUInt32() { TestSubtraction(); } + [RequiresPreviewFeatures] [Fact] public void SubtractionInt32() { TestSubtraction(); } + [RequiresPreviewFeatures] [Fact] public void SubtractionUInt64() { TestSubtraction(); } + [RequiresPreviewFeatures] [Fact] public void SubtractionInt64() { TestSubtraction(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void SubtractionSingle() { TestSubtraction(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void SubtractionDouble() { TestSubtraction(); } - private void TestSubtraction() where T : struct + [RequiresPreviewFeatures] + private void TestSubtraction() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); T[] values2 = GenerateRandomValuesForVector(); @@ -1044,23 +1076,32 @@ private void TestSubtraction() where T : struct }); } + [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowByte() { TestSubtractionOverflow(); } + [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowSByte() { TestSubtractionOverflow(); } + [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowUInt16() { TestSubtractionOverflow(); } + [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowInt16() { TestSubtractionOverflow(); } + [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowUInt32() { TestSubtractionOverflow(); } + [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowInt32() { TestSubtractionOverflow(); } + [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowUInt64() { TestSubtractionOverflow(); } + [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowInt64() { TestSubtractionOverflow(); } - private void TestSubtractionOverflow() where T : struct + [RequiresPreviewFeatures] + private void TestSubtractionOverflow() where T : struct, INumber { T minValue = GetMinValueExact(); Vector minValueVector = new Vector(minValue); @@ -1075,29 +1116,40 @@ private void TestSubtractionOverflow() where T : struct }); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationByte() { TestMultiplication(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationSByte() { TestMultiplication(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationUInt16() { TestMultiplication(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationInt16() { TestMultiplication(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationUInt32() { TestMultiplication(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationInt32() { TestMultiplication(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationUInt64() { TestMultiplication(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationInt64() { TestMultiplication(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MultiplicationSingle() { TestMultiplication(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MultiplicationDouble() { TestMultiplication(); } - private void TestMultiplication() where T : struct + [RequiresPreviewFeatures] + private void TestMultiplication() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); T[] values2 = GenerateRandomValuesForVector(); @@ -1111,29 +1163,40 @@ private void TestMultiplication() where T : struct }); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarByte() { TestMultiplicationWithScalar(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarSByte() { TestMultiplicationWithScalar(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarUInt16() { TestMultiplicationWithScalar(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarInt16() { TestMultiplicationWithScalar(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarUInt32() { TestMultiplicationWithScalar(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarInt32() { TestMultiplicationWithScalar(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarUInt64() { TestMultiplicationWithScalar(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarInt64() { TestMultiplicationWithScalar(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MultiplicationWithScalarSingle() { TestMultiplicationWithScalar(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MultiplicationWithScalarDouble() { TestMultiplicationWithScalar(); } - private void TestMultiplicationWithScalar() where T : struct + [RequiresPreviewFeatures] + private void TestMultiplicationWithScalar() where T : struct, INumber { T[] values = GenerateRandomValuesForVector(); T factor = Util.GenerateSingleValue(GetMinValue(), GetMaxValue()); @@ -1155,29 +1218,40 @@ private void TestMultiplicationWithScalar() where T : struct }); } + [RequiresPreviewFeatures] [Fact] public void DivisionByte() { TestDivision(); } + [RequiresPreviewFeatures] [Fact] public void DivisionSByte() { TestDivision(); } + [RequiresPreviewFeatures] [Fact] public void DivisionUInt16() { TestDivision(); } + [RequiresPreviewFeatures] [Fact] public void DivisionInt16() { TestDivision(); } + [RequiresPreviewFeatures] [Fact] public void DivisionUInt32() { TestDivision(); } + [RequiresPreviewFeatures] [Fact] public void DivisionInt32() { TestDivision(); } + [RequiresPreviewFeatures] [Fact] public void DivisionUInt64() { TestDivision(); } + [RequiresPreviewFeatures] [Fact] public void DivisionInt64() { TestDivision(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void DivisionSingle() { TestDivision(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void DivisionDouble() { TestDivision(); } - private void TestDivision() where T : struct + [RequiresPreviewFeatures] + private void TestDivision() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); values1 = values1.Select(val => val.Equals(Util.Zero()) ? Util.One() : val).ToArray(); // Avoid divide-by-zero @@ -1217,29 +1291,40 @@ private void TestDivisionByZeroException() where T : struct }); } + [RequiresPreviewFeatures] [Fact] public void UnaryMinusByte() { TestUnaryMinus(); } + [RequiresPreviewFeatures] [Fact] public void UnaryMinusSByte() { TestUnaryMinus(); } + [RequiresPreviewFeatures] [Fact] public void UnaryMinusUInt16() { TestUnaryMinus(); } + [RequiresPreviewFeatures] [Fact] public void UnaryMinusInt16() { TestUnaryMinus(); } + [RequiresPreviewFeatures] [Fact] public void UnaryMinusUInt32() { TestUnaryMinus(); } + [RequiresPreviewFeatures] [Fact] public void UnaryMinusInt32() { TestUnaryMinus(); } + [RequiresPreviewFeatures] [Fact] public void UnaryMinusUInt64() { TestUnaryMinus(); } + [RequiresPreviewFeatures] [Fact] public void UnaryMinusInt64() { TestUnaryMinus(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void UnaryMinusSingle() { TestUnaryMinus(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void UnaryMinusDouble() { TestUnaryMinus(); } - private void TestUnaryMinus() where T : struct + [RequiresPreviewFeatures] + private void TestUnaryMinus() where T : struct, INumber { T[] values = GenerateRandomValuesForVector(); Vector vector = new Vector(values); @@ -1320,23 +1405,32 @@ private void TestBitwiseOrOperator() where T : struct Assert.Equal(allOnesVector, allOnesOrZero); } + [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorByte() { TestBitwiseXorOperator(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorSByte() { TestBitwiseXorOperator(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorUInt16() { TestBitwiseXorOperator(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorInt16() { TestBitwiseXorOperator(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorUInt32() { TestBitwiseXorOperator(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorInt32() { TestBitwiseXorOperator(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorUInt64() { TestBitwiseXorOperator(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorInt64() { TestBitwiseXorOperator(); } - private void TestBitwiseXorOperator() where T : struct + [RequiresPreviewFeatures] + private void TestBitwiseXorOperator() where T : struct, IBitwiseOperators { T[] values1 = GenerateRandomValuesForVector(); T[] values2 = GenerateRandomValuesForVector(); @@ -1352,23 +1446,32 @@ private void TestBitwiseXorOperator() where T : struct }); } + [RequiresPreviewFeatures] [Fact] public void BitwiseOnesComplementOperatorByte() { TestBitwiseOnesComplementOperator(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseOnesComplementOperatorSByte() { TestBitwiseOnesComplementOperator(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseOnesComplementOperatorUInt16() { TestBitwiseOnesComplementOperator(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseOnesComplementOperatorInt16() { TestBitwiseOnesComplementOperator(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseOnesComplementOperatorUInt32() { TestBitwiseOnesComplementOperator(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseOnesComplementOperatorInt32() { TestBitwiseOnesComplementOperator(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseOnesComplementOperatorUInt64() { TestBitwiseOnesComplementOperator(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseOnesComplementOperatorInt64() { TestBitwiseOnesComplementOperator(); } - private void TestBitwiseOnesComplementOperator() where T : struct + [RequiresPreviewFeatures] + private void TestBitwiseOnesComplementOperator() where T : struct, IBitwiseOperators { T[] values1 = GenerateRandomValuesForVector(); Vector randomVector1 = new Vector(values1); @@ -1382,23 +1485,32 @@ private void TestBitwiseOnesComplementOperator() where T : struct }); } + [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotByte() { TestBitwiseAndNot(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotSByte() { TestBitwiseAndNot(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotUInt16() { TestBitwiseAndNot(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotInt16() { TestBitwiseAndNot(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotUInt32() { TestBitwiseAndNot(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotInt32() { TestBitwiseAndNot(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotUInt64() { TestBitwiseAndNot(); } + [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotInt64() { TestBitwiseAndNot(); } - private void TestBitwiseAndNot() where T : struct + [RequiresPreviewFeatures] + private void TestBitwiseAndNot() where T : struct, IBitwiseOperators { T[] values1 = GenerateRandomValuesForVector(); T[] values2 = GenerateRandomValuesForVector(); @@ -1419,29 +1531,40 @@ private void TestBitwiseAndNot() where T : struct #endregion #region Comparison Tests + [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanByte() { TestVectorGreaterThan(); } + [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanSByte() { TestVectorGreaterThan(); } + [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanUInt16() { TestVectorGreaterThan(); } + [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanInt16() { TestVectorGreaterThan(); } + [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanUInt32() { TestVectorGreaterThan(); } + [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanInt32() { TestVectorGreaterThan(); } + [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanUInt64() { TestVectorGreaterThan(); } + [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanInt64() { TestVectorGreaterThan(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void VectorGreaterThanSingle() { TestVectorGreaterThan(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void VectorGreaterThanDouble() { TestVectorGreaterThan(); } - private void TestVectorGreaterThan() where T : struct + [RequiresPreviewFeatures] + private void TestVectorGreaterThan() where T : struct, INumber { var values1 = GenerateRandomValuesForVector(); var values2 = GenerateRandomValuesForVector(); @@ -1458,29 +1581,40 @@ private void TestVectorGreaterThan() where T : struct }); } + [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualByte() { TestVectorGreaterThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualSByte() { TestVectorGreaterThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualUInt16() { TestVectorGreaterThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualInt16() { TestVectorGreaterThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualUInt32() { TestVectorGreaterThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualInt32() { TestVectorGreaterThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualUInt64() { TestVectorGreaterThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualInt64() { TestVectorGreaterThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void GreaterThanOrEqualSingle() { TestVectorGreaterThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void GreaterThanOrEqualDouble() { TestVectorGreaterThanOrEqual(); } - private void TestVectorGreaterThanOrEqual() where T : struct + [RequiresPreviewFeatures] + private void TestVectorGreaterThanOrEqual() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); T[] values2 = GenerateRandomValuesForVector(); @@ -1713,29 +1847,40 @@ private void TestVectorGreaterThanOrEqualAll() where T : struct Assert.True(Vector.GreaterThanOrEqualAll(vec3, vec3)); } + [RequiresPreviewFeatures] [Fact] public void LessThanByte() { TestVectorLessThan(); } + [RequiresPreviewFeatures] [Fact] public void LessThanSByte() { TestVectorLessThan(); } + [RequiresPreviewFeatures] [Fact] public void LessThanUInt16() { TestVectorLessThan(); } + [RequiresPreviewFeatures] [Fact] public void LessThanInt16() { TestVectorLessThan(); } + [RequiresPreviewFeatures] [Fact] public void LessThanUInt32() { TestVectorLessThan(); } + [RequiresPreviewFeatures] [Fact] public void LessThanInt32() { TestVectorLessThan(); } + [RequiresPreviewFeatures] [Fact] public void LessThanUInt64() { TestVectorLessThan(); } + [RequiresPreviewFeatures] [Fact] public void LessThanInt64() { TestVectorLessThan(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void LessThanSingle() { TestVectorLessThan(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void LessThanDouble() { TestVectorLessThan(); } - private void TestVectorLessThan() where T : struct + [RequiresPreviewFeatures] + private void TestVectorLessThan() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); T[] values2 = GenerateRandomValuesForVector(); @@ -1752,29 +1897,40 @@ private void TestVectorLessThan() where T : struct }); } + [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualByte() { TestVectorLessThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualSByte() { TestVectorLessThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualUInt16() { TestVectorLessThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualInt16() { TestVectorLessThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualUInt32() { TestVectorLessThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualInt32() { TestVectorLessThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualUInt64() { TestVectorLessThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualInt64() { TestVectorLessThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void LessThanOrEqualSingle() { TestVectorLessThanOrEqual(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void LessThanOrEqualDouble() { TestVectorLessThanOrEqual(); } - private void TestVectorLessThanOrEqual() where T : struct + [RequiresPreviewFeatures] + private void TestVectorLessThanOrEqual() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); T[] values2 = GenerateRandomValuesForVector(); @@ -1791,29 +1947,40 @@ private void TestVectorLessThanOrEqual() where T : struct }); } + [RequiresPreviewFeatures] [Fact] public void LessThanAnyByte() { TestVectorLessThanAny(); } + [RequiresPreviewFeatures] [Fact] public void LessThanAnySByte() { TestVectorLessThanAny(); } + [RequiresPreviewFeatures] [Fact] public void LessThanAnyUInt16() { TestVectorLessThanAny(); } + [RequiresPreviewFeatures] [Fact] public void LessThanAnyInt16() { TestVectorLessThanAny(); } + [RequiresPreviewFeatures] [Fact] public void LessThanAnyUInt32() { TestVectorLessThanAny(); } + [RequiresPreviewFeatures] [Fact] public void LessThanAnyInt32() { TestVectorLessThanAny(); } + [RequiresPreviewFeatures] [Fact] public void LessThanAnyUInt64() { TestVectorLessThanAny(); } + [RequiresPreviewFeatures] [Fact] public void LessThanAnyInt64() { TestVectorLessThanAny(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void LessThanAnySingle() { TestVectorLessThanAny(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void LessThanAnyDouble() { TestVectorLessThanAny(); } - private void TestVectorLessThanAny() where T : struct + [RequiresPreviewFeatures] + private void TestVectorLessThanAny() where T : struct, INumber { T[] values1 = new T[Vector.Count]; for (int g = 0; g < Vector.Count; g++) @@ -2119,29 +2286,40 @@ private void TestVectorEqualsAll() where T : struct #endregion #region Selection Tests + [RequiresPreviewFeatures] [Fact] public void ConditionalSelectByte() { TestConditionalSelect(); } + [RequiresPreviewFeatures] [Fact] public void ConditionalSelectSByte() { TestConditionalSelect(); } + [RequiresPreviewFeatures] [Fact] public void ConditionalSelectUInt16() { TestConditionalSelect(); } + [RequiresPreviewFeatures] [Fact] public void ConditionalSelectInt16() { TestConditionalSelect(); } + [RequiresPreviewFeatures] [Fact] public void ConditionalSelectUInt32() { TestConditionalSelect(); } + [RequiresPreviewFeatures] [Fact] public void ConditionalSelectInt32() { TestConditionalSelect(); } + [RequiresPreviewFeatures] [Fact] public void ConditionalSelectUInt64() { TestConditionalSelect(); } + [RequiresPreviewFeatures] [Fact] public void ConditionalSelectInt64() { TestConditionalSelect(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void ConditionalSelectSingle() { TestConditionalSelect(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void ConditionalSelectDouble() { TestConditionalSelect(); } - private void TestConditionalSelect() where T : struct + [RequiresPreviewFeatures] + private void TestConditionalSelect() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); T[] values2 = GenerateRandomValuesForVector(); @@ -2173,29 +2351,40 @@ private void TestConditionalSelect() where T : struct #endregion #region Vector Tests + [RequiresPreviewFeatures] [Fact] public void DotProductByte() { TestDotProduct(); } + [RequiresPreviewFeatures] [Fact] public void DotProductSByte() { TestDotProduct(); } + [RequiresPreviewFeatures] [Fact] public void DotProductUInt16() { TestDotProduct(); } + [RequiresPreviewFeatures] [Fact] public void DotProductInt16() { TestDotProduct(); } + [RequiresPreviewFeatures] [Fact] public void DotProductUInt32() { TestDotProduct(); } + [RequiresPreviewFeatures] [Fact] public void DotProductInt32() { TestDotProduct(); } + [RequiresPreviewFeatures] [Fact] public void DotProductUInt64() { TestDotProduct(); } + [RequiresPreviewFeatures] [Fact] public void DotProductInt64() { TestDotProduct(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void DotProductSingle() { TestDotProduct(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void DotProductDouble() { TestDotProduct(); } - private void TestDotProduct() where T : struct + [RequiresPreviewFeatures] + private void TestDotProduct() where T : struct, INumber { T[] values1 = Util.GenerateRandomValues(Vector.Count); T[] values2 = Util.GenerateRandomValues(Vector.Count); @@ -2211,29 +2400,40 @@ private void TestDotProduct() where T : struct Assert.Equal(expected, dotProduct); } + [RequiresPreviewFeatures] [Fact] public void MaxByte() { TestMax(); } + [RequiresPreviewFeatures] [Fact] public void MaxSByte() { TestMax(); } + [RequiresPreviewFeatures] [Fact] public void MaxUInt16() { TestMax(); } + [RequiresPreviewFeatures] [Fact] public void MaxInt16() { TestMax(); } + [RequiresPreviewFeatures] [Fact] public void MaxUInt32() { TestMax(); } + [RequiresPreviewFeatures] [Fact] public void MaxInt32() { TestMax(); } + [RequiresPreviewFeatures] [Fact] public void MaxUInt64() { TestMax(); } + [RequiresPreviewFeatures] [Fact] public void MaxInt64() { TestMax(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MaxSingle() { TestMax(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MaxDouble() { TestMax(); } - private void TestMax() where T : struct + [RequiresPreviewFeatures] + private void TestMax() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); T[] values2 = GenerateRandomValuesForVector(); @@ -2249,29 +2449,40 @@ private void TestMax() where T : struct }); } + [RequiresPreviewFeatures] [Fact] public void MinByte() { TestMin(); } + [RequiresPreviewFeatures] [Fact] public void MinSByte() { TestMin(); } + [RequiresPreviewFeatures] [Fact] public void MinUInt16() { TestMin(); } + [RequiresPreviewFeatures] [Fact] public void MinInt16() { TestMin(); } + [RequiresPreviewFeatures] [Fact] public void MinUInt32() { TestMin(); } + [RequiresPreviewFeatures] [Fact] public void MinInt32() { TestMin(); } + [RequiresPreviewFeatures] [Fact] public void MinUInt64() { TestMin(); } + [RequiresPreviewFeatures] [Fact] public void MinInt64() { TestMin(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MinSingle() { TestMin(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MinDouble() { TestMin(); } - private void TestMin() where T : struct + [RequiresPreviewFeatures] + private void TestMin() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); T[] values2 = GenerateRandomValuesForVector(); @@ -2303,12 +2514,14 @@ private void TestMin() where T : struct public void SquareRootUInt64() { TestSquareRoot(-1); } [Fact] public void SquareRootInt64() { TestSquareRoot(-1); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] - public void SquareRootSingle() { TestSquareRoot(6); } + public void SquareRootSingle() { TestSquareRootGenericMath(6); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] - public void SquareRootDouble() { TestSquareRoot(15); } + public void SquareRootDouble() { TestSquareRootGenericMath(15); } private void TestSquareRoot(int precision = -1) where T : struct, IEquatable { T[] values = GenerateRandomValuesForVector(); @@ -2322,6 +2535,20 @@ private void TestSquareRoot(int precision = -1) where T : struct, IEquatable< AssertEqual(expected, val, $"SquareRoot( {FullString(values[index])} )", precision); }); } + [RequiresPreviewFeatures] + private void TestSquareRootGenericMath(int precision = -1) where T : struct, IFloatingPoint, IEquatable + { + T[] values = GenerateRandomValuesForVector(); + Vector vector = new Vector(values); + + Vector squareRootVector = Vector.SquareRoot(vector); + ValidateVector(squareRootVector, + (index, val) => + { + T expected = Util.SqrtGenericMath(values[index]); + AssertEqual(expected, val, $"SquareRoot( {FullString(values[index])} )", precision); + }); + } [Fact] public void CeilingSingle() @@ -2383,29 +2610,40 @@ public void FloorDouble() }); } + [RequiresPreviewFeatures] [Fact] public void AbsByte() { TestAbs(); } + [RequiresPreviewFeatures] [Fact] public void AbsSByte() { TestAbs(); } + [RequiresPreviewFeatures] [Fact] public void AbsUInt16() { TestAbs(); } + [RequiresPreviewFeatures] [Fact] public void AbsInt16() { TestAbs(); } + [RequiresPreviewFeatures] [Fact] public void AbsUInt32() { TestAbs(); } + [RequiresPreviewFeatures] [Fact] public void AbsInt32() { TestAbs(); } + [RequiresPreviewFeatures] [Fact] public void AbsUInt64() { TestAbs(); } + [RequiresPreviewFeatures] [Fact] public void AbsInt64() { TestAbs(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void AbsSingle() { TestAbs(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void AbsDouble() { TestAbs(); } - private void TestAbs() where T : struct + [RequiresPreviewFeatures] + private void TestAbs() where T : struct, INumber { T[] values = Util.GenerateRandomValues(Vector.Count, GetMinValue() + 1, GetMaxValue()); Vector vector = new Vector(values); @@ -2423,29 +2661,40 @@ private void TestAbs() where T : struct #region Reflection Tests // These tests ensure that, when invoked through reflection, methods behave as expected. There are potential // oddities when intrinsic methods are invoked through reflection which could have unexpected effects for the developer. + [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionByte() { TestMultiplicationReflection(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionSByte() { TestMultiplicationReflection(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionUInt16() { TestMultiplicationReflection(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionInt16() { TestMultiplicationReflection(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionUInt32() { TestMultiplicationReflection(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionInt32() { TestMultiplicationReflection(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionUInt64() { TestMultiplicationReflection(); } + [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionInt64() { TestMultiplicationReflection(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MultiplicationReflectionSingle() { TestMultiplicationReflection(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MultiplicationReflectionDouble() { TestMultiplicationReflection(); } - private void TestMultiplicationReflection() where T : struct + [RequiresPreviewFeatures] + private void TestMultiplicationReflection() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); T[] values2 = GenerateRandomValuesForVector(); @@ -2462,29 +2711,40 @@ private void TestMultiplicationReflection() where T : struct }); } + [RequiresPreviewFeatures] [Fact] public void AdditionReflectionByte() { TestAdditionReflection(); } + [RequiresPreviewFeatures] [Fact] public void AdditionReflectionSByte() { TestAdditionReflection(); } + [RequiresPreviewFeatures] [Fact] public void AdditionReflectionUInt16() { TestAdditionReflection(); } + [RequiresPreviewFeatures] [Fact] public void AdditionReflectionInt16() { TestAdditionReflection(); } + [RequiresPreviewFeatures] [Fact] public void AdditionReflectionUInt32() { TestAdditionReflection(); } + [RequiresPreviewFeatures] [Fact] public void AdditionReflectionInt32() { TestAdditionReflection(); } + [RequiresPreviewFeatures] [Fact] public void AdditionReflectionUInt64() { TestAdditionReflection(); } + [RequiresPreviewFeatures] [Fact] public void AdditionReflectionInt64() { TestAdditionReflection(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void AdditionReflectionSingle() { TestAdditionReflection(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void AdditionReflectionDouble() { TestAdditionReflection(); } - private void TestAdditionReflection() where T : struct + [RequiresPreviewFeatures] + private void TestAdditionReflection() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); T[] values2 = GenerateRandomValuesForVector(); @@ -2501,29 +2761,40 @@ private void TestAdditionReflection() where T : struct }); } + [RequiresPreviewFeatures] [Fact] public void DivisionReflectionByte() { TestDivisionReflection(); } + [RequiresPreviewFeatures] [Fact] public void DivisionReflectionSByte() { TestDivisionReflection(); } + [RequiresPreviewFeatures] [Fact] public void DivisionReflectionUInt16() { TestDivisionReflection(); } + [RequiresPreviewFeatures] [Fact] public void DivisionReflectionInt16() { TestDivisionReflection(); } + [RequiresPreviewFeatures] [Fact] public void DivisionReflectionUInt32() { TestDivisionReflection(); } + [RequiresPreviewFeatures] [Fact] public void DivisionReflectionInt32() { TestDivisionReflection(); } + [RequiresPreviewFeatures] [Fact] public void DivisionReflectionUInt64() { TestDivisionReflection(); } + [RequiresPreviewFeatures] [Fact] public void DivisionReflectionInt64() { TestDivisionReflection(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void DivisionReflectionSingle() { TestDivisionReflection(); } + [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void DivisionReflectionDouble() { TestDivisionReflection(); } - private void TestDivisionReflection() where T : struct + [RequiresPreviewFeatures] + private void TestDivisionReflection() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); values1 = values1.Select(val => val.Equals(Util.Zero()) ? Util.One() : val).ToArray(); // Avoid divide-by-zero diff --git a/src/libraries/System.Numerics.Vectors/tests/System.Numerics.Vectors.Tests.csproj b/src/libraries/System.Numerics.Vectors/tests/System.Numerics.Vectors.Tests.csproj index c8cff8865d09d..ff4201deb1b70 100644 --- a/src/libraries/System.Numerics.Vectors/tests/System.Numerics.Vectors.Tests.csproj +++ b/src/libraries/System.Numerics.Vectors/tests/System.Numerics.Vectors.Tests.csproj @@ -17,4 +17,8 @@ + + + + diff --git a/src/libraries/System.Numerics.Vectors/tests/Util.cs b/src/libraries/System.Numerics.Vectors/tests/Util.cs index 135b3fc0e65e4..40408ae2b27da 100644 --- a/src/libraries/System.Numerics.Vectors/tests/Util.cs +++ b/src/libraries/System.Numerics.Vectors/tests/Util.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Runtime.Versioning; + namespace System.Numerics.Tests { public static class Util @@ -89,21 +91,16 @@ public static T GenerateSingleValue(int min = 1, int max = 100) where T : str return value; } - public static T Abs(T value) where T : struct + [RequiresPreviewFeatures] + public static T Abs(T value) where T : INumber { - // unsigned types - if (value is byte) return value; - else if (value is ushort) return value; - else if (value is uint) return value; - else if (value is ulong) return value; - // signed types - else if (value is short) return (T)(ValueType)(short) ( Math.Abs((short) (ValueType)value) ); - else if (value is int) return (T)(ValueType)(int) ( Math.Abs((int) (ValueType)value) ); - else if (value is long) return (T)(ValueType)(long) ( Math.Abs((long) (ValueType)value) ); - else if (value is sbyte) return (T)(ValueType)(sbyte) ( Math.Abs((sbyte) (ValueType)value) ); - else if (value is float) return (T)(ValueType)(float) ( Math.Abs((float) (ValueType)value) ); - else if (value is double) return (T)(ValueType)(double) ( Math.Abs((double)(ValueType)value) ); - else throw new NotImplementedException(); + return T.Abs(value); + } + + [RequiresPreviewFeatures] + public static T SqrtGenericMath(T value) where T : IFloatingPoint + { + return T.Sqrt(value); } public static T Sqrt(T value) where T : struct @@ -118,121 +115,50 @@ public static T Sqrt(T value) where T : struct else if (value is ulong) return (T)(ValueType)(ulong) ( Math.Sqrt((ulong) (ValueType)value) ); else if (value is byte) return (T)(ValueType)(byte) ( Math.Sqrt((byte) (ValueType)value) ); else if (value is sbyte) return (T)(ValueType)(sbyte) ( Math.Sqrt((sbyte) (ValueType)value) ); - else if (value is float) return (T)(ValueType)(float) ( Math.Sqrt((float) (ValueType)value) ); - else if (value is double) return (T)(ValueType)(double) ( Math.Sqrt((double)(ValueType)value) ); else throw new NotImplementedException(); } } - public static T Multiply(T left, T right) where T : struct + [RequiresPreviewFeatures] + public static T Multiply(T left, T right) where T : INumber { - unchecked - { - if (left is short) return (T)(ValueType)(short) ( (short) (ValueType)left * (short) (ValueType)right ); - else if (left is int) return (T)(ValueType)(int) ( (int) (ValueType)left * (int) (ValueType)right ); - else if (left is long) return (T)(ValueType)(long) ( (long) (ValueType)left * (long) (ValueType)right ); - else if (left is ushort) return (T)(ValueType)(ushort) ( (ushort)(ValueType)left * (ushort)(ValueType)right ); - else if (left is uint) return (T)(ValueType)(uint) ( (uint) (ValueType)left * (uint) (ValueType)right ); - else if (left is ulong) return (T)(ValueType)(ulong) ( (ulong) (ValueType)left * (ulong) (ValueType)right ); - else if (left is byte) return (T)(ValueType)(byte) ( (byte) (ValueType)left * (byte) (ValueType)right ); - else if (left is sbyte) return (T)(ValueType)(sbyte) ( (sbyte) (ValueType)left * (sbyte) (ValueType)right ); - else if (left is float) return (T)(ValueType)(float) ( (float) (ValueType)left * (float) (ValueType)right ); - else if (left is double) return (T)(ValueType)(double) ( (double)(ValueType)left * (double)(ValueType)right ); - else throw new NotImplementedException(); - } + return left * right; } - public static T Divide(T left, T right) where T : struct + [RequiresPreviewFeatures] + public static T Divide(T left, T right) where T : INumber { - if (left is short) return (T)(ValueType)(short) ( (short) (ValueType)left / (short) (ValueType)right ); - else if (left is int) return (T)(ValueType)(int) ( (int) (ValueType)left / (int) (ValueType)right ); - else if (left is long) return (T)(ValueType)(long) ( (long) (ValueType)left / (long) (ValueType)right ); - else if (left is ushort) return (T)(ValueType)(ushort) ( (ushort)(ValueType)left / (ushort)(ValueType)right ); - else if (left is uint) return (T)(ValueType)(uint) ( (uint) (ValueType)left / (uint) (ValueType)right ); - else if (left is ulong) return (T)(ValueType)(ulong) ( (ulong) (ValueType)left / (ulong) (ValueType)right ); - else if (left is byte) return (T)(ValueType)(byte) ( (byte) (ValueType)left / (byte) (ValueType)right ); - else if (left is sbyte) return (T)(ValueType)(sbyte) ( (sbyte) (ValueType)left / (sbyte) (ValueType)right ); - else if (left is float) return (T)(ValueType)(float) ( (float) (ValueType)left / (float) (ValueType)right ); - else if (left is double) return (T)(ValueType)(double) ( (double)(ValueType)left / (double)(ValueType)right ); - else throw new NotImplementedException(); + return left / right; } - public static T Add(T left, T right) where T : struct + [RequiresPreviewFeatures] + public static T Add(T left, T right) where T : INumber { - unchecked - { - if (left is short) return (T)(ValueType)(short) ( (short) (ValueType)left + (short) (ValueType)right ); - else if (left is int) return (T)(ValueType)(int) ( (int) (ValueType)left + (int) (ValueType)right ); - else if (left is long) return (T)(ValueType)(long) ( (long) (ValueType)left + (long) (ValueType)right ); - else if (left is ushort) return (T)(ValueType)(ushort) ( (ushort)(ValueType)left + (ushort)(ValueType)right ); - else if (left is uint) return (T)(ValueType)(uint) ( (uint) (ValueType)left + (uint) (ValueType)right ); - else if (left is ulong) return (T)(ValueType)(ulong) ( (ulong) (ValueType)left + (ulong) (ValueType)right ); - else if (left is byte) return (T)(ValueType)(byte) ( (byte) (ValueType)left + (byte) (ValueType)right ); - else if (left is sbyte) return (T)(ValueType)(sbyte) ( (sbyte) (ValueType)left + (sbyte) (ValueType)right ); - else if (left is float) return (T)(ValueType)(float) ( (float) (ValueType)left + (float) (ValueType)right ); - else if (left is double) return (T)(ValueType)(double) ( (double)(ValueType)left + (double)(ValueType)right ); - else throw new NotImplementedException(); - } + return left + right; } - public static T Subtract(T left, T right) where T : struct + [RequiresPreviewFeatures] + public static T Subtract(T left, T right) where T : INumber { - unchecked - { - if (left is short) return (T)(ValueType)(short) ( (short) (ValueType)left - (short) (ValueType)right ); - else if (left is int) return (T)(ValueType)(int) ( (int) (ValueType)left - (int) (ValueType)right ); - else if (left is long) return (T)(ValueType)(long) ( (long) (ValueType)left - (long) (ValueType)right ); - else if (left is ushort) return (T)(ValueType)(ushort) ( (ushort)(ValueType)left - (ushort)(ValueType)right ); - else if (left is uint) return (T)(ValueType)(uint) ( (uint) (ValueType)left - (uint) (ValueType)right ); - else if (left is ulong) return (T)(ValueType)(ulong) ( (ulong) (ValueType)left - (ulong) (ValueType)right ); - else if (left is byte) return (T)(ValueType)(byte) ( (byte) (ValueType)left - (byte) (ValueType)right ); - else if (left is sbyte) return (T)(ValueType)(sbyte) ( (sbyte) (ValueType)left - (sbyte) (ValueType)right ); - else if (left is float) return (T)(ValueType)(float) ( (float) (ValueType)left - (float) (ValueType)right ); - else if (left is double) return (T)(ValueType)(double) ( (double)(ValueType)left - (double)(ValueType)right ); - else throw new NotImplementedException(); - } + return left - right; } - public static T Xor(T left, T right) where T : struct + [RequiresPreviewFeatures] + public static T Xor(T left, T right) where T : IBitwiseOperators { - if (left is short) return (T)(ValueType)(short) ( (short) (ValueType)left ^ (short) (ValueType)right ); - else if (left is int) return (T)(ValueType)(int) ( (int) (ValueType)left ^ (int) (ValueType)right ); - else if (left is long) return (T)(ValueType)(long) ( (long) (ValueType)left ^ (long) (ValueType)right ); - else if (left is ushort) return (T)(ValueType)(ushort) ( (ushort)(ValueType)left ^ (ushort)(ValueType)right ); - else if (left is uint) return (T)(ValueType)(uint) ( (uint) (ValueType)left ^ (uint) (ValueType)right ); - else if (left is ulong) return (T)(ValueType)(ulong) ( (ulong) (ValueType)left ^ (ulong) (ValueType)right ); - else if (left is byte) return (T)(ValueType)(byte) ( (byte) (ValueType)left ^ (byte) (ValueType)right ); - else if (left is sbyte) return (T)(ValueType)(sbyte) ( (sbyte) (ValueType)left ^ (sbyte) (ValueType)right ); - else throw new NotImplementedException(); + return left ^ right; } - public static T AndNot(T left, T right) where T : struct + [RequiresPreviewFeatures] + public static T AndNot(T left, T right) where T : IBitwiseOperators { - if (left is short) return (T)(ValueType)(short) ( (short) (ValueType)left & ~(short) (ValueType)right ); - else if (left is int) return (T)(ValueType)(int) ( (int) (ValueType)left & ~(int) (ValueType)right ); - else if (left is long) return (T)(ValueType)(long) ( (long) (ValueType)left & ~(long) (ValueType)right ); - else if (left is ushort) return (T)(ValueType)(ushort) ( (ushort)(ValueType)left & ~(ushort)(ValueType)right ); - else if (left is uint) return (T)(ValueType)(uint) ( (uint) (ValueType)left & ~(uint) (ValueType)right ); - else if (left is ulong) return (T)(ValueType)(ulong) ( (ulong) (ValueType)left & ~(ulong) (ValueType)right ); - else if (left is byte) return (T)(ValueType)(byte) ( (byte) (ValueType)left & ~(byte) (ValueType)right ); - else if (left is sbyte) return (T)(ValueType)(sbyte) ( (sbyte) (ValueType)left & ~(sbyte) (ValueType)right ); - else throw new NotImplementedException(); + return left & ~ right; } - public static T OnesComplement(T left) where T : struct + [RequiresPreviewFeatures] + public static T OnesComplement(T left) where T : IBitwiseOperators { - unchecked - { - if (left is short) return (T)(ValueType)(short) ( ~(short) (ValueType)left ); - else if (left is int) return (T)(ValueType)(int) ( ~(int) (ValueType)left ); - else if (left is long) return (T)(ValueType)(long) ( ~(long) (ValueType)left ); - else if (left is ushort) return (T)(ValueType)(ushort) ( ~(ushort)(ValueType)left ); - else if (left is uint) return (T)(ValueType)(uint) ( ~(uint) (ValueType)left ); - else if (left is ulong) return (T)(ValueType)(ulong) ( ~(ulong) (ValueType)left ); - else if (left is byte) return (T)(ValueType)(byte) ( ~(byte) (ValueType)left ); - else if (left is sbyte) return (T)(ValueType)(sbyte) ( ~(sbyte) (ValueType)left ); - else throw new NotImplementedException(); - } + return ~left; } public static float Clamp(float value, float min, float max) @@ -270,64 +196,28 @@ public static T One() where T : struct else throw new NotImplementedException(); } - public static bool GreaterThan(T left, T right) where T : struct + [RequiresPreviewFeatures] + public static bool GreaterThan(T left, T right) where T : INumber { - if (left is short) return (short)(ValueType) left > (short)(ValueType) right; - else if (left is int) return (int)(ValueType) left > (int)(ValueType) right; - else if (left is long) return (long)(ValueType) left > (long)(ValueType) right; - else if (left is ushort) return (ushort)(ValueType) left > (ushort)(ValueType) right; - else if (left is uint) return (uint)(ValueType) left > (uint)(ValueType) right; - else if (left is ulong) return (ulong)(ValueType) left > (ulong)(ValueType) right; - else if (left is byte) return (byte)(ValueType) left > (byte)(ValueType) right; - else if (left is sbyte) return (sbyte)(ValueType) left > (sbyte)(ValueType) right; - else if (left is float) return (float)(ValueType) left > (float)(ValueType) right; - else if (left is double) return (double)(ValueType) left > (double)(ValueType) right; - else throw new NotImplementedException(); + return left > right; } - public static bool GreaterThanOrEqual(T left, T right) where T : struct - { - if (left is short) return (short)(ValueType) left >= (short)(ValueType) right; - else if (left is int) return (int)(ValueType) left >= (int)(ValueType) right; - else if (left is long) return (long)(ValueType) left >= (long)(ValueType) right; - else if (left is ushort) return (ushort)(ValueType) left >= (ushort)(ValueType) right; - else if (left is uint) return (uint)(ValueType) left >= (uint)(ValueType) right; - else if (left is ulong) return (ulong)(ValueType) left >= (ulong)(ValueType) right; - else if (left is byte) return (byte)(ValueType) left >= (byte)(ValueType) right; - else if (left is sbyte) return (sbyte)(ValueType) left >= (sbyte)(ValueType) right; - else if (left is float) return (float)(ValueType) left >= (float)(ValueType) right; - else if (left is double) return (double)(ValueType) left >= (double)(ValueType) right; - else throw new NotImplementedException(); + [RequiresPreviewFeatures] + public static bool GreaterThanOrEqual(T left, T right) where T : INumber + { + return left >= right; } - public static bool LessThan(T left, T right) where T : struct + [RequiresPreviewFeatures] + public static bool LessThan(T left, T right) where T : INumber { - if (left is short) return (short)(ValueType) left < (short)(ValueType) right; - else if (left is int) return (int)(ValueType) left < (int)(ValueType) right; - else if (left is long) return (long)(ValueType) left < (long)(ValueType) right; - else if (left is ushort) return (ushort)(ValueType) left < (ushort)(ValueType) right; - else if (left is uint) return (uint)(ValueType) left < (uint)(ValueType) right; - else if (left is ulong) return (ulong)(ValueType) left < (ulong)(ValueType) right; - else if (left is byte) return (byte)(ValueType) left < (byte)(ValueType) right; - else if (left is sbyte) return (sbyte)(ValueType) left < (sbyte)(ValueType) right; - else if (left is float) return (float)(ValueType) left < (float)(ValueType) right; - else if (left is double) return (double)(ValueType) left < (double)(ValueType) right; - else throw new NotImplementedException(); + return left < right; } - public static bool LessThanOrEqual(T left, T right) where T : struct + [RequiresPreviewFeatures] + public static bool LessThanOrEqual(T left, T right) where T : INumber { - if (left is short) return (short)(ValueType) left <= (short)(ValueType) right; - else if (left is int) return (int)(ValueType) left <= (int)(ValueType) right; - else if (left is long) return (long)(ValueType) left <= (long)(ValueType) right; - else if (left is ushort) return (ushort)(ValueType) left <= (ushort)(ValueType) right; - else if (left is uint) return (uint)(ValueType) left <= (uint)(ValueType) right; - else if (left is ulong) return (ulong)(ValueType) left <= (ulong)(ValueType) right; - else if (left is byte) return (byte)(ValueType) left <= (byte)(ValueType) right; - else if (left is sbyte) return (sbyte)(ValueType) left <= (sbyte)(ValueType) right; - else if (left is float) return (float)(ValueType) left <= (float)(ValueType) right; - else if (left is double) return (double)(ValueType) left <= (double)(ValueType) right; - else throw new NotImplementedException(); + return left <= right; } public static bool AnyEqual(T[] left, T[] right) where T : struct From 6be1a07253eacefbb4c20ab34c6ecfb057212d8b Mon Sep 17 00:00:00 2001 From: Sychev Vadim Date: Wed, 27 Oct 2021 23:35:13 +0300 Subject: [PATCH 2/3] Add more use of the Generic Math (#60365) --- .../tests/GenericVectorTests.cs | 291 +----------------- .../System.Numerics.Vectors/tests/Util.cs | 65 ++-- 2 files changed, 32 insertions(+), 324 deletions(-) diff --git a/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs b/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs index 101ed97d0e352..b7fbaec38f14f 100644 --- a/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs +++ b/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs @@ -15,6 +15,7 @@ namespace System.Numerics.Tests /// /// Vector{T} tests that use random number generation and a unified generic test structure /// + [RequiresPreviewFeatures] public class GenericVectorTests { // Static constructor in top-level class\ @@ -516,7 +517,7 @@ private void TestIndexerOutOfRange() where T : struct public void StaticOneVectorSingle() { TestStaticOneVector(); } [Fact] public void StaticOneVectorDouble() { TestStaticOneVector(); } - private void TestStaticOneVector() where T : struct + private void TestStaticOneVector() where T : struct, INumber { Vector vector = Vector.One; T oneValue = Util.One(); @@ -547,7 +548,7 @@ private void TestStaticOneVector() where T : struct public void StaticZeroVectorSingle() { TestStaticZeroVector(); } [Fact] public void StaticZeroVectorDouble() { TestStaticZeroVector(); } - private void TestStaticZeroVector() where T : struct + private void TestStaticZeroVector() where T : struct, INumber { Vector vector = Vector.Zero; T zeroValue = Util.Zero(); @@ -813,7 +814,7 @@ private void TestEqualsObject() where T : struct public void EqualsVectorSingle() { TestEqualsVector(); } [Fact] public void EqualsVectorDouble() { TestEqualsVector(); } - private void TestEqualsVector() where T : struct + private void TestEqualsVector() where T : struct, INumber { T[] values = GenerateRandomValuesForVector(); Vector vector1 = new Vector(values); @@ -942,39 +943,28 @@ private void TestToString(string format, IFormatProvider provider) where T : #endregion System.Object Overloads #region Arithmetic Operator Tests - [RequiresPreviewFeatures] [Fact] public void AdditionByte() { TestAddition(); } - [RequiresPreviewFeatures] [Fact] public void AdditionSByte() { TestAddition(); } - [RequiresPreviewFeatures] [Fact] public void AdditionUInt16() { TestAddition(); } - [RequiresPreviewFeatures] [Fact] public void AdditionInt16() { TestAddition(); } - [RequiresPreviewFeatures] [Fact] public void AdditionUInt32() { TestAddition(); } - [RequiresPreviewFeatures] [Fact] public void AdditionInt32() { TestAddition(); } - [RequiresPreviewFeatures] [Fact] public void AdditionUInt64() { TestAddition(); } - [RequiresPreviewFeatures] [Fact] public void AdditionInt64() { TestAddition(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void AdditionSingle() { TestAddition(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void AdditionDouble() { TestAddition(); } - [RequiresPreviewFeatures] private void TestAddition() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); @@ -989,31 +979,22 @@ private void TestAddition() where T : struct, INumber }); } - [RequiresPreviewFeatures] [Fact] public void AdditionOverflowByte() { TestAdditionOverflow(); } - [RequiresPreviewFeatures] [Fact] public void AdditionOverflowSByte() { TestAdditionOverflow(); } - [RequiresPreviewFeatures] [Fact] public void AdditionOverflowUInt16() { TestAdditionOverflow(); } - [RequiresPreviewFeatures] [Fact] public void AdditionOverflowInt16() { TestAdditionOverflow(); } - [RequiresPreviewFeatures] [Fact] public void AdditionOverflowUInt32() { TestAdditionOverflow(); } - [RequiresPreviewFeatures] [Fact] public void AdditionOverflowInt32() { TestAdditionOverflow(); } - [RequiresPreviewFeatures] [Fact] public void AdditionOverflowUInt64() { TestAdditionOverflow(); } - [RequiresPreviewFeatures] [Fact] public void AdditionOverflowInt64() { TestAdditionOverflow(); } - [RequiresPreviewFeatures] private void TestAdditionOverflow() where T : struct, INumber { T maxValue = GetMaxValueExact(); @@ -1029,39 +1010,28 @@ private void TestAdditionOverflow() where T : struct, INumber }); } - [RequiresPreviewFeatures] [Fact] public void SubtractionByte() { TestSubtraction(); } - [RequiresPreviewFeatures] [Fact] public void SubtractionSByte() { TestSubtraction(); } - [RequiresPreviewFeatures] [Fact] public void SubtractionUInt16() { TestSubtraction(); } - [RequiresPreviewFeatures] [Fact] public void SubtractionInt16() { TestSubtraction(); } - [RequiresPreviewFeatures] [Fact] public void SubtractionUInt32() { TestSubtraction(); } - [RequiresPreviewFeatures] [Fact] public void SubtractionInt32() { TestSubtraction(); } - [RequiresPreviewFeatures] [Fact] public void SubtractionUInt64() { TestSubtraction(); } - [RequiresPreviewFeatures] [Fact] public void SubtractionInt64() { TestSubtraction(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void SubtractionSingle() { TestSubtraction(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void SubtractionDouble() { TestSubtraction(); } - [RequiresPreviewFeatures] private void TestSubtraction() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); @@ -1076,31 +1046,22 @@ private void TestSubtraction() where T : struct, INumber }); } - [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowByte() { TestSubtractionOverflow(); } - [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowSByte() { TestSubtractionOverflow(); } - [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowUInt16() { TestSubtractionOverflow(); } - [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowInt16() { TestSubtractionOverflow(); } - [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowUInt32() { TestSubtractionOverflow(); } - [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowInt32() { TestSubtractionOverflow(); } - [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowUInt64() { TestSubtractionOverflow(); } - [RequiresPreviewFeatures] [Fact] public void SubtractionOverflowInt64() { TestSubtractionOverflow(); } - [RequiresPreviewFeatures] private void TestSubtractionOverflow() where T : struct, INumber { T minValue = GetMinValueExact(); @@ -1116,39 +1077,28 @@ private void TestSubtractionOverflow() where T : struct, INumber }); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationByte() { TestMultiplication(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationSByte() { TestMultiplication(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationUInt16() { TestMultiplication(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationInt16() { TestMultiplication(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationUInt32() { TestMultiplication(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationInt32() { TestMultiplication(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationUInt64() { TestMultiplication(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationInt64() { TestMultiplication(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MultiplicationSingle() { TestMultiplication(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MultiplicationDouble() { TestMultiplication(); } - [RequiresPreviewFeatures] private void TestMultiplication() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); @@ -1163,39 +1113,28 @@ private void TestMultiplication() where T : struct, INumber }); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarByte() { TestMultiplicationWithScalar(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarSByte() { TestMultiplicationWithScalar(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarUInt16() { TestMultiplicationWithScalar(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarInt16() { TestMultiplicationWithScalar(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarUInt32() { TestMultiplicationWithScalar(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarInt32() { TestMultiplicationWithScalar(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarUInt64() { TestMultiplicationWithScalar(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationWithScalarInt64() { TestMultiplicationWithScalar(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MultiplicationWithScalarSingle() { TestMultiplicationWithScalar(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MultiplicationWithScalarDouble() { TestMultiplicationWithScalar(); } - [RequiresPreviewFeatures] private void TestMultiplicationWithScalar() where T : struct, INumber { T[] values = GenerateRandomValuesForVector(); @@ -1218,39 +1157,28 @@ private void TestMultiplicationWithScalar() where T : struct, INumber }); } - [RequiresPreviewFeatures] [Fact] public void DivisionByte() { TestDivision(); } - [RequiresPreviewFeatures] [Fact] public void DivisionSByte() { TestDivision(); } - [RequiresPreviewFeatures] [Fact] public void DivisionUInt16() { TestDivision(); } - [RequiresPreviewFeatures] [Fact] public void DivisionInt16() { TestDivision(); } - [RequiresPreviewFeatures] [Fact] public void DivisionUInt32() { TestDivision(); } - [RequiresPreviewFeatures] [Fact] public void DivisionInt32() { TestDivision(); } - [RequiresPreviewFeatures] [Fact] public void DivisionUInt64() { TestDivision(); } - [RequiresPreviewFeatures] [Fact] public void DivisionInt64() { TestDivision(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void DivisionSingle() { TestDivision(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void DivisionDouble() { TestDivision(); } - [RequiresPreviewFeatures] private void TestDivision() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); @@ -1291,39 +1219,28 @@ private void TestDivisionByZeroException() where T : struct }); } - [RequiresPreviewFeatures] [Fact] public void UnaryMinusByte() { TestUnaryMinus(); } - [RequiresPreviewFeatures] [Fact] public void UnaryMinusSByte() { TestUnaryMinus(); } - [RequiresPreviewFeatures] [Fact] public void UnaryMinusUInt16() { TestUnaryMinus(); } - [RequiresPreviewFeatures] [Fact] public void UnaryMinusInt16() { TestUnaryMinus(); } - [RequiresPreviewFeatures] [Fact] public void UnaryMinusUInt32() { TestUnaryMinus(); } - [RequiresPreviewFeatures] [Fact] public void UnaryMinusInt32() { TestUnaryMinus(); } - [RequiresPreviewFeatures] [Fact] public void UnaryMinusUInt64() { TestUnaryMinus(); } - [RequiresPreviewFeatures] [Fact] public void UnaryMinusInt64() { TestUnaryMinus(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void UnaryMinusSingle() { TestUnaryMinus(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void UnaryMinusDouble() { TestUnaryMinus(); } - [RequiresPreviewFeatures] private void TestUnaryMinus() where T : struct, INumber { T[] values = GenerateRandomValuesForVector(); @@ -1405,31 +1322,22 @@ private void TestBitwiseOrOperator() where T : struct Assert.Equal(allOnesVector, allOnesOrZero); } - [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorByte() { TestBitwiseXorOperator(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorSByte() { TestBitwiseXorOperator(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorUInt16() { TestBitwiseXorOperator(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorInt16() { TestBitwiseXorOperator(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorUInt32() { TestBitwiseXorOperator(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorInt32() { TestBitwiseXorOperator(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorUInt64() { TestBitwiseXorOperator(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseXorOperatorInt64() { TestBitwiseXorOperator(); } - [RequiresPreviewFeatures] private void TestBitwiseXorOperator() where T : struct, IBitwiseOperators { T[] values1 = GenerateRandomValuesForVector(); @@ -1446,31 +1354,22 @@ private void TestBitwiseXorOperator() where T : struct, IBitwiseOperators(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseOnesComplementOperatorSByte() { TestBitwiseOnesComplementOperator(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseOnesComplementOperatorUInt16() { TestBitwiseOnesComplementOperator(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseOnesComplementOperatorInt16() { TestBitwiseOnesComplementOperator(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseOnesComplementOperatorUInt32() { TestBitwiseOnesComplementOperator(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseOnesComplementOperatorInt32() { TestBitwiseOnesComplementOperator(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseOnesComplementOperatorUInt64() { TestBitwiseOnesComplementOperator(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseOnesComplementOperatorInt64() { TestBitwiseOnesComplementOperator(); } - [RequiresPreviewFeatures] private void TestBitwiseOnesComplementOperator() where T : struct, IBitwiseOperators { T[] values1 = GenerateRandomValuesForVector(); @@ -1485,31 +1384,22 @@ private void TestBitwiseOnesComplementOperator() where T : struct, IBitwiseOp }); } - [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotByte() { TestBitwiseAndNot(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotSByte() { TestBitwiseAndNot(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotUInt16() { TestBitwiseAndNot(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotInt16() { TestBitwiseAndNot(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotUInt32() { TestBitwiseAndNot(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotInt32() { TestBitwiseAndNot(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotUInt64() { TestBitwiseAndNot(); } - [RequiresPreviewFeatures] [Fact] public void BitwiseAndNotInt64() { TestBitwiseAndNot(); } - [RequiresPreviewFeatures] private void TestBitwiseAndNot() where T : struct, IBitwiseOperators { T[] values1 = GenerateRandomValuesForVector(); @@ -1531,39 +1421,28 @@ private void TestBitwiseAndNot() where T : struct, IBitwiseOperators #endregion #region Comparison Tests - [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanByte() { TestVectorGreaterThan(); } - [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanSByte() { TestVectorGreaterThan(); } - [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanUInt16() { TestVectorGreaterThan(); } - [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanInt16() { TestVectorGreaterThan(); } - [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanUInt32() { TestVectorGreaterThan(); } - [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanInt32() { TestVectorGreaterThan(); } - [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanUInt64() { TestVectorGreaterThan(); } - [RequiresPreviewFeatures] [Fact] public void VectorGreaterThanInt64() { TestVectorGreaterThan(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void VectorGreaterThanSingle() { TestVectorGreaterThan(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void VectorGreaterThanDouble() { TestVectorGreaterThan(); } - [RequiresPreviewFeatures] private void TestVectorGreaterThan() where T : struct, INumber { var values1 = GenerateRandomValuesForVector(); @@ -1581,39 +1460,28 @@ private void TestVectorGreaterThan() where T : struct, INumber }); } - [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualByte() { TestVectorGreaterThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualSByte() { TestVectorGreaterThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualUInt16() { TestVectorGreaterThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualInt16() { TestVectorGreaterThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualUInt32() { TestVectorGreaterThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualInt32() { TestVectorGreaterThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualUInt64() { TestVectorGreaterThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] public void GreaterThanOrEqualInt64() { TestVectorGreaterThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void GreaterThanOrEqualSingle() { TestVectorGreaterThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void GreaterThanOrEqualDouble() { TestVectorGreaterThanOrEqual(); } - [RequiresPreviewFeatures] private void TestVectorGreaterThanOrEqual() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); @@ -1847,39 +1715,28 @@ private void TestVectorGreaterThanOrEqualAll() where T : struct Assert.True(Vector.GreaterThanOrEqualAll(vec3, vec3)); } - [RequiresPreviewFeatures] [Fact] public void LessThanByte() { TestVectorLessThan(); } - [RequiresPreviewFeatures] [Fact] public void LessThanSByte() { TestVectorLessThan(); } - [RequiresPreviewFeatures] [Fact] public void LessThanUInt16() { TestVectorLessThan(); } - [RequiresPreviewFeatures] [Fact] public void LessThanInt16() { TestVectorLessThan(); } - [RequiresPreviewFeatures] [Fact] public void LessThanUInt32() { TestVectorLessThan(); } - [RequiresPreviewFeatures] [Fact] public void LessThanInt32() { TestVectorLessThan(); } - [RequiresPreviewFeatures] [Fact] public void LessThanUInt64() { TestVectorLessThan(); } - [RequiresPreviewFeatures] [Fact] public void LessThanInt64() { TestVectorLessThan(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void LessThanSingle() { TestVectorLessThan(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void LessThanDouble() { TestVectorLessThan(); } - [RequiresPreviewFeatures] private void TestVectorLessThan() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); @@ -1897,39 +1754,28 @@ private void TestVectorLessThan() where T : struct, INumber }); } - [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualByte() { TestVectorLessThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualSByte() { TestVectorLessThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualUInt16() { TestVectorLessThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualInt16() { TestVectorLessThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualUInt32() { TestVectorLessThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualInt32() { TestVectorLessThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualUInt64() { TestVectorLessThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] public void LessThanOrEqualInt64() { TestVectorLessThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void LessThanOrEqualSingle() { TestVectorLessThanOrEqual(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void LessThanOrEqualDouble() { TestVectorLessThanOrEqual(); } - [RequiresPreviewFeatures] private void TestVectorLessThanOrEqual() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); @@ -1947,39 +1793,28 @@ private void TestVectorLessThanOrEqual() where T : struct, INumber }); } - [RequiresPreviewFeatures] [Fact] public void LessThanAnyByte() { TestVectorLessThanAny(); } - [RequiresPreviewFeatures] [Fact] public void LessThanAnySByte() { TestVectorLessThanAny(); } - [RequiresPreviewFeatures] [Fact] public void LessThanAnyUInt16() { TestVectorLessThanAny(); } - [RequiresPreviewFeatures] [Fact] public void LessThanAnyInt16() { TestVectorLessThanAny(); } - [RequiresPreviewFeatures] [Fact] public void LessThanAnyUInt32() { TestVectorLessThanAny(); } - [RequiresPreviewFeatures] [Fact] public void LessThanAnyInt32() { TestVectorLessThanAny(); } - [RequiresPreviewFeatures] [Fact] public void LessThanAnyUInt64() { TestVectorLessThanAny(); } - [RequiresPreviewFeatures] [Fact] public void LessThanAnyInt64() { TestVectorLessThanAny(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void LessThanAnySingle() { TestVectorLessThanAny(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void LessThanAnyDouble() { TestVectorLessThanAny(); } - [RequiresPreviewFeatures] private void TestVectorLessThanAny() where T : struct, INumber { T[] values1 = new T[Vector.Count]; @@ -2015,7 +1850,7 @@ private void TestVectorLessThanAny() where T : struct, INumber public void LessThanAllSingle() { TestVectorLessThanAll(); } [Fact] public void LessThanAllDouble() { TestVectorLessThanAll(); } - private void TestVectorLessThanAll() where T : struct + private void TestVectorLessThanAll() where T : struct, INumber { T[] values1 = new T[Vector.Count]; for (int g = 0; g < Vector.Count; g++) @@ -2170,7 +2005,7 @@ private void TestVectorLessThanOrEqualAll() where T : struct public void VectorEqualsSingle() { TestVectorEquals(); } [Fact] public void VectorEqualsDouble() { TestVectorEquals(); } - private void TestVectorEquals() where T : struct + private void TestVectorEquals() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); T[] values2; @@ -2215,7 +2050,7 @@ private void TestVectorEquals() where T : struct public void VectorEqualsAnySingle() { TestVectorEqualsAny(); } [Fact] public void VectorEqualsAnyDouble() { TestVectorEqualsAny(); } - private void TestVectorEqualsAny() where T : struct + private void TestVectorEqualsAny() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); T[] values2; @@ -2263,7 +2098,7 @@ private void TestVectorEqualsAny() where T : struct public void VectorEqualsAllSingle() { TestVectorEqualsAll(); } [Fact] public void VectorEqualsAllDouble() { TestVectorEqualsAll(); } - private void TestVectorEqualsAll() where T : struct + private void TestVectorEqualsAll() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); T[] values2; @@ -2286,39 +2121,28 @@ private void TestVectorEqualsAll() where T : struct #endregion #region Selection Tests - [RequiresPreviewFeatures] [Fact] public void ConditionalSelectByte() { TestConditionalSelect(); } - [RequiresPreviewFeatures] [Fact] public void ConditionalSelectSByte() { TestConditionalSelect(); } - [RequiresPreviewFeatures] [Fact] public void ConditionalSelectUInt16() { TestConditionalSelect(); } - [RequiresPreviewFeatures] [Fact] public void ConditionalSelectInt16() { TestConditionalSelect(); } - [RequiresPreviewFeatures] [Fact] public void ConditionalSelectUInt32() { TestConditionalSelect(); } - [RequiresPreviewFeatures] [Fact] public void ConditionalSelectInt32() { TestConditionalSelect(); } - [RequiresPreviewFeatures] [Fact] public void ConditionalSelectUInt64() { TestConditionalSelect(); } - [RequiresPreviewFeatures] [Fact] public void ConditionalSelectInt64() { TestConditionalSelect(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void ConditionalSelectSingle() { TestConditionalSelect(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void ConditionalSelectDouble() { TestConditionalSelect(); } - [RequiresPreviewFeatures] private void TestConditionalSelect() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); @@ -2351,39 +2175,28 @@ private void TestConditionalSelect() where T : struct, INumber #endregion #region Vector Tests - [RequiresPreviewFeatures] [Fact] public void DotProductByte() { TestDotProduct(); } - [RequiresPreviewFeatures] [Fact] public void DotProductSByte() { TestDotProduct(); } - [RequiresPreviewFeatures] [Fact] public void DotProductUInt16() { TestDotProduct(); } - [RequiresPreviewFeatures] [Fact] public void DotProductInt16() { TestDotProduct(); } - [RequiresPreviewFeatures] [Fact] public void DotProductUInt32() { TestDotProduct(); } - [RequiresPreviewFeatures] [Fact] public void DotProductInt32() { TestDotProduct(); } - [RequiresPreviewFeatures] [Fact] public void DotProductUInt64() { TestDotProduct(); } - [RequiresPreviewFeatures] [Fact] public void DotProductInt64() { TestDotProduct(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void DotProductSingle() { TestDotProduct(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void DotProductDouble() { TestDotProduct(); } - [RequiresPreviewFeatures] private void TestDotProduct() where T : struct, INumber { T[] values1 = Util.GenerateRandomValues(Vector.Count); @@ -2400,39 +2213,28 @@ private void TestDotProduct() where T : struct, INumber Assert.Equal(expected, dotProduct); } - [RequiresPreviewFeatures] [Fact] public void MaxByte() { TestMax(); } - [RequiresPreviewFeatures] [Fact] public void MaxSByte() { TestMax(); } - [RequiresPreviewFeatures] [Fact] public void MaxUInt16() { TestMax(); } - [RequiresPreviewFeatures] [Fact] public void MaxInt16() { TestMax(); } - [RequiresPreviewFeatures] [Fact] public void MaxUInt32() { TestMax(); } - [RequiresPreviewFeatures] [Fact] public void MaxInt32() { TestMax(); } - [RequiresPreviewFeatures] [Fact] public void MaxUInt64() { TestMax(); } - [RequiresPreviewFeatures] [Fact] public void MaxInt64() { TestMax(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MaxSingle() { TestMax(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MaxDouble() { TestMax(); } - [RequiresPreviewFeatures] private void TestMax() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); @@ -2449,39 +2251,28 @@ private void TestMax() where T : struct, INumber }); } - [RequiresPreviewFeatures] [Fact] public void MinByte() { TestMin(); } - [RequiresPreviewFeatures] [Fact] public void MinSByte() { TestMin(); } - [RequiresPreviewFeatures] [Fact] public void MinUInt16() { TestMin(); } - [RequiresPreviewFeatures] [Fact] public void MinInt16() { TestMin(); } - [RequiresPreviewFeatures] [Fact] public void MinUInt32() { TestMin(); } - [RequiresPreviewFeatures] [Fact] public void MinInt32() { TestMin(); } - [RequiresPreviewFeatures] [Fact] public void MinUInt64() { TestMin(); } - [RequiresPreviewFeatures] [Fact] public void MinInt64() { TestMin(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MinSingle() { TestMin(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MinDouble() { TestMin(); } - [RequiresPreviewFeatures] private void TestMin() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); @@ -2514,15 +2305,13 @@ private void TestMin() where T : struct, INumber public void SquareRootUInt64() { TestSquareRoot(-1); } [Fact] public void SquareRootInt64() { TestSquareRoot(-1); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] - public void SquareRootSingle() { TestSquareRootGenericMath(6); } - [RequiresPreviewFeatures] + public void SquareRootSingle() { TestSquareRoot(6); } [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] - public void SquareRootDouble() { TestSquareRootGenericMath(15); } - private void TestSquareRoot(int precision = -1) where T : struct, IEquatable + public void SquareRootDouble() { TestSquareRoot(15); } + private void TestSquareRoot(int precision = -1) where T : struct, INumber, IEquatable { T[] values = GenerateRandomValuesForVector(); Vector vector = new Vector(values); @@ -2535,20 +2324,6 @@ private void TestSquareRoot(int precision = -1) where T : struct, IEquatable< AssertEqual(expected, val, $"SquareRoot( {FullString(values[index])} )", precision); }); } - [RequiresPreviewFeatures] - private void TestSquareRootGenericMath(int precision = -1) where T : struct, IFloatingPoint, IEquatable - { - T[] values = GenerateRandomValuesForVector(); - Vector vector = new Vector(values); - - Vector squareRootVector = Vector.SquareRoot(vector); - ValidateVector(squareRootVector, - (index, val) => - { - T expected = Util.SqrtGenericMath(values[index]); - AssertEqual(expected, val, $"SquareRoot( {FullString(values[index])} )", precision); - }); - } [Fact] public void CeilingSingle() @@ -2610,39 +2385,28 @@ public void FloorDouble() }); } - [RequiresPreviewFeatures] [Fact] public void AbsByte() { TestAbs(); } - [RequiresPreviewFeatures] [Fact] public void AbsSByte() { TestAbs(); } - [RequiresPreviewFeatures] [Fact] public void AbsUInt16() { TestAbs(); } - [RequiresPreviewFeatures] [Fact] public void AbsInt16() { TestAbs(); } - [RequiresPreviewFeatures] [Fact] public void AbsUInt32() { TestAbs(); } - [RequiresPreviewFeatures] [Fact] public void AbsInt32() { TestAbs(); } - [RequiresPreviewFeatures] [Fact] public void AbsUInt64() { TestAbs(); } - [RequiresPreviewFeatures] [Fact] public void AbsInt64() { TestAbs(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void AbsSingle() { TestAbs(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void AbsDouble() { TestAbs(); } - [RequiresPreviewFeatures] private void TestAbs() where T : struct, INumber { T[] values = Util.GenerateRandomValues(Vector.Count, GetMinValue() + 1, GetMaxValue()); @@ -2661,39 +2425,28 @@ private void TestAbs() where T : struct, INumber #region Reflection Tests // These tests ensure that, when invoked through reflection, methods behave as expected. There are potential // oddities when intrinsic methods are invoked through reflection which could have unexpected effects for the developer. - [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionByte() { TestMultiplicationReflection(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionSByte() { TestMultiplicationReflection(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionUInt16() { TestMultiplicationReflection(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionInt16() { TestMultiplicationReflection(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionUInt32() { TestMultiplicationReflection(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionInt32() { TestMultiplicationReflection(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionUInt64() { TestMultiplicationReflection(); } - [RequiresPreviewFeatures] [Fact] public void MultiplicationReflectionInt64() { TestMultiplicationReflection(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MultiplicationReflectionSingle() { TestMultiplicationReflection(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void MultiplicationReflectionDouble() { TestMultiplicationReflection(); } - [RequiresPreviewFeatures] private void TestMultiplicationReflection() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); @@ -2711,39 +2464,28 @@ private void TestMultiplicationReflection() where T : struct, INumber }); } - [RequiresPreviewFeatures] [Fact] public void AdditionReflectionByte() { TestAdditionReflection(); } - [RequiresPreviewFeatures] [Fact] public void AdditionReflectionSByte() { TestAdditionReflection(); } - [RequiresPreviewFeatures] [Fact] public void AdditionReflectionUInt16() { TestAdditionReflection(); } - [RequiresPreviewFeatures] [Fact] public void AdditionReflectionInt16() { TestAdditionReflection(); } - [RequiresPreviewFeatures] [Fact] public void AdditionReflectionUInt32() { TestAdditionReflection(); } - [RequiresPreviewFeatures] [Fact] public void AdditionReflectionInt32() { TestAdditionReflection(); } - [RequiresPreviewFeatures] [Fact] public void AdditionReflectionUInt64() { TestAdditionReflection(); } - [RequiresPreviewFeatures] [Fact] public void AdditionReflectionInt64() { TestAdditionReflection(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void AdditionReflectionSingle() { TestAdditionReflection(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void AdditionReflectionDouble() { TestAdditionReflection(); } - [RequiresPreviewFeatures] private void TestAdditionReflection() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); @@ -2761,39 +2503,28 @@ private void TestAdditionReflection() where T : struct, INumber }); } - [RequiresPreviewFeatures] [Fact] public void DivisionReflectionByte() { TestDivisionReflection(); } - [RequiresPreviewFeatures] [Fact] public void DivisionReflectionSByte() { TestDivisionReflection(); } - [RequiresPreviewFeatures] [Fact] public void DivisionReflectionUInt16() { TestDivisionReflection(); } - [RequiresPreviewFeatures] [Fact] public void DivisionReflectionInt16() { TestDivisionReflection(); } - [RequiresPreviewFeatures] [Fact] public void DivisionReflectionUInt32() { TestDivisionReflection(); } - [RequiresPreviewFeatures] [Fact] public void DivisionReflectionInt32() { TestDivisionReflection(); } - [RequiresPreviewFeatures] [Fact] public void DivisionReflectionUInt64() { TestDivisionReflection(); } - [RequiresPreviewFeatures] [Fact] public void DivisionReflectionInt64() { TestDivisionReflection(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void DivisionReflectionSingle() { TestDivisionReflection(); } - [RequiresPreviewFeatures] [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/60347", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoRuntime), nameof(PlatformDetection.IsX86Process))] public void DivisionReflectionDouble() { TestDivisionReflection(); } - [RequiresPreviewFeatures] private void TestDivisionReflection() where T : struct, INumber { T[] values1 = GenerateRandomValuesForVector(); diff --git a/src/libraries/System.Numerics.Vectors/tests/Util.cs b/src/libraries/System.Numerics.Vectors/tests/Util.cs index 40408ae2b27da..7432b3aecb9a8 100644 --- a/src/libraries/System.Numerics.Vectors/tests/Util.cs +++ b/src/libraries/System.Numerics.Vectors/tests/Util.cs @@ -96,29 +96,22 @@ public static T Abs(T value) where T : INumber { return T.Abs(value); } - [RequiresPreviewFeatures] - public static T SqrtGenericMath(T value) where T : IFloatingPoint - { - return T.Sqrt(value); - } - - public static T Sqrt(T value) where T : struct + public static T Sqrt(T value) where T : struct, INumber { unchecked { - if (value is short) return (T)(ValueType)(short) ( Math.Sqrt((short) (ValueType)value) ); - else if (value is int) return (T)(ValueType)(int) ( Math.Sqrt((int) (ValueType)value) ); - else if (value is long) return (T)(ValueType)(long) ( Math.Sqrt((long) (ValueType)value) ); - else if (value is ushort) return (T)(ValueType)(ushort) ( Math.Sqrt((ushort)(ValueType)value) ); - else if (value is uint) return (T)(ValueType)(uint) ( Math.Sqrt((uint) (ValueType)value) ); - else if (value is ulong) return (T)(ValueType)(ulong) ( Math.Sqrt((ulong) (ValueType)value) ); - else if (value is byte) return (T)(ValueType)(byte) ( Math.Sqrt((byte) (ValueType)value) ); - else if (value is sbyte) return (T)(ValueType)(sbyte) ( Math.Sqrt((sbyte) (ValueType)value) ); - else throw new NotImplementedException(); + double dValue = Create(value); + return (T)(dynamic)Math.Sqrt(dValue); } } + [RequiresPreviewFeatures] + private static TSelf Create(TOther value) + where TOther : INumber + where TSelf : INumber + => TSelf.Create(value); + [RequiresPreviewFeatures] public static T Multiply(T left, T right) where T : INumber { @@ -166,34 +159,16 @@ public static float Clamp(float value, float min, float max) return value > max ? max : value < min ? min : value; } - public static T Zero() where T : struct + [RequiresPreviewFeatures] + public static T Zero() where T : struct, INumber { - if (typeof(T) == typeof(short)) return (T)(ValueType)(short) 0; - else if (typeof(T) == typeof(int)) return (T)(ValueType)(int) 0; - else if (typeof(T) == typeof(long)) return (T)(ValueType)(long) 0; - else if (typeof(T) == typeof(ushort)) return (T)(ValueType)(ushort) 0; - else if (typeof(T) == typeof(uint)) return (T)(ValueType)(uint) 0; - else if (typeof(T) == typeof(ulong)) return (T)(ValueType)(ulong) 0; - else if (typeof(T) == typeof(byte)) return (T)(ValueType)(byte) 0; - else if (typeof(T) == typeof(sbyte)) return (T)(ValueType)(sbyte) 0; - else if (typeof(T) == typeof(float)) return (T)(ValueType)(float) 0; - else if (typeof(T) == typeof(double)) return (T)(ValueType)(double) 0; - else throw new NotImplementedException(); + return T.Zero; } - public static T One() where T : struct + [RequiresPreviewFeatures] + public static T One() where T : struct, INumber { - if (typeof(T) == typeof(short)) return (T)(ValueType)(short) 1; - else if (typeof(T) == typeof(int)) return (T)(ValueType)(int) 1; - else if (typeof(T) == typeof(long)) return (T)(ValueType)(long) 1; - else if (typeof(T) == typeof(ushort)) return (T)(ValueType)(ushort) 1; - else if (typeof(T) == typeof(uint)) return (T)(ValueType)(uint) 1; - else if (typeof(T) == typeof(ulong)) return (T)(ValueType)(ulong) 1; - else if (typeof(T) == typeof(byte)) return (T)(ValueType)(byte) 1; - else if (typeof(T) == typeof(sbyte)) return (T)(ValueType)(sbyte) 1; - else if (typeof(T) == typeof(float)) return (T)(ValueType)(float) 1; - else if (typeof(T) == typeof(double)) return (T)(ValueType)(double) 1; - else throw new NotImplementedException(); + return T.One; } [RequiresPreviewFeatures] @@ -220,11 +195,12 @@ public static bool LessThanOrEqual(T left, T right) where T : INumber return left <= right; } - public static bool AnyEqual(T[] left, T[] right) where T : struct + [RequiresPreviewFeatures] + public static bool AnyEqual(T[] left, T[] right) where T : INumber { for (int g = 0; g < left.Length; g++) { - if (((IEquatable)left[g]).Equals(right[g])) + if(left[g] == right[g]) { return true; } @@ -232,11 +208,12 @@ public static bool AnyEqual(T[] left, T[] right) where T : struct return false; } - public static bool AllEqual(T[] left, T[] right) where T : struct + [RequiresPreviewFeatures] + public static bool AllEqual(T[] left, T[] right) where T : INumber { for (int g = 0; g < left.Length; g++) { - if (!((IEquatable)left[g]).Equals(right[g])) + if (left[g] != right[g]) { return false; } From 79efaa745b7f5dbd0005525dd40fcaecfadaf2b7 Mon Sep 17 00:00:00 2001 From: Sychev Vadim Date: Thu, 28 Oct 2021 18:29:03 +0300 Subject: [PATCH 3/3] Got rid of the dynamic cast (#60365) --- src/libraries/System.Numerics.Vectors/tests/Util.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Numerics.Vectors/tests/Util.cs b/src/libraries/System.Numerics.Vectors/tests/Util.cs index 7432b3aecb9a8..74affb1bd52ab 100644 --- a/src/libraries/System.Numerics.Vectors/tests/Util.cs +++ b/src/libraries/System.Numerics.Vectors/tests/Util.cs @@ -99,11 +99,9 @@ public static T Abs(T value) where T : INumber [RequiresPreviewFeatures] public static T Sqrt(T value) where T : struct, INumber { - unchecked - { - double dValue = Create(value); - return (T)(dynamic)Math.Sqrt(dValue); - } + double dValue = Create(value); + double dSqrt = Math.Sqrt(dValue); + return T.CreateTruncating(dSqrt); } [RequiresPreviewFeatures]