Skip to content

Commit 7147919

Browse files
committed
Speed up rebaser build.
1 parent a9b7dda commit 7147919

4 files changed

Lines changed: 69 additions & 2 deletions

File tree

hipparchus-core/src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ If the output is not quite correct, check for invisible trailing spaces!
5050
</properties>
5151
<body>
5252
<release version="4.1" date="TBD" description="TBD">
53+
<action dev="luc" type="fix" issue="issues/423">
54+
Reduced overhead of Taylor map compilation.
55+
</action>
5356
<action dev="serrof" type="update">
5457
Add some FunctionalInterface tag.
5558
</action>

hipparchus-core/src/main/java/org/hipparchus/analysis/differentiation/DSCompiler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,12 +550,15 @@ private MultivariateCompositionMapper[][] getRebaser(final DSCompiler baseCompil
550550
final List<MultivariateCompositionMapper> row = new ArrayList<>();
551551

552552
// find a variable with respect to which we have a derivative
553+
// we select the minimum non-zero derivation order to speed up computation
553554
final int[] orders = baseCompiler.derivativesOrders[k].clone();
555+
int minNonZeroOrder = Integer.MAX_VALUE;
554556
int qIndex = -1;
555557
for (int j = 0; j < orders.length; ++j) {
556-
if (orders[j] > 0) {
558+
final int oj = orders[j];
559+
if (oj > 0 && oj < minNonZeroOrder) {
560+
minNonZeroOrder = oj;
557561
qIndex = j;
558-
break;
559562
}
560563
}
561564

hipparchus-core/src/test/java/org/hipparchus/analysis/differentiation/TaylorMapTest.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import org.junit.jupiter.api.Assertions;
2626
import org.junit.jupiter.api.Test;
2727

28+
import java.lang.reflect.Field;
29+
import java.util.List;
30+
2831
import static org.junit.jupiter.api.Assertions.assertEquals;
2932
import static org.junit.jupiter.api.Assertions.fail;
3033

@@ -304,6 +307,61 @@ void testInvertBiDimensional() {
304307
}
305308
}
306309

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+
307365
@Test
308366
public void testIssue423() {
309367
final DSFactory factory = new DSFactory(3, 8);

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ If the output is not quite correct, check for invisible trailing spaces!
5050
</properties>
5151
<body>
5252
<release version="4.1" date="TBD" description="TBD">
53+
<action dev="luc" type="fix" issue="issues/423">
54+
Reduced overhead of Taylor map compilation.
55+
</action>
5356
<action dev="serrof" type="update">
5457
Add some FunctionalInterface tag.
5558
</action>

0 commit comments

Comments
 (0)