Skip to content

Commit 07039fc

Browse files
committed
[rntuple] implement kReal32Quant
It is simple - just rescale n-bits to min..max range
1 parent 8280289 commit 07039fc

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

modules/rntuple.mjs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,13 @@ class ReaderItem {
871871
case kReal32Trunc:
872872
case kReal32Quant:
873873
this.nbits = this.column.bitsOnStorage;
874-
this.buf = new DataView(new ArrayBuffer(4), 0);
874+
if (this.coltype === kReal32Trunc)
875+
this.buf = new DataView(new ArrayBuffer(4), 0);
876+
else {
877+
this.factor = (this.column.maxValue - this.column.minValue) / ((1 << this.nbits) - 1);
878+
this.min = this.column.minValue;
879+
}
880+
875881
this.func = function(obj) {
876882
let res = 0, len = this.nbits;
877883
// extract nbits from the
@@ -893,8 +899,11 @@ class ReaderItem {
893899
len = 0;
894900
}
895901
}
896-
this.buf.setUint32(0, res << (32 - this.nbits), true);
897-
obj[this.name] = this.buf.getFloat32(0, true);
902+
if (this.buf) {
903+
this.buf.setUint32(0, res << (32 - this.nbits), true);
904+
obj[this.name] = this.buf.getFloat32(0, true);
905+
} else
906+
obj[this.name] = res * this.factor + this.min;
898907
};
899908
break;
900909
case kInt64:
@@ -1025,12 +1034,8 @@ class ReaderItem {
10251034
async unzipBlob(blob, cluster_locations, page_indx) {
10261035
const colEntry = cluster_locations[this.id], // Access column entry
10271036
numElements = Number(colEntry.pages[page_indx].numElements),
1028-
elementSize = this.column.bitsOnStorage / 8;
1029-
1030-
let expectedSize = numElements * elementSize;
1031-
// Special handling for boolean fields
1032-
if (this.coltype === kBit)
1033-
expectedSize = Math.ceil(numElements / 8);
1037+
elementSize = this.column.bitsOnStorage / 8,
1038+
expectedSize = Math.ceil(numElements * elementSize);
10341039

10351040
// Check if data is compressed
10361041
if ((colEntry.compression === 0) || (blob.byteLength === expectedSize))

0 commit comments

Comments
 (0)