Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MATH-1538] refine some codes dealing with filling an array with its first and second elements. #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1497,11 +1497,11 @@ public void cosh(final double[] operand, final int operandOffset,

// create the function value and derivatives
double[] function = new double[1 + order];
function[0] = FastMath.cosh(operand[operandOffset]);
final double function0 = function[0] = FastMath.cosh(operand[operandOffset]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final is useless, and not the code style for these files

Copy link
Contributor Author

@XenoAmess XenoAmess Jun 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@efge

final is useless

Yep, if you think it that way.

and not the code style for these files

There is final for local variable for class FieldDenseMatrix , TricubicInterpolator , UnivariatePeriodicInterpolator , FieldDenseMatrix , SobolSequenceGenerator, GeometryExample, and several test classes.
So I think the final I used is not outside of "the code style for these files", thus no need to change.
Or if I mis-understand something, please tell me.
Thanks.

if (order > 0) {
function[1] = FastMath.sinh(operand[operandOffset]);
final double function1 = function[1] = FastMath.sinh(operand[operandOffset]);
for (int i = 2; i <= order; ++i) {
function[i] = function[i - 2];
function[i] = (i & 1) == 0 ? function0 : function1;
}
}

Expand All @@ -1523,11 +1523,11 @@ public void sinh(final double[] operand, final int operandOffset,

// create the function value and derivatives
double[] function = new double[1 + order];
function[0] = FastMath.sinh(operand[operandOffset]);
final double function0 = function[0] = FastMath.sinh(operand[operandOffset]);
if (order > 0) {
function[1] = FastMath.cosh(operand[operandOffset]);
final double function1 = function[1] = FastMath.cosh(operand[operandOffset]);
for (int i = 2; i <= order; ++i) {
function[i] = function[i - 2];
function[i] = (i & 1) == 0 ? function0 : function1;
}
}

Expand Down
28 changes: 13 additions & 15 deletions src/main/java/org/apache/commons/math4/analysis/function/Logit.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,20 @@ public DerivativeStructure value(final DerivativeStructure t)
double[] f = new double[t.getOrder() + 1];

// function value
f[0] = FastMath.log((x - lo) / (hi - x));

if (Double.isInfinite(f[0])) {

if (f.length > 1) {
f[1] = Double.POSITIVE_INFINITY;
final double f0 = f[0] = FastMath.log((x - lo) / (hi - x));
final int fLen = f.length;
if (Double.isInfinite(f0)) {
if (fLen > 1) {
final double f1 = f[1] = Double.POSITIVE_INFINITY;
// fill the array with infinities
// (for x close to lo the signs will flip between -inf and +inf,
// for x close to hi the signs will always be +inf)
// this is probably overkill, since the call to compose at the end
// of the method will transform most infinities into NaN ...
for (int i = 2; i < fLen; ++i) {
f[i] = (i & 1) == 0 ? f0 : f1;
}
}
// fill the array with infinities
// (for x close to lo the signs will flip between -inf and +inf,
// for x close to hi the signs will always be +inf)
// this is probably overkill, since the call to compose at the end
// of the method will transform most infinities into NaN ...
for (int i = 2; i < f.length; ++i) {
f[i] = f[i - 2];
}

} else {

// function derivatives
Expand Down