Skip to content

Commit

Permalink
Optimize shuffle method (#1347)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed May 23, 2024
1 parent 984009e commit 004f75d
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions cdm/core/src/main/java/ucar/nc2/filter/Shuffle.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,24 @@ public byte[] encode(byte[] dataIn) {

@Override
public byte[] decode(byte[] dataIn) {
if (dataIn.length % elemSize != 0 || elemSize <= 1) {
return dataIn;
}

int nElems = dataIn.length / elemSize;
int[] start = new int[elemSize];
for (int k = 0; k < elemSize; k++) {
start[k] = k * nElems;
}

byte[] result = new byte[dataIn.length];
for (int i = 0; i < nElems; i++) {
for (int j = 0; j < elemSize; j++) {
result[(i * elemSize) + j] = dataIn[i + start[j]];
if (dataIn.length % this.elemSize == 0 && this.elemSize > 1) {
int nElems = dataIn.length / this.elemSize;
byte[] result = new byte[dataIn.length];

for (int j = 0; j < this.elemSize; ++j) {
int sourceIndex = j * nElems;
int destIndex = j;
for (int i = 0; i < nElems; ++i) {
result[destIndex] = dataIn[sourceIndex];
sourceIndex++;
destIndex += this.elemSize;
}
}
}

return result;
return result;
} else {
return dataIn;
}
}

public static class Provider implements FilterProvider {
Expand Down

0 comments on commit 004f75d

Please sign in to comment.