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, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 2 , 2 , 1 , 1 , 2 , 4 , 6 , 4 } ;
17+ float expected = 884.7585f ;
18+
19+ float actual = LosslessUtils . CombinedShannonEntropy ( x , y ) ;
20+
21+ Assert . Equal ( expected , actual , 5 ) ;
22+ }
23+
1324 private static void RunSubtractGreenTest ( )
1425 {
1526 uint [ ] pixelData =
@@ -193,6 +204,9 @@ private static void RunPredictor13Test()
193204 }
194205 }
195206
207+ [ Fact ]
208+ public void CombinedShannonEntropy_Works ( ) => RunCombinedShannonEntropyTest ( ) ;
209+
196210 [ Fact ]
197211 public void Predictor11_Works ( ) => RunPredictor11Test ( ) ;
198212
@@ -216,6 +230,12 @@ private static void RunPredictor13Test()
216230
217231#if SUPPORTS_RUNTIME_INTRINSICS
218232
233+ [ Fact ]
234+ public void CombinedShannonEntropy_WithHardwareIntrinsics_Works ( ) => FeatureTestRunner . RunWithHwIntrinsicsFeature ( RunCombinedShannonEntropyTest , HwIntrinsics . AllowAll ) ;
235+
236+ [ Fact ]
237+ public void CombinedShannonEntropy_WithoutAVX2_Works ( ) => FeatureTestRunner . RunWithHwIntrinsicsFeature ( RunCombinedShannonEntropyTest , HwIntrinsics . DisableAVX2 ) ;
238+
219239 [ Fact ]
220240 public void Predictor11_WithHardwareIntrinsics_Works ( ) => FeatureTestRunner . RunWithHwIntrinsicsFeature ( RunPredictor11Test , HwIntrinsics . AllowAll ) ;
221241
@@ -238,19 +258,19 @@ private static void RunPredictor13Test()
238258 public void SubtractGreen_WithHardwareIntrinsics_Works ( ) => FeatureTestRunner . RunWithHwIntrinsicsFeature ( RunSubtractGreenTest , HwIntrinsics . AllowAll ) ;
239259
240260 [ Fact ]
241- public void SubtractGreen_WithoutAvx_Works ( ) => FeatureTestRunner . RunWithHwIntrinsicsFeature ( RunSubtractGreenTest , HwIntrinsics . DisableAVX ) ;
261+ public void SubtractGreen_WithoutAVX2_Works ( ) => FeatureTestRunner . RunWithHwIntrinsicsFeature ( RunSubtractGreenTest , HwIntrinsics . DisableAVX2 ) ;
242262
243263 [ Fact ]
244- public void SubtractGreen_WithoutAvxOrSSSE3_Works ( ) => FeatureTestRunner . RunWithHwIntrinsicsFeature ( RunSubtractGreenTest , HwIntrinsics . DisableAVX | HwIntrinsics . DisableSSSE3 ) ;
264+ public void SubtractGreen_WithoutAvxOrSSSE3_Works ( ) => FeatureTestRunner . RunWithHwIntrinsicsFeature ( RunSubtractGreenTest , HwIntrinsics . DisableAVX2 | HwIntrinsics . DisableSSSE3 ) ;
245265
246266 [ Fact ]
247267 public void AddGreenToBlueAndRed_WithHardwareIntrinsics_Works ( ) => FeatureTestRunner . RunWithHwIntrinsicsFeature ( RunAddGreenToBlueAndRedTest , HwIntrinsics . AllowAll ) ;
248268
249269 [ Fact ]
250- public void AddGreenToBlueAndRed_WithoutAvx_Works ( ) => FeatureTestRunner . RunWithHwIntrinsicsFeature ( RunAddGreenToBlueAndRedTest , HwIntrinsics . DisableAVX ) ;
270+ public void AddGreenToBlueAndRed_WithoutAVX2_Works ( ) => FeatureTestRunner . RunWithHwIntrinsicsFeature ( RunAddGreenToBlueAndRedTest , HwIntrinsics . DisableAVX2 ) ;
251271
252272 [ Fact ]
253- public void AddGreenToBlueAndRed_WithoutAvxOrSSSE3_Works ( ) => FeatureTestRunner . RunWithHwIntrinsicsFeature ( RunAddGreenToBlueAndRedTest , HwIntrinsics . DisableAVX | HwIntrinsics . DisableSSE2 | HwIntrinsics . DisableSSSE3 ) ;
273+ public void AddGreenToBlueAndRed_WithoutAVX2OrSSSE3_Works ( ) => FeatureTestRunner . RunWithHwIntrinsicsFeature ( RunAddGreenToBlueAndRedTest , HwIntrinsics . DisableAVX2 | HwIntrinsics . DisableSSE2 | HwIntrinsics . DisableSSSE3 ) ;
254274
255275 [ Fact ]
256276 public void TransformColor_WithHardwareIntrinsics_Works ( ) => FeatureTestRunner . RunWithHwIntrinsicsFeature ( RunTransformColorTest , HwIntrinsics . AllowAll ) ;
0 commit comments