yLock.lock();
try {
float[] toFeatures = Y.get(toItemID);
if (toFeatures == null) {
throw new NoSuchItemException(toItemID);
}
double toFeaturesNorm = SimpleVectorMath.norm(toFeatures);
boolean anyFound = false;
for (int i = 0; i < similarities.length; i++) {
float[] features = Y.get(itemIDs[i]);
if (features == null) {
similarities[i] = Float.NaN;
} else {
anyFound = true;
double featuresNorm = SimpleVectorMath.norm(features);
similarities[i] = (float) (SimpleVectorMath.dot(features, toFeatures) / (featuresNorm * toFeaturesNorm));
}
}
if (!anyFound) {
throw new NoSuchItemException(Arrays.toString(itemIDs));
}
} finally {
yLock.unlock();
}