OJAlgo matrix multiplcation - only the upper triangle

21 Views Asked by At

I'm computing the cosine similarity for a number of embeddings using ojAlgo

Primitive32Store embeddingsMatrix = VECTOR_FACTORY.make(
                 embeddingsMatrix.size(),
                 EMBEDDING_LENGTH // 756
         );
//add the embeddings to embeddingsMatrix
double[][] similarityMatrix = embeddingsMatrix.multiply(embeddingsMatrix.transpose()).toRawCopy2D();

the resulting matrix is symmetric along the diagonal and I only ever use the results from the upper right triangle of the matrix (since the lower left is identical). I'm wondering if there is anyway to speed up the computation by short circuiting and only computing the upper right triangle?

0

There are 0 best solutions below