### Question:
VectorMath { public static double[] transposeTimesSelf(Collection<float[]> M) { if (M == null || M.isEmpty()) { return null; } int features = M.iterator().next().length; double[] result = new double[features * (features + 1) / 2]; double[] vectorD = new double[features]; for (float[] vector : M) { for (int i = 0; i < vector.length; i++) { vectorD[i] = vector[i]; } blas.dspr("L", features, 1.0, vectorD, 1, result); } return result; } private  VectorMath(); static double dot(float[] x, float[] y); static double norm(float[] x); static double norm(double[] x); static double cosineSimilarity(float[] x, float[] y, double normY); static double[] transposeTimesSelf(Collection<float[]> M); static double[] parseVector(String[] values); static float[] randomVectorF(int features, RandomGenerator random);  }### Answer:
@Test public void testTransposeTimesSelf() { Map<Integer,float[]> a = new HashMap<>(); a.put(-1, new float[] {1.3f, -2.0f, 3.0f}); a.put(1, new float[] {2.0f, 0.0f, 5.0f}); a.put(3, new float[] {0.0f, -1.5f, 5.5f}); double[] ata = VectorMath.transposeTimesSelf(a.values()); double[] expected = {5.69, -2.6, 13.9, 6.25, -14.25, 64.25}; assertArrayEquals(expected, ata, FLOAT_EPSILON); }
@Test public void testNullTranspose() { assertNull(VectorMath.transposeTimesSelf(null)); assertNull(VectorMath.transposeTimesSelf(Collections.emptyList())); }