|
| 1 | +/* |
| 2 | + * Copyright 2023 quafadas |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package vecxt |
| 18 | + |
| 19 | +import all.* |
| 20 | +import narr.* |
| 21 | + |
| 22 | +class MinMaxSIMDSuite extends munit.FunSuite: |
| 23 | + |
| 24 | + test("maxSIMD finds maximum in small array"): |
| 25 | + val arr = NArray[Double](1.0, 5.0, 3.0, 9.0, 2.0) |
| 26 | + val result = arr.maxSIMD |
| 27 | + assertEquals(result, 9.0) |
| 28 | + |
| 29 | + test("maxSIMD finds maximum in large array with SIMD lanes"): |
| 30 | + // Create array larger than SIMD vector length to test SIMD path |
| 31 | + val arr = NArray.tabulate[Double](100)(i => (i * 2.5) % 37.0) |
| 32 | + arr(75) = 1000.0 // Insert known maximum |
| 33 | + val result = arr.maxSIMD |
| 34 | + assertEquals(result, 1000.0) |
| 35 | + |
| 36 | + test("minSIMD finds minimum in array with positive integers"): |
| 37 | + val arr = Array(5, 3, 9, 1, 7, 2, 8, 4, 6) |
| 38 | + val result = arr.minSIMD |
| 39 | + assertEquals(result, 1) |
| 40 | + |
| 41 | + test("minSIMD finds minimum in large array crossing SIMD boundaries"): |
| 42 | + // Create array larger than SIMD vector length to test both SIMD and scalar paths |
| 43 | + val arr = Array.tabulate(100)(i => if i == 73 then -5 else i * 2 + 10) |
| 44 | + val result = arr.minSIMD |
| 45 | + assertEquals(result, -5) |
0 commit comments