diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-04-26 14:55:04 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-04-26 14:55:04 +0200 |
commit | e92b8dd81cfc469d42f858785919964baf8afb0e (patch) | |
tree | 9dee2f63092b51082f842b9b84b740c2f4ebfdea /vespajlib/src/main/java/com/yahoo/tensor/serialization | |
parent | f0f7f4962e6339ad2b4fbd293e89df86a6ec7a0a (diff) |
Encode directly as float
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/serialization')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/serialization/DenseBinaryFormat.java | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/serialization/DenseBinaryFormat.java b/vespajlib/src/main/java/com/yahoo/tensor/serialization/DenseBinaryFormat.java index ec8c7de1e72..0cec09157fb 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/serialization/DenseBinaryFormat.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/serialization/DenseBinaryFormat.java @@ -38,7 +38,7 @@ public class DenseBinaryFormat implements BinaryFormat { if ( ! ( tensor instanceof IndexedTensor)) throw new RuntimeException("The dense format is only supported for indexed tensors"); encodeDimensions(buffer, (IndexedTensor)tensor); - encodeCells(buffer, tensor); + encodeCells(buffer, (IndexedTensor)tensor); } private void encodeDimensions(GrowableByteBuffer buffer, IndexedTensor tensor) { @@ -49,25 +49,21 @@ public class DenseBinaryFormat implements BinaryFormat { } } - private void encodeCells(GrowableByteBuffer buffer, Tensor tensor) { + private void encodeCells(GrowableByteBuffer buffer, IndexedTensor tensor) { switch (serializationValueType) { case DOUBLE: encodeDoubleCells(tensor, buffer); break; case FLOAT: encodeFloatCells(tensor, buffer); break; } } - private void encodeDoubleCells(Tensor tensor, GrowableByteBuffer buffer) { - Iterator<Double> i = tensor.valueIterator(); - while (i.hasNext()) { - buffer.putDouble(i.next()); - } + private void encodeDoubleCells(IndexedTensor tensor, GrowableByteBuffer buffer) { + for (int i = 0; i < tensor.size(); i++) + buffer.putDouble(tensor.get(i)); } - private void encodeFloatCells(Tensor tensor, GrowableByteBuffer buffer) { - Iterator<Double> i = tensor.valueIterator(); // TODO: floatValueIterator - while (i.hasNext()) { - buffer.putFloat(i.next().floatValue()); - } + private void encodeFloatCells(IndexedTensor tensor, GrowableByteBuffer buffer) { + for (int i = 0; i < tensor.size(); i++) + buffer.putFloat(tensor.getFloat(i)); } @Override |