|
25 | 25 | import org.junit.jupiter.api.Assertions; |
26 | 26 | import org.junit.jupiter.api.Test; |
27 | 27 |
|
| 28 | +import java.lang.reflect.Field; |
| 29 | +import java.util.List; |
| 30 | + |
28 | 31 | import static org.junit.jupiter.api.Assertions.assertEquals; |
29 | 32 | import static org.junit.jupiter.api.Assertions.fail; |
30 | 33 |
|
@@ -304,6 +307,61 @@ void testInvertBiDimensional() { |
304 | 307 | } |
305 | 308 | } |
306 | 309 |
|
| 310 | + @Test |
| 311 | + public void testCountRebaseMappers22() throws NoSuchFieldException, IllegalAccessException { |
| 312 | + doTestCountRebaseMappers(2, 2, 21, 2); |
| 313 | + } |
| 314 | + |
| 315 | + @Test |
| 316 | + public void testCountRebaseMappers36() throws NoSuchFieldException, IllegalAccessException { |
| 317 | + doTestCountRebaseMappers(3, 6, 44884, 180); |
| 318 | + } |
| 319 | + |
| 320 | + @Test |
| 321 | + public void testCountRebaseMappers37() throws NoSuchFieldException, IllegalAccessException { |
| 322 | + doTestCountRebaseMappers(3, 7, 182323, 1260); |
| 323 | + } |
| 324 | + |
| 325 | + @Test |
| 326 | + public void testCountRebaseMappers38() throws NoSuchFieldException, IllegalAccessException { |
| 327 | + doTestCountRebaseMappers(3, 8, 702847, 5040); |
| 328 | + } |
| 329 | + |
| 330 | + private void doTestCountRebaseMappers(final int parameters, final int order, |
| 331 | + final int expectedCount, final int expectedMaxCoeff) |
| 332 | + throws NoSuchFieldException, IllegalAccessException { |
| 333 | + final DSFactory factory = new DSFactory(parameters, order); |
| 334 | + final double[] point = new double[parameters]; |
| 335 | + final DerivativeStructure[] function = new DerivativeStructure[parameters]; |
| 336 | + for (int i = 0; i < parameters; ++i) { |
| 337 | + function[i] = factory.variable(i, 0); |
| 338 | + } |
| 339 | + final TaylorMap map = new TaylorMap(point, function).invert(new QRDecomposer(1.0e-10)); |
| 340 | + Assertions.assertNotNull(map); |
| 341 | + Field rbi = DSCompiler.class.getDeclaredField("rebaseIndirection"); |
| 342 | + rbi.setAccessible(true); |
| 343 | + Field coeff = null; |
| 344 | + for (final Class<?> c : DSCompiler.class.getDeclaredClasses()) { |
| 345 | + if (c.getName().endsWith("AbstractMapper")) { |
| 346 | + coeff = c.getDeclaredField("coeff"); |
| 347 | + coeff.setAccessible(true); |
| 348 | + } |
| 349 | + } |
| 350 | + |
| 351 | + @SuppressWarnings("unchecked") |
| 352 | + List<Object[][]> list = (List<Object[][]>) rbi.get(DSCompiler.getCompiler(parameters, order)); |
| 353 | + int count = 0; |
| 354 | + int maxCoeff = 0; |
| 355 | + for (final Object[] m : list.get(parameters)) { |
| 356 | + for (final Object mcm : m) { |
| 357 | + ++count; |
| 358 | + maxCoeff = FastMath.max(maxCoeff, (Integer) coeff.get(mcm)); |
| 359 | + } |
| 360 | + } |
| 361 | + Assertions.assertEquals(expectedCount, count); |
| 362 | + Assertions.assertEquals(expectedMaxCoeff, maxCoeff); |
| 363 | + } |
| 364 | + |
307 | 365 | @Test |
308 | 366 | public void testIssue423() { |
309 | 367 | final DSFactory factory = new DSFactory(3, 8); |
|
0 commit comments