### Question:
MatrixUtils { public static RealMatrix transposeTimesSelf(LongObjectMap<float[]> M) { if (M == null || M.isEmpty()) { return null; } RealMatrix result = null; for (LongObjectMap.MapEntry<float[]> entry : M.entrySet()) { float[] vector = entry.getValue(); int dimension = vector.length; if (result == null) { result = new Array2DRowRealMatrix(dimension, dimension); } for (int row = 0; row < dimension; row++) { float rowValue = vector[row]; for (int col = 0; col < dimension; col++) { result.addToEntry(row, col, rowValue * vector[col]); } } } Preconditions.checkNotNull(result); return result; } private  MatrixUtils(); static void addTo(long row,
                           long column,
                           float value,
                           LongObjectMap<LongFloatMap> RbyRow,
                           LongObjectMap<LongFloatMap> RbyColumn); static void remove(long row,
                            long column,
                            LongObjectMap<LongFloatMap> RbyRow,
                            LongObjectMap<LongFloatMap> RbyColumn); static boolean isNonSingular(RealMatrix M); static Solver getSolver(RealMatrix M); static double[][] accessMatrixDataDirectly(RealMatrix matrix); static RealMatrix transposeTimesSelf(LongObjectMap<float[]> M);  }### Answer:
@Test public void testTransposeTimesSelf() { LongObjectMap<float[]> M = new LongObjectMap<float[]>(); M.put(1L, new float[] {4.0f, -1.0f, -5.0f}); M.put(2L, new float[] {2.0f, 0.0f, 3.0f}); RealMatrix MTM = MatrixUtils.transposeTimesSelf(M); assertArrayEquals(new double[]{20.0, -4.0, -14.0}, MTM.getRow(0)); assertArrayEquals(new double[]{-4.0, 1.0, 5.0}, MTM.getRow(1)); assertArrayEquals(new double[]{-14.0, 5.0, 34.0}, MTM.getRow(2)); }