Skip to content

Commit ac09d3e

Browse files
committed
manual code cleanups
1 parent 5072ed9 commit ac09d3e

3 files changed

Lines changed: 41 additions & 42 deletions

File tree

reader/src/main/java/io/github/dfa1/vortex/reader/array/LazyAlpRdDoubleArray.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/// @param dtype logical element type
2020
/// @param length total logical row count
2121
/// @param dict small u16 dictionary lookup table (length typically ≤ 16)
22-
/// @param rightBitWidth bit width of the right payload
22+
/// @param rightBitWidth a bit width of the right payload
2323
/// @param leftArr per-row u16 dict codes
2424
/// @param rightArr per-row u64 right payloads (raw bits)
2525
/// @param patchIndices sorted absolute indices of patched rows (or {@code null} when no patches)
@@ -43,17 +43,15 @@ public double getDouble(long i) {
4343

4444
@Override
4545
public void forEachDouble(DoubleConsumer c) {
46-
long n = length;
47-
for (long i = 0; i < n; i++) {
46+
for (long i = 0; i < length; i++) {
4847
c.accept(getDouble(i));
4948
}
5049
}
5150

5251
@Override
5352
public double fold(double identity, DoubleBinaryOperator op) {
5453
double acc = identity;
55-
long n = length;
56-
for (long i = 0; i < n; i++) {
54+
for (long i = 0; i < length; i++) {
5755
acc = op.applyAsDouble(acc, getDouble(i));
5856
}
5957
return acc;

reader/src/main/java/io/github/dfa1/vortex/reader/decode/AlpRdEncodingDecoder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ private static Array unwrap(Array arr) {
9191

9292
/// Decoded patches: sorted absolute indices (as a typed Array for in-place lookup)
9393
/// plus the actual left u16 values pulled into a short[].
94+
@SuppressWarnings("java:S6218") // internal data carrier; record components are arrays of immutable primitives or refs that flow through pipelines without ever being compared.
9495
private record Patches(Array indices, short[] leftValues, long offset) {
9596
static final Patches EMPTY = new Patches(null, new short[0], 0L);
9697
}

writer/src/main/java/io/github/dfa1/vortex/writer/encode/PcoEncodingEncoder.java

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@ private record ChunkResult(MemorySegment chunkMeta, MemorySegment page, int page
6464
}
6565

6666
// Per-stream encoded ANS state. Used for both single-stream (Classic) and dual-stream (IntMult) modes.
67-
@SuppressWarnings("java:S6218") // internal data carrier; record components are arrays of immutable primitives or refs that flow through pipelines without ever being compared.
67+
@SuppressWarnings("java:S6218")
68+
// internal data carrier; record components are arrays of immutable primitives or refs that flow through pipelines without ever being compared.
6869
private record StreamData(
69-
int[] symbols,
70-
long[] offsets,
71-
int[] binOffsetBits,
72-
int ansSizeLog,
73-
long[][] batchBits,
74-
int[][] batchNumBits,
75-
int[] initialStateIdxs
70+
int[] symbols,
71+
long[] offsets,
72+
int[] binOffsetBits,
73+
int ansSizeLog,
74+
long[][] batchBits,
75+
int[][] batchNumBits,
76+
int[] initialStateIdxs
7677
) {
7778
}
7879

@@ -83,7 +84,7 @@ static EncodeResult encode(DType dtype, Object data, EncodeContext ctx) {
8384
int n = allLatents.length;
8485

8586
if (n == 0) {
86-
return encodeEmpty(ctx.arena());
87+
return encodeEmpty();
8788
}
8889

8990
List<MemorySegment> chunkMetas = new ArrayList<>();
@@ -178,12 +179,12 @@ private static ChunkResult encodeChunkClassic(long[] latents, int dtypeSize, Are
178179
PcoAnsEncoder ansEncoder = PcoAnsEncoder.build(deltaQ.sizeLog(), deltaQ.weights());
179180
chunkMetaSeg = buildClassicChunkMeta(dtypeSize, deltaBins, deltaQ, 1, 1, arena);
180181
pageSeg = buildClassicPage(deltas, toSortKeys(deltas), deltaBins,
181-
deltaQ.sizeLog(), ansEncoder, dtypeSize, latents[0], true, arena);
182+
deltaQ.sizeLog(), ansEncoder, dtypeSize, latents[0], true, arena);
182183
} else {
183184
PcoAnsEncoder ansEncoder = PcoAnsEncoder.build(noOpQ.sizeLog(), noOpQ.weights());
184185
chunkMetaSeg = buildClassicChunkMeta(dtypeSize, noOpBins, noOpQ, 0, 0, arena);
185186
pageSeg = buildClassicPage(latents, sortKeys, noOpBins,
186-
noOpQ.sizeLog(), ansEncoder, dtypeSize, 0L, false, arena);
187+
noOpQ.sizeLog(), ansEncoder, dtypeSize, 0L, false, arena);
187188
}
188189

189190
return new ChunkResult(chunkMetaSeg, pageSeg, n);
@@ -194,7 +195,6 @@ private static ChunkResult encodeChunkClassic(long[] latents, int dtypeSize, Are
194195
// Returns null if IntMult fails to actually beat Classic after full bin optimization.
195196
private static ChunkResult tryEncodeIntMult(long[] latents, long base, int dtypeSize, Arena arena) {
196197
int n = latents.length;
197-
long mask = typeMask(dtypeSize);
198198
long[] mults = new long[n];
199199
long[] adjs = new long[n];
200200
for (int i = 0; i < n; i++) {
@@ -233,9 +233,9 @@ private static ChunkResult tryEncodeIntMult(long[] latents, long base, int dtype
233233

234234
MemorySegment chunkMetaSeg = buildIntMultChunkMeta(dtypeSize, base, multBins, multQ, adjBins, adjQ, arena);
235235
MemorySegment pageSeg = buildIntMultPage(
236-
mults, multSortKeys, multBins, multQ.sizeLog(), multAnsEncoder,
237-
adjs, adjSortKeys, adjBins, adjQ.sizeLog(), adjAnsEncoder,
238-
arena);
236+
mults, multSortKeys, multBins, multQ.sizeLog(), multAnsEncoder,
237+
adjSortKeys, adjBins, adjQ.sizeLog(), adjAnsEncoder,
238+
arena);
239239
return new ChunkResult(chunkMetaSeg, pageSeg, n);
240240
}
241241

@@ -280,7 +280,7 @@ private static List<PcoHistBin> buildHistogram(long[] sortedKeys, int n, int nBi
280280
targetEnd++;
281281
}
282282
int end = Math.min(targetEnd, n);
283-
bins.add(new PcoHistBin(sortedKeys[start], sortedKeys[end - 1], end - start));
283+
bins.add(new PcoHistBin(sortedKeys[start], sortedKeys[end - 1], (long) end - start));
284284
start = end;
285285
}
286286
return bins;
@@ -289,8 +289,8 @@ private static List<PcoHistBin> buildHistogram(long[] sortedKeys, int n, int nBi
289289
// ── Classic chunk meta ────────────────────────────────────────────────
290290

291291
private static MemorySegment buildClassicChunkMeta(
292-
int dtypeSize, List<PcoBinOptimizer.Bin> bins, PcoWeightQuantizer.Result qw,
293-
int deltaVariant, int deltaOrder, Arena arena) {
292+
int dtypeSize, List<PcoBinOptimizer.Bin> bins, PcoWeightQuantizer.Result qw,
293+
int deltaVariant, int deltaOrder, Arena arena) {
294294
int ansSizeLog = qw.sizeLog();
295295
int[] weights = qw.weights();
296296
LeBitWriter w = new LeBitWriter(64);
@@ -316,10 +316,10 @@ private static MemorySegment buildClassicChunkMeta(
316316
// ── IntMult chunk meta ────────────────────────────────────────────────
317317

318318
private static MemorySegment buildIntMultChunkMeta(
319-
int dtypeSize, long base,
320-
List<PcoBinOptimizer.Bin> primaryBins, PcoWeightQuantizer.Result primaryQ,
321-
List<PcoBinOptimizer.Bin> secondaryBins, PcoWeightQuantizer.Result secondaryQ,
322-
Arena arena) {
319+
int dtypeSize, long base,
320+
List<PcoBinOptimizer.Bin> primaryBins, PcoWeightQuantizer.Result primaryQ,
321+
List<PcoBinOptimizer.Bin> secondaryBins, PcoWeightQuantizer.Result secondaryQ,
322+
Arena arena) {
323323
int primaryAnsSizeLog = primaryQ.sizeLog();
324324
int[] primaryWeights = primaryQ.weights();
325325
int secondaryAnsSizeLog = secondaryQ.sizeLog();
@@ -358,10 +358,10 @@ private static MemorySegment buildIntMultChunkMeta(
358358
// ── Classic page encoding ─────────────────────────────────────────────
359359

360360
private static MemorySegment buildClassicPage(
361-
long[] values, long[] valueSortKeys,
362-
List<PcoBinOptimizer.Bin> bins, int ansSizeLog,
363-
PcoAnsEncoder ansEncoder, int dtypeSize,
364-
long moment, boolean hasMoment, Arena arena) {
361+
long[] values, long[] valueSortKeys,
362+
List<PcoBinOptimizer.Bin> bins, int ansSizeLog,
363+
PcoAnsEncoder ansEncoder, int dtypeSize,
364+
long moment, boolean hasMoment, Arena arena) {
365365

366366
int n = values.length;
367367
StreamData stream = prepareStream(valueSortKeys, bins, ansSizeLog, ansEncoder);
@@ -387,11 +387,11 @@ private static MemorySegment buildClassicPage(
387387
// ── IntMult page encoding ─────────────────────────────────────────────
388388

389389
private static MemorySegment buildIntMultPage(
390-
long[] mults, long[] multSortKeys, List<PcoBinOptimizer.Bin> multBins,
391-
int multAnsSizeLog, PcoAnsEncoder multAnsEncoder,
392-
long[] adjs, long[] adjSortKeys, List<PcoBinOptimizer.Bin> adjBins,
393-
int adjAnsSizeLog, PcoAnsEncoder adjAnsEncoder,
394-
Arena arena) {
390+
long[] mults, long[] multSortKeys, List<PcoBinOptimizer.Bin> multBins,
391+
int multAnsSizeLog, PcoAnsEncoder multAnsEncoder,
392+
long[] adjSortKeys, List<PcoBinOptimizer.Bin> adjBins,
393+
int adjAnsSizeLog, PcoAnsEncoder adjAnsEncoder,
394+
Arena arena) {
395395

396396
int n = mults.length;
397397
StreamData primary = prepareStream(multSortKeys, multBins, multAnsSizeLog, multAnsEncoder);
@@ -428,7 +428,7 @@ private static MemorySegment buildIntMultPage(
428428
// ── Stream preparation: ANS encode LIFO, collect bits per batch ──────
429429

430430
private static StreamData prepareStream(
431-
long[] sortKeys, List<PcoBinOptimizer.Bin> bins, int ansSizeLog, PcoAnsEncoder ansEncoder) {
431+
long[] sortKeys, List<PcoBinOptimizer.Bin> bins, int ansSizeLog, PcoAnsEncoder ansEncoder) {
432432
int n = sortKeys.length;
433433
long[] binLowers = new long[bins.size()];
434434
int[] binOffsetBits = new int[bins.size()];
@@ -475,7 +475,7 @@ private static StreamData prepareStream(
475475
}
476476

477477
return new StreamData(symbols, offsets, binOffsetBits, ansSizeLog,
478-
batchBits, batchNumBits, initialStateIdxs);
478+
batchBits, batchNumBits, initialStateIdxs);
479479
}
480480

481481
private static long streamPayloadBits(StreamData s) {
@@ -564,7 +564,7 @@ private static long[] toSortKeys(long[] latents) {
564564
// ── weight quantization ───────────────────────────────────────────────
565565

566566
private static PcoWeightQuantizer.Result quantize(
567-
List<PcoBinOptimizer.Bin> bins, int totalCount, int maxSizeLog) {
567+
List<PcoBinOptimizer.Bin> bins, int totalCount, int maxSizeLog) {
568568
int[] counts = new int[bins.size()];
569569
for (int i = 0; i < counts.length; i++) {
570570
counts[i] = bins.get(i).weight();
@@ -574,7 +574,7 @@ private static PcoWeightQuantizer.Result quantize(
574574

575575
// ── metadata ─────────────────────────────────────────────────────────
576576

577-
private static EncodeResult encodeEmpty(Arena arena) {
577+
private static EncodeResult encodeEmpty() {
578578
byte[] header = {PCO_FORMAT_MAJOR, PCO_FORMAT_MINOR};
579579
PcoMetadata meta = new PcoMetadata(header, List.of());
580580
ByteBuffer metaBuf = ByteBuffer.wrap(meta.encode());
@@ -644,8 +644,8 @@ private static long[] toLatents(PType ptype, Object data) {
644644
for (int i = 0; i < arr.length; i++) {
645645
int bits = Float.floatToRawIntBits(arr[i]);
646646
l[i] = (bits & 0x80000000) != 0
647-
? (~bits) & 0xFFFFFFFFL
648-
: (bits ^ 0x80000000) & 0xFFFFFFFFL;
647+
? (~bits) & 0xFFFFFFFFL
648+
: (bits ^ 0x80000000) & 0xFFFFFFFFL;
649649
}
650650
yield l;
651651
}

0 commit comments

Comments
 (0)