Skip to content

Commit

Permalink
Merge pull request Hipparchus-Math#323 from MaximeJo/issue-322
Browse files Browse the repository at this point in the history
Hipparchus-Math#322: Extracted JacobiKey from PolynomialsUtils.
  • Loading branch information
maisonobe authored Mar 20, 2024
2 parents 6a43f85 + 77885bb commit 49de2c9
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 43 deletions.
3 changes: 3 additions & 0 deletions hipparchus-core/src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ If the output is not quite correct, check for invisible trailing spaces!
</properties>
<body>
<release version="3.1" date="TBD" description="TBD.">
<action dev="maxime" type="update" issue="issues/322">
Extracted class JacobiKey from PolynomialsUtils.
</action>
<action dev="serrof" type="update" issue="issues/302">
Improved performance of Gradient.
</action>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Licensed to the Hipparchus project under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The Hipparchus project licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.hipparchus.analysis.polynomials;


/** Class for handling Jacobi polynomials keys.
* @since 3.1
*/
public class JacobiKey {

/** First exponent. */
private final int v;

/** Second exponent. */
private final int w;

/** Simple constructor.
* @param v first exponent
* @param w second exponent
*/
public JacobiKey(final int v, final int w) {
this.v = v;
this.w = w;
}

/** Get hash code.
* @return hash code
*/
@Override
public int hashCode() {
return (v << 16) ^ w;
}

/** Check if the instance represent the same key as another instance.
* @param key other key
* @return true if the instance and the other key refer to the same polynomial
*/
@Override
public boolean equals(final Object key) {

if (!(key instanceof JacobiKey)) {
return false;
}

final JacobiKey otherK = (JacobiKey) key;
return (v == otherK.v) && (w == otherK.w);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,49 +266,6 @@ public BigFraction[] generate(int k) {

}

/** Inner class for Jacobi polynomials keys. */
private static class JacobiKey {

/** First exponent. */
private final int v;

/** Second exponent. */
private final int w;

/** Simple constructor.
* @param v first exponent
* @param w second exponent
*/
JacobiKey(final int v, final int w) {
this.v = v;
this.w = w;
}

/** Get hash code.
* @return hash code
*/
@Override
public int hashCode() {
return (v << 16) ^ w;
}

/** Check if the instance represent the same key as another instance.
* @param key other key
* @return true if the instance and the other key refer to the same polynomial
*/
@Override
public boolean equals(final Object key) {

if ((key == null) || !(key instanceof JacobiKey)) {
return false;
}

final JacobiKey otherK = (JacobiKey) key;
return (v == otherK.v) && (w == otherK.w);

}
}

/**
* Compute the coefficients of the polynomial \(P_s(x)\)
* whose values at point {@code x} will be the same as the those from the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,22 @@ public double value(double x) {
}
}

/** {@link JacobiKey} coverage tests.
* @since 3.1
*/
@Test
public void testJacobiKeyCoverage() {

final JacobiKey key = new JacobiKey(3, 4);

Assert.assertEquals(false, key.equals(null));
Assert.assertEquals(false, key.equals(new Object()));
Assert.assertEquals(false, key.equals(new JacobiKey(3, 5)));
Assert.assertEquals(false, key.equals(new JacobiKey(5, 4)));
Assert.assertEquals(false, key.equals(new JacobiKey(5, 5)));
Assert.assertEquals(true, key.equals(new JacobiKey(3, 4)));
}

@Test
public void testShift() {
// f1(x) = 1 + x + 2 x^2
Expand Down

0 comments on commit 49de2c9

Please sign in to comment.