|
25 | 25 | import org.hipparchus.util.MathArrays; |
26 | 26 | import org.hipparchus.util.MathUtils; |
27 | 27 |
|
| 28 | +import java.util.Arrays; |
| 29 | + |
28 | 30 | /** Class representing both the value and the differentials of a function. |
29 | 31 | * <p>This class is similar to {@link DerivativeStructure} except function |
30 | 32 | * parameters and value can be any {@link CalculusFieldElement}.</p> |
@@ -89,14 +91,14 @@ public FDSFactory<T> getFactory() { |
89 | 91 | return factory; |
90 | 92 | } |
91 | 93 |
|
92 | | - @Override |
93 | 94 | /** {@inheritDoc} */ |
| 95 | + @Override |
94 | 96 | public int getFreeParameters() { |
95 | 97 | return getFactory().getCompiler().getFreeParameters(); |
96 | 98 | } |
97 | 99 |
|
98 | | - @Override |
99 | 100 | /** {@inheritDoc} */ |
| 101 | + @Override |
100 | 102 | public int getOrder() { |
101 | 103 | return getFactory().getCompiler().getOrder(); |
102 | 104 | } |
@@ -131,6 +133,14 @@ T getDerivativeComponent(final int index) { |
131 | 133 | return data[index]; |
132 | 134 | } |
133 | 135 |
|
| 136 | + /** {@inheritDoc} */ |
| 137 | + @Override |
| 138 | + public FieldDerivativeStructure<T> getAddendum() { |
| 139 | + final T[] addendum = data.clone(); |
| 140 | + addendum[0] = addendum[0].getField().getZero(); |
| 141 | + return new FieldDerivativeStructure<>(factory, addendum); |
| 142 | + } |
| 143 | + |
134 | 144 | /** Get the value part of the derivative structure. |
135 | 145 | * @return value part of the derivative structure |
136 | 146 | * @see #getPartialDerivative(int...) |
@@ -1301,4 +1311,41 @@ public FieldDerivativeStructure<T> getPi() { |
1301 | 1311 | return factory.getDerivativeField().getPi(); |
1302 | 1312 | } |
1303 | 1313 |
|
| 1314 | + /** |
| 1315 | + * Test for the equality of two derivative structures. |
| 1316 | + * <p> |
| 1317 | + * Derivative structures are considered equal if they have the same number |
| 1318 | + * of free parameters, the same derivation order, and the same derivatives. |
| 1319 | + * </p> |
| 1320 | + * @param other Object to test for equality to this |
| 1321 | + * @return true if two derivative structures are equal |
| 1322 | + */ |
| 1323 | + @Override |
| 1324 | + public boolean equals(Object other) { |
| 1325 | + |
| 1326 | + if (this == other) { |
| 1327 | + return true; |
| 1328 | + } |
| 1329 | + |
| 1330 | + if (other instanceof FieldDerivativeStructure && |
| 1331 | + ((FieldDerivativeStructure<?>) other).getField().equals(getField())) { |
| 1332 | + final FieldDerivativeStructure<T> rhs = (FieldDerivativeStructure<T>) other; |
| 1333 | + return (getFreeParameters() == rhs.getFreeParameters()) && |
| 1334 | + (getOrder() == rhs.getOrder()) && |
| 1335 | + MathArrays.equals(data, rhs.data); |
| 1336 | + } |
| 1337 | + |
| 1338 | + return false; |
| 1339 | + |
| 1340 | + } |
| 1341 | + |
| 1342 | + /** |
| 1343 | + * Get a hashCode for the derivative structure. |
| 1344 | + * @return a hash code value for this object |
| 1345 | + */ |
| 1346 | + @Override |
| 1347 | + public int hashCode() { |
| 1348 | + return 227 + 229 * getFreeParameters() + 233 * getOrder() + 239 * Arrays.hashCode(data); |
| 1349 | + } |
| 1350 | + |
1304 | 1351 | } |
0 commit comments