Initial commit
This commit is contained in:
93
sources/com/google/common/math/DoubleMath.java
Normal file
93
sources/com/google/common/math/DoubleMath.java
Normal file
@@ -0,0 +1,93 @@
|
||||
package com.google.common.math;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class DoubleMath {
|
||||
|
||||
/* renamed from: com.google.common.math.DoubleMath$1, reason: invalid class name */
|
||||
static /* synthetic */ class AnonymousClass1 {
|
||||
static final /* synthetic */ int[] a = new int[RoundingMode.values().length];
|
||||
|
||||
static {
|
||||
try {
|
||||
a[RoundingMode.UNNECESSARY.ordinal()] = 1;
|
||||
} catch (NoSuchFieldError unused) {
|
||||
}
|
||||
try {
|
||||
a[RoundingMode.FLOOR.ordinal()] = 2;
|
||||
} catch (NoSuchFieldError unused2) {
|
||||
}
|
||||
try {
|
||||
a[RoundingMode.CEILING.ordinal()] = 3;
|
||||
} catch (NoSuchFieldError unused3) {
|
||||
}
|
||||
try {
|
||||
a[RoundingMode.DOWN.ordinal()] = 4;
|
||||
} catch (NoSuchFieldError unused4) {
|
||||
}
|
||||
try {
|
||||
a[RoundingMode.UP.ordinal()] = 5;
|
||||
} catch (NoSuchFieldError unused5) {
|
||||
}
|
||||
try {
|
||||
a[RoundingMode.HALF_EVEN.ordinal()] = 6;
|
||||
} catch (NoSuchFieldError unused6) {
|
||||
}
|
||||
try {
|
||||
a[RoundingMode.HALF_UP.ordinal()] = 7;
|
||||
} catch (NoSuchFieldError unused7) {
|
||||
}
|
||||
try {
|
||||
a[RoundingMode.HALF_DOWN.ordinal()] = 8;
|
||||
} catch (NoSuchFieldError unused8) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
Math.log(2.0d);
|
||||
}
|
||||
|
||||
static double a(double d, RoundingMode roundingMode) {
|
||||
if (!DoubleUtils.c(d)) {
|
||||
throw new ArithmeticException("input is infinite or NaN");
|
||||
}
|
||||
switch (AnonymousClass1.a[roundingMode.ordinal()]) {
|
||||
case 1:
|
||||
MathPreconditions.c(a(d));
|
||||
return d;
|
||||
case 2:
|
||||
return (d >= 0.0d || a(d)) ? d : ((long) d) - 1;
|
||||
case 3:
|
||||
return (d <= 0.0d || a(d)) ? d : ((long) d) + 1;
|
||||
case 4:
|
||||
return d;
|
||||
case 5:
|
||||
if (a(d)) {
|
||||
return d;
|
||||
}
|
||||
return ((long) d) + (d > 0.0d ? 1 : -1);
|
||||
case 6:
|
||||
return Math.rint(d);
|
||||
case 7:
|
||||
double rint = Math.rint(d);
|
||||
return Math.abs(d - rint) == 0.5d ? d + Math.copySign(0.5d, d) : rint;
|
||||
case 8:
|
||||
double rint2 = Math.rint(d);
|
||||
return Math.abs(d - rint2) == 0.5d ? d : rint2;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
public static long b(double d, RoundingMode roundingMode) {
|
||||
double a = a(d, roundingMode);
|
||||
MathPreconditions.a((a < 9.223372036854776E18d) & ((-9.223372036854776E18d) - a < 1.0d));
|
||||
return (long) a;
|
||||
}
|
||||
|
||||
public static boolean a(double d) {
|
||||
return DoubleUtils.c(d) && (d == 0.0d || 52 - Long.numberOfTrailingZeros(DoubleUtils.b(d)) <= Math.getExponent(d));
|
||||
}
|
||||
}
|
29
sources/com/google/common/math/DoubleUtils.java
Normal file
29
sources/com/google/common/math/DoubleUtils.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.google.common.math;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class DoubleUtils {
|
||||
static {
|
||||
Double.doubleToRawLongBits(1.0d);
|
||||
}
|
||||
|
||||
static double a(double d) {
|
||||
Preconditions.a(!Double.isNaN(d));
|
||||
if (d > 0.0d) {
|
||||
return d;
|
||||
}
|
||||
return 0.0d;
|
||||
}
|
||||
|
||||
static long b(double d) {
|
||||
Preconditions.a(c(d), "not a normal value");
|
||||
int exponent = Math.getExponent(d);
|
||||
long doubleToRawLongBits = Double.doubleToRawLongBits(d) & 4503599627370495L;
|
||||
return exponent == -1023 ? doubleToRawLongBits << 1 : doubleToRawLongBits | 4503599627370496L;
|
||||
}
|
||||
|
||||
static boolean c(double d) {
|
||||
return Math.getExponent(d) <= 1023;
|
||||
}
|
||||
}
|
11
sources/com/google/common/math/IntMath.java
Normal file
11
sources/com/google/common/math/IntMath.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.google.common.math;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class IntMath {
|
||||
public static int a(int i, int i2) {
|
||||
long j = i + i2;
|
||||
int i3 = (int) j;
|
||||
MathPreconditions.b(j == ((long) i3));
|
||||
return i3;
|
||||
}
|
||||
}
|
78
sources/com/google/common/math/LinearTransformation.java
Normal file
78
sources/com/google/common/math/LinearTransformation.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package com.google.common.math;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public abstract class LinearTransformation {
|
||||
|
||||
public static final class LinearTransformationBuilder {
|
||||
private final double a;
|
||||
private final double b;
|
||||
|
||||
public LinearTransformation a(double d) {
|
||||
Preconditions.a(!Double.isNaN(d));
|
||||
return DoubleUtils.c(d) ? new RegularLinearTransformation(d, this.b - (this.a * d)) : new VerticalLinearTransformation(this.a);
|
||||
}
|
||||
|
||||
private LinearTransformationBuilder(double d, double d2) {
|
||||
this.a = d;
|
||||
this.b = d2;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class NaNLinearTransformation extends LinearTransformation {
|
||||
static final NaNLinearTransformation a = new NaNLinearTransformation();
|
||||
|
||||
private NaNLinearTransformation() {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "NaN";
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RegularLinearTransformation extends LinearTransformation {
|
||||
final double a;
|
||||
final double b;
|
||||
|
||||
RegularLinearTransformation(double d, double d2) {
|
||||
this.a = d;
|
||||
this.b = d2;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("y = %g * x + %g", Double.valueOf(this.a), Double.valueOf(this.b));
|
||||
}
|
||||
}
|
||||
|
||||
private static final class VerticalLinearTransformation extends LinearTransformation {
|
||||
final double a;
|
||||
|
||||
VerticalLinearTransformation(double d) {
|
||||
this.a = d;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("x = %g", Double.valueOf(this.a));
|
||||
}
|
||||
}
|
||||
|
||||
public static LinearTransformationBuilder a(double d, double d2) {
|
||||
Preconditions.a(DoubleUtils.c(d) && DoubleUtils.c(d2));
|
||||
return new LinearTransformationBuilder(d, d2);
|
||||
}
|
||||
|
||||
public static LinearTransformation b(double d) {
|
||||
Preconditions.a(DoubleUtils.c(d));
|
||||
return new VerticalLinearTransformation(d);
|
||||
}
|
||||
|
||||
public static LinearTransformation a(double d) {
|
||||
Preconditions.a(DoubleUtils.c(d));
|
||||
return new RegularLinearTransformation(0.0d, d);
|
||||
}
|
||||
|
||||
public static LinearTransformation a() {
|
||||
return NaNLinearTransformation.a;
|
||||
}
|
||||
}
|
166
sources/com/google/common/math/LongMath.java
Normal file
166
sources/com/google/common/math/LongMath.java
Normal file
@@ -0,0 +1,166 @@
|
||||
package com.google.common.math;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class LongMath {
|
||||
|
||||
/* renamed from: com.google.common.math.LongMath$1, reason: invalid class name */
|
||||
static /* synthetic */ class AnonymousClass1 {
|
||||
static final /* synthetic */ int[] a = new int[RoundingMode.values().length];
|
||||
|
||||
static {
|
||||
try {
|
||||
a[RoundingMode.UNNECESSARY.ordinal()] = 1;
|
||||
} catch (NoSuchFieldError unused) {
|
||||
}
|
||||
try {
|
||||
a[RoundingMode.DOWN.ordinal()] = 2;
|
||||
} catch (NoSuchFieldError unused2) {
|
||||
}
|
||||
try {
|
||||
a[RoundingMode.FLOOR.ordinal()] = 3;
|
||||
} catch (NoSuchFieldError unused3) {
|
||||
}
|
||||
try {
|
||||
a[RoundingMode.UP.ordinal()] = 4;
|
||||
} catch (NoSuchFieldError unused4) {
|
||||
}
|
||||
try {
|
||||
a[RoundingMode.CEILING.ordinal()] = 5;
|
||||
} catch (NoSuchFieldError unused5) {
|
||||
}
|
||||
try {
|
||||
a[RoundingMode.HALF_DOWN.ordinal()] = 6;
|
||||
} catch (NoSuchFieldError unused6) {
|
||||
}
|
||||
try {
|
||||
a[RoundingMode.HALF_UP.ordinal()] = 7;
|
||||
} catch (NoSuchFieldError unused7) {
|
||||
}
|
||||
try {
|
||||
a[RoundingMode.HALF_EVEN.ordinal()] = 8;
|
||||
} catch (NoSuchFieldError unused8) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
long[][] jArr = {new long[]{291830, 126401071349994536L}, new long[]{885594168, 725270293939359937L, 3569819667048198375L}, new long[]{273919523040L, 15, 7363882082L, 992620450144556L}, new long[]{47636622961200L, 2, 2570940, 211991001, 3749873356L}, new long[]{7999252175582850L, 2, 4130806001517L, 149795463772692060L, 186635894390467037L, 3967304179347715805L}, new long[]{585226005592931976L, 2, 123635709730000L, 9233062284813009L, 43835965440333360L, 761179012939631437L, 1263739024124850375L}, new long[]{Long.MAX_VALUE, 2, 325, 9375, 28178, 450775, 9780504, 1795265022}};
|
||||
}
|
||||
|
||||
/* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
|
||||
/* JADX WARN: Code restructure failed: missing block: B:23:0x0051, code lost:
|
||||
|
||||
if (r2 > 0) goto L35;
|
||||
*/
|
||||
/* JADX WARN: Code restructure failed: missing block: B:24:0x0054, code lost:
|
||||
|
||||
if (r10 > 0) goto L35;
|
||||
*/
|
||||
/* JADX WARN: Code restructure failed: missing block: B:25:0x0057, code lost:
|
||||
|
||||
if (r10 < 0) goto L35;
|
||||
*/
|
||||
/* JADX WARN: Removed duplicated region for block: B:31:0x0064 */
|
||||
/* JADX WARN: Removed duplicated region for block: B:33:? A[RETURN, SYNTHETIC] */
|
||||
/*
|
||||
Code decompiled incorrectly, please refer to instructions dump.
|
||||
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
||||
*/
|
||||
public static long a(long r9, long r11, java.math.RoundingMode r13) {
|
||||
/*
|
||||
com.google.common.base.Preconditions.a(r13)
|
||||
long r0 = r9 / r11
|
||||
long r2 = r11 * r0
|
||||
long r2 = r9 - r2
|
||||
r4 = 0
|
||||
int r6 = (r2 > r4 ? 1 : (r2 == r4 ? 0 : -1))
|
||||
if (r6 != 0) goto L10
|
||||
return r0
|
||||
L10:
|
||||
long r9 = r9 ^ r11
|
||||
r7 = 63
|
||||
long r9 = r9 >> r7
|
||||
int r10 = (int) r9
|
||||
r9 = 1
|
||||
r10 = r10 | r9
|
||||
int[] r7 = com.google.common.math.LongMath.AnonymousClass1.a
|
||||
int r8 = r13.ordinal()
|
||||
r7 = r7[r8]
|
||||
r8 = 0
|
||||
switch(r7) {
|
||||
case 1: goto L5a;
|
||||
case 2: goto L61;
|
||||
case 3: goto L57;
|
||||
case 4: goto L62;
|
||||
case 5: goto L54;
|
||||
case 6: goto L29;
|
||||
case 7: goto L29;
|
||||
case 8: goto L29;
|
||||
default: goto L23;
|
||||
}
|
||||
L23:
|
||||
java.lang.AssertionError r9 = new java.lang.AssertionError
|
||||
r9.<init>()
|
||||
throw r9
|
||||
L29:
|
||||
long r2 = java.lang.Math.abs(r2)
|
||||
long r11 = java.lang.Math.abs(r11)
|
||||
long r11 = r11 - r2
|
||||
long r2 = r2 - r11
|
||||
int r11 = (r2 > r4 ? 1 : (r2 == r4 ? 0 : -1))
|
||||
if (r11 != 0) goto L51
|
||||
java.math.RoundingMode r11 = java.math.RoundingMode.HALF_UP
|
||||
if (r13 != r11) goto L3d
|
||||
r11 = 1
|
||||
goto L3e
|
||||
L3d:
|
||||
r11 = 0
|
||||
L3e:
|
||||
java.math.RoundingMode r12 = java.math.RoundingMode.HALF_EVEN
|
||||
if (r13 != r12) goto L44
|
||||
r12 = 1
|
||||
goto L45
|
||||
L44:
|
||||
r12 = 0
|
||||
L45:
|
||||
r2 = 1
|
||||
long r2 = r2 & r0
|
||||
int r13 = (r2 > r4 ? 1 : (r2 == r4 ? 0 : -1))
|
||||
if (r13 == 0) goto L4d
|
||||
goto L4e
|
||||
L4d:
|
||||
r9 = 0
|
||||
L4e:
|
||||
r9 = r9 & r12
|
||||
r9 = r9 | r11
|
||||
goto L62
|
||||
L51:
|
||||
if (r11 <= 0) goto L61
|
||||
goto L62
|
||||
L54:
|
||||
if (r10 <= 0) goto L61
|
||||
goto L62
|
||||
L57:
|
||||
if (r10 >= 0) goto L61
|
||||
goto L62
|
||||
L5a:
|
||||
if (r6 != 0) goto L5d
|
||||
goto L5e
|
||||
L5d:
|
||||
r9 = 0
|
||||
L5e:
|
||||
com.google.common.math.MathPreconditions.c(r9)
|
||||
L61:
|
||||
r9 = 0
|
||||
L62:
|
||||
if (r9 == 0) goto L66
|
||||
long r9 = (long) r10
|
||||
long r0 = r0 + r9
|
||||
L66:
|
||||
return r0
|
||||
*/
|
||||
throw new UnsupportedOperationException("Method not decompiled: com.google.common.math.LongMath.a(long, long, java.math.RoundingMode):long");
|
||||
}
|
||||
}
|
22
sources/com/google/common/math/MathPreconditions.java
Normal file
22
sources/com/google/common/math/MathPreconditions.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.google.common.math;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class MathPreconditions {
|
||||
static void a(boolean z) {
|
||||
if (!z) {
|
||||
throw new ArithmeticException("not in range");
|
||||
}
|
||||
}
|
||||
|
||||
static void b(boolean z) {
|
||||
if (!z) {
|
||||
throw new ArithmeticException("overflow");
|
||||
}
|
||||
}
|
||||
|
||||
static void c(boolean z) {
|
||||
if (!z) {
|
||||
throw new ArithmeticException("mode was UNNECESSARY, but rounding was necessary");
|
||||
}
|
||||
}
|
||||
}
|
132
sources/com/google/common/math/PairedStats.java
Normal file
132
sources/com/google/common/math/PairedStats.java
Normal file
@@ -0,0 +1,132 @@
|
||||
package com.google.common.math;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.io.Serializable;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class PairedStats implements Serializable {
|
||||
private static final int BYTES = 88;
|
||||
private static final long serialVersionUID = 0;
|
||||
private final double sumOfProductsOfDeltas;
|
||||
private final Stats xStats;
|
||||
private final Stats yStats;
|
||||
|
||||
PairedStats(Stats stats, Stats stats2, double d) {
|
||||
this.xStats = stats;
|
||||
this.yStats = stats2;
|
||||
this.sumOfProductsOfDeltas = d;
|
||||
}
|
||||
|
||||
private static double ensureInUnitRange(double d) {
|
||||
if (d >= 1.0d) {
|
||||
return 1.0d;
|
||||
}
|
||||
if (d <= -1.0d) {
|
||||
return -1.0d;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
private static double ensurePositive(double d) {
|
||||
if (d > 0.0d) {
|
||||
return d;
|
||||
}
|
||||
return Double.MIN_VALUE;
|
||||
}
|
||||
|
||||
public static PairedStats fromByteArray(byte[] bArr) {
|
||||
Preconditions.a(bArr);
|
||||
Preconditions.a(bArr.length == 88, "Expected PairedStats.BYTES = %s, got %s", 88, bArr.length);
|
||||
ByteBuffer order = ByteBuffer.wrap(bArr).order(ByteOrder.LITTLE_ENDIAN);
|
||||
return new PairedStats(Stats.readFrom(order), Stats.readFrom(order), order.getDouble());
|
||||
}
|
||||
|
||||
public long count() {
|
||||
return this.xStats.count();
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null || PairedStats.class != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
PairedStats pairedStats = (PairedStats) obj;
|
||||
return this.xStats.equals(pairedStats.xStats) && this.yStats.equals(pairedStats.yStats) && Double.doubleToLongBits(this.sumOfProductsOfDeltas) == Double.doubleToLongBits(pairedStats.sumOfProductsOfDeltas);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return Objects.a(this.xStats, this.yStats, Double.valueOf(this.sumOfProductsOfDeltas));
|
||||
}
|
||||
|
||||
public LinearTransformation leastSquaresFit() {
|
||||
Preconditions.b(count() > 1);
|
||||
if (Double.isNaN(this.sumOfProductsOfDeltas)) {
|
||||
return LinearTransformation.a();
|
||||
}
|
||||
double sumOfSquaresOfDeltas = this.xStats.sumOfSquaresOfDeltas();
|
||||
if (sumOfSquaresOfDeltas > 0.0d) {
|
||||
return this.yStats.sumOfSquaresOfDeltas() > 0.0d ? LinearTransformation.a(this.xStats.mean(), this.yStats.mean()).a(this.sumOfProductsOfDeltas / sumOfSquaresOfDeltas) : LinearTransformation.a(this.yStats.mean());
|
||||
}
|
||||
Preconditions.b(this.yStats.sumOfSquaresOfDeltas() > 0.0d);
|
||||
return LinearTransformation.b(this.xStats.mean());
|
||||
}
|
||||
|
||||
public double pearsonsCorrelationCoefficient() {
|
||||
Preconditions.b(count() > 1);
|
||||
if (Double.isNaN(this.sumOfProductsOfDeltas)) {
|
||||
return Double.NaN;
|
||||
}
|
||||
double sumOfSquaresOfDeltas = xStats().sumOfSquaresOfDeltas();
|
||||
double sumOfSquaresOfDeltas2 = yStats().sumOfSquaresOfDeltas();
|
||||
Preconditions.b(sumOfSquaresOfDeltas > 0.0d);
|
||||
Preconditions.b(sumOfSquaresOfDeltas2 > 0.0d);
|
||||
return ensureInUnitRange(this.sumOfProductsOfDeltas / Math.sqrt(ensurePositive(sumOfSquaresOfDeltas * sumOfSquaresOfDeltas2)));
|
||||
}
|
||||
|
||||
public double populationCovariance() {
|
||||
Preconditions.b(count() != 0);
|
||||
return this.sumOfProductsOfDeltas / count();
|
||||
}
|
||||
|
||||
public double sampleCovariance() {
|
||||
Preconditions.b(count() > 1);
|
||||
return this.sumOfProductsOfDeltas / (count() - 1);
|
||||
}
|
||||
|
||||
double sumOfProductsOfDeltas() {
|
||||
return this.sumOfProductsOfDeltas;
|
||||
}
|
||||
|
||||
public byte[] toByteArray() {
|
||||
ByteBuffer order = ByteBuffer.allocate(88).order(ByteOrder.LITTLE_ENDIAN);
|
||||
this.xStats.writeTo(order);
|
||||
this.yStats.writeTo(order);
|
||||
order.putDouble(this.sumOfProductsOfDeltas);
|
||||
return order.array();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (count() <= 0) {
|
||||
MoreObjects.ToStringHelper a = MoreObjects.a(this);
|
||||
a.a("xStats", this.xStats);
|
||||
a.a("yStats", this.yStats);
|
||||
return a.toString();
|
||||
}
|
||||
MoreObjects.ToStringHelper a2 = MoreObjects.a(this);
|
||||
a2.a("xStats", this.xStats);
|
||||
a2.a("yStats", this.yStats);
|
||||
a2.a("populationCovariance", populationCovariance());
|
||||
return a2.toString();
|
||||
}
|
||||
|
||||
public Stats xStats() {
|
||||
return this.xStats;
|
||||
}
|
||||
|
||||
public Stats yStats() {
|
||||
return this.yStats;
|
||||
}
|
||||
}
|
210
sources/com/google/common/math/Stats.java
Normal file
210
sources/com/google/common/math/Stats.java
Normal file
@@ -0,0 +1,210 @@
|
||||
package com.google.common.math;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.primitives.Doubles;
|
||||
import java.io.Serializable;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Iterator;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class Stats implements Serializable {
|
||||
static final int BYTES = 40;
|
||||
private static final long serialVersionUID = 0;
|
||||
private final long count;
|
||||
private final double max;
|
||||
private final double mean;
|
||||
private final double min;
|
||||
private final double sumOfSquaresOfDeltas;
|
||||
|
||||
Stats(long j, double d, double d2, double d3, double d4) {
|
||||
this.count = j;
|
||||
this.mean = d;
|
||||
this.sumOfSquaresOfDeltas = d2;
|
||||
this.min = d3;
|
||||
this.max = d4;
|
||||
}
|
||||
|
||||
public static Stats fromByteArray(byte[] bArr) {
|
||||
Preconditions.a(bArr);
|
||||
Preconditions.a(bArr.length == 40, "Expected Stats.BYTES = %s remaining , got %s", 40, bArr.length);
|
||||
return readFrom(ByteBuffer.wrap(bArr).order(ByteOrder.LITTLE_ENDIAN));
|
||||
}
|
||||
|
||||
public static double meanOf(Iterable<? extends Number> iterable) {
|
||||
return meanOf(iterable.iterator());
|
||||
}
|
||||
|
||||
public static Stats of(Iterable<? extends Number> iterable) {
|
||||
StatsAccumulator statsAccumulator = new StatsAccumulator();
|
||||
statsAccumulator.a(iterable);
|
||||
return statsAccumulator.a();
|
||||
}
|
||||
|
||||
static Stats readFrom(ByteBuffer byteBuffer) {
|
||||
Preconditions.a(byteBuffer);
|
||||
Preconditions.a(byteBuffer.remaining() >= 40, "Expected at least Stats.BYTES = %s remaining , got %s", 40, byteBuffer.remaining());
|
||||
return new Stats(byteBuffer.getLong(), byteBuffer.getDouble(), byteBuffer.getDouble(), byteBuffer.getDouble(), byteBuffer.getDouble());
|
||||
}
|
||||
|
||||
public long count() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null || Stats.class != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Stats stats = (Stats) obj;
|
||||
return this.count == stats.count && Double.doubleToLongBits(this.mean) == Double.doubleToLongBits(stats.mean) && Double.doubleToLongBits(this.sumOfSquaresOfDeltas) == Double.doubleToLongBits(stats.sumOfSquaresOfDeltas) && Double.doubleToLongBits(this.min) == Double.doubleToLongBits(stats.min) && Double.doubleToLongBits(this.max) == Double.doubleToLongBits(stats.max);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return Objects.a(Long.valueOf(this.count), Double.valueOf(this.mean), Double.valueOf(this.sumOfSquaresOfDeltas), Double.valueOf(this.min), Double.valueOf(this.max));
|
||||
}
|
||||
|
||||
public double max() {
|
||||
Preconditions.b(this.count != 0);
|
||||
return this.max;
|
||||
}
|
||||
|
||||
public double mean() {
|
||||
Preconditions.b(this.count != 0);
|
||||
return this.mean;
|
||||
}
|
||||
|
||||
public double min() {
|
||||
Preconditions.b(this.count != 0);
|
||||
return this.min;
|
||||
}
|
||||
|
||||
public double populationStandardDeviation() {
|
||||
return Math.sqrt(populationVariance());
|
||||
}
|
||||
|
||||
public double populationVariance() {
|
||||
Preconditions.b(this.count > 0);
|
||||
if (Double.isNaN(this.sumOfSquaresOfDeltas)) {
|
||||
return Double.NaN;
|
||||
}
|
||||
if (this.count == 1) {
|
||||
return 0.0d;
|
||||
}
|
||||
return DoubleUtils.a(this.sumOfSquaresOfDeltas) / count();
|
||||
}
|
||||
|
||||
public double sampleStandardDeviation() {
|
||||
return Math.sqrt(sampleVariance());
|
||||
}
|
||||
|
||||
public double sampleVariance() {
|
||||
Preconditions.b(this.count > 1);
|
||||
if (Double.isNaN(this.sumOfSquaresOfDeltas)) {
|
||||
return Double.NaN;
|
||||
}
|
||||
return DoubleUtils.a(this.sumOfSquaresOfDeltas) / (this.count - 1);
|
||||
}
|
||||
|
||||
public double sum() {
|
||||
return this.mean * this.count;
|
||||
}
|
||||
|
||||
double sumOfSquaresOfDeltas() {
|
||||
return this.sumOfSquaresOfDeltas;
|
||||
}
|
||||
|
||||
public byte[] toByteArray() {
|
||||
ByteBuffer order = ByteBuffer.allocate(40).order(ByteOrder.LITTLE_ENDIAN);
|
||||
writeTo(order);
|
||||
return order.array();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if (count() <= 0) {
|
||||
MoreObjects.ToStringHelper a = MoreObjects.a(this);
|
||||
a.a("count", this.count);
|
||||
return a.toString();
|
||||
}
|
||||
MoreObjects.ToStringHelper a2 = MoreObjects.a(this);
|
||||
a2.a("count", this.count);
|
||||
a2.a("mean", this.mean);
|
||||
a2.a("populationStandardDeviation", populationStandardDeviation());
|
||||
a2.a("min", this.min);
|
||||
a2.a("max", this.max);
|
||||
return a2.toString();
|
||||
}
|
||||
|
||||
void writeTo(ByteBuffer byteBuffer) {
|
||||
Preconditions.a(byteBuffer);
|
||||
Preconditions.a(byteBuffer.remaining() >= 40, "Expected at least Stats.BYTES = %s remaining , got %s", 40, byteBuffer.remaining());
|
||||
byteBuffer.putLong(this.count).putDouble(this.mean).putDouble(this.sumOfSquaresOfDeltas).putDouble(this.min).putDouble(this.max);
|
||||
}
|
||||
|
||||
public static double meanOf(Iterator<? extends Number> it) {
|
||||
Preconditions.a(it.hasNext());
|
||||
double doubleValue = it.next().doubleValue();
|
||||
long j = 1;
|
||||
while (it.hasNext()) {
|
||||
double doubleValue2 = it.next().doubleValue();
|
||||
j++;
|
||||
doubleValue = (Doubles.b(doubleValue2) && Doubles.b(doubleValue)) ? doubleValue + ((doubleValue2 - doubleValue) / j) : StatsAccumulator.a(doubleValue, doubleValue2);
|
||||
}
|
||||
return doubleValue;
|
||||
}
|
||||
|
||||
public static Stats of(Iterator<? extends Number> it) {
|
||||
StatsAccumulator statsAccumulator = new StatsAccumulator();
|
||||
statsAccumulator.a(it);
|
||||
return statsAccumulator.a();
|
||||
}
|
||||
|
||||
public static Stats of(double... dArr) {
|
||||
StatsAccumulator statsAccumulator = new StatsAccumulator();
|
||||
statsAccumulator.a(dArr);
|
||||
return statsAccumulator.a();
|
||||
}
|
||||
|
||||
public static double meanOf(double... dArr) {
|
||||
Preconditions.a(dArr.length > 0);
|
||||
double d = dArr[0];
|
||||
for (int i = 1; i < dArr.length; i++) {
|
||||
double d2 = dArr[i];
|
||||
d = (Doubles.b(d2) && Doubles.b(d)) ? d + ((d2 - d) / (i + 1)) : StatsAccumulator.a(d, d2);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
public static Stats of(int... iArr) {
|
||||
StatsAccumulator statsAccumulator = new StatsAccumulator();
|
||||
statsAccumulator.a(iArr);
|
||||
return statsAccumulator.a();
|
||||
}
|
||||
|
||||
public static Stats of(long... jArr) {
|
||||
StatsAccumulator statsAccumulator = new StatsAccumulator();
|
||||
statsAccumulator.a(jArr);
|
||||
return statsAccumulator.a();
|
||||
}
|
||||
|
||||
public static double meanOf(int... iArr) {
|
||||
Preconditions.a(iArr.length > 0);
|
||||
double d = iArr[0];
|
||||
for (int i = 1; i < iArr.length; i++) {
|
||||
double d2 = iArr[i];
|
||||
d = (Doubles.b(d2) && Doubles.b(d)) ? d + ((d2 - d) / (i + 1)) : StatsAccumulator.a(d, d2);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
public static double meanOf(long... jArr) {
|
||||
Preconditions.a(jArr.length > 0);
|
||||
double d = jArr[0];
|
||||
for (int i = 1; i < jArr.length; i++) {
|
||||
double d2 = jArr[i];
|
||||
d = (Doubles.b(d2) && Doubles.b(d)) ? d + ((d2 - d) / (i + 1)) : StatsAccumulator.a(d, d2);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
85
sources/com/google/common/math/StatsAccumulator.java
Normal file
85
sources/com/google/common/math/StatsAccumulator.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package com.google.common.math;
|
||||
|
||||
import com.google.common.primitives.Doubles;
|
||||
import java.util.Iterator;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class StatsAccumulator {
|
||||
private long a = 0;
|
||||
private double b = 0.0d;
|
||||
private double c = 0.0d;
|
||||
private double d = Double.NaN;
|
||||
private double e = Double.NaN;
|
||||
|
||||
public void a(double d) {
|
||||
long j = this.a;
|
||||
if (j == 0) {
|
||||
this.a = 1L;
|
||||
this.b = d;
|
||||
this.d = d;
|
||||
this.e = d;
|
||||
if (Doubles.b(d)) {
|
||||
return;
|
||||
}
|
||||
this.c = Double.NaN;
|
||||
return;
|
||||
}
|
||||
this.a = j + 1;
|
||||
if (Doubles.b(d) && Doubles.b(this.b)) {
|
||||
double d2 = this.b;
|
||||
double d3 = d - d2;
|
||||
this.b = d2 + (d3 / this.a);
|
||||
this.c += d3 * (d - this.b);
|
||||
} else {
|
||||
this.b = a(this.b, d);
|
||||
this.c = Double.NaN;
|
||||
}
|
||||
this.d = Math.min(this.d, d);
|
||||
this.e = Math.max(this.e, d);
|
||||
}
|
||||
|
||||
public void a(Iterable<? extends Number> iterable) {
|
||||
Iterator<? extends Number> it = iterable.iterator();
|
||||
while (it.hasNext()) {
|
||||
a(it.next().doubleValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void a(Iterator<? extends Number> it) {
|
||||
while (it.hasNext()) {
|
||||
a(it.next().doubleValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void a(double... dArr) {
|
||||
for (double d : dArr) {
|
||||
a(d);
|
||||
}
|
||||
}
|
||||
|
||||
public void a(int... iArr) {
|
||||
for (int i : iArr) {
|
||||
a(i);
|
||||
}
|
||||
}
|
||||
|
||||
public void a(long... jArr) {
|
||||
for (long j : jArr) {
|
||||
a(j);
|
||||
}
|
||||
}
|
||||
|
||||
public Stats a() {
|
||||
return new Stats(this.a, this.b, this.c, this.d, this.e);
|
||||
}
|
||||
|
||||
static double a(double d, double d2) {
|
||||
if (Doubles.b(d)) {
|
||||
return d2;
|
||||
}
|
||||
if (Doubles.b(d2) || d == d2) {
|
||||
return d;
|
||||
}
|
||||
return Double.NaN;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user