Skip to content

Commit

Permalink
Java formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdunkerley committed Jan 23, 2025
1 parent 108861d commit df39a40
Show file tree
Hide file tree
Showing 19 changed files with 221 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import java.math.MathContext;
import java.util.List;
import org.enso.base.polyglot.NumericConverter;
import org.enso.table.data.column.storage.ColumnDoubleStorage;
import org.enso.table.data.column.storage.ColumnLongStorage;
import org.enso.table.data.column.storage.Storage;
import org.enso.table.data.column.storage.numeric.AbstractLongStorage;
import org.enso.table.data.column.storage.numeric.DoubleStorage;
import org.enso.table.data.column.storage.type.AnyObjectType;
import org.enso.table.data.column.storage.type.BigDecimalType;
import org.enso.table.data.column.storage.type.BigIntegerType;
Expand Down Expand Up @@ -79,15 +79,15 @@ private final class FloatMeanAccumulator extends MeanAccumulator {
void accumulate(
List<Integer> indexes, Storage<?> storage, ProblemAggregator problemAggregator) {
Context context = Context.getCurrent();
if (storage instanceof DoubleStorage doubleStorage) {
if (storage instanceof ColumnDoubleStorage doubleStorage) {
for (int i : indexes) {
if (!doubleStorage.isNothing(i)) {
total += doubleStorage.get(i);
count++;
}
context.safepoint();
}
} else if (storage instanceof AbstractLongStorage longStorage) {
} else if (storage instanceof ColumnLongStorage longStorage) {
for (int i : indexes) {
if (!longStorage.isNothing(i)) {
total += longStorage.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.enso.table.data.column.builder.Builder;
import org.enso.table.data.column.builder.InferredIntegerBuilder;
import org.enso.table.data.column.operation.map.MapOperationProblemAggregator;
import org.enso.table.data.column.storage.ColumnLongStorage;
import org.enso.table.data.column.storage.Storage;
import org.enso.table.data.column.storage.numeric.AbstractLongStorage;
import org.enso.table.data.column.storage.numeric.BigIntegerStorage;
import org.enso.table.data.column.storage.numeric.DoubleStorage;
import org.enso.table.data.column.storage.type.BigIntegerType;
Expand Down Expand Up @@ -87,7 +87,7 @@ void add(Object value) {
@Override
void accumulate(List<Integer> indexes, Storage<?> storage) {
Context context = Context.getCurrent();
if (storage instanceof AbstractLongStorage longStorage) {
if (storage instanceof ColumnLongStorage longStorage) {
for (int row : indexes) {
if (!longStorage.isNothing(row)) {
addLong(longStorage.get(row));
Expand All @@ -96,15 +96,15 @@ void accumulate(List<Integer> indexes, Storage<?> storage) {
}
} else if (storage instanceof BigIntegerStorage bigIntegerStorage) {
for (int row : indexes) {
BigInteger value = bigIntegerStorage.getItemBoxed(row);
BigInteger value = bigIntegerStorage.getBoxed(row);
if (value != null) {
addBigInteger(value);
}
context.safepoint();
}
} else {
for (int row : indexes) {
add(storage.getItemBoxed(row));
add(storage.getBoxed(row));
context.safepoint();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Builder retypeTo(StorageType type) {

@Override
protected Storage<BigInteger> doSeal() {
return new BigIntegerStorage(data, currentSize);
return new BigIntegerStorage(data);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public BigInteger doBigInteger(

@Override
public BigDecimal doBigDecimal(
BigDecimal a, BigDecimal b, int ix, MapOperationProblemAggregator problemAggregator) {
BigDecimal a, BigDecimal b, long ix, MapOperationProblemAggregator problemAggregator) {
return a.add(b);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public BigDecimalDivideOp() {

@Override
public BigDecimal doBigDecimal(
BigDecimal a, BigDecimal b, int ix, MapOperationProblemAggregator problemAggregator) {
BigDecimal a, BigDecimal b, long ix, MapOperationProblemAggregator problemAggregator) {
try {
return a.divide(b);
} catch (ArithmeticException e) {
String extraMessage =
" Please use `.divide` with an explicit `Math_Context` to limit the numeric precision.";
problemAggregator.reportArithmeticError(e.getMessage() + extraMessage, ix);
problemAggregator.reportArithmeticError(e.getMessage() + extraMessage, (int)ix);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public BigInteger doBigInteger(

@Override
public BigDecimal doBigDecimal(
BigDecimal a, BigDecimal b, int ix, MapOperationProblemAggregator problemAggregator) {
BigDecimal a, BigDecimal b, long ix, MapOperationProblemAggregator problemAggregator) {
return a.max(b);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public BigInteger doBigInteger(

@Override
public BigDecimal doBigDecimal(
BigDecimal a, BigDecimal b, int ix, MapOperationProblemAggregator problemAggregator) {
BigDecimal a, BigDecimal b, long ix, MapOperationProblemAggregator problemAggregator) {
return a.min(b);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public BigInteger doBigInteger(

@Override
public BigDecimal doBigDecimal(
BigDecimal a, BigDecimal b, int ix, MapOperationProblemAggregator problemAggregator) {
BigDecimal a, BigDecimal b, long ix, MapOperationProblemAggregator problemAggregator) {
if (b.equals(BigDecimal.ZERO)) {
problemAggregator.reportDivisionByZero(ix);
problemAggregator.reportDivisionByZero((int) ix);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public BigInteger doBigInteger(

@Override
public BigDecimal doBigDecimal(
BigDecimal a, BigDecimal b, int ix, MapOperationProblemAggregator problemAggregator) {
BigDecimal a, BigDecimal b, long ix, MapOperationProblemAggregator problemAggregator) {
return a.multiply(b);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
import org.enso.table.data.column.operation.map.numeric.helpers.BigDecimalArrayAdapter;
import org.enso.table.data.column.operation.map.numeric.helpers.BigIntegerArrayAdapter;
import org.enso.table.data.column.operation.map.numeric.helpers.DoubleArrayAdapter;
import org.enso.table.data.column.storage.SpecializedStorage;
import org.enso.table.data.column.storage.Storage;
import org.enso.table.data.column.storage.numeric.AbstractLongStorage;
import org.enso.table.data.column.storage.numeric.BigDecimalStorage;
import org.enso.table.data.column.storage.numeric.BigIntegerStorage;
import org.enso.table.data.column.storage.type.FloatType;
import org.enso.table.data.column.storage.type.IntegerType;
import org.graalvm.polyglot.Context;
Expand All @@ -29,13 +26,14 @@ public NumericBinaryOpCoalescing(String name) {
@Override
protected Storage<Double> runDoubleZip(
DoubleArrayAdapter a, DoubleArrayAdapter b, MapOperationProblemAggregator problemAggregator) {
Context context = Context.getCurrent();
int n = a.size();
int m = Math.min(a.size(), b.size());
var builder = Builder.getForDouble(FloatType.FLOAT_64, n, null);
for (int i = 0; i < m; i++) {
int m = Math.min(n, b.size());
var builder = Builder.getForDouble(FloatType.FLOAT_64, n, problemAggregator);
Context context = Context.getCurrent();

for (int i = 0; i < n; i++) {
boolean aNothing = a.isNothing(i);
boolean bNothing = b.isNothing(i);
boolean bNothing = i >= m || b.isNothing(i);
if (aNothing && bNothing) {
builder.appendNulls(1);
} else {
Expand All @@ -53,16 +51,6 @@ protected Storage<Double> runDoubleZip(
context.safepoint();
}

for (int i = m; i < n; ++i) {
if (a.isNothing(i)) {
builder.appendNulls(1);
} else {
builder.appendDouble(a.getItemAsDouble(i));
}

context.safepoint();
}

return builder.seal();
}

Expand Down Expand Up @@ -93,13 +81,14 @@ protected Storage<Long> runLongZip(
AbstractLongStorage a,
AbstractLongStorage b,
MapOperationProblemAggregator problemAggregator) {
Context context = Context.getCurrent();
int n = a.size();
int m = Math.min(a.size(), b.size());
var builder = Builder.getForLong(IntegerType.INT_64, n, null);
for (int i = 0; i < m; i++) {
Context context = Context.getCurrent();

for (int i = 0; i < n; i++) {
boolean aNothing = a.isNothing(i);
boolean bNothing = b.isNothing(i);
boolean bNothing = i >= m || b.isNothing(i);
if (aNothing && bNothing) {
builder.appendNulls(1);
} else {
Expand All @@ -120,16 +109,6 @@ protected Storage<Long> runLongZip(
context.safepoint();
}

for (int i = m; i < n; ++i) {
if (a.isNothing(i)) {
builder.appendNulls(1);
} else {
builder.appendLong(a.get(i));
}

context.safepoint();
}

return builder.seal();
}

Expand Down Expand Up @@ -161,109 +140,108 @@ protected Storage<Long> runLongMap(
return builder.seal();
}

protected BigIntegerStorage runBigIntegerZip(
protected Storage<BigInteger> runBigIntegerZip(
BigIntegerArrayAdapter a,
BigIntegerArrayAdapter b,
MapOperationProblemAggregator problemAggregator) {
Context context = Context.getCurrent();
int n = a.size();
int m = Math.min(a.size(), b.size());
BigInteger[] out = new BigInteger[n];
for (int i = 0; i < m; i++) {
var builder = Builder.getForBigInteger(n, problemAggregator);
Context context = Context.getCurrent();

for (int i = 0; i < n; i++) {
BigInteger x = a.getItem(i);
BigInteger y = b.getItem(i);
BigInteger y = i >= m ? null : b.getItem(i);
if (x == null && y == null) {
out[i] = null;
builder.appendNulls(1);
} else {
if (x == null) {
out[i] = y;
builder.append(y);
} else if (y == null) {
out[i] = x;
builder.append(x);
} else {
BigInteger r = doBigInteger(x, y, i, problemAggregator);
out[i] = r;
builder.append(r);
}
}
context.safepoint();
}

return new BigIntegerStorage(out);
return builder.seal();
}

protected BigIntegerStorage runBigIntegerMap(
protected Storage<BigInteger> runBigIntegerMap(
BigIntegerArrayAdapter a, BigInteger b, MapOperationProblemAggregator problemAggregator) {
if (b == null) {
return a.intoStorage();
}

Context context = Context.getCurrent();
int n = a.size();
BigInteger[] out = new BigInteger[n];
var builder = Builder.getForBigInteger(n, problemAggregator);
for (int i = 0; i < n; i++) {
BigInteger x = a.getItem(i);
if (x == null) {
out[i] = b;
builder.append(b);
} else {
BigInteger r = doBigInteger(x, b, i, problemAggregator);
out[i] = r;
builder.append(doBigInteger(x, b, i, problemAggregator));
}

context.safepoint();
}

return new BigIntegerStorage(out);
return builder.seal();
}

protected BigDecimalStorage runBigDecimalZip(
protected Storage<BigDecimal> runBigDecimalZip(
BigDecimalArrayAdapter a,
BigDecimalArrayAdapter b,
MapOperationProblemAggregator problemAggregator) {
long n = a.size();
long m = Math.min(a.size(), b.size());
var builder = Builder.getForBigDecimal(n);
Context context = Context.getCurrent();
int n = a.size();
int m = Math.min(a.size(), b.size());
BigDecimal[] out = new BigDecimal[n];
for (int i = 0; i < m; i++) {

for (long i = 0; i < n; i++) {
BigDecimal x = a.getItem(i);
BigDecimal y = b.getItem(i);
BigDecimal y = i >= m ? null : b.getItem(i);
if (x == null && y == null) {
out[i] = null;
builder.appendNulls(1);
} else {
if (x == null) {
out[i] = y;
builder.append(y);
} else if (y == null) {
out[i] = x;
builder.append(x);
} else {
BigDecimal r = doBigDecimal(x, y, i, problemAggregator);
out[i] = r;
builder.append(doBigDecimal(x, y, i, problemAggregator));
}
}
context.safepoint();
}

return new BigDecimalStorage(out);
return builder.seal();
}

protected SpecializedStorage<BigDecimal> runBigDecimalMap(
protected Storage<BigDecimal> runBigDecimalMap(
BigDecimalArrayAdapter a, BigDecimal b, MapOperationProblemAggregator problemAggregator) {
if (b == null) {
return a.intoStorage();
}

Context context = Context.getCurrent();
int n = a.size();
BigDecimal[] out = new BigDecimal[n];
for (int i = 0; i < n; i++) {
long n = a.size();
var builder = Builder.getForBigDecimal(n);
for (long i = 0; i < n; i++) {
BigDecimal x = a.getItem(i);
if (x == null) {
out[i] = b;
builder.append(b);
} else {
BigDecimal r = doBigDecimal(x, b, i, problemAggregator);
out[i] = r;
builder.append(doBigDecimal(x, b, i, problemAggregator));
}

context.safepoint();
}

return new BigDecimalStorage(out);
return builder.seal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ BigInteger doBigInteger(
BigInteger a, BigInteger b, int ix, MapOperationProblemAggregator problemAggregator);

BigDecimal doBigDecimal(
BigDecimal a, BigDecimal b, int ix, MapOperationProblemAggregator problemAggregator);
BigDecimal a, BigDecimal b, long ix, MapOperationProblemAggregator problemAggregator);
}
Loading

0 comments on commit df39a40

Please sign in to comment.