diff options
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/tensor/IndexedFloatTensor.java')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/IndexedFloatTensor.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/tensor/IndexedFloatTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/IndexedFloatTensor.java new file mode 100644 index 00000000000..563d72137e7 --- /dev/null +++ b/vespajlib/src/main/java/com/yahoo/tensor/IndexedFloatTensor.java @@ -0,0 +1,44 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.tensor; + +import java.util.Arrays; + +/** + * An indexed tensor implementation holding values as floats + * + * @author bratseth + */ +class IndexedFloatTensor extends IndexedTensor { + + private final float[] values; + + IndexedFloatTensor(TensorType type, DimensionSizes dimensionSizes, float[] values) { + super(type, dimensionSizes); + this.values = values; + } + + @Override + public long size() { + return values.length; + } + + /** + * Returns the value at the given index by direct lookup. Only use + * if you know the underlying data layout. + * + * @param valueIndex the direct index into the underlying data. + * @throws IndexOutOfBoundsException if index is out of bounds + */ + @Override + public double get(long valueIndex) { return values[(int)valueIndex]; } + + @Override + public IndexedTensor withType(TensorType type) { + throwOnIncompatibleType(type); + return new IndexedFloatTensor(type, dimensionSizes(), values); + } + + @Override + public int hashCode() { return Arrays.hashCode(values); } + +} |