This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit f0f0af1353f30dce0b6e0e4607960f4164328c6e
Author: Alex Herbert <[email protected]>
AuthorDate: Thu May 21 14:00:02 2026 +0100

    MATH-1690: Document violation of equals and hashCode contract
---
 .../math4/legacy/analysis/differentiation/SparseGradient.java    | 9 +++++++++
 src/changes/changes.xml                                          | 3 +++
 2 files changed, 12 insertions(+)

diff --git 
a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java
 
b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java
index bb4686785..ac901bd7b 100644
--- 
a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java
+++ 
b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/analysis/differentiation/SparseGradient.java
@@ -37,6 +37,15 @@ import org.apache.commons.math4.core.jdkmath.JdkMath;
  * {@link DerivativeStructure} and use less memory.
  * </p>
  *
+ * <p><strong>Implementation note</strong>
+ *
+ * <p>This class violates the {@link #equals(Object)} contract that equal 
objects must
+ * have the same {@link #hashCode()}. The gradient value and its derivatives 
are
+ * considered equal if they have no floating-point representations between the 
respective
+ * values being compared; these two objects may have non-equal hash codes. A
+ * {@link SparseGradient} should not be used as a key in a {@code HashMap} or
+ * {@code HashSet}.
+ *
  * @since 3.3
  */
 public final class SparseGradient implements RealFieldElement<SparseGradient> {
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 7e3c89def..1c822ffa6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -96,6 +96,9 @@ Caveat:
  to support the whole codebase (it was one of the main reasons for
  creating more focused components).
 ">
+      <action dev="aherbert" type="update" issue="MATH-1690" due-to="Ruiqi 
Dong">
+        "SparseGradient": Document violation of equals and hashCode contract.
+      </action>
       <action dev="aherbert" type="update" issue="MATH-1689" due-to="Ruiqi 
Dong">
         "Frequency": Document behaviour of equals and hashCode that ignores
         the value Comparator. The comparator only affects the cumulative

Reply via email to