Skip to content

Commit

Permalink
VectorDescriptorAggregator uses Double instead of Float
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaro committed Aug 23, 2024
1 parent 7fd87b5 commit a2ca74a
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,50 +26,50 @@ class VectorDescriptorAggregator : TransformerFactory {
MEAN {
override fun aggregate(collection: Collection<VectorDescriptor<*, *>>): VectorDescriptor<*, *> {

val vec = FloatArray(collection.first().vector.size)
val vec = DoubleArray(collection.first().vector.size)

collection.forEach { descriptor ->
when (descriptor) {
is FloatVectorDescriptor -> {
for (i in vec.indices) {
vec[i] += descriptor.vector.value[i]
vec[i] += descriptor.vector.value[i].toDouble()
}
}

is DoubleVectorDescriptor -> {
for (i in vec.indices) {
vec[i] += descriptor.vector.value[i].toFloat()
vec[i] += descriptor.vector.value[i]
}
}

is IntVectorDescriptor -> {
for (i in vec.indices) {
vec[i] += descriptor.vector.value[i].toFloat()
vec[i] += descriptor.vector.value[i].toDouble()
}
}

is LongVectorDescriptor -> {
for (i in vec.indices) {
vec[i] += descriptor.vector.value[i].toFloat()
vec[i] += descriptor.vector.value[i].toDouble()
}
}

is BooleanVectorDescriptor -> {
for (i in vec.indices) {
vec[i] += if (descriptor.vector.value[i]) 1f else 0f
vec[i] += if (descriptor.vector.value[i]) 1.0 else 0.0
}
}
}
}

val div = collection.size.toFloat()
val div = collection.size.toDouble()

for (i in vec.indices) {
vec[i] /= div
}

return FloatVectorDescriptor(
UUID.randomUUID(), null, Value.FloatVector(vec)
return DoubleVectorDescriptor(
UUID.randomUUID(), null, Value.DoubleVector(vec)
)
}
};
Expand Down

0 comments on commit a2ca74a

Please sign in to comment.